PHP code example of ale10257 / error-message-yii2

1. Go to this page and download the library: Download ale10257/error-message-yii2 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/ */

    

ale10257 / error-message-yii2 example snippets


'components' => [
    'queue' => [
        'class' => \yii\queue\file\Queue::class,
        'path' => '@runtime/queue',
    ],
    'sendErrorMessage' => [
        'class' => \ale10257\sendError\ErrorMsgComponent::class,
        'queueComponentId' => 'queue',
        'enableBotError' => (int)($_ENV['ENABLE_BOT_ERROR']) === 1,
        'enableEmailError' => (int)($_ENV['ENABLE_EMAIL_ERROR']) === 1,
        'emailRecipients' => [
            (string)$_ENV['ADMIN_EMAIL'],
            (string)$_ENV['PROCTOLEHA_EMAIL'],
        ],
        'client' => [
            'class' => \YourNamespace\YourMessenger::class,  // реализация IErrorBot
            'apiKey'   => $_ENV['YOUR_MESSENGER_API_KEY'],
            'chatId'   => $_ENV['YOUR_MESSENGER_CHAT_ID'],
        ],
        'useQueue' => true,
        'errorCodeMap' => [
            \yii\web\NotFoundHttpException::class => 404,
            \yii\web\ForbiddenHttpException::class => 403,
        ],
    ],
],

// config/web.php
'components' => [
    'errorHandler' => [
        'class' => \ale10257\sendError\ErrorHandler::class,
    ],
    // ...
],

\Yii::$app->sendErrorMessage->send('Критическая ошибка: сервис недоступен');

use ale10257\sendError\LogError;

try {
    // ...
} catch (\Throwable $e) {
    LogError::error('Ошибка при обработке заказа', $e, false);
}

namespace YourNamespace;

use ale10257\sendError\IErrorBot;

class YourMessenger implements IErrorBot
{
    private string $apiKey;
    private string $chatId;

    public function __construct(string $apiKey, string $chatId)
    {
        $this->apiKey = $apiKey;
        $this->chatId = $chatId;
    }

    public function sendErrorMsg(string $message): void
    {
        // POST в API your-messenger (или другой сервис)
    }
}
bash
php yii queue/listen --verbose=1