PHP code example of post-hawk / hawk-api-bundle

1. Go to this page and download the library: Download post-hawk/hawk-api-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

post-hawk / hawk-api-bundle example snippets


//app/AppKernel.php
$bundles = array(
	...
    new Hawk\ApiBundle\HawkApiBundle(),
);

$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')
;