Skip to content

Commit

Permalink
Merge pull request #18 from anzusystems/bigint
Browse files Browse the repository at this point in the history
Add `IdentityBigIntTrait`, mark `IdentityTrait` as deprecated
  • Loading branch information
pulzarraider authored Aug 1, 2024
2 parents 82902d4 + aecdb9a commit 29cd3d1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Entity/Traits/IdentityBigIntTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 IdentityBigIntTrait
{
use NamedResourceTrait;

/**
* Primary key of this item.
*/
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: Types::BIGINT, options: ['unsigned' => 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);
}
}
3 changes: 3 additions & 0 deletions src/Entity/Traits/IdentityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
* @deprecated Use IdentityIntTrait
*/
trait IdentityTrait
{
use NamedResourceTrait;
Expand Down

0 comments on commit 29cd3d1

Please sign in to comment.