Skip to content

Commit

Permalink
add ramsey uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 23, 2023
1 parent 4fa1b93 commit 2341d1a
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 39 deletions.
7 changes: 7 additions & 0 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<file src="tests/Benchmark/SimpleSetupBench.php">
<MissingConstructor>
<code>$bus</code>
<code>$id</code>
<code>$repository</code>
<code>$store</code>
</MissingConstructor>
Expand All @@ -93,14 +94,19 @@
<MissingConstructor>
<code>$adapter</code>
<code>$bus</code>
<code>$id</code>
<code>$repository</code>
<code>$snapshotStore</code>
<code>$store</code>
</MissingConstructor>
</file>
<file src="tests/Benchmark/SplitStreamBench.php">
<ArgumentTypeCoercion>
<code><![CDATA[$this->id]]></code>
</ArgumentTypeCoercion>
<MissingConstructor>
<code>$bus</code>
<code>$id</code>
<code>$repository</code>
<code>$snapshotStore</code>
<code>$store</code>
Expand All @@ -109,6 +115,7 @@
<file src="tests/Benchmark/SyncProjectionistBench.php">
<MissingConstructor>
<code>$bus</code>
<code>$id</code>
<code>$profile</code>
<code>$repository</code>
<code>$store</code>
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"psr/clock": "^1.0",
"psr/log": "^2.0.0|^3.0.0",
"psr/simple-cache": "^2.0.0|^3.0.0",
"ramsey/uuid": "^4.7",
"symfony/console": "^5.4.32|^6.4.1|^7.0.1",
"symfony/finder": "^5.4.27|^6.4.0|^7.0.0",
"symfony/lock": "^5.4.32|^6.4.0|^7.0.0"
Expand Down
238 changes: 237 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/Aggregate/AggregateRootId.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
interface AggregateRootId
{
public function toString(): string;

public static function fromString(string $id): self;
}
10 changes: 1 addition & 9 deletions src/Aggregate/BasicAggregateRootId.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@

final class BasicAggregateRootId implements AggregateRootId
{
public function __construct(
private readonly string $id,
) {
}

public function toString(): string
{
return $this->id;
}
use ValueAggregateIdBehaviour;
}
31 changes: 31 additions & 0 deletions src/Aggregate/RamseyAggregateIdBehaviour.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Aggregate;

use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

trait RamseyAggregateIdBehaviour
{
public function __construct(
private readonly UuidInterface $id,
) {
}

public static function fromString(string $id): self
{
return new self(Uuid::fromString($id));
}

public function toString(): string
{
return $this->id->toString();
}

public static function generate(): self
{
return new self(Uuid::uuid7());
}
}
10 changes: 10 additions & 0 deletions src/Aggregate/UuidAggregateRootId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Aggregate;

final class UuidAggregateRootId implements AggregateRootId
{
use RamseyAggregateIdBehaviour;
}
23 changes: 23 additions & 0 deletions src/Aggregate/ValueAggregateIdBehaviour.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Aggregate;

trait ValueAggregateIdBehaviour
{
public function __construct(
private readonly string $id,
) {
}

public static function fromString(string $id): self
{
return new self($id);
}

public function toString(): string
{
return $this->id;
}
}
Loading

0 comments on commit 2341d1a

Please sign in to comment.