1 | <?php |
||
8 | trait DoNotDelete |
||
9 | { |
||
10 | /** |
||
11 | * @Column(type="datetime", name="deleted_at", nullable=true) |
||
12 | */ |
||
13 | private $deleted_at; |
||
14 | |||
15 | /** |
||
16 | * Getter |
||
17 | */ |
||
18 | public function getDeletedAt($format = null) |
||
|
|||
19 | { |
||
20 | switch (true) { |
||
21 | case is_string($this->deleted_at): |
||
22 | case is_object($this->deleted_at) && get_class($this->deleted_at) !== 'DateTime': |
||
23 | throw new \Exception("deleted_at is not a datetime", 400); |
||
24 | case $this->deleted_at === null: |
||
25 | case $format === null: |
||
26 | return $this->deleted_at; |
||
27 | default: |
||
28 | return $this->deleted_at->format($format); |
||
29 | } |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Setter |
||
34 | */ |
||
35 | public function setDeletedAt($datetime) |
||
47 | |||
48 | /** |
||
49 | * @PreRemove |
||
50 | */ |
||
51 | public function canNotDelete() |
||
55 | } |
||
56 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.