Completed
Pull Request — master (#6)
by De Cramer
11:31
created

AbstractDataProvider::deletePlugin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: olive
5
 * Date: 12/03/2017
6
 * Time: 11:53
7
 */
8
9
namespace eXpansion\Core\DataProviders;
10
11
/**
12
 * AbstractDataProvider for all data providers to use to simplify registration & dispatch.
13
 *
14
 * @package eXpansion\Core\DataProviders
15
 */
16
abstract class AbstractDataProvider
17
{
18
    protected $plugins = [];
19
20
    /**
21
     * Register a plugin to be handled by ths provider
22
     *
23
     * @param string $pluginId The service name of the plugin.
24
     *
25
     * @param Object $pluginService The plugin object.
26
     */
27
    public function registerPlugin($pluginId, $pluginService)
28
    {
29
        $this->plugins[$pluginId] = $pluginService;
30
    }
31
32
    /**
33
     * Remove a plugin so that it won't be handled anymore.
34
     *
35
     * @param $pluginId
36
     *
37
     */
38
    public function deletePlugin($pluginId)
39
    {
40
        if (isset($this->plugins[$pluginId])) {
41
            unset($this->plugins[$pluginId]);
42
        }
43
    }
44
45
    /**
46
     * Dispatch method call to all plugins.
47
     *
48
     * @param string $method method to call.
49
     * @param array $params
50
     */
51
    protected function dispatch($method, $params)
52
    {
53
        foreach ($this->plugins as $plugin) {
54
            $plugin->$method(...$params);
55
        }
56
    }
57
}