deslynx / alert-bundle
Send alert email service and specialized Monolog handler
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
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
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
composer require deslynx/alert-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require deslynx/alert-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php return [ // ... DesLynx\AlertBundle\DesLynxAlertBundle::class => ['all' => true], ];
Configuration
# /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
Important note
This bundle rely on the Symfony Mailer component for sending email so be sure to have it configured.
Usage (service)
This bundle provide a single service for sending an alert email which you can autowire by using the AlertHelper
type-hint:
// 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) ); } }
Usage (Monolog Handler)
This bundle provide a Monolog Handler using the AlertHelper
service. It allows to add a monolog handler config to send an alert email with the full log stack on every critical error happening in the project.
To enable this functionality, require the MonologBundle if not already done then just add this to your monolog config:
# 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