1 | <?php |
||
12 | trait TimestampableEntity |
||
13 | { |
||
14 | //<editor-fold desc="Fields"> |
||
15 | /** |
||
16 | * @var \DateTime |
||
17 | * @\Gedmo\Mapping\Annotation\Timestampable(on="create") |
||
18 | * @ORM\Column(type="datetime") |
||
19 | */ |
||
20 | private $createdAt; |
||
21 | |||
22 | /** |
||
23 | * @var \DateTime |
||
24 | * @\Gedmo\Mapping\Annotation\Timestampable(on="update") |
||
25 | * @ORM\Column(type="datetime") |
||
26 | */ |
||
27 | private $updatedAt; |
||
28 | |||
29 | //</editor-fold desc="Fields"> |
||
30 | |||
31 | //<editor-fold desc="Public Methods"> |
||
32 | /** |
||
33 | * @return \DateTime |
||
34 | */ |
||
35 | public function getCreatedAt(): \DateTime |
||
39 | |||
40 | /** |
||
41 | * @return \DateTime |
||
42 | */ |
||
43 | public function getUpdatedAt(): \DateTime |
||
47 | |||
48 | /** |
||
49 | * @param \DateTime $createdAt |
||
50 | * @return $this|TimestampableEntity |
||
|
|||
51 | */ |
||
52 | public function setCreatedAt(\DateTime $createdAt) |
||
57 | |||
58 | /** |
||
59 | * @param \DateTime $updatedAt |
||
60 | * @return $this|TimestampableEntity |
||
61 | */ |
||
62 | public function setUpdatedAt(\DateTime $updatedAt) |
||
67 | //</editor-fold desc="Public Methods"> |
||
68 | } |
||
69 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.