RolloutStorageFactory::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 3
nop 3
1
<?php
2
/*
3
 * This file is part of the Adlogix package.
4
 *
5
 * (c) Allan Segebarth <[email protected]>
6
 * (c) Jean-Jacques Courtens <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Adlogix\Zf2Rollout\Service\Factory;
13
14
15
use Interop\Container\ContainerInterface;
16
use Opensoft\Rollout\Storage\StorageInterface;
17
use Zend\ServiceManager\FactoryInterface;
18
use Zend\ServiceManager\ServiceLocatorInterface;
19
20
class RolloutStorageFactory implements FactoryInterface
21
{
22
    private static $storage_service = 'storage_service';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function createService(ServiceLocatorInterface $serviceLocator)
28
    {
29
        return $this($serviceLocator, null);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
36
    {
37
        /** @var array $config */
38
        $config = $container->get('zf2_rollout_config');
39
40
        if (!isset($config[self::$storage_service]) || $config[self::$storage_service] === '') {
41
            throw new \RuntimeException('No "' . self::$storage_service . '" defined in the rollout configuration!"');
42
        }
43
44
        $storage = $container->get($config[self::$storage_service]);
45
46
        if (!$storage instanceof StorageInterface) {
47
            throw new \RuntimeException(sprintf('The "' . self::$storage_service . '" should be an instance of StorageInterface but was %s',
48
                get_class($storage)));
49
        }
50
51
        return $storage;
52
    }
53
}