mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
Add worker listeners for Octane and Symfony, update FallbackSession
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Laravel\EventListener;
|
||||
|
||||
use Flasher\Laravel\Storage\FallbackSession;
|
||||
use Flasher\Prime\EventDispatcher\EventListener\NotificationLoggerListener;
|
||||
use Laravel\Octane\Events\RequestReceived;
|
||||
|
||||
@@ -11,8 +12,13 @@ final readonly class OctaneListener
|
||||
{
|
||||
public function __invoke(RequestReceived $event): void
|
||||
{
|
||||
// Reset the notification logger to prevent state leakage between requests
|
||||
/** @var NotificationLoggerListener $listener */
|
||||
$listener = $event->sandbox->make('flasher.notification_logger_listener');
|
||||
$listener->reset();
|
||||
|
||||
// Reset the fallback session static storage to prevent notification leakage
|
||||
// when session is not started (e.g., during API requests)
|
||||
FallbackSession::reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Symfony\EventListener;
|
||||
|
||||
use Flasher\Symfony\Storage\FallbackSession;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
/**
|
||||
* Resets static state between requests in long-running processes
|
||||
* like FrankenPHP, Swoole, or RoadRunner.
|
||||
*
|
||||
* Tagged with kernel.reset in services.php to be automatically called
|
||||
* by Symfony's kernel between requests.
|
||||
*/
|
||||
final class WorkerListener implements ResetInterface
|
||||
{
|
||||
public function reset(): void
|
||||
{
|
||||
FallbackSession::reset();
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ use Flasher\Symfony\Command\InstallCommand;
|
||||
use Flasher\Symfony\Component\FlasherComponent;
|
||||
use Flasher\Symfony\EventListener\FlasherListener;
|
||||
use Flasher\Symfony\EventListener\SessionListener;
|
||||
use Flasher\Symfony\EventListener\WorkerListener;
|
||||
use Flasher\Symfony\Factory\NotificationFactoryLocator;
|
||||
use Flasher\Symfony\Profiler\FlasherDataCollector;
|
||||
use Flasher\Symfony\Storage\SessionBag;
|
||||
@@ -78,6 +79,9 @@ return static function (ContainerConfigurator $container): void {
|
||||
->tag('flasher.event_listener')
|
||||
->tag('kernel.reset', ['method' => 'reset'])
|
||||
|
||||
->set('flasher.worker_listener', WorkerListener::class)
|
||||
->tag('kernel.reset', ['method' => 'reset'])
|
||||
|
||||
->set('flasher.translation_listener', TranslationListener::class)
|
||||
->args([service('flasher.translator')->nullOnInvalid()])
|
||||
->tag('flasher.event_listener')
|
||||
|
||||
@@ -18,4 +18,13 @@ final class FallbackSession implements FallbackSessionInterface
|
||||
{
|
||||
self::$storage[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the static storage to prevent state leakage between requests
|
||||
* in long-running processes (e.g., FrankenPHP, Swoole).
|
||||
*/
|
||||
public static function reset(): void
|
||||
{
|
||||
self::$storage = [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user