Passed
Push — master ( a3fb64...670096 )
by Andreas
17:05
created

dispatcher::trigger_watch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
    public function add_watches(array $watches, $component)
36
    {
37
        foreach ($watches as $watch) {
38
            foreach ($this->watches as $operation_id => $event_name) {
39
                // Check whether the operations flag list from the component
40
                // contains the operation_id we're checking a watch for.
41
                if ($watch['operations'] & $operation_id) {
42
                    $listener = new watcher($component, $watch['classes']);
43
                    $this->addListener($event_name, [$listener, 'handle_event']);
44
                }
45
            }
46
        }
47
    }
48
}
49