|
17 | 17 | #[ORM\MappedSuperclass] |
18 | 18 | abstract class AbstractEntity implements ArraySerializableInterface |
19 | 19 | { |
| 20 | + #[ORM\Id] |
| 21 | + #[ORM\Column(name: 'id', type: 'uuid', unique: true, nullable: false)] |
| 22 | + protected UuidInterface $id; |
| 23 | + |
20 | 24 | #[ORM\Column(name: 'created', type: 'datetime_immutable', nullable: false)] |
21 | 25 | protected DateTimeImmutable $created; |
22 | 26 |
|
23 | 27 | #[ORM\Column(name: 'updated', type: 'datetime_immutable', nullable: true)] |
24 | 28 | protected ?DateTimeImmutable $updated = null; |
25 | 29 |
|
26 | | - #[ORM\Id] |
27 | | - #[ORM\Column(name: 'id', type: 'uuid', unique: true, nullable: false)] |
28 | | - protected UuidInterface $uuid; |
29 | | - |
30 | | - #[ORM\PrePersist] |
31 | | - public function created(): void |
32 | | - { |
33 | | - $this->created = new DateTimeImmutable(); |
34 | | - } |
35 | | - |
36 | | - #[ORM\PreUpdate] |
37 | | - public function touch(): void |
38 | | - { |
39 | | - $this->updated = new DateTimeImmutable(); |
40 | | - } |
41 | | - |
42 | 30 | public function __construct() |
43 | 31 | { |
44 | | - $this->uuid = Uuid::uuid7(); |
| 32 | + $this->id = Uuid::uuid7(); |
45 | 33 | } |
46 | 34 |
|
47 | 35 | public function getId(): UuidInterface |
48 | 36 | { |
49 | | - return $this->uuid; |
| 37 | + return $this->id; |
50 | 38 | } |
51 | 39 |
|
52 | 40 | public function setId(UuidInterface $id): static |
53 | 41 | { |
54 | | - $this->uuid = $id; |
| 42 | + $this->id = $id; |
55 | 43 |
|
56 | 44 | return $this; |
57 | 45 | } |
@@ -80,6 +68,18 @@ public function getUpdatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): ?string |
80 | 68 | return null; |
81 | 69 | } |
82 | 70 |
|
| 71 | + #[ORM\PrePersist] |
| 72 | + public function created(): void |
| 73 | + { |
| 74 | + $this->created = new DateTimeImmutable(); |
| 75 | + } |
| 76 | + |
| 77 | + #[ORM\PreUpdate] |
| 78 | + public function touch(): void |
| 79 | + { |
| 80 | + $this->updated = new DateTimeImmutable(); |
| 81 | + } |
| 82 | + |
83 | 83 | /** |
84 | 84 | * @param array<non-empty-string, mixed> $array |
85 | 85 | */ |
|
0 commit comments