Completed
Push — master ( 3251d2...b9f4b9 )
by Walter
09:12
created

StorageFactory::loadContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code 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 3
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of phpab/phpab-module. (https://github.com/phpab/phpab-module)
4
 *
5
 * @link https://github.com/phpab/phpab-module for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab-module/master/LICENSE MIT
8
 */
9
10
namespace PhpAbModule\Service;
11
12
use PhpAb\Storage\Adapter\Cookie;
13
use PhpAb\Storage\Adapter\Runtime;
14
use PhpAb\Storage\Adapter\Session;
15
use PhpAb\Storage\Adapter\ZendSession;
16
use PhpAb\Storage\Storage;
17
use RuntimeException;
18
use Zend\ServiceManager\FactoryInterface;
19
use Zend\ServiceManager\ServiceLocatorInterface;
20
21
class StorageFactory implements FactoryInterface
22
{
23
    public function createService(ServiceLocatorInterface $serviceLocator)
24
    {
25
        $config = $serviceLocator->get('Config');
26
27
        if (array_key_exists('storage_options', $config['phpab'])) {
28
            $options = $config['phpab']['storage_options'];
29
        } else {
30
            $options = [];
31
        }
32
33
        switch ($config['phpab']['storage']) {
34
            case 'cookie':
35
                $adapter = new Cookie($options['name'], $options['ttl']);
36
                break;
37
38
            case 'runtime':
39
                $adapter = new Runtime();
40
                break;
41
42
            case 'session':
43
                $adapter = new ZendSession($options['name']);
44
                break;
45
46
            default:
47
                throw new RuntimeException('Invalid storage adapter set: ' . $config['phpab']['storage']);
48
        }
49
50
        return new Storage($adapter);
51
    }
52
53
    private function loadContainer(ServiceLocatorInterface $serviceLocator)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Unused Code introduced by
The parameter $serviceLocator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
    }
56
}
57