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

CacheConfig   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 74
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultStore() 0 4 1
A hasStore() 0 4 1
A storeClass() 0 9 2
A storeOptions() 0 4 1
A detectStore() 0 10 3
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
}