-
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
5ce6710
commit 55e28a7
Showing
12 changed files
with
373 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/Metadata/AggregateRoot/Psr16AggregateRootMetadataFactory.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\AggregateRoot; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateRoot; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
||
final class Psr16AggregateRootMetadataFactory implements AggregateRootMetadataFactory | ||
{ | ||
public function __construct( | ||
private readonly AggregateRootMetadataFactory $aggregateRootMetadataFactory, | ||
private readonly CacheInterface $cache, | ||
) { | ||
} | ||
|
||
/** | ||
* @param class-string<T> $aggregate | ||
* | ||
* @return AggregateRootMetadata<T> | ||
* | ||
* @template T of AggregateRoot | ||
*/ | ||
public function metadata(string $aggregate): AggregateRootMetadata | ||
{ | ||
/** @var ?AggregateRootMetadata $metadata */ | ||
$metadata = $this->cache->get($aggregate); | ||
|
||
if ($metadata !== null) { | ||
return $metadata; | ||
} | ||
|
||
$metadata = $this->aggregateRootMetadataFactory->metadata($aggregate); | ||
|
||
$this->cache->set($aggregate, $metadata); | ||
|
||
return $metadata; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Metadata/AggregateRoot/Psr16AggregateRootRegistryFactory.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\AggregateRoot; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
final class Psr16AggregateRootRegistryFactory implements AggregateRootRegistryFactory | ||
{ | ||
public function __construct( | ||
private readonly AggregateRootRegistryFactory $aggregateRootRegistryFactory, | ||
private readonly CacheInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param list<string> $paths */ | ||
public function create(array $paths): AggregateRootRegistry | ||
{ | ||
/** @var ?AggregateRootRegistry $registry */ | ||
$registry = $this->cache->get('aggregate_roots'); | ||
|
||
if ($registry !== null) { | ||
return $registry; | ||
} | ||
|
||
$registry = $this->aggregateRootRegistryFactory->create($paths); | ||
|
||
$this->cache->set('aggregate_roots', $registry); | ||
|
||
return $registry; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Metadata/AggregateRoot/Psr6AggregateRootMetadataFactory.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\AggregateRoot; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateRoot; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
use function assert; | ||
|
||
final class Psr6AggregateRootMetadataFactory implements AggregateRootMetadataFactory | ||
{ | ||
public function __construct( | ||
private readonly AggregateRootMetadataFactory $aggregateRootMetadataFactory, | ||
private readonly CacheItemPoolInterface $cache, | ||
) { | ||
} | ||
|
||
/** | ||
* @param class-string<T> $aggregate | ||
* | ||
* @return AggregateRootMetadata<T> | ||
* | ||
* @template T of AggregateRoot | ||
*/ | ||
public function metadata(string $aggregate): AggregateRootMetadata | ||
{ | ||
$item = $this->cache->getItem($aggregate); | ||
|
||
if ($item->isHit()) { | ||
$data = $item->get(); | ||
assert($data instanceof AggregateRootMetadata); | ||
|
||
return $data; | ||
} | ||
|
||
$metadata = $this->aggregateRootMetadataFactory->metadata($aggregate); | ||
|
||
$item->set($metadata); | ||
$this->cache->save($item); | ||
|
||
return $metadata; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Metadata/AggregateRoot/Psr6AggregateRootRegistryFactory.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\AggregateRoot; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
use function assert; | ||
|
||
final class Psr6AggregateRootRegistryFactory implements AggregateRootRegistryFactory | ||
{ | ||
public function __construct( | ||
private readonly AggregateRootRegistryFactory $aggregateRootRegistryFactory, | ||
private readonly CacheItemPoolInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param list<string> $paths */ | ||
public function create(array $paths): AggregateRootRegistry | ||
{ | ||
$item = $this->cache->getItem('aggregate_roots'); | ||
|
||
if ($item->isHit()) { | ||
$data = $item->get(); | ||
assert($data instanceof AggregateRootRegistry); | ||
|
||
return $data; | ||
} | ||
|
||
$registry = $this->aggregateRootRegistryFactory->create($paths); | ||
|
||
$item->set($registry); | ||
$this->cache->save($item); | ||
|
||
return $registry; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Event; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
final class Psr16EventMetadataFactory implements EventMetadataFactory | ||
{ | ||
public function __construct( | ||
private readonly EventMetadataFactory $eventMetadataFactory, | ||
private readonly CacheInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param class-string $event */ | ||
public function metadata(string $event): EventMetadata | ||
{ | ||
/** @var ?EventMetadata $metadata */ | ||
$metadata = $this->cache->get($event); | ||
|
||
if ($metadata !== null) { | ||
return $metadata; | ||
} | ||
|
||
$metadata = $this->eventMetadataFactory->metadata($event); | ||
|
||
$this->cache->set($event, $metadata); | ||
|
||
return $metadata; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Event; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
final class Psr16EventRegistryFactory implements EventRegistryFactory | ||
{ | ||
public function __construct( | ||
private readonly EventRegistryFactory $eventRegistryFactory, | ||
private readonly CacheInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param list<string> $paths */ | ||
public function create(array $paths): EventRegistry | ||
{ | ||
/** @var ?EventRegistry $registry */ | ||
$registry = $this->cache->get('events'); | ||
|
||
if ($registry !== null) { | ||
return $registry; | ||
} | ||
|
||
$registry = $this->eventRegistryFactory->create($paths); | ||
|
||
$this->cache->set('events', $registry); | ||
|
||
return $registry; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Event; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
use function assert; | ||
|
||
final class Psr6EventMetadataFactory implements EventMetadataFactory | ||
{ | ||
public function __construct( | ||
private readonly EventMetadataFactory $eventMetadataFactory, | ||
private readonly CacheItemPoolInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param class-string $event */ | ||
public function metadata(string $event): EventMetadata | ||
{ | ||
$item = $this->cache->getItem($event); | ||
|
||
if ($item->isHit()) { | ||
$data = $item->get(); | ||
assert($data instanceof EventMetadata); | ||
|
||
return $data; | ||
} | ||
|
||
$metadata = $this->eventMetadataFactory->metadata($event); | ||
|
||
$item->set($metadata); | ||
$this->cache->save($item); | ||
|
||
return $metadata; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Event; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
use function assert; | ||
|
||
final class Psr6EventRegistryFactory implements EventRegistryFactory | ||
{ | ||
public function __construct( | ||
private readonly EventRegistryFactory $eventRegistryFactory, | ||
private readonly CacheItemPoolInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param list<string> $paths */ | ||
public function create(array $paths): EventRegistry | ||
{ | ||
$item = $this->cache->getItem('events'); | ||
|
||
if ($item->isHit()) { | ||
$data = $item->get(); | ||
assert($data instanceof EventRegistry); | ||
|
||
return $data; | ||
} | ||
|
||
$registry = $this->eventRegistryFactory->create($paths); | ||
|
||
$item->set($registry); | ||
$this->cache->save($item); | ||
|
||
return $registry; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Projector; | ||
|
||
use Patchlevel\EventSourcing\Projection\Projector\Projector; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
||
final class Psr16ProjectorMetadataFactory implements ProjectorMetadataFactory | ||
{ | ||
public function __construct( | ||
private readonly ProjectorMetadataFactory $projectorMetadataFactory, | ||
private readonly CacheInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param class-string<Projector> $projector */ | ||
public function metadata(string $projector): ProjectorMetadata | ||
{ | ||
/** @var ?ProjectorMetadata $metadata */ | ||
$metadata = $this->cache->get($projector); | ||
|
||
if ($metadata !== null) { | ||
return $metadata; | ||
} | ||
|
||
$metadata = $this->projectorMetadataFactory->metadata($projector); | ||
|
||
$this->cache->set($projector, $metadata); | ||
|
||
return $metadata; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Projector; | ||
|
||
use Patchlevel\EventSourcing\Projection\Projector\Projector; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
use function assert; | ||
|
||
final class Psr6ProjectorMetadataFactory implements ProjectorMetadataFactory | ||
{ | ||
public function __construct( | ||
private readonly ProjectorMetadataFactory $projectorMetadataFactory, | ||
private readonly CacheItemPoolInterface $cache, | ||
) { | ||
} | ||
|
||
/** @param class-string<Projector> $projector */ | ||
public function metadata(string $projector): ProjectorMetadata | ||
{ | ||
$item = $this->cache->getItem($projector); | ||
|
||
if ($item->isHit()) { | ||
$data = $item->get(); | ||
assert($data instanceof ProjectorMetadata); | ||
|
||
return $data; | ||
} | ||
|
||
$metadata = $this->projectorMetadataFactory->metadata($projector); | ||
|
||
$item->set($metadata); | ||
$this->cache->save($item); | ||
|
||
return $metadata; | ||
} | ||
} |
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