diff --git a/baseline.xml b/baseline.xml index 0dd1d9878..9e011574d 100644 --- a/baseline.xml +++ b/baseline.xml @@ -1,5 +1,5 @@ - + new static() @@ -15,6 +15,11 @@ class DoctrineHelper + + + getName()]]> + + $headers diff --git a/docs/pages/getting_started.md b/docs/pages/getting_started.md index 63aa6b980..2567d0daa 100644 --- a/docs/pages/getting_started.md +++ b/docs/pages/getting_started.md @@ -325,10 +325,6 @@ $eventBus = SyncProjectionistEventBusWrapper::createWithDefaultLockStrategy( $projectionist ); -$eventBus = DefaultEventBus::create([ - new SendCheckInEmailProcessor($mailer), -]); - $repositoryManager = new DefaultRepositoryManager( $aggregateRegistry, $store, diff --git a/src/EventBus/DefaultEventBus.php b/src/EventBus/DefaultEventBus.php index 1e0aa8d37..4ece0ab2a 100644 --- a/src/EventBus/DefaultEventBus.php +++ b/src/EventBus/DefaultEventBus.php @@ -40,32 +40,34 @@ public function dispatch(Message ...$messages): void return; } - $this->processing = true; + try { + $this->processing = true; - $this->logger?->debug('EventBus: Start processing queue.'); + $this->logger?->debug('EventBus: Start processing queue.'); - while ($message = array_shift($this->queue)) { - $this->logger?->debug(sprintf( - 'EventBus: Dispatch message "%s" to listeners.', - $message->event()::class, - )); - - $listeners = $this->listenerProvider->listenersForEvent($message->event()); - - foreach ($listeners as $listener) { - $this->logger?->info(sprintf( - 'EventBus: Dispatch message with event "%s" to listener "%s".', + while ($message = array_shift($this->queue)) { + $this->logger?->debug(sprintf( + 'EventBus: Dispatch message "%s" to listeners.', $message->event()::class, - $listener->name(), )); - ($listener->callable())($message); - } - } + $listeners = $this->listenerProvider->listenersForEvent($message->event()); - $this->processing = false; + foreach ($listeners as $listener) { + $this->logger?->info(sprintf( + 'EventBus: Dispatch message with event "%s" to listener "%s".', + $message->event()::class, + $listener->name(), + )); - $this->logger?->debug('EventBus: Finished processing queue.'); + ($listener->callable())($message); + } + } + } finally { + $this->processing = false; + + $this->logger?->debug('EventBus: Finished processing queue.'); + } } /** @param iterable $listeners */ diff --git a/src/EventBus/ListenerDescriptor.php b/src/EventBus/ListenerDescriptor.php index 6d0214966..f1b3aab3c 100644 --- a/src/EventBus/ListenerDescriptor.php +++ b/src/EventBus/ListenerDescriptor.php @@ -7,6 +7,8 @@ use Closure; use ReflectionFunction; +use function method_exists; + final class ListenerDescriptor { private readonly Closure $callable; @@ -20,15 +22,23 @@ public function __construct(callable $callable) $r = new ReflectionFunction($callable); - if ($r->isAnonymous()) { + if (method_exists($r, 'isAnonymous') && $r->isAnonymous()) { $this->name = 'Closure'; - } elseif (!$callable = $r->getClosureThis()) { + + return; + } + + $callable = $r->getClosureThis(); + + if (!$callable) { $class = $r->getClosureCalledClass(); $this->name = ($class ? $class->name . '::' : '') . $r->name; - } else { - $this->name = $callable::class . '::' . $r->name; + + return; } + + $this->name = $callable::class . '::' . $r->name; } public function name(): string diff --git a/src/Projection/Projectionist/DefaultProjectionist.php b/src/Projection/Projectionist/DefaultProjectionist.php index 754ef5bc5..4a3d8cf50 100644 --- a/src/Projection/Projectionist/DefaultProjectionist.php +++ b/src/Projection/Projectionist/DefaultProjectionist.php @@ -15,7 +15,7 @@ use Patchlevel\EventSourcing\Projection\Projector\MetadataProjectorResolver; use Patchlevel\EventSourcing\Projection\Projector\ProjectorRepository; use Patchlevel\EventSourcing\Projection\Projector\ProjectorResolver; -use Patchlevel\EventSourcing\Store\CriteriaBuilder; +use Patchlevel\EventSourcing\Store\Criteria; use Patchlevel\EventSourcing\Store\Store; use Psr\Log\LoggerInterface; use Throwable; @@ -128,7 +128,7 @@ public function boot( $stream = null; try { - $criteria = (new CriteriaBuilder())->fromIndex($currentPosition)->build(); + $criteria = new Criteria(fromIndex: $currentPosition); $stream = $this->streamableMessageStore->load($criteria); $messageCounter = 0; @@ -210,7 +210,7 @@ public function run( $stream = null; try { - $criteria = (new CriteriaBuilder())->fromIndex($currentPosition)->build(); + $criteria = new Criteria(fromIndex: $currentPosition); $stream = $this->streamableMessageStore->load($criteria); $messageCounter = 0; diff --git a/tests/Unit/EventBus/ListenerDescriptorTest.php b/tests/Unit/EventBus/ListenerDescriptorTest.php index 361d4665c..3b4f45070 100644 --- a/tests/Unit/EventBus/ListenerDescriptorTest.php +++ b/tests/Unit/EventBus/ListenerDescriptorTest.php @@ -6,6 +6,7 @@ use Patchlevel\EventSourcing\EventBus\ListenerDescriptor; use Patchlevel\EventSourcing\Tests\Unit\Fixture\DummyListener; +use PHPUnit\Framework\Attributes\RequiresPhp; use PHPUnit\Framework\TestCase; final class ListenerDescriptorTest extends TestCase @@ -20,6 +21,7 @@ public function testClass(): void self::assertEquals('Patchlevel\EventSourcing\Tests\Unit\Fixture\DummyListener::__invoke', $descriptor->name()); } + #[RequiresPhp('>= 8.2')] public function testAnonymousFunction(): void { $listener = static function (): void {