Skip to content

Commit

Permalink
remove projector repository
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Feb 17, 2024
1 parent 56e915c commit 4f59f20
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 203 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ parameters:
count: 1
path: src/Projection/Projection/Store/DoctrineStore.php

-
message: "#^Method Patchlevel\\\\EventSourcing\\\\Projection\\\\Projector\\\\InMemoryProjectorRepository\\:\\:projectors\\(\\) should return array\\<int, object\\> but returns array\\<int\\|string, object\\>\\.$#"
count: 1
path: src/Projection/Projector/InMemoryProjectorRepository.php

-
message: "#^Parameter \\#2 \\$data of method Patchlevel\\\\Hydrator\\\\Hydrator\\:\\:hydrate\\(\\) expects array\\<string, mixed\\>, mixed given\\.$#"
count: 1
Expand Down
27 changes: 9 additions & 18 deletions src/Projection/Projectionist/DefaultProjectionist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Patchlevel\EventSourcing\Projection\Projection\ProjectionError;
use Patchlevel\EventSourcing\Projection\Projection\ProjectionStatus;
use Patchlevel\EventSourcing\Projection\Projection\Store\ProjectionStore;
use Patchlevel\EventSourcing\Projection\Projector\ProjectorRepository;
use Patchlevel\EventSourcing\Store\Criteria;
use Patchlevel\EventSourcing\Store\Store;
use Psr\Log\LoggerInterface;
Expand All @@ -30,12 +29,13 @@ final class DefaultProjectionist implements Projectionist
private const RETRY_LIMIT = 5;

/** @var array<string, object>|null */
private array|null $projectors = null;
private array|null $projectorIndex = null;

/** @param iterable<object> $projectors */
public function __construct(
private readonly Store $streamableMessageStore,
private readonly ProjectionStore $projectionStore,
private readonly ProjectorRepository $projectorRepository,
private readonly iterable $projectors,
private readonly ProjectorMetadataFactory $metadataFactory = new AttributeProjectorMetadataFactory(),
private readonly LoggerInterface|null $logger = null,
) {
Expand Down Expand Up @@ -442,9 +442,8 @@ public function reactivate(ProjectionCriteria $criteria = new ProjectionCriteria
public function projections(): ProjectionCollection
{
$projections = $this->projectionStore->all();
$projectors = $this->projectors();

foreach ($projectors as $projector) {
foreach ($this->projectors as $projector) {
$projectorId = $this->projectorId($projector);

if ($projections->has($projectorId)) {
Expand Down Expand Up @@ -529,25 +528,17 @@ private function handleMessage(int $index, Message $message, Projection $project

private function projector(string $projectorId): object|null
{
$projectors = $this->projectors();
if ($this->projectorIndex === null) {
$this->projectorIndex = [];

return $projectors[$projectorId] ?? null;
}

/** @return array<string, object> */
private function projectors(): array
{
if ($this->projectors === null) {
$this->projectors = [];

foreach ($this->projectorRepository->projectors() as $projector) {
foreach ($this->projectors as $projector) {
$projectorId = $this->projectorId($projector);

$this->projectors[$projectorId] = $projector;
$this->projectorIndex[$projectorId] = $projector;
}
}

return $this->projectors;
return $this->projectorIndex[$projectorId] ?? null;
}

private function handleOutdatedProjections(ProjectionCollection $projections): void
Expand Down
20 changes: 0 additions & 20 deletions src/Projection/Projector/InMemoryProjectorRepository.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Projection/Projector/ProjectorRepository.php

This file was deleted.

6 changes: 1 addition & 5 deletions tests/Benchmark/SyncProjectionistBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistEventBus;
use Patchlevel\EventSourcing\Projection\Projector\InMemoryProjectorRepository;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\ChainSchemaConfigurator;
Expand Down Expand Up @@ -62,14 +61,11 @@ public function setUp(): void
);

$profileProjection = new ProfileProjector($connection);
$projectionRepository = new InMemoryProjectorRepository(
[$profileProjection],
);

$projectionist = new DefaultProjectionist(
$this->store,
new InMemoryStore(),
$projectionRepository,
[$profileProjection],
);

$lockStorage = new LockDoctrineDbalStore($connection);
Expand Down
4 changes: 1 addition & 3 deletions tests/Integration/BankAccountSplitStream/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistEventBus;
use Patchlevel\EventSourcing\Projection\Projector\InMemoryProjectorRepository;
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
Expand Down Expand Up @@ -56,12 +55,11 @@ public function testSuccessful(): void
);

$bankAccountProjector = new BankAccountProjector($this->connection);
$projectionRepository = new InMemoryProjectorRepository([$bankAccountProjector]);

$projectionist = new DefaultProjectionist(
$store,
new InMemoryStore(),
$projectionRepository,
[$bankAccountProjector],
);

$eventBus = new ChainEventBus([
Expand Down
11 changes: 2 additions & 9 deletions tests/Integration/BasicImplementation/BasicIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistEventBus;
use Patchlevel\EventSourcing\Projection\Projector\InMemoryProjectorRepository;
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
Expand Down Expand Up @@ -53,14 +52,11 @@ public function testSuccessful(): void
);

$profileProjector = new ProfileProjector($this->connection);
$projectorRepository = new InMemoryProjectorRepository(
[$profileProjector],
);

$projectionist = new DefaultProjectionist(
$store,
new InMemoryStore(),
$projectorRepository,
[$profileProjector],
);

$eventBus = new ChainEventBus([
Expand Down Expand Up @@ -127,14 +123,11 @@ public function testSnapshot(): void
);

$profileProjection = new ProfileProjector($this->connection);
$projectorRepository = new InMemoryProjectorRepository(
[$profileProjection],
);

$projectionist = new DefaultProjectionist(
$store,
new InMemoryStore(),
$projectorRepository,
[$profileProjection],
);

$eventBus = new ChainEventBus([
Expand Down
6 changes: 1 addition & 5 deletions tests/Integration/Outbox/OutboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistEventBus;
use Patchlevel\EventSourcing\Projection\Projector\InMemoryProjectorRepository;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Schema\ChainSchemaConfigurator;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
Expand Down Expand Up @@ -66,14 +65,11 @@ public function testSuccessful(): void
$outboxEventBus = new OutboxEventBus($outboxStore);

$profileProjector = new ProfileProjector($this->connection);
$projectorRepository = new InMemoryProjectorRepository(
[$profileProjector],
);

$projectionist = new DefaultProjectionist(
$store,
new InMemoryStore(),
$projectorRepository,
[$profileProjector],
);

$eventBusConsumer = DefaultConsumer::create([new SendEmailProcessor()]);
Expand Down
9 changes: 2 additions & 7 deletions tests/Integration/Projectionist/ProjectionistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Patchlevel\EventSourcing\Projection\Projection\Store\DoctrineStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistEventBus;
use Patchlevel\EventSourcing\Projection\Projector\InMemoryProjectorRepository;
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
use Patchlevel\EventSourcing\Schema\ChainSchemaConfigurator;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
Expand Down Expand Up @@ -76,9 +75,7 @@ public function testAsync(): void
$projectionist = new DefaultProjectionist(
$store,
$projectionStore,
new InMemoryProjectorRepository(
[new ProfileProjector($this->connection)],
),
[new ProfileProjector($this->connection)],
);

$projectionist->boot();
Expand Down Expand Up @@ -110,9 +107,7 @@ public function testSync(): void
$projectionist = new DefaultProjectionist(
$store,
$projectionStore,
new InMemoryProjectorRepository(
[new ProfileProjector($this->connection)],
),
[new ProfileProjector($this->connection)],
);

$manager = new DefaultRepositoryManager(
Expand Down
Loading

0 comments on commit 4f59f20

Please sign in to comment.