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

Notification Bundle Laravel Package

ano/notification-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require ano/notification-bundle
    

    Ensure ano/system-bundle (v1.0.x-dev) is also installed as a dependency.

  2. Bundle Registration Add to config/bundles.php:

    return [
        // ...
        Ano\NotificationBundle\AnoNotificationBundle::class => ['all' => true],
    ];
    
  3. First Use Case Trigger a basic anonymization notification via a service:

    use Ano\NotificationBundle\Service\NotificationService;
    
    $notificationService = $this->container->get('ano_notification.notification_service');
    $notificationService->sendAnonymizationNotification(
        userId: 123,
        reason: 'Data privacy request',
        callbackUrl: '/user/123/privacy'
    );
    
  4. Configuration Check config/packages/ano_notification.yaml for default settings (e.g., channels, templates). Override in config/packages/ano_notification.yaml:

    ano_notification:
        channels:
            email:
                enabled: true
                template: 'emails.anonymization_notification'
    

Implementation Patterns

Core Workflows

  1. Triggering Notifications

    • Service Layer: Use NotificationService for business logic:
      $service->sendAnonymizationNotification(
          userId: $userId,
          reason: $reason,
          metadata: ['custom_field' => 'value'] // Optional
      );
      
    • Events: Listen for AnoNotificationEvents::ANONYMIZATION_REQUESTED:
      $dispatcher->addListener(
          AnoNotificationEvents::ANONYMIZATION_REQUESTED,
          [$this, 'handleAnonymizationRequest']
      );
      
  2. Channel-Specific Logic

    • Email: Extend Ano\NotificationBundle\Channel\EmailChannel for custom templates/transports.
    • Webhooks: Implement Ano\NotificationBundle\Channel\WebhookChannelInterface:
      class SlackChannel implements WebhookChannelInterface {
          public function send(array $notificationData): bool {
              // Custom Slack logic
          }
      }
      
  3. Templates

    • Override Twig templates in templates/ano_notification/ (e.g., emails/anonymization_notification.html.twig).
    • Dynamic variables:
      {{ notification.user.email }}
      {{ notification.reason }}
      {{ notification.callbackUrl|url }}
      
  4. Batch Processing Use BatchNotificationService for bulk anonymizations:

    $batchService->processBatch(
        userIds: [1, 2, 3],
        reason: 'System cleanup'
    );
    

Integration Tips

  • Symfony Messenger: Bridge notifications to Messenger for async processing:
    # config/packages/messenger.yaml
    framework:
        messenger:
            transports:
                async_notifications: '%env(MESSENGER_TRANSPORT_DSN)%'
            routing:
                'Ano\NotificationBundle\Message\AnonymizationNotificationMessage': async_notifications
    
  • Doctrine Events: Hook into preUpdate/preRemove to auto-trigger notifications:
    $entityManager->getEventManager()->addEventListener(
        [User::class],
        new AnoNotificationListener($notificationService)
    );
    

Gotchas and Tips

Pitfalls

  1. Circular Dependencies

    • ano/system-bundle must be installed before ano/notification-bundle. Composer may fail silently if not.
  2. Template Overrides

    • Forgetting to clear cache after updating Twig templates:
      php bin/console cache:clear
      
  3. Channel Misconfiguration

    • If channels.email.enabled: false, notifications will silently drop. Validate config with:
      php bin/console debug:config ano_notification
      
  4. User Data Leaks

    • Critical: Ensure callbackUrl and metadata do not expose PII (Personally Identifiable Information) in logs. Sanitize:
      $service->sendAnonymizationNotification(
          userId: 123,
          reason: 'Privacy request',
          callbackUrl: '/user/123/privacy', // Avoid direct IDs in URLs
          metadata: ['ip_address' => '192.168.1.1'] // Log carefully
      );
      

Debugging

  • Enable Debug Mode Set ano_notification.debug: true in config to log raw notification payloads to var/log/ano_notification.log.

  • Test Channels Isolated Use the test channel for development:

    ano_notification:
        channels:
            test:
                enabled: true
                class: Ano\NotificationBundle\Channel\TestChannel
    

Extension Points

  1. Custom Notifications Extend Ano\NotificationBundle\Notification\AbstractNotification:

    class CustomNotification extends AbstractNotification {
        protected $customField;
    
        public function __construct($userId, $customField) {
            parent::__construct($userId);
            $this->customField = $customField;
        }
    
        public function getCustomField() { return $this->customField; }
    }
    
  2. Dynamic Recipients Implement Ano\NotificationBundle\Recipient\RecipientResolverInterface:

    class TeamRecipientResolver implements RecipientResolverInterface {
        public function resolve($userId, $notification): array {
            return $this->teamService->getTeamMembers($userId);
        }
    }
    
  3. Rate Limiting Use Symfony’s RateLimiter to throttle notifications:

    ano_notification:
        rate_limiter:
            enabled: true
            limit: 5/minute
            key: 'user_{userId}'
    

Pro Tips

  • Localization: Override translation files in translations/ano_notification.{locale}.yml:
    anonymization:
        subject: 'Your data will be anonymized'
        body: 'Click here to review: {{ callbackUrl }}'
    
  • Webhook Retries: Configure exponential backoff for WebhookChannel:
    ano_notification:
        channels:
            webhook:
                retry_attempts: 3
                retry_delay: 1000 # ms
    
  • Audit Logging: Integrate with monolog to log all notifications:
    $logger->info('Anonymization triggered', [
        'user_id' => $userId,
        'reason' => $reason,
        'metadata' => $metadata
    ]);
    
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.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields
splash/sonata-admin
splash/metadata