Completed
Push — master ( 0a5bf7...5f5ea6 )
by Alexander
03:45
created

RoutesCacheDecorator::setPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Class for routes config caching
4
 *
5
 * @file      RoutesCacheDecorator.php
6
 *
7
 * PHP version 5.6+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2016 Alexander Yancharuk
11
 * @date      2015-05-24 20:14
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Routing;
17
18
use Veles\Cache\Cache;
19
20
/**
21
 * Class RoutesCacheDecorator
22
 * @author  Yancharuk Alexander <alex at itvault dot info>
23
 */
24
class RoutesCacheDecorator extends AbstractRoutesConfig
25
{
26
	protected $config;
27
	/** @var  string */
28
	protected $prefix;
29
30 1
	public function __construct(RoutesConfig $config)
31
	{
32 1
		$this->config = $config;
33 1
	}
34
35
	/**
36
	 * Returns array that contains routes configuration
37
	 *
38
	 * @return array
39
	 */
40 1
	public function getData()
41
	{
42 1
		if (false !== ($data = Cache::get($this->getPrefix()))) {
43 1
			return $data;
44
		}
45
46 1
		$data = $this->config->getData();
47 1
		Cache::set($this->getPrefix(), $data);
48
49 1
		return $data;
50
	}
51
52
	/**
53
	 * @return string
54
	 */
55 1
	public function getPrefix()
56
	{
57 1
		return $this->prefix;
58
	}
59
60
	/**
61
	 * @param string $prefix
62
	 */
63 2
	public function setPrefix($prefix)
64
	{
65 2
		$this->prefix = $prefix;
66 2
	}
67
68
	/**
69
	 * Returns array that contains routes configuration
70
	 *
71
	 * @param string $name Name of section
72
	 *
73
	 * @return array
74
	 */
75
	public function getSection($name)
76
	{
77
		$this->config->getSection($name);
78
	}
79
}
80