1. Go to this page and download the library: Download oliverthiele/ot-alerts 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/ */
oliverthiele / ot-alerts example snippets
use OliverThiele\OtAlerts\Alert\Alert;
use OliverThiele\OtAlerts\Alert\AlertSeverity;
use OliverThiele\OtAlerts\Service\AlertManager;
class MyService
{
public function __construct(
private readonly ?AlertManager $alertManager = null,
) {}
public function doSomething(): void
{
// ... your logic ...
// notify — only fires when ot_alerts is installed
$this->alertManager?->notify(new Alert(
source: 'my_extension',
eventKey: 'api.connection.failed',
message: 'Could not connect to external API',
severity: AlertSeverity::ERROR,
));
}
}
$this->alertManager?->notify(new Alert(
source: 'my_extension',
eventKey: 'api.connection.failed',
message: 'Could not connect to external API',
severity: AlertSeverity::ERROR,
));
$this->alertManager?->notify(new Alert(
source: 'my_extension',
eventKey: 'api.connection.failed',
message: 'Could not connect to external API',
severity: AlertSeverity::ERROR,
context: ['url' => 'https://example.com/affected-page/'],
));
$this->alertManager?->notify(new Alert(
source: 'my_extension',
eventKey: 'quota.warning',
message: 'API quota at 90 %',
severity: AlertSeverity::WARNING,
reminderInterval: 300, // remind every 5 minutes instead of the global default
));
$this->alertManager?->notify(new Alert(
source: 'my_extension',
eventKey: 'order.received',
message: 'New order #4711 — Jane Doe, 249.00 EUR',
severity: AlertSeverity::NOTICE,
throttle: false,
));