-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeTrackingTrait.php
59 lines (46 loc) · 1.29 KB
/
TimeTrackingTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace AnzuSystems\Contracts\Entity\Traits;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
trait TimeTrackingTrait
{
/**
* Time of creation of this item.
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Serialize]
protected DateTimeImmutable $createdAt;
/**
* Time of modification of this item.
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Serialize]
protected DateTimeImmutable $modifiedAt;
public function getCreatedAt(): DateTimeImmutable
{
if (false === isset($this->createdAt)) {
$this->setCreatedAt(new DateTimeImmutable());
}
return $this->createdAt;
}
public function setCreatedAt(DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getModifiedAt(): DateTimeImmutable
{
if (false === isset($this->modifiedAt)) {
$this->setModifiedAt(new DateTimeImmutable());
}
return $this->modifiedAt;
}
public function setModifiedAt(DateTimeImmutable $modifiedAt): static
{
$this->modifiedAt = $modifiedAt;
return $this;
}
}