PHP code example of codex-team / hawk.php
1. Go to this page and download the library: Download codex-team/hawk.php 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/ */
codex-team / hawk.php example snippets
\Hawk\Catcher::init([
'integrationToken' => 'your integration token'
]);
use Hawk\Event;
use Hawk\Options;
use Hawk\Transport\TransportInterface;
class CustomGuzzleTransport implements TransportInterface
{
private $url;
private $client;
public function __construct(string $url = Options::DEFAULT_URL)
{
$this->url = $url;
$this->client = new \GuzzleHttp\Client();
}
public function getUrl(): string
{
return $this->url;
}
public function send(Event $event)
{
$this->client->request('POST', $this->url, [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => json_encode($event, JSON_UNESCAPED_UNICODE),
]);
}
}
\Hawk\Catcher::init([
'integrationToken' => 'your integration token',
'transport' => new CustomGuzzleTransport(),
]);
\Hawk\Catcher::get()
->setUser([
'name' => 'user name',
'photo' => 'user photo',
])
->setContext([
...
]);
try {
throw new Exception("Error Processing Request", 1);
} catch (Exception $e) {
\Hawk\Catcher::get()->sendException($e);
}
\Hawk\Catcher::get()->sendMessage('your message', [
... // Context
]);
\Hawk\Catcher::init([
// ...
'beforeSend' => function (\Hawk\EventPayload $eventPayload) {
$user = $eventPayload->getUser();
if (!empty($user['email'])){
unset($user['email']);
$eventPayload->setUser($user);
}
return $eventPayload;
}
]);
bash
$ composer