Total Complexity | 8 |
Total Lines | 71 |
Duplicated Lines | 0 % |
Coverage | 94.44% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | trait HasStoresTrait |
||
13 | { |
||
14 | /** |
||
15 | * The array of resolved cache stores. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $stores = []; |
||
20 | |||
21 | /** |
||
22 | * Get a cache store instance by name. |
||
23 | * |
||
24 | * @param string|null $name |
||
25 | * @return Repository |
||
26 | */ |
||
27 | 3 | public function store($name = null) |
|
28 | { |
||
29 | 3 | $name = $name ?: $this->getDefaultStore(); |
|
30 | 3 | return $this->getStore($name); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * Get the default cache driver name. |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | 2 | public function getDefaultStore() |
|
39 | { |
||
40 | 2 | return $this->getConfig('default', 'file'); |
|
|
|||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Attempt to get the store from the local cache. |
||
45 | * |
||
46 | * @param string $name |
||
47 | * @return Repository |
||
48 | */ |
||
49 | 2 | protected function getStore($name) |
|
50 | { |
||
51 | 2 | $this->stores[$name] = $this->stores[$name] ?? $this->resolve($name); |
|
52 | 2 | return $this->stores[$name]; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param $name |
||
57 | * @return Repository |
||
58 | */ |
||
59 | 2 | protected function resolve($name) |
|
73 | ); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param $driver |
||
78 | * @return Repository |
||
79 | */ |
||
80 | 2 | protected function repository($driver) |
|
83 | } |
||
84 | } |
||
85 |