Installation:
composer require andreas-glaser/notify-bundle dev-master
Ensure your project uses Symfony 2.8.x LTS and PHP 7.x.
Enable the Bundle:
Add to app/AppKernel.php:
new AndreasGlaser\NotifyBundle\AndreasGlaserNotifyBundle(),
Configure Channels:
Define a default email channel in app/config/config.yml:
andreas_glaser_notify:
enabled: true
channels:
email:
from_name: "Your App"
from_email: "noreply@example.com"
emails:
welcome:
subject: "Welcome, :name!"
template_content: "AppBundle:Email:welcome.html.twig"
First Use Case: Send a templated email in a controller:
$subjectData = ['name' => 'John Doe'];
$bodyData = []; // Pass dynamic data for Twig templates
$email = $this->get('andreas_glaser_notify.channel_email.loader')
->load('welcome', $bodyData, $subjectData);
$this->get('andreas_glaser_notify.channel.email.dispatcher')
->dispatch($email);
email, sms) in config.yml under andreas_glaser_notify.channels.
channels:
email:
emails: { ... }
sms:
provider: "twilio"
credentials: { ... }
:name) in templates and pass data via $subjectData/$bodyData.load('welcome', $bodyData, $subjectData)).dispatch($email)).andreas_glaser_notify.channel.email.dispatcher) to add logging, retries, or analytics.Resources/views/ (e.g., AppBundle:Email:welcome.html.twig).$this->get('andreas_glaser_notify.channel.email.dispatcher')
->expects($this->once())
->method('dispatch');
%kernel.environment% in config.yml to switch channels (e.g., sms in dev, email in prod).template_content YAML path exactly (case-sensitive).channel_email.loader) may break if extended. Prefer dependency injection.php app/console config:dump-reference andreas_glaser_notify to verify settings.:name) are missing from $subjectData.try {
$dispatcher->dispatch($email);
} catch (\Exception $e) {
$this->get('logger')->error('Notification failed', ['exception' => $e]);
}
AndreasGlaser\NotifyBundle\Channel\Email\Dispatcher to add features like:
services:
app.email_dispatcher:
class: AppBundle\Service\CustomEmailDispatcher
decorates: andreas_glaser_notify.channel.email.dispatcher
arguments: ['@app.email_dispatcher.inner']
AndreasGlaser\NotifyBundle\Channel\ChannelInterface for custom channels (e.g., Slack).notify.channel.dispatch events to intercept notifications.enabled: true/false is set; defaults may not work as expected.emails: under email:).from_email must be a valid, deliverable address for production use.How can I help you explore Laravel packages today?