From b53f881070f1fa0786aec60272efc01803b3efcf Mon Sep 17 00:00:00 2001 From: Andrej Hudec Date: Thu, 1 Aug 2024 13:45:00 +0200 Subject: [PATCH] Add IdentityBigIntTrait --- src/Entity/Traits/IdentityBigIntTrait.php | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Entity/Traits/IdentityBigIntTrait.php diff --git a/src/Entity/Traits/IdentityBigIntTrait.php b/src/Entity/Traits/IdentityBigIntTrait.php new file mode 100644 index 0000000..a5cefab --- /dev/null +++ b/src/Entity/Traits/IdentityBigIntTrait.php @@ -0,0 +1,50 @@ + true])] + #[Serialize] + protected ?int $id = null; + + public function getId(): ?int + { + return $this->id; + } + + public function setId(?int $id): static + { + $this->id = $id; + + return $this; + } + + public function is(BaseIdentifiableInterface $identifiable): bool + { + if ($identifiable::getResourceName() === $this->getResourceName()) { + return $identifiable->getId() === $this->getId(); + } + + return false; + } + + public function isNot(BaseIdentifiableInterface $identifiable): bool + { + return false === $this->is($identifiable); + } +}