1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HtaccessCapabilityTester; |
4
|
|
|
|
5
|
|
|
use \HtaccessCapabilityTester\Testers\AbstractTester; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class caching test results |
9
|
|
|
* |
10
|
|
|
* @package HtaccessCapabilityTester |
11
|
|
|
* @author Bjørn Rosell <[email protected]> |
12
|
|
|
* @since Class available since the beginning |
13
|
|
|
*/ |
14
|
|
|
class TestResultCache |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/* @var array Array for caching */ |
18
|
|
|
protected static $cache; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
* @param array $cacheKeys Two keys for caching (usually: basedir and the getCacheKey() for the Tester) |
23
|
|
|
* @param TestResult $testResult The test result to cache |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
35 |
|
public static function cache($cacheKeys, $testResult) |
28
|
|
|
{ |
29
|
35 |
|
if (!isset(self::$cache)) { |
30
|
35 |
|
self::$cache = []; |
31
|
|
|
} |
32
|
35 |
|
list($key1, $key2) = $cacheKeys; |
33
|
35 |
|
if (!isset(self::$cache[$key1])) { |
34
|
35 |
|
self::$cache[$key1] = []; |
35
|
|
|
} |
36
|
35 |
|
self::$cache[$key1][$key2] = $testResult; |
37
|
35 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Check if in cache. |
41
|
|
|
* |
42
|
|
|
* @param array $cacheKeys Keys for caching (usually: basedir and the getCacheKey() for the Tester) |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
35 |
|
public static function isCached($cacheKeys) |
47
|
|
|
{ |
48
|
35 |
|
if (!isset(self::$cache)) { |
49
|
35 |
|
return false; |
50
|
|
|
} |
51
|
21 |
|
list($key1, $key2) = $cacheKeys; |
52
|
21 |
|
if (!isset(self::$cache[$key1])) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
21 |
|
if (!isset(self::$cache[$key1][$key2])) { |
56
|
21 |
|
return false; |
57
|
|
|
} |
58
|
18 |
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get from cache. |
63
|
|
|
* |
64
|
|
|
* @param array $cacheKeys Keys for caching (usually: basedir and the getCacheKey() for the Tester) |
65
|
|
|
* |
66
|
|
|
* @return TestResult The test result |
67
|
|
|
*/ |
68
|
18 |
|
public static function getCached($cacheKeys) |
69
|
|
|
{ |
70
|
18 |
|
if (!self::isCached($cacheKeys)) { |
71
|
|
|
throw new \Exception('Not in cache'); |
72
|
|
|
} |
73
|
18 |
|
list($key1, $key2) = $cacheKeys; |
74
|
18 |
|
return self::$cache[$key1][$key2]; |
75
|
|
|
} |
76
|
|
|
|
77
|
80 |
|
public static function clear() |
78
|
|
|
{ |
79
|
80 |
|
self::$cache = null; |
80
|
80 |
|
} |
81
|
|
|
} |
82
|
|
|
|