1 | <?php |
||
19 | class Cerberus implements CerberusInterface |
||
20 | { |
||
21 | /** |
||
22 | * The storage object. |
||
23 | * |
||
24 | * @var \Zend\Cache\Storage\StorageInterface |
||
25 | */ |
||
26 | private $storage; |
||
27 | |||
28 | /** |
||
29 | * Maximum number of failures to open the circuit. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | private $maxFailures; |
||
34 | |||
35 | /** |
||
36 | * Number of seconds to change from OPEN to HALF OPEN and try the connection again. |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | private $timeout; |
||
41 | |||
42 | /** |
||
43 | * The default namespace used by the zend-cache storage. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $defaultNamespace; |
||
48 | |||
49 | /** |
||
50 | * Constructor. |
||
51 | * |
||
52 | * @param StorageInterface $storage The storage object |
||
53 | * @param int $maxFailures Maximum number of failures to open the circuit |
||
54 | * @param int $timeout Number of seconds to change from OPEN to HALF OPEN |
||
55 | */ |
||
56 | public function __construct(StorageInterface $storage, $maxFailures = 5, $timeout = 30) |
||
57 | { |
||
58 | $this->maxFailures = (int) $maxFailures; |
||
59 | $this->timeout = (int) $timeout; |
||
60 | $this->storage = $storage; |
||
61 | $this->defaultNamespace = $this->storage->getOptions()->getNamespace(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | * |
||
67 | * @see \Cerberus\CerberusInterface::isAvailable() |
||
68 | */ |
||
69 | public function isAvailable($serviceName = null) |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | * |
||
77 | * @see \Cerberus\CerberusInterface::getStatus() |
||
78 | */ |
||
79 | public function getStatus($serviceName = null) |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | * |
||
121 | * @see \Cerberus\CerberusInterface::reportFailure() |
||
122 | */ |
||
123 | public function reportFailure($serviceName = null) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | * |
||
132 | * @see \Cerberus\CerberusInterface::reportSuccess() |
||
133 | */ |
||
134 | public function reportSuccess($serviceName = null) |
||
139 | |||
140 | /** |
||
141 | * Sets the zend-cache storage namespace. |
||
142 | * |
||
143 | * @param string $serviceName |
||
144 | */ |
||
145 | private function setNamespace($serviceName = null) |
||
153 | } |
||
154 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.