67 lines
1.1 KiB
PHP
67 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Doctrine;
|
||
|
|
||
|
trait Timestampable
|
||
|
{
|
||
|
/**
|
||
|
* @var \DateTime
|
||
|
*
|
||
|
* @ORM\Column(name="created_at", type="datetime")
|
||
|
*/
|
||
|
private $createdAt;
|
||
|
|
||
|
/**
|
||
|
* @var \DateTime
|
||
|
*
|
||
|
* @ORM\Column(name="updated_at", type="datetime")
|
||
|
*/
|
||
|
private $updatedAt;
|
||
|
|
||
|
/**
|
||
|
* Gets triggered only on insert.
|
||
|
*
|
||
|
* @ORM\PrePersist
|
||
|
*/
|
||
|
public function onPrePersist(): void
|
||
|
{
|
||
|
$this->createdAt = new \DateTime();
|
||
|
$this->updatedAt = new \DateTime();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets triggered every time on update.
|
||
|
*
|
||
|
* @ORM\PreUpdate
|
||
|
*/
|
||
|
public function onPreUpdate(): void
|
||
|
{
|
||
|
$this->updatedAt = new \DateTime();
|
||
|
}
|
||
|
|
||
|
public function setCreatedAt(?\DateTime $createdAt): self
|
||
|
{
|
||
|
$this->createdAt = $createdAt;
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function getCreatedAt()
|
||
|
{
|
||
|
return $this->createdAt;
|
||
|
}
|
||
|
|
||
|
|
||
|
public function setUpdatedAt(?DateTime $updatedAt): self
|
||
|
{
|
||
|
$this->updatedAt = $updatedAt;
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function getUpdatedAt(): ?\DateTime
|
||
|
{
|
||
|
return $this->updatedAt;
|
||
|
}
|
||
|
}
|