createService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 Adlogix\Zf2Rollout\Storage\ZendDbAdapterStorage;
16
use Interop\Container\ContainerInterface;
17
use Zend\Db\Adapter\Adapter;
18
use Zend\ServiceManager\FactoryInterface;
19
use Zend\ServiceManager\ServiceLocatorInterface;
20
21
class RolloutZendDbAdapterStorageFactory implements FactoryInterface
22
{
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
        $rolloutConfig = $container->get('zf2_rollout_config');
38
39
        if (!isset($rolloutConfig['zend_db_storage']['table_name'])) {
40
            throw new \RuntimeException('Missing table_name config when using zend db storage!');
41
        }
42
43
        /** @var Adapter $adapter */
44
        $adapter = $container->get('Zend\Db\Adapter\Adapter');
45
46
        return new ZendDbAdapterStorage($adapter, $rolloutConfig['zend_db_storage']['table_name']);
47
    }
48
}