wallabag/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php
Jeremy Benoist 927c9e796f
Add EntityTimestampsTrait to handle dates
Refactorize timestamps() method to avoid re-writing it on each entity
2017-07-06 09:01:51 +02:00

25 lines
426 B
PHP

<?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();
}
}