-
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.
Merge pull request #578 from patchlevel/improve-store-criteria
improve store criteria
- Loading branch information
Showing
25 changed files
with
508 additions
and
110 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
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
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
final class AggregateIdCriterion | ||
{ | ||
public function __construct( | ||
public readonly string $aggregateId, | ||
) { | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
final class AggregateNameCriterion | ||
{ | ||
public function __construct( | ||
public readonly string $aggregateName, | ||
) { | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
final class ArchivedCriterion | ||
{ | ||
public function __construct( | ||
public readonly bool $archived, | ||
) { | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
use function array_key_exists; | ||
use function array_values; | ||
|
||
final class Criteria | ||
{ | ||
/** @var array<class-string, object> */ | ||
private readonly array $criteria; | ||
|
||
public function __construct(object ...$criteria) | ||
{ | ||
$result = []; | ||
|
||
foreach ($criteria as $criterion) { | ||
$result[$criterion::class] = $criterion; | ||
} | ||
|
||
$this->criteria = $result; | ||
} | ||
|
||
/** | ||
* @param class-string<T> $criteriaClass | ||
* | ||
* @return T | ||
* | ||
* @template T of object | ||
*/ | ||
public function get(string $criteriaClass): object | ||
{ | ||
if (!array_key_exists($criteriaClass, $this->criteria)) { | ||
throw new CriterionNotFound($criteriaClass); | ||
} | ||
|
||
return $this->criteria[$criteriaClass]; | ||
} | ||
|
||
public function has(string $criteriaClass): bool | ||
{ | ||
return array_key_exists($criteriaClass, $this->criteria); | ||
} | ||
|
||
/** @return list<object> */ | ||
public function all(): array | ||
{ | ||
return array_values($this->criteria); | ||
} | ||
|
||
public function add(object $criteria): self | ||
{ | ||
return new self( | ||
...$this->all(), | ||
...[$criteria], | ||
); | ||
} | ||
|
||
public function remove(string $criteriaClass): self | ||
{ | ||
$criteria = $this->criteria; | ||
unset($criteria[$criteriaClass]); | ||
|
||
return new self(...$criteria); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
use RuntimeException; | ||
|
||
use function sprintf; | ||
|
||
final class CriterionNotFound extends RuntimeException | ||
{ | ||
/** @param class-string $criterionClass */ | ||
public function __construct(string $criterionClass) | ||
{ | ||
parent::__construct(sprintf('criterion %s not found', $criterionClass)); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
final class FromIndexCriterion | ||
{ | ||
public function __construct( | ||
public readonly int $fromIndex, | ||
) { | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Criteria; | ||
|
||
final class FromPlayheadCriterion | ||
{ | ||
public function __construct( | ||
public readonly int $fromPlayhead, | ||
) { | ||
} | ||
} |
Oops, something went wrong.