-
Notifications
You must be signed in to change notification settings - Fork 0
/
IdentityTrait.php
50 lines (39 loc) · 1.06 KB
/
IdentityTrait.php
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
<?php
declare(strict_types=1);
namespace AnzuSystems\Contracts\Entity\Traits;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\Contracts\Entity\Interfaces\BaseIdentifiableInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
trait IdentityTrait
{
use NamedResourceTrait;
/**
* Primary key of this item.
*/
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: Types::INTEGER)]
#[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);
}
}