deslynx / alert-bundle
发送警报电子邮件和专业的Monolog处理器
v1.1.1
2024-07-18 08:51 UTC
Requires
- php: ^7.4 || ^8.0
- monolog/monolog: ^2.0 || ^3.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/mailer: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8.6
- phpstan/phpstan-symfony: ^1.1
- roave/security-advisories: dev-latest
README
安装
确保Composer已全局安装,具体请参阅Composer文档中的安装章节。
使用Symfony Flex的应用程序
打开命令行,进入您的项目目录,并执行以下命令
composer require deslynx/alert-bundle
未使用Symfony Flex的应用程序
步骤 1:下载Bundle
打开命令行,进入您的项目目录,并执行以下命令以下载此Bundle的最新稳定版本
composer require deslynx/alert-bundle
步骤 2:启用Bundle
然后,通过将其添加到项目 config/bundles.php
文件中注册的Bundle列表中来启用此Bundle
// config/bundles.php return [ // ... DesLynx\AlertBundle\DesLynxAlertBundle::class => ['all' => true], ];
配置
# /config/packages/deslynx_alert.yaml deslynx_alert: # The sender of the email, like "Name <email@address.com>" or a simple email. from: ~ # Required # A list of always added recipients for the email, like "Name <email@address.com>" or a simple email. to: [] # Required # Your project name. Included in the email subject projectName: 'My project' # If you want to use a custom email transport set this to the name of the transport. transport: null # If you need another configuration for specific environments you can overwrite some configs #when@dev: # deslynx_alert: # from: ~ # to: [] # projectName: 'My project' # transport: null
重要提示
此Bundle依赖于Symfony Mailer组件来发送电子邮件,因此请确保已配置它。
使用(服务)
此Bundle提供用于发送警报电子邮件的单个服务,您可以通过使用AlertHelper
类型提示来自动注入。
// src/Controller/SomeController.php use DesLynx\AlertBundle\Service\AlertHelper; //... class SomeController { public function index(AlertHelper $alertHelper) { $alertHelper->sendAlert( 'A significant subject.', 'A significant message. Either text or HTML.', false, // Optional. Set to true if the message is HTML ['email1@address.com', 'email2@address.com' /*, ...*/] // Optional. A list of recipients to add in cc in addition to the globally defined recipients (see configuration) ); } }
使用(Monolog处理器)
此Bundle提供使用AlertHelper
服务的Monolog处理器。它允许在项目中发生每个关键错误时发送带有完整日志堆栈的警报电子邮件。
要启用此功能,如果尚未安装,则要求安装MonologBundle,然后只需将其添加到您的monolog配置中即可。
# config/packages/monolog.yaml monolog: handlers: # ... deslynx_critical: type: fingers_crossed action_level: critical handler: deslynx_deduplicated deslynx_deduplicated: type: deduplication handler: deslynx_alert_mailer deslynx_alert_mailer: type: service id: DesLynx\AlertBundle\Monolog\Handler\AlertMailerHandler level: debug