Installation
composer require ano/notification-bundle
Ensure ano/system-bundle (v1.0.x-dev) is also installed as a dependency.
Bundle Registration
Add to config/bundles.php:
return [
// ...
Ano\NotificationBundle\AnoNotificationBundle::class => ['all' => true],
];
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'
);
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'
Triggering Notifications
NotificationService for business logic:
$service->sendAnonymizationNotification(
userId: $userId,
reason: $reason,
metadata: ['custom_field' => 'value'] // Optional
);
AnoNotificationEvents::ANONYMIZATION_REQUESTED:
$dispatcher->addListener(
AnoNotificationEvents::ANONYMIZATION_REQUESTED,
[$this, 'handleAnonymizationRequest']
);
Channel-Specific Logic
Ano\NotificationBundle\Channel\EmailChannel for custom templates/transports.Ano\NotificationBundle\Channel\WebhookChannelInterface:
class SlackChannel implements WebhookChannelInterface {
public function send(array $notificationData): bool {
// Custom Slack logic
}
}
Templates
templates/ano_notification/ (e.g., emails/anonymization_notification.html.twig).{{ notification.user.email }}
{{ notification.reason }}
{{ notification.callbackUrl|url }}
Batch Processing
Use BatchNotificationService for bulk anonymizations:
$batchService->processBatch(
userIds: [1, 2, 3],
reason: 'System cleanup'
);
# config/packages/messenger.yaml
framework:
messenger:
transports:
async_notifications: '%env(MESSENGER_TRANSPORT_DSN)%'
routing:
'Ano\NotificationBundle\Message\AnonymizationNotificationMessage': async_notifications
preUpdate/preRemove to auto-trigger notifications:
$entityManager->getEventManager()->addEventListener(
[User::class],
new AnoNotificationListener($notificationService)
);
Circular Dependencies
ano/system-bundle must be installed before ano/notification-bundle. Composer may fail silently if not.Template Overrides
php bin/console cache:clear
Channel Misconfiguration
channels.email.enabled: false, notifications will silently drop. Validate config with:
php bin/console debug:config ano_notification
User Data Leaks
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
);
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
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; }
}
Dynamic Recipients
Implement Ano\NotificationBundle\Recipient\RecipientResolverInterface:
class TeamRecipientResolver implements RecipientResolverInterface {
public function resolve($userId, $notification): array {
return $this->teamService->getTeamMembers($userId);
}
}
Rate Limiting
Use Symfony’s RateLimiter to throttle notifications:
ano_notification:
rate_limiter:
enabled: true
limit: 5/minute
key: 'user_{userId}'
translations/ano_notification.{locale}.yml:
anonymization:
subject: 'Your data will be anonymized'
body: 'Click here to review: {{ callbackUrl }}'
WebhookChannel:
ano_notification:
channels:
webhook:
retry_attempts: 3
retry_delay: 1000 # ms
monolog to log all notifications:
$logger->info('Anonymization triggered', [
'user_id' => $userId,
'reason' => $reason,
'metadata' => $metadata
]);
How can I help you explore Laravel packages today?