forked from fa/breadcrumb-the-shire
feat: add notifications module with bell UI, event listeners, and cleanup job
In-app notification system with topbar bell icon, dropdown panel, mark-as-read/dismiss actions, and scheduled cleanup of old read notifications. Includes event listeners for user.created and user.deleted events, authorization policy, and full test coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Notifications\Providers;
|
||||
|
||||
use MintyPHP\App\AppContainer;
|
||||
use MintyPHP\App\Module\Contracts\SessionProvider;
|
||||
use MintyPHP\Http\SessionStoreInterface;
|
||||
use MintyPHP\Module\Notifications\Service\NotificationService;
|
||||
|
||||
final class NotificationsSessionProvider implements SessionProvider
|
||||
{
|
||||
private const SESSION_KEY = 'module.notifications.unread_count';
|
||||
|
||||
public function populate(array $user, AppContainer $container): void
|
||||
{
|
||||
$userId = (int) ($user['id'] ?? 0);
|
||||
if ($userId <= 0) {
|
||||
unset($_SESSION[self::SESSION_KEY]);
|
||||
return;
|
||||
}
|
||||
|
||||
$sessionStore = $container->get(SessionStoreInterface::class);
|
||||
$service = $container->get(NotificationService::class);
|
||||
if (!$sessionStore instanceof SessionStoreInterface || !$service instanceof NotificationService) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sessionStore->set(self::SESSION_KEY, $service->unreadCount($userId));
|
||||
}
|
||||
|
||||
public function clear(): void
|
||||
{
|
||||
unset($_SESSION[self::SESSION_KEY]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user