AbstractPluginManagerFactory::getClassName()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
nc 1
1
<?php
2
/**
3
 * Dash
4
 *
5
 * @link      http://github.com/DASPRiD/Dash For the canonical source repository
6
 * @copyright 2013-2015 Ben Scholzen 'DASPRiD'
7
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
8
 */
9
10
namespace Dash;
11
12
use Interop\Container\ContainerInterface;
13
use Zend\ServiceManager\AbstractPluginManager;
14
15
/**
16
 * Abstract factory for plugin managers.
17
 */
18
abstract class AbstractPluginManagerFactory
19
{
20
    /**
21
     * @var string
22
     */
23
    private $configKey;
24
25
    /**
26
     * @var string
27
     */
28
    private $className;
29
30
    /**
31
     * Caches the abstract getter results to eliminate performance impact.
32
     */
33
    public function __construct()
34
    {
35
        $this->configKey = $this->getConfigKey();
36
        $this->className = $this->getClassName();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @return AbstractPluginManager
43
     */
44
    public function __invoke(ContainerInterface $container)
45
    {
46
        $config = $container->has('config') ? $container->get('config') : [];
47
48
        if (isset($config['dash'][$this->configKey]) && is_array($config['dash'][$this->configKey])) {
49
            return new $this->className($container, $config['dash'][$this->configKey]);
50
        }
51
52
        return new $this->className($container);
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    abstract protected function getConfigKey();
59
60
    /**
61
     * @return string
62
     */
63
    abstract protected function getClassName();
64
}
65