EventDispatcherServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 22
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 3
1
<?php
2
3
namespace EasyIM\Kernel\Providers;
4
5
use Pimple\Container;
6
use Pimple\ServiceProviderInterface;
7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
9
/**
10
 * Class EventDispatcherServiceProvider.
11
 */
12
class EventDispatcherServiceProvider implements ServiceProviderInterface
13
{
14
    /**
15
     * Registers services on the given container.
16
     *
17
     * This method should only be used to configure services and parameters.
18
     * It should not get services.
19
     *
20
     * @param Container $pimple A container instance
21
     */
22
    public function register(Container $pimple)
23
    {
24
        $pimple['events'] = function ($app) {
25
            $dispatcher = new EventDispatcher();
26
27
            foreach ($app->config->get('events.listen', []) as $event => $listeners) {
28
                foreach ($listeners as $listener) {
29
                    $dispatcher->addListener($event, $listener);
30
                }
31
            }
32
33
            return $dispatcher;
34
        };
35
    }
36
}
37