Add EntityTimestampsTrait to handle dates

Refactorize timestamps() method to avoid re-writing it on each entity
This commit is contained in:
Jeremy Benoist
2017-07-06 09:00:37 +02:00
parent b5d7eb148c
commit 927c9e796f
5 changed files with 36 additions and 48 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace Wallabag\CoreBundle\Helper;
use Doctrine\ORM\Mapping as ORM;
/**
* Trait to handle created & updated date of an Entity.
*/
trait EntityTimestampsTrait
{
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function timestamps()
{
if (null === $this->createdAt) {
$this->createdAt = new \DateTime();
}
$this->updatedAt = new \DateTime();
}
}