1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Caridea |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
7
|
|
|
* use this file except in compliance with the License. You may obtain a copy of |
8
|
|
|
* the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations under |
16
|
|
|
* the License. |
17
|
|
|
* |
18
|
|
|
* @copyright 2015-2016 LibreWorks contributors |
19
|
|
|
* @license http://opensource.org/licenses/Apache-2.0 Apache 2.0 License |
20
|
|
|
*/ |
21
|
|
|
namespace Caridea\Dao\Event; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Publishes events. |
25
|
|
|
* |
26
|
|
|
* We don't build this into the DAO itself because your persistence layer may |
27
|
|
|
* implement an event system. Duplicity is bad! |
28
|
|
|
* |
29
|
|
|
* @copyright 2015-2016 LibreWorks contributors |
30
|
|
|
* @license http://opensource.org/licenses/Apache-2.0 Apache 2.0 License |
31
|
|
|
*/ |
32
|
|
|
trait Publishing |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var \Caridea\Event\Publisher |
36
|
|
|
*/ |
37
|
|
|
protected $publisher; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Sends a pre-delete event. |
41
|
|
|
* |
42
|
|
|
* @param array|object $entity - The event entity |
43
|
|
|
*/ |
44
|
1 |
|
protected function preDelete($entity) |
45
|
|
|
{ |
46
|
1 |
|
$this->publisher->publish(new PreDelete($this, $entity)); |
47
|
1 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Sends a post-delete event. |
51
|
|
|
* |
52
|
|
|
* @param array|object $entity - The event entity |
53
|
|
|
*/ |
54
|
1 |
|
protected function postDelete($entity) |
55
|
|
|
{ |
56
|
1 |
|
$this->publisher->publish(new PostDelete($this, $entity)); |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Sends a pre-insert event. |
61
|
|
|
* |
62
|
|
|
* @param array|object $entity - The event entity |
63
|
|
|
*/ |
64
|
1 |
|
protected function preInsert($entity) |
65
|
|
|
{ |
66
|
1 |
|
$this->publisher->publish(new PreInsert($this, $entity)); |
67
|
1 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Sends a post-insert event. |
71
|
|
|
* |
72
|
|
|
* @param array|object $entity - The event entity |
73
|
|
|
*/ |
74
|
1 |
|
protected function postInsert($entity) |
75
|
|
|
{ |
76
|
1 |
|
$this->publisher->publish(new PostInsert($this, $entity)); |
77
|
1 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Sends a pre-update event. |
81
|
|
|
* |
82
|
|
|
* @param array|object $entity - The event entity |
83
|
|
|
*/ |
84
|
1 |
|
protected function preUpdate($entity) |
85
|
|
|
{ |
86
|
1 |
|
$this->publisher->publish(new PreUpdate($this, $entity)); |
87
|
1 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sends a post-update event. |
91
|
|
|
* |
92
|
|
|
* @param array|object $entity - The event entity |
93
|
|
|
*/ |
94
|
1 |
|
protected function postUpdate($entity) |
95
|
|
|
{ |
96
|
1 |
|
$this->publisher->publish(new PostUpdate($this, $entity)); |
97
|
1 |
|
} |
98
|
|
|
} |
99
|
|
|
|