52 lines
1,002 B
PHP
52 lines
1,002 B
PHP
<?php
|
|
|
|
namespace App\Core\Doctrine;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
trait Timestampable
|
|
{
|
|
#[ORM\Column(name: 'created_at', type: 'datetime')]
|
|
protected $createdAt;
|
|
|
|
#[ORM\Column(name: 'updated_at', type: 'datetime')]
|
|
protected $updatedAt;
|
|
|
|
#[ORM\PrePersist]
|
|
public function onPrePersist(): void
|
|
{
|
|
$this->createdAt = new \DateTime();
|
|
$this->updatedAt = new \DateTime();
|
|
}
|
|
|
|
#[ORM\PreUpdate]
|
|
public function onPreUpdate(): void
|
|
{
|
|
$this->updatedAt = new \DateTime();
|
|
}
|
|
|
|
public function setCreatedAt(?\DateTime $createdAt): self
|
|
{
|
|
$this->createdAt = $createdAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCreatedAt(): ?\DateTime
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function setUpdatedAt(?\DateTime $updatedAt): self
|
|
{
|
|
$this->updatedAt = $updatedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?\DateTime
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
}
|