Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Notify Bundle Laravel Package

andreas-glaser/notify-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require andreas-glaser/notify-bundle dev-master
    

    Ensure your project uses Symfony 2.8.x LTS and PHP 7.x.

  2. Enable the Bundle: Add to app/AppKernel.php:

    new AndreasGlaser\NotifyBundle\AndreasGlaserNotifyBundle(),
    
  3. 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"
    
  4. 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);
    

Implementation Patterns

Channel Configuration

  • Modular Channels: Define multiple channels (e.g., email, sms) in config.yml under andreas_glaser_notify.channels.
    channels:
        email:
            emails: { ... }
        sms:
            provider: "twilio"
            credentials: { ... }
    
  • Dynamic Data Binding: Use Twig placeholders (:name) in templates and pass data via $subjectData/$bodyData.

Dispatching Workflow

  1. Load: Use the channel loader to instantiate a notification (e.g., load('welcome', $bodyData, $subjectData)).
  2. Dispatch: Pass the loaded notification to the dispatcher (e.g., dispatch($email)).
  3. Extend: Override services (e.g., andreas_glaser_notify.channel.email.dispatcher) to add logging, retries, or analytics.

Integration Tips

  • Twig Templates: Store templates in Resources/views/ (e.g., AppBundle:Email:welcome.html.twig).
  • Testing: Mock the dispatcher service in PHPUnit:
    $this->get('andreas_glaser_notify.channel.email.dispatcher')
        ->expects($this->once())
        ->method('dispatch');
    
  • Environment-Specific Config: Use %kernel.environment% in config.yml to switch channels (e.g., sms in dev, email in prod).

Gotchas and Tips

Pitfalls

  1. Archived Status: The package is unmaintained (archived). Validate compatibility with Symfony 2.8.x before use.
  2. No SMS/Other Channels: The README mentions SMS but lacks implementation details. Assume email-only functionality.
  3. Template Paths: Twig templates must match the template_content YAML path exactly (case-sensitive).
  4. Service Naming: Hardcoded service IDs (e.g., channel_email.loader) may break if extended. Prefer dependency injection.

Debugging

  • Dump Config: Run php app/console config:dump-reference andreas_glaser_notify to verify settings.
  • Template Errors: Check Twig errors in logs if placeholders (e.g., :name) are missing from $subjectData.
  • Dispatcher Failures: Wrap dispatch calls in try-catch to log failures:
    try {
        $dispatcher->dispatch($email);
    } catch (\Exception $e) {
        $this->get('logger')->error('Notification failed', ['exception' => $e]);
    }
    

Extension Points

  1. Custom Dispatchers: Extend AndreasGlaser\NotifyBundle\Channel\Email\Dispatcher to add features like:
    • Rate limiting.
    • Queue integration (e.g., Symfony Messenger).
    services:
        app.email_dispatcher:
            class: AppBundle\Service\CustomEmailDispatcher
            decorates: andreas_glaser_notify.channel.email.dispatcher
            arguments: ['@app.email_dispatcher.inner']
    
  2. New Channels: Implement AndreasGlaser\NotifyBundle\Channel\ChannelInterface for custom channels (e.g., Slack).
  3. Event Listeners: Subscribe to notify.channel.dispatch events to intercept notifications.

Configuration Quirks

  • Boolean Values: Ensure enabled: true/false is set; defaults may not work as expected.
  • YAML Indentation: Use 2 spaces for nested config (e.g., emails: under email:).
  • From Email: The from_email must be a valid, deliverable address for production use.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware