From e3b5f49870f6dc081090b1e82ea6e9e35417f4b4 Mon Sep 17 00:00:00 2001 From: n3wborn Date: Wed, 1 Nov 2023 08:53:55 +0100 Subject: [PATCH] refactor(entity): add CreatableUpdateableTrait --- src/Entity/CreatableUpdateableTrait.php | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Entity/CreatableUpdateableTrait.php diff --git a/src/Entity/CreatableUpdateableTrait.php b/src/Entity/CreatableUpdateableTrait.php new file mode 100644 index 0000000..86f420f --- /dev/null +++ b/src/Entity/CreatableUpdateableTrait.php @@ -0,0 +1,50 @@ +createdAt; + } + + final public function setCreatedAt(\DateTimeImmutable $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + final public function getUpdatedAt(): ?\DateTimeImmutable + { + return $this->updatedAt; + } + + final public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self + { + $this->updatedAt = $updatedAt; + + return $this; + } + + #[ORM\PrePersist] + final public function setCreatedAtValue(): void + { + $this->createdAt = new \DateTimeImmutable(); + } + + #[ORM\PreUpdate] + final public function setUpdatedAtValue(): void + { + $this->updatedAt = new \DateTimeImmutable(); + } +}