|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Acme\Domain\Order; |
| 6 | + |
| 7 | +use Acme\Domain\AggregateRootBehaviourTrait; |
| 8 | +use Acme\Domain\AggregateRootInterface; |
| 9 | +use Acme\Domain\Shared\ValueObject\DateTime; |
| 10 | +use Ramsey\Uuid\Uuid; |
| 11 | + |
| 12 | +class Order implements AggregateRootInterface |
| 13 | +{ |
| 14 | + use AggregateRootBehaviourTrait; |
| 15 | + |
| 16 | + private string $number; |
| 17 | + |
| 18 | + private int $total; |
| 19 | + |
| 20 | + private string $state; |
| 21 | + |
| 22 | + private DateTime $createdAt; |
| 23 | + |
| 24 | + private DateTime $updatedAt; |
| 25 | + |
| 26 | + public static function create(string $number, string $state, int $total) |
| 27 | + { |
| 28 | + $order = new static(); |
| 29 | + $order->setUuid(Uuid::uuid4()); |
| 30 | + $order->setNumber($number); |
| 31 | + $order->setState($state); |
| 32 | + $order->setTotal($total); |
| 33 | + $order->setCreatedAt(DateTime::now()); |
| 34 | + |
| 35 | + return $order; |
| 36 | + } |
| 37 | + |
| 38 | + public function setNumber(string $number): void |
| 39 | + { |
| 40 | + $this->number = $number; |
| 41 | + } |
| 42 | + |
| 43 | + public function getNumber(): string |
| 44 | + { |
| 45 | + return $this->number; |
| 46 | + } |
| 47 | + |
| 48 | + public function setTotal(int $total): void |
| 49 | + { |
| 50 | + $this->total = $total; |
| 51 | + } |
| 52 | + |
| 53 | + public function getTotal(): int |
| 54 | + { |
| 55 | + return $this->total; |
| 56 | + } |
| 57 | + |
| 58 | + public function setState(string $state): void |
| 59 | + { |
| 60 | + $this->state = $state; |
| 61 | + } |
| 62 | + |
| 63 | + public function getState(): string |
| 64 | + { |
| 65 | + return $this->state; |
| 66 | + } |
| 67 | + |
| 68 | + public function setCreatedAt(DateTime $createdAt): void |
| 69 | + { |
| 70 | + $this->createdAt = $createdAt; |
| 71 | + } |
| 72 | +} |
0 commit comments