30 lines
602 B
PHP
30 lines
602 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity\Behavior;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* Требует у класса-сущности свойство `$updateAt` (mapped column).
|
|
*
|
|
* @property \DateTimeInterface|null $updateAt
|
|
*/
|
|
trait UpdateTimestampTrait
|
|
{
|
|
#[ORM\PrePersist]
|
|
public function setInitialUpdateAt(): void
|
|
{
|
|
if ($this->updateAt === null) {
|
|
$this->updateAt = new \DateTimeImmutable();
|
|
}
|
|
}
|
|
|
|
#[ORM\PreUpdate]
|
|
public function refreshUpdateAt(): void
|
|
{
|
|
$this->updateAt = new \DateTimeImmutable();
|
|
}
|
|
}
|