Completed
Pull Request — master (#50)
by De Cramer
03:04
created

Dispatcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 62
rs 10
c 0
b 0
f 0
ccs 12
cts 18
cp 0.6667

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A init() 0 5 1
A reset() 0 4 1
A addEventProcesseor() 0 4 1
A dispatch() 0 8 2
1
<?php
2
3
namespace eXpansion\Framework\Core\Services\Application;
4
5
use eXpansion\Framework\Core\Services\DataProviderManager;
6
use eXpansion\Framework\Core\Services\PluginManager;
7
8
/**
9
 * Class Dispatcher, dispatches events to the Data Providers.
10
 *
11
 * @package eXpansion\Framework\Core\Services\Application
12
 * @author Oliver de Cramer
13
 */
14
class Dispatcher implements DispatcherInterface
15
{
16
    /** @var DataProviderManager  */
17
    protected $dataProviderManager;
18
19
    /** @var PluginManager */
20
    protected $pluginManager;
21
22
    /** @var EventProcessorInterface[] */
23
    protected $eventProcessors = [];
24
25
    /**
26
     * Dispatcher constructor.
27
     *
28
     * @param DataProviderManager $dataProviderManager
29
     * @param PluginManager $pluginManager
30
     */
31 40
    public function __construct(DataProviderManager $dataProviderManager, PluginManager $pluginManager)
32
    {
33 40
        $this->dataProviderManager = $dataProviderManager;
34 40
        $this->pluginManager = $pluginManager;
35 40
    }
36
37
    /**
38
     * Init.
39
     */
40
    public function init()
41
    {
42
        $this->pluginManager->init();
43
        $this->dataProviderManager->init($this->pluginManager);
44
    }
45
46
    /**
47
     * Reset when game mode changes.
48
     */
49
    public function reset()
50
    {
51
52
    }
53
54
    /**
55
     * Add a processor of events.
56
     *
57
     * @param EventProcessorInterface $eventProcessor
58
     */
59 40
    public function addEventProcesseor(EventProcessorInterface $eventProcessor)
60
    {
61 40
        $this->eventProcessors[] = $eventProcessor;
62 40
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 24
    public function dispatch($event, $params)
68
    {
69 24
        foreach ($this->eventProcessors as $eventProcessor) {
70 24
            $eventProcessor->dispatch($event, $params);
71
        }
72
73 24
        $this->dataProviderManager->dispatch($event, $params);
74
    }
75
}