|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package midcom.events |
|
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace midcom\events; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* midcom event dispatcher |
|
15
|
|
|
* |
|
16
|
|
|
* @package midcom.events |
|
17
|
|
|
*/ |
|
18
|
|
|
class dispatcher extends EventDispatcher |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* This array contains all registered MidCOM operation watches. They are indexed by |
|
22
|
|
|
* operation and map to components / libraries which have registered to classes. |
|
23
|
|
|
* Values consist of an array whose first element is the component and subsequent |
|
24
|
|
|
* elements are the types involved (so a single count means all objects). |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
private $watches = [ |
|
29
|
|
|
\MIDCOM_OPERATION_DBA_CREATE => dbaevent::CREATE, |
|
30
|
|
|
\MIDCOM_OPERATION_DBA_UPDATE => dbaevent::UPDATE, |
|
31
|
|
|
\MIDCOM_OPERATION_DBA_DELETE => dbaevent::DELETE, |
|
32
|
|
|
\MIDCOM_OPERATION_DBA_IMPORT => dbaevent::IMPORT, |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Compat function for ragnaroek-style events. |
|
37
|
|
|
* |
|
38
|
|
|
* @param int $operation_id One of the MIDCOM_OPERATION_DBA_ constants |
|
39
|
|
|
* @param \midcom_core_dbaobject $object The current object |
|
40
|
|
|
*/ |
|
41
|
|
|
public function trigger_watch($operation_id, $object) |
|
42
|
|
|
{ |
|
43
|
|
|
$event_name = $this->watches[$operation_id]; |
|
44
|
|
|
$event = new dbaevent($object); |
|
45
|
|
|
$this->dispatch($event_name, $event); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function add_watches(array $watches, $component) |
|
49
|
|
|
{ |
|
50
|
|
|
foreach ($watches as $watch) { |
|
51
|
|
|
foreach ($this->watches as $operation_id => $event_name) { |
|
52
|
|
|
// Check whether the operations flag list from the component |
|
53
|
|
|
// contains the operation_id we're checking a watch for. |
|
54
|
|
|
if ($watch['operations'] & $operation_id) { |
|
55
|
|
|
$listener = new watcher($component, $watch['classes']); |
|
56
|
|
|
$this->addListener($event_name, [$listener, 'handle_event']); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|