Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
EventsServiceProvider | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
register | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
registerEvents | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Events; |
6 | |
7 | use Engelsystem\Config\Config; |
8 | use Engelsystem\Container\ServiceProvider; |
9 | |
10 | class EventsServiceProvider extends ServiceProvider |
11 | { |
12 | public function register(): void |
13 | { |
14 | $dispatcher = $this->app->make(EventDispatcher::class); |
15 | |
16 | $this->app->instance(EventDispatcher::class, $dispatcher); |
17 | $this->app->instance('events.dispatcher', $dispatcher); |
18 | |
19 | $this->registerEvents($dispatcher); |
20 | } |
21 | |
22 | protected function registerEvents(EventDispatcher $dispatcher): void |
23 | { |
24 | /** @var Config $config */ |
25 | $config = $this->app->get('config'); |
26 | |
27 | foreach ($config->get('event-handlers', []) as $event => $handlers) { |
28 | foreach ((array) $handlers as $handler) { |
29 | $dispatcher->listen($event, $handler); |
30 | } |
31 | } |
32 | } |
33 | } |