post-hawk / hawk-api-bundle
Bundle for symfony based on post hawk api
Installs: 97
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ~5.5|~7.0
- friendsofsymfony/jsrouting-bundle: ~1.6
- post-hawk/hawk-api: ~1.0
This package is not auto-updated.
Last update: 2025-01-04 20:55:57 UTC
README
bundle for symfony based on post hawk api
###Установка:
composer require post-hawk/hawk-api-bundle dev-master
Для windows:
cd path/to/project mklink /J web\bundles\hawkapi vendor\post-hawk\hawk-api\Resources\public\
Для unix:
cd path/to/project ln -s web\bundles\hawkapi vendor\post-hawk\hawk-api\Resources\public\
###Кофигурация:
//app/AppKernel.php $bundles = array( ... new Hawk\ApiBundle\HawkApiBundle(), );
#app/config/config.yml hawk_api: client: host: client_addres #ip или домен port: 7777 #порт, который слушает клиент key: 'ваш апи ключ'
#app/config/routing.yml hawk: resource: '@HawkApiBundle/Controller/' prefix: /hawk
<script src="{{ asset('/bundles/hawkapi/js/hawk_api.js') }}"></script>
###Использование
$api = $this->get('hawk_api.api')->getApi(); $api ->registerUser($id) ->getToken($id, $this->getApi()->getSalt()) ->execute() ->getResult('getToken') ;
или так:
$msg = new Message(); $msg ->setFrom('mail_demon') ->setTo($this->getUser()) ->setText(['msg' => 'test']) ->setEvent('new_push') ; $gMessage = new GroupMessage(); $gMessage ->setFrom('mail_demon') ->setGroups(['groups']) ->setText(['msg' => 'test']) ->setEvent('event') ; $this ->container ->get('event_dispatcher') ->dispatch(Message::NEW_MESSAGE, $msg) ->getResult() //HawkApi ->getResult('sendMessage') ; $this ->container ->get('event_dispatcher') ->dispatch(GroupMessage::NEW_MESSAGE, $gMessage) ->getResult() //HawkApi ->getResult('sendGroupMessage') ;
$.post(Routing.generate('hawk_token'), {}, function (data) { if(data.errors === false) { HAWK_API.init({ user_id: data.result.id, token: data.result.token, url: data.result.ws, debug: true }); HAWK_API.unbind_handler('new_push'); HAWK_API.bind_handler('new_push', function(e, msg){ if(msg.from === 'hawk_client') { return; } //делаем что-нибудь }); } else { if(data.errors !== 'no_user') { console.error(data.errors); } } });
Про методы, доступные для использования вы можете прочесть в документации