Completed
Branch develop (85a9c8)
by Anton
05:44
created

CacheConfig::defaultStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Cache\Configs;
9
10
use Spiral\Core\InjectableConfig;
11
use Spiral\Core\Traits\Config\AliasTrait;
12
13
/**
14
 * Cache component configuration manager.
15
 */
16
class CacheConfig extends InjectableConfig
17
{
18
    use AliasTrait;
19
20
    /**
21
     * Configuration section.
22
     */
23
    const CONFIG = 'cache';
24
25
    /**
26
     * @var array
27
     */
28
    protected $config = [
29
        'store'  => '',
30
        'stores' => []
31
    ];
32
33
    /**
34
     * @return string
35
     */
36
    public function defaultStore()
37
    {
38
        return $this->config['store'];
39
    }
40
41
    /**
42
     * @param string $store
43
     * @return bool
44
     */
45
    public function hasStore($store)
46
    {
47
        return isset($this->config['stores'][$store]);
48
    }
49
50
    /**
51
     * @param string $store
52
     * @return string
53
     */
54
    public function storeClass($store)
55
    {
56
        if (class_exists($store)) {
57
            //Legacy format support
58
            return $store;
59
        }
60
61
        return $this->config['stores'][$store]['class'];
62
    }
63
64
    /**
65
     * @param string $store
66
     * @return array
67
     */
68
    public function storeOptions($store)
69
    {
70
        return $this->config['stores'][$store];
71
    }
72
73
    /**
74
     * Detect store ID based on provided store class.
75
     *
76
     * @param \ReflectionClass $class
77
     * @return string|null
78
     */
79
    public function detectStore(\ReflectionClass $class)
80
    {
81
        foreach ($this->config['stores'] as $store => $options) {
82
            if ($options['class'] == $class->getName()) {
83
                return $store;
84
            }
85
        }
86
87
        return null;
88
    }
89
}