Skip to content

Commit

Permalink
Merge pull request #430 from 27pchrisl/abstract-event-handlers
Browse files Browse the repository at this point in the history
Ignore abstract event handlers
  • Loading branch information
sebastiandedeyne authored Oct 2, 2023
2 parents 21e8cea + de17178 commit 428e9a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Support/DiscoverEventHandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use ReflectionClass;
use Spatie\EventSourcing\EventHandlers\EventHandler;
use Spatie\EventSourcing\Projectionist;
use SplFileInfo;
Expand Down Expand Up @@ -64,6 +65,7 @@ public function addToProjectionist(Projectionist $projectionist)
->reject(fn (SplFileInfo $file) => in_array($file->getPathname(), $this->ignoredFiles))
->map(fn (SplFileInfo $file) => $this->fullQualifiedClassNameFromFile($file))
->filter(fn (string $eventHandlerClass) => is_subclass_of($eventHandlerClass, EventHandler::class))
->filter(fn (string $eventHandlerClass) => (new ReflectionClass($eventHandlerClass))->isInstantiable())
->pipe(function (Collection $eventHandlers) use ($projectionist) {
$projectionist->addEventHandlers($eventHandlers->toArray());
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers;

use Spatie\EventSourcing\EventHandlers\Projectors\Projector;

abstract class AbstractProjector extends Projector
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers;

use Spatie\EventSourcing\EventHandlers\Reactors\Reactor;

abstract class AbstractReactor extends Reactor
{
}

0 comments on commit 428e9a4

Please sign in to comment.