-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IdentityIntTrait with unsigned int. Add static AnzuApp::date func…
…tion.
- Loading branch information
sakulb
committed
Jul 24, 2023
1 parent
3fca06e
commit d4ee7c7
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 IdentityIntTrait | ||
{ | ||
use NamedResourceTrait; | ||
|
||
/** | ||
* Primary key of this item. | ||
*/ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'AUTO')] | ||
#[ORM\Column(type: Types::INTEGER, 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); | ||
} | ||
} |