-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fbcbe1
commit b8a0094
Showing
16 changed files
with
207 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 19 additions & 21 deletions
40
src/Projection/Projector/MetadataProjectorAccessorRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Projection\Projector; | ||
|
||
use Patchlevel\EventSourcing\Metadata\Projector\AttributeProjectorMetadataFactory; | ||
use Patchlevel\EventSourcing\Metadata\Projector\ProjectorMetadataFactory; | ||
|
||
use function array_values; | ||
|
||
final class MetadataProjectorAccessorRepository implements ProjectorAccessorRepository | ||
{ | ||
private bool $init = false; | ||
|
||
/** | ||
* @var array<string, ProjectorAccessor> | ||
*/ | ||
/** @var array<string, ProjectorAccessor> */ | ||
private array $projectorsMap = []; | ||
|
||
/** @param iterable<object> $projectors */ | ||
public function __construct( | ||
private readonly iterable $projectors, | ||
private readonly ProjectorMetadataFactory $metadataFactory = new AttributeProjectorMetadataFactory() | ||
private readonly ProjectorMetadataFactory $metadataFactory = new AttributeProjectorMetadataFactory(), | ||
) { | ||
} | ||
|
||
/** | ||
* @return iterable<ProjectorAccessor> | ||
*/ | ||
/** @return iterable<ProjectorAccessor> */ | ||
public function all(): iterable | ||
{ | ||
if ($this->init === false) { | ||
$this->init(); | ||
} | ||
|
||
return array_values($this->projectorsMap); | ||
return array_values($this->projectorAccessorMap()); | ||
} | ||
|
||
public function get(string $id): ProjectorAccessor|null | ||
{ | ||
if ($this->init === false) { | ||
$this->init(); | ||
} | ||
$map = $this->projectorAccessorMap(); | ||
|
||
return $this->projectorsMap[$id] ?? null; | ||
return $map[$id] ?? null; | ||
} | ||
|
||
private function init(): void | ||
/** @return array<string, ProjectorAccessor> */ | ||
private function projectorAccessorMap(): array | ||
{ | ||
$this->init = true; | ||
if ($this->projectorsMap !== []) { | ||
return $this->projectorsMap; | ||
} | ||
|
||
foreach ($this->projectors as $projector) { | ||
$metadata = $this->metadataFactory->metadata($projector::class); | ||
$this->projectorsMap[$metadata->id] = new MetadataProjectorAccessor($projector, $metadata); | ||
} | ||
|
||
return $this->projectorsMap; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Projection\Projector; | ||
|
||
interface ProjectorAccessorRepository | ||
{ | ||
/** | ||
* @return iterable<ProjectorAccessor> | ||
*/ | ||
/** @return iterable<ProjectorAccessor> */ | ||
public function all(): iterable; | ||
|
||
public function get(string $id): ProjectorAccessor|null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Repository\MessageDecorator; | ||
|
||
/** @experimental */ | ||
final class Trace | ||
{ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly string $category, | ||
) | ||
{ | ||
) { | ||
} | ||
} | ||
} |
Oops, something went wrong.