|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
namespace Paymaxi\Component\CircuitBreaker\Storage\Adapter; |
|
6
|
|
|
|
|
7
|
|
|
use Paymaxi\Component\CircuitBreaker\Storage\StorageInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Does not really persist stats between requests! |
|
11
|
|
|
* |
|
12
|
|
|
* Can only be used for tests and as fallback instance. |
|
13
|
|
|
* |
|
14
|
|
|
* When real storage handler throws exception it means it cant be used any more. |
|
15
|
|
|
* Then storage user can safely fallback to this dummy instance. |
|
16
|
|
|
* |
|
17
|
|
|
* @see \Paymaxi\Component\CircuitBreaker\Storage\StorageInterface |
|
18
|
|
|
* @package Paymaxi\Component\CircuitBreaker\Components |
|
19
|
|
|
*/ |
|
20
|
|
|
final class DummyAdapter implements StorageInterface |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var mixed[] Array of all the values (transient) |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $data = array(); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Loads circuit breaker service status value. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $serviceName name of service to load stats for |
|
32
|
|
|
* @param string $attributeName name of attribute to load |
|
33
|
|
|
* |
|
34
|
|
|
* @return string value stored or '' if value was not found |
|
35
|
|
|
*/ |
|
36
|
13 |
|
public function loadStatus($serviceName, $attributeName) |
|
37
|
|
|
{ |
|
38
|
13 |
|
if (isset($this->data[$serviceName][$attributeName])) { |
|
39
|
11 |
|
return $this->data[$serviceName][$attributeName]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
11 |
|
return ""; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Saves circuit breaker service status value. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $serviceName name of service to load stats for |
|
49
|
|
|
* @param string $attributeName name of the attribute to load |
|
50
|
|
|
* @param string $value string value loaded or '' if nothing found |
|
51
|
|
|
* @param boolean $flush set to true will force immediate save, false does not guaranteed saving at all. |
|
52
|
|
|
* |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
11 |
|
public function saveStatus($serviceName, $attributeName, $value, $flush = false) |
|
56
|
|
|
{ |
|
57
|
11 |
|
$this->data[$serviceName][$attributeName] = $value; |
|
58
|
11 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |