for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types = 1);
namespace Fousky\Traits\Timestampable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\HasLifecycleCallbacks()
*
* @author Lukáš Brzák <[email protected]>
*/
trait TimestampableTrait
{
* @var \DateTime|null
* @ORM\Column(name="created_at", type="datetime", nullable=false)
protected $createdAt;
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
protected $updatedAt;
public function __construct()
$this->createdAt = new \DateTime();
}
* @ORM\PrePersist()
public function _timestampable_prePersist(): void
* @ORM\PreUpdate()
public function _timestampable_preUpdate(): void
$this->updatedAt = new \DateTime();
public function getCreatedAt(): ?\DateTime
return $this->createdAt;
public function setCreatedAt(?\DateTime $createdAt): self
$this->createdAt = $createdAt;
return $this;
public function getUpdatedAt(): ?\DateTime
return $this->updatedAt;
public function setUpdatedAt(?\DateTime $updatedAt): self
$this->updatedAt = $updatedAt;