-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderCreated.php
More file actions
69 lines (56 loc) · 1.91 KB
/
Copy pathOrderCreated.php
File metadata and controls
69 lines (56 loc) · 1.91 KB
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
<?php
declare(strict_types=1);
namespace ComplexHeart\Domain\Model\Test\Fixtures\OrderManagement\Domain\Events;
use ComplexHeart\Domain\Contracts\Events\Event;
use ComplexHeart\Domain\Model\Test\Fixtures\OrderManagement\Domain\OrderLine;
use ComplexHeart\Domain\Model\Test\Fixtures\OrderManagement\Domain\Order;
use ComplexHeart\Domain\Model\ValueObjects\DateTimeValue as Timestamp;
use ComplexHeart\Domain\Model\ValueObjects\UUIDValue as ID;
/**
* Class OrderCreated
*
* @author Unay Santisteban <usantisteban@othercode.io>
* @package ComplexHeart\Domain\Model\Test\OrderManagement\Events
*/
class OrderCreated implements Event
{
private ID $id;
private string $name = 'order_management.order.created';
private array $payload;
private Timestamp $timestamp;
public function __construct(Order $order, ?ID $id = null, ?Timestamp $timestamp = null)
{
$this->id = is_null($id) ? ID::random() : $id;
$this->payload = [
'id' => $order->id()->value(),
'customer' => [
'id' => $order->customer->id,
'name' => $order->customer->name,
],
'orderLines' => $order->lines->map(fn (OrderLine $line) => $line->values()),
'tags' => $order->tags->values()['value'],
'created' => $order->created->toIso8601String(),
];
$this->timestamp = is_null($timestamp) ? new Timestamp() : $timestamp;
}
public function eventId(): string
{
return $this->id->value();
}
public function eventName(): string
{
return $this->name;
}
public function occurredOn(): string
{
return (string) (((float) ($this->timestamp->getTimestamp().'.'.$this->timestamp->format('u'))) * 1000);
}
public function payload(): array
{
return $this->payload;
}
public function aggregateId(): string
{
return $this->payload['id'];
}
}