<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use \DateTimeInterface;
/**
* @ORM\MappedSuperclass()
*/
abstract class AbstractBaseEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="datetime")
*/
protected DateTimeInterface $created;
/**
* @ORM\Column(type="datetime")
*/
protected DateTimeInterface $updated;
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return DateTimeInterface|null
*/
public function getCreated(): ?DateTimeInterface
{
return $this->created;
}
/**
* @param DateTimeInterface $created
* @return $this
*/
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
/**
* @return DateTimeInterface|null
*/
public function getUpdated(): ?DateTimeInterface
{
return $this->updated;
}
/**
* @param DateTimeInterface $updated
* @return $this
*/
public function setUpdated(DateTimeInterface $updated): self
{
$this->updated = $updated;
return $this;
}
/**
* constructor
*/
public function __construct()
{
$currentTimestamp = new \DateTime();
$this->created = $currentTimestamp;
$this->updated = $currentTimestamp;
}
/**
* @ORM\PreUpdate()
* @return void
*/
public function updateTimestamp(): void
{
$currentTimestamp = new \DateTime();
$this->updated = $currentTimestamp;
if (is_null($this->getCreated())) {
$this->setCreated($currentTimestamp);
}
}
}