| Total Complexity | 7 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | trait EventHandlerTrait |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var array stack of events attached to the manager |
||
| 9 | */ |
||
| 10 | protected $events = []; |
||
| 11 | /** |
||
| 12 | * Adds an Event instance to the stack based on the name. |
||
| 13 | * |
||
| 14 | * @param string $name the identifier of the stack |
||
| 15 | * @param Event $event the event instance to add |
||
| 16 | */ |
||
| 17 | 4 | public function attach($name, Event $event) |
|
| 18 | { |
||
| 19 | 4 | if (!isset($this->events[$name])) { |
|
| 20 | 4 | $this->events[$name] = []; |
|
| 21 | 4 | } |
|
| 22 | |||
| 23 | 4 | $this->events[$name][] = $event; |
|
| 24 | 4 | } |
|
| 25 | |||
| 26 | /** |
||
| 27 | * Removes the handlers of stack by its name. |
||
| 28 | * |
||
| 29 | * @param string $name |
||
| 30 | */ |
||
| 31 | 1 | public function detach($name) |
|
| 32 | { |
||
| 33 | 1 | if (array_key_exists($name, $this->events)) { |
|
| 34 | 1 | unset($this->events[$name]); |
|
| 35 | 1 | } |
|
| 36 | 1 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Fires the handlers of a stack by its name. |
||
| 40 | * |
||
| 41 | * @param string $name the name of the stack to fire |
||
| 42 | * @param array $data |
||
| 43 | */ |
||
| 44 | 4 | public function trigger($name, array $data = []) |
|
| 50 | 4 | } |
|
| 51 | 4 | } |
|
| 52 | 4 | } |
|
| 54 |