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-2018 LibreWorks contributors |
19
|
|
|
* @license Apache-2.0 |
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-2018 LibreWorks contributors |
30
|
|
|
* @license Apache-2.0 |
31
|
|
|
*/ |
32
|
|
|
trait Publishing |
33
|
|
|
{ |
34
|
|
|
use \Caridea\Event\PublisherSetter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Sends a pre-delete event. |
38
|
|
|
* |
39
|
|
|
* @param array|object $entity - The event entity |
40
|
|
|
*/ |
41
|
1 |
|
protected function preDelete($entity) |
42
|
|
|
{ |
43
|
1 |
|
$this->publisher->publish(new PreDelete($this, $entity)); |
44
|
1 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Sends a post-delete event. |
48
|
|
|
* |
49
|
|
|
* @param array|object $entity - The event entity |
50
|
|
|
*/ |
51
|
1 |
|
protected function postDelete($entity) |
52
|
|
|
{ |
53
|
1 |
|
$this->publisher->publish(new PostDelete($this, $entity)); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Sends a pre-insert event. |
58
|
|
|
* |
59
|
|
|
* @param array|object $entity - The event entity |
60
|
|
|
*/ |
61
|
1 |
|
protected function preInsert($entity) |
62
|
|
|
{ |
63
|
1 |
|
$this->publisher->publish(new PreInsert($this, $entity)); |
64
|
1 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Sends a post-insert event. |
68
|
|
|
* |
69
|
|
|
* @param array|object $entity - The event entity |
70
|
|
|
*/ |
71
|
1 |
|
protected function postInsert($entity) |
72
|
|
|
{ |
73
|
1 |
|
$this->publisher->publish(new PostInsert($this, $entity)); |
74
|
1 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sends a pre-update event. |
78
|
|
|
* |
79
|
|
|
* @param array|object $entity - The event entity |
80
|
|
|
*/ |
81
|
1 |
|
protected function preUpdate($entity) |
82
|
|
|
{ |
83
|
1 |
|
$this->publisher->publish(new PreUpdate($this, $entity)); |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Sends a post-update event. |
88
|
|
|
* |
89
|
|
|
* @param array|object $entity - The event entity |
90
|
|
|
*/ |
91
|
1 |
|
protected function postUpdate($entity) |
92
|
|
|
{ |
93
|
1 |
|
$this->publisher->publish(new PostUpdate($this, $entity)); |
94
|
1 |
|
} |
95
|
|
|
} |
96
|
|
|
|