Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
composer require deslynx/alert-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
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],
];
# /config/packages/deslynx_alert.yaml
deslynx_alert:
# The sender of the email, like "Name <[email protected]>" or a simple email.
from: ~ # Required
# A list of always added recipients for the email, like "Name <[email protected]>" 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
This bundle rely on the Symfony Mailer component for sending email so be sure to have it configured.
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
['[email protected]', '[email protected]' /*, ...*/] // Optional. A list of recipients to add in cc in addition to the globally defined recipients (see configuration)
);
}
}
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