for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the TheAlternativeZurich/events project.
*
* (c) Florian Moser <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Entity\Traits;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
* automatically keeps track of creation time & last change time
trait TimeTrait
{
/**
* @var DateTime
* @ORM\Column(type="datetime")
private $createdAt;
private $lastChangedAt;
* @ORM\PrePersist()
* @throws Exception
public function prePersistTime()
$this->createdAt = new DateTime();
$this->lastChangedAt = new DateTime();
}
* @ORM\PreUpdate()
public function preUpdateTime()
* @return DateTime
public function getCreatedAt()
return $this->createdAt;
public function getLastChangedAt()
return $this->lastChangedAt;