PHP code example of g-giani / notifier

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

    

g-giani / notifier example snippets


use GGiani\Notifier\{Notifier, Message, Severity};
use GGiani\Notifier\Channel\{EmailChannel, SignalChannel};
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use GuzzleHttp\Client;

$email = new EmailChannel(
    mailer: new Mailer(Transport::fromDsn('smtp://user:[email protected]:587')),
    from: '[email protected]',
    to: ['[email protected]'],
    subjectPrefix: '[Monitor]',
);

$signal = new SignalChannel(
    http: new Client(['base_uri' => 'http://localhost:8080/']),
    sender: '+4915112345678',
    recipients: ['+4915187654321'],
);

$notifier = new Notifier($email, $signal);

$failures = $notifier->notify(new Message(
    title: 'Provider sync failed',
    body: 'Provider.com returned no records for 3 consecutive runs.',
    severity: Severity::Critical,
    context: ['provider_id' => 117, 'process_id' => '5dhxl36s'],
));

// $failures is a list<ChannelException> — empty when everything went through.