-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
70 lines (56 loc) · 1.49 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
use App\Common\Domain\Aggregate\AggregateRoot;
use App\Common\Domain\Aggregate\AggregateRootBehavior;
use App\Common\Domain\Messaging\Event\DomainEvent;
use App\Common\Domain\Messaging\Event\DomainEventBehavior;
require_once __DIR__ . '/vendor/autoload.php';
final class PersonRenamed implements DomainEvent
{
use DomainEventBehavior;
public static function type(): string
{
return 'poc.users.1.event.user.renamed';
}
}
final class Fullname implements Stringable
{
public function __construct(
private string $name,
private string $middle,
private string $last
) {
}
public function name(): string
{
return $this->name;
}
public function middle(): string
{
return $this->middle;
}
public function last(): string
{
return $this->last;
}
public function __toString(): string
{
return sprintf('%s %s %s', $this->name, $this->middle, $this->last);
}
}
final class Person implements AggregateRoot
{
use AggregateRootBehavior;
private ?Fullname $name;
public function rename(string $name, string $middle, string $last): void
{
$this->recordThat(new PersonRenamed(
$this->aggregateRootId()->value(),
payload: compact('name', 'middle', 'last')
));
}
public function applyPersonRenamed(PersonRenamed $event): void
{
$this->name = new Fullname(...$event->payload());
}
}