PHP code example of swiftyper / emperror-php

1. Go to this page and download the library: Download swiftyper/emperror-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/ */

    

swiftyper / emperror-php example snippets


\Swiftyper\Emperror::setup([
    'apiKey' => 'your api key'
]);

\Swiftyper\Emperror::get()
    ->setUser([
        'name' => 'user name',
        'photo' => 'user photo',
    ])
    ->setContext([
        'orderId' => 1234,
    ]);

try {
    throw new Exception("Payment processing error", 1);
} catch (Exception $e) {
    \Swiftyper\Emperror::get()->sendException($e);
}

\Swiftyper\Emperror::get()->sendMessage('Payment webhook received twice', [
    'webhookId' => $webhookId,
]);

\Swiftyper\Catcher::get()->sendEvent([
    'title'   => 'Custom event title',
    'context' => [
        'orderId' => 1234,
    ],
]);

\Swiftyper\Emperror::setup([
    // ...
    'beforeSend' => function (\Swiftyper\EventPayload $eventPayload) {
        $user = $eventPayload->getUser();
        
        if (!empty($user['email'])){
            unset($user['email']);
        
            $eventPayload->setUser($user);
        }

        return $eventPayload;
    }
]);
shell
$ composer