fix: make OctaneListener invokable for Laravel event dispatcher

Laravel's event dispatcher expects listener classes to be invokable
(have __invoke method) when registered as a class name string.

The OctaneListener was using a handle() method which caused the
listener to never be invoked, resulting in notification state leaking
between Octane requests.

Renamed handle() to __invoke() to fix the issue.
This commit is contained in:
Younes ENNAJI
2026-03-01 19:59:25 +00:00
parent 83dc9e49dc
commit 9e7bb17faa
2 changed files with 36 additions and 1 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ use Laravel\Octane\Events\RequestReceived;
final readonly class OctaneListener
{
public function handle(RequestReceived $event): void
public function __invoke(RequestReceived $event): void
{
/** @var NotificationLoggerListener $listener */
$listener = $event->sandbox->make('flasher.notification_logger_listener');
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Flasher\Tests\Laravel\EventListener;
use Flasher\Laravel\EventListener\OctaneListener;
use PHPUnit\Framework\TestCase;
final class OctaneListenerTest extends TestCase
{
public function testListenerIsInvokable(): void
{
$listener = new OctaneListener();
// Verify the listener is invokable (has __invoke method)
// This is crucial for Laravel's event dispatcher to call it correctly
$this->assertTrue(is_callable($listener));
}
public function testListenerHasInvokeMethod(): void
{
// Verify the __invoke method exists and has the correct signature
$reflection = new \ReflectionClass(OctaneListener::class);
$this->assertTrue($reflection->hasMethod('__invoke'));
$method = $reflection->getMethod('__invoke');
$this->assertTrue($method->isPublic());
$parameters = $method->getParameters();
$this->assertCount(1, $parameters);
$this->assertSame('event', $parameters[0]->getName());
}
}