Completed
Push — master ( ab4a72...99f0f9 )
by Sergey
05:20
created

DALMediator::attach()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Isswp101\Persimmon\DAL;
4
5
class DALMediator
6
{
7
    const EVENT_BEFORE_SEARCH = 'EVENT_BEFORE_SEARCH';
8
    const EVENT_AFTER_SEARCH = 'EVENT_AFTER_SEARCH';
9
10
    protected $events = [];
11
12 54
    public function attach($event, callable $callback)
13
    {
14 54
        if (!isset($this->events[$event])) {
15 54
            $this->events[$event] = [];
16 54
        }
17 54
        $this->events[$event][] = $callback;
18 54
    }
19
20 22
    public function trigger($event, $data = null)
21
    {
22 22
        if (isset($this->events[$event])) {
23 22
            foreach ($this->events[$event] as $callback) {
24 22
                $callback($data);
25 22
            }
26 22
        }
27 22
    }
28
}
29