Completed
Push — master ( bdaae5...96cf96 )
by Tobias
02:12
created

ArrayFactory::configureOptionResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of php-cache organization.
5
 *
6
 * (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\AdapterBundle\Factory;
13
14
use Cache\Adapter\PHPArray\ArrayCachePool;
15
use Cache\Namespaced\NamespacedCachePool;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
class ArrayFactory extends AbstractAdapterFactory
22
{
23
    protected static $dependencies = [
24
        ['requiredClass' => 'Cache\Adapter\PHPArray\ArrayCachePool', 'packageName' => 'cache/array-adapter'],
25
    ];
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getAdapter(array $config)
31
    {
32
        $pool = new ArrayCachePool();
33
34
        if (null !== $config['pool_namespace']) {
35
            $pool = new NamespacedCachePool($pool, $config['pool_namespace']);
36
        }
37
38
        return $pool;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected static function configureOptionResolver(OptionsResolver $resolver)
45
    {
46
        parent::configureOptionResolver($resolver);
47
48
        $resolver->setDefaults(
49
          [
50
            'pool_namespace' => null,
51
          ]
52
        );
53
54
        $resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
55
    }
56
}
57