@@ -35,8 +35,7 @@ |
||
35 | 35 | * @return static |
36 | 36 | * @throws PhpfastcacheInvalidArgumentException |
37 | 37 | */ |
38 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
39 | - { |
|
38 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) { |
|
40 | 39 | if ($driver instanceof ClusterPoolInterface) { |
41 | 40 | $this->driver = $driver; |
42 | 41 |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | * @param AggregatablePoolInterface ...$driverPools |
54 | 54 | * @throws PhpfastcacheLogicException |
55 | 55 | */ |
56 | - public function __construct(string $clusterAggregatorName = '', AggregatablePoolInterface ...$driverPools) |
|
57 | - { |
|
56 | + public function __construct(string $clusterAggregatorName = '', AggregatablePoolInterface ...$driverPools) { |
|
58 | 57 | $clusterAggregatorName = trim($clusterAggregatorName); |
59 | 58 | if (empty($clusterAggregatorName)) { |
60 | 59 | try { |
61 | 60 | $clusterAggregatorName = 'cluster_' . \bin2hex(\random_bytes(15)); |
62 | - } catch (Exception $e) { |
|
61 | + } |
|
62 | + catch (Exception $e) { |
|
63 | 63 | $clusterAggregatorName = 'cluster_' . \str_shuffle(\spl_object_hash(new stdClass())); |
64 | 64 | } |
65 | 65 | } |
@@ -89,7 +89,8 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | $this->driverPools[$splHash] = $driverPool; |
92 | - } else { |
|
92 | + } |
|
93 | + else { |
|
93 | 94 | throw new PhpfastcacheLogicException('This pool has been already aggregated !'); |
94 | 95 | } |
95 | 96 | } |
@@ -129,7 +130,8 @@ discard block |
||
129 | 130 | $splHash = \spl_object_hash($driverPool); |
130 | 131 | if (isset($this->driverPools[$splHash])) { |
131 | 132 | unset($this->driverPools[$splHash]); |
132 | - } else { |
|
133 | + } |
|
134 | + else { |
|
133 | 135 | throw new PhpfastcacheLogicException('This pool was not aggregated !'); |
134 | 136 | } |
135 | 137 | } |
@@ -157,7 +159,8 @@ discard block |
||
157 | 159 | */ |
158 | 160 | $this->cluster->getEventManager()->dispatch('CacheClusterBuilt', $this, $this->cluster); |
159 | 161 | } |
160 | - } else { |
|
162 | + } |
|
163 | + else { |
|
161 | 164 | throw new PhpfastcacheInvalidArgumentException('Unknown cluster strategy'); |
162 | 165 | } |
163 | 166 |
@@ -66,8 +66,7 @@ discard block |
||
66 | 66 | * @throws PhpfastcacheInvalidConfigurationException |
67 | 67 | * @throws ReflectionException |
68 | 68 | */ |
69 | - public function __construct(string $clusterName, ExtendedCacheItemPoolInterface ...$driverPools) |
|
70 | - { |
|
69 | + public function __construct(string $clusterName, ExtendedCacheItemPoolInterface ...$driverPools) { |
|
71 | 70 | if (count($driverPools) < 2) { |
72 | 71 | throw new PhpfastcacheInvalidArgumentException('A cluster requires at least two pools to be working.'); |
73 | 72 | } |
@@ -101,8 +100,7 @@ discard block |
||
101 | 100 | /** |
102 | 101 | * @inheritDoc |
103 | 102 | */ |
104 | - public function getItems(array $keys = []) |
|
105 | - { |
|
103 | + public function getItems(array $keys = []) { |
|
106 | 104 | $items = []; |
107 | 105 | |
108 | 106 | foreach ($keys as $key) { |
@@ -118,8 +116,7 @@ discard block |
||
118 | 116 | /** |
119 | 117 | * @inheritDoc |
120 | 118 | */ |
121 | - public function deleteItems(array $keys) |
|
122 | - { |
|
119 | + public function deleteItems(array $keys) { |
|
123 | 120 | $hasDeletedOnce = false; |
124 | 121 | foreach ($this->clusterPools as $driverPool) { |
125 | 122 | if ($result = $driverPool->deleteItems($keys)) { |
@@ -133,8 +130,7 @@ discard block |
||
133 | 130 | /** |
134 | 131 | * @inheritDoc |
135 | 132 | */ |
136 | - public function saveDeferred(CacheItemInterface $item) |
|
137 | - { |
|
133 | + public function saveDeferred(CacheItemInterface $item) { |
|
138 | 134 | /** @var ExtendedCacheItemInterface $item */ |
139 | 135 | $hasSavedOnce = false; |
140 | 136 | foreach ($this->clusterPools as $driverPool) { |
@@ -39,8 +39,7 @@ |
||
39 | 39 | * @param CacheItemInterface $item |
40 | 40 | * @return null |
41 | 41 | */ |
42 | - protected function driverRead(CacheItemInterface $item) |
|
43 | - { |
|
42 | + protected function driverRead(CacheItemInterface $item) { |
|
44 | 43 | return null; |
45 | 44 | } |
46 | 45 |
@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @inheritDoc |
31 | 31 | */ |
32 | - public function getItem($key) |
|
33 | - { |
|
32 | + public function getItem($key) { |
|
34 | 33 | /** @var ExtendedCacheItemPoolInterface[] $poolsToResync */ |
35 | 34 | $poolsToResync = []; |
36 | 35 | /** @var ExtendedCacheItemInterface $item */ |
@@ -52,12 +51,14 @@ discard block |
||
52 | 51 | if ($item->get() != $poolItemData) { |
53 | 52 | $poolsToResync[] = $driverPool; |
54 | 53 | } |
55 | - } else { |
|
54 | + } |
|
55 | + else { |
|
56 | 56 | if ($item->get() !== $poolItemData) { |
57 | 57 | $poolsToResync[] = $driverPool; |
58 | 58 | } |
59 | 59 | } |
60 | - } else { |
|
60 | + } |
|
61 | + else { |
|
61 | 62 | $poolsToResync[] = $driverPool; |
62 | 63 | } |
63 | 64 | } |
@@ -81,8 +82,7 @@ discard block |
||
81 | 82 | /** |
82 | 83 | * @inheritDoc |
83 | 84 | */ |
84 | - public function hasItem($key) |
|
85 | - { |
|
85 | + public function hasItem($key) { |
|
86 | 86 | foreach ($this->clusterPools as $driverPool) { |
87 | 87 | $poolItem = $driverPool->getItem($key); |
88 | 88 | if ($poolItem->isHit()) { |
@@ -96,8 +96,7 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * @inheritDoc |
98 | 98 | */ |
99 | - public function clear() |
|
100 | - { |
|
99 | + public function clear() { |
|
101 | 100 | $hasClearedOnce = false; |
102 | 101 | foreach ($this->clusterPools as $driverPool) { |
103 | 102 | if ($result = $driverPool->clear()) { |
@@ -111,8 +110,7 @@ discard block |
||
111 | 110 | /** |
112 | 111 | * @inheritDoc |
113 | 112 | */ |
114 | - public function deleteItem($key) |
|
115 | - { |
|
113 | + public function deleteItem($key) { |
|
116 | 114 | $hasDeletedOnce = false; |
117 | 115 | foreach ($this->clusterPools as $driverPool) { |
118 | 116 | if ($result = $driverPool->deleteItem($key)) { |
@@ -126,8 +124,7 @@ discard block |
||
126 | 124 | /** |
127 | 125 | * @inheritDoc |
128 | 126 | */ |
129 | - public function save(CacheItemInterface $item) |
|
130 | - { |
|
127 | + public function save(CacheItemInterface $item) { |
|
131 | 128 | /** @var ExtendedCacheItemInterface $item */ |
132 | 129 | $hasSavedOnce = false; |
133 | 130 | foreach ($this->clusterPools as $driverPool) { |
@@ -143,8 +140,7 @@ discard block |
||
143 | 140 | /** |
144 | 141 | * @inheritDoc |
145 | 142 | */ |
146 | - public function saveDeferred(CacheItemInterface $item) |
|
147 | - { |
|
143 | + public function saveDeferred(CacheItemInterface $item) { |
|
148 | 144 | /** @var ExtendedCacheItemInterface $item */ |
149 | 145 | $hasSavedOnce = false; |
150 | 146 | foreach ($this->clusterPools as $driverPool) { |
@@ -160,8 +156,7 @@ discard block |
||
160 | 156 | /** |
161 | 157 | * @inheritDoc |
162 | 158 | */ |
163 | - public function commit() |
|
164 | - { |
|
159 | + public function commit() { |
|
165 | 160 | $hasCommitOnce = false; |
166 | 161 | foreach ($this->clusterPools as $driverPool) { |
167 | 162 | if ($result = $driverPool->commit()) { |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @inheritDoc |
32 | 32 | */ |
33 | - public function getItem($key) |
|
34 | - { |
|
33 | + public function getItem($key) { |
|
35 | 34 | /** @var ExtendedCacheItemInterface $item */ |
36 | 35 | $item = null; |
37 | 36 | $eCount = 0; |
@@ -45,7 +44,8 @@ discard block |
||
45 | 44 | break; |
46 | 45 | } |
47 | 46 | } |
48 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
47 | + } |
|
48 | + catch (PhpfastcacheExceptionInterface $e) { |
|
49 | 49 | $eCount++; |
50 | 50 | } |
51 | 51 | } |
@@ -60,8 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @inheritDoc |
62 | 62 | */ |
63 | - public function hasItem($key) |
|
64 | - { |
|
63 | + public function hasItem($key) { |
|
65 | 64 | $eCount = 0; |
66 | 65 | foreach ($this->clusterPools as $driverPool) { |
67 | 66 | try { |
@@ -69,7 +68,8 @@ discard block |
||
69 | 68 | if ($poolItem->isHit()) { |
70 | 69 | return true; |
71 | 70 | } |
72 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
71 | + } |
|
72 | + catch (PhpfastcacheExceptionInterface $e) { |
|
73 | 73 | $eCount++; |
74 | 74 | } |
75 | 75 | } |
@@ -84,8 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * @inheritDoc |
86 | 86 | */ |
87 | - public function clear() |
|
88 | - { |
|
87 | + public function clear() { |
|
89 | 88 | $hasClearedOnce = false; |
90 | 89 | $eCount = 0; |
91 | 90 | |
@@ -94,7 +93,8 @@ discard block |
||
94 | 93 | if ($result = $driverPool->clear()) { |
95 | 94 | $hasClearedOnce = $result; |
96 | 95 | } |
97 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
96 | + } |
|
97 | + catch (PhpfastcacheExceptionInterface $e) { |
|
98 | 98 | $eCount++; |
99 | 99 | } |
100 | 100 | } |
@@ -110,8 +110,7 @@ discard block |
||
110 | 110 | /** |
111 | 111 | * @inheritDoc |
112 | 112 | */ |
113 | - public function deleteItem($key) |
|
114 | - { |
|
113 | + public function deleteItem($key) { |
|
115 | 114 | $hasDeletedOnce = false; |
116 | 115 | $eCount = 0; |
117 | 116 | |
@@ -120,7 +119,8 @@ discard block |
||
120 | 119 | if ($result = $driverPool->deleteItem($key)) { |
121 | 120 | $hasDeletedOnce = $result; |
122 | 121 | } |
123 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
122 | + } |
|
123 | + catch (PhpfastcacheExceptionInterface $e) { |
|
124 | 124 | $eCount++; |
125 | 125 | } |
126 | 126 | } |
@@ -135,8 +135,7 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @inheritDoc |
137 | 137 | */ |
138 | - public function save(CacheItemInterface $item) |
|
139 | - { |
|
138 | + public function save(CacheItemInterface $item) { |
|
140 | 139 | /** @var ExtendedCacheItemInterface $item */ |
141 | 140 | $hasSavedOnce = false; |
142 | 141 | $eCount = 0; |
@@ -147,7 +146,8 @@ discard block |
||
147 | 146 | if ($result = $driverPool->save($poolItem)) { |
148 | 147 | $hasSavedOnce = $result; |
149 | 148 | } |
150 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
149 | + } |
|
150 | + catch (PhpfastcacheExceptionInterface $e) { |
|
151 | 151 | $eCount++; |
152 | 152 | } |
153 | 153 | } |
@@ -162,8 +162,7 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * @inheritDoc |
164 | 164 | */ |
165 | - public function saveDeferred(CacheItemInterface $item) |
|
166 | - { |
|
165 | + public function saveDeferred(CacheItemInterface $item) { |
|
167 | 166 | /** @var ExtendedCacheItemInterface $item */ |
168 | 167 | $hasSavedOnce = false; |
169 | 168 | foreach ($this->clusterPools as $driverPool) { |
@@ -179,8 +178,7 @@ discard block |
||
179 | 178 | /** |
180 | 179 | * @inheritDoc |
181 | 180 | */ |
182 | - public function commit() |
|
183 | - { |
|
181 | + public function commit() { |
|
184 | 182 | $hasCommitOnce = false; |
185 | 183 | $eCount = 0; |
186 | 184 | |
@@ -189,7 +187,8 @@ discard block |
||
189 | 187 | if ($result = $driverPool->commit()) { |
190 | 188 | $hasCommitOnce = $result; |
191 | 189 | } |
192 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
190 | + } |
|
191 | + catch (PhpfastcacheExceptionInterface $e) { |
|
193 | 192 | $eCount++; |
194 | 193 | } |
195 | 194 | } |
@@ -43,8 +43,7 @@ discard block |
||
43 | 43 | * @throws PhpfastcacheInvalidConfigurationException |
44 | 44 | * @throws ReflectionException |
45 | 45 | */ |
46 | - public function __construct(string $clusterName, ExtendedCacheItemPoolInterface ...$driverPools) |
|
47 | - { |
|
46 | + public function __construct(string $clusterName, ExtendedCacheItemPoolInterface ...$driverPools) { |
|
48 | 47 | if (\count($driverPools) !== 2) { |
49 | 48 | throw new PhpfastcacheInvalidArgumentException('A "master/slave" cluster requires exactly two pools to be working.'); |
50 | 49 | } |
@@ -55,8 +54,7 @@ discard block |
||
55 | 54 | /** |
56 | 55 | * @inheritDoc |
57 | 56 | */ |
58 | - public function getItem($key) |
|
59 | - { |
|
57 | + public function getItem($key) { |
|
60 | 58 | return $this->getStandardizedItem( |
61 | 59 | $this->makeOperation( |
62 | 60 | static function (ExtendedCacheItemPoolInterface $pool) use ($key) { |
@@ -72,11 +70,11 @@ discard block |
||
72 | 70 | * @return mixed |
73 | 71 | * @throws PhpfastcacheReplicationException |
74 | 72 | */ |
75 | - protected function makeOperation(callable $operation) |
|
76 | - { |
|
73 | + protected function makeOperation(callable $operation) { |
|
77 | 74 | try { |
78 | 75 | return $operation($this->getMasterPool()); |
79 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
76 | + } |
|
77 | + catch (PhpfastcacheExceptionInterface $e) { |
|
80 | 78 | try { |
81 | 79 | $this->eventManager->dispatch( |
82 | 80 | 'CacheReplicationSlaveFallback', |
@@ -84,7 +82,8 @@ discard block |
||
84 | 82 | \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'] |
85 | 83 | ); |
86 | 84 | return $operation($this->getSlavePool()); |
87 | - } catch (PhpfastcacheExceptionInterface $e) { |
|
85 | + } |
|
86 | + catch (PhpfastcacheExceptionInterface $e) { |
|
88 | 87 | throw new PhpfastcacheReplicationException('Master and Slave thrown an exception !'); |
89 | 88 | } |
90 | 89 | } |
@@ -109,8 +108,7 @@ discard block |
||
109 | 108 | /** |
110 | 109 | * @inheritDoc |
111 | 110 | */ |
112 | - public function hasItem($key) |
|
113 | - { |
|
111 | + public function hasItem($key) { |
|
114 | 112 | return $this->makeOperation( |
115 | 113 | static function (ExtendedCacheItemPoolInterface $pool) use ($key) { |
116 | 114 | return $pool->hasItem($key); |
@@ -121,8 +119,7 @@ discard block |
||
121 | 119 | /** |
122 | 120 | * @inheritDoc |
123 | 121 | */ |
124 | - public function clear() |
|
125 | - { |
|
122 | + public function clear() { |
|
126 | 123 | return $this->makeOperation( |
127 | 124 | static function (ExtendedCacheItemPoolInterface $pool) { |
128 | 125 | return $pool->clear(); |
@@ -133,8 +130,7 @@ discard block |
||
133 | 130 | /** |
134 | 131 | * @inheritDoc |
135 | 132 | */ |
136 | - public function deleteItem($key) |
|
137 | - { |
|
133 | + public function deleteItem($key) { |
|
138 | 134 | return $this->makeOperation( |
139 | 135 | static function (ExtendedCacheItemPoolInterface $pool) use ($key) { |
140 | 136 | return $pool->deleteItem($key); |
@@ -145,8 +141,7 @@ discard block |
||
145 | 141 | /** |
146 | 142 | * @inheritDoc |
147 | 143 | */ |
148 | - public function save(CacheItemInterface $item) |
|
149 | - { |
|
144 | + public function save(CacheItemInterface $item) { |
|
150 | 145 | return $this->makeOperation( |
151 | 146 | function (ExtendedCacheItemPoolInterface $pool) use ($item) { |
152 | 147 | $item->setHit(true); |
@@ -159,8 +154,7 @@ discard block |
||
159 | 154 | /** |
160 | 155 | * @inheritDoc |
161 | 156 | */ |
162 | - public function commit() |
|
163 | - { |
|
157 | + public function commit() { |
|
164 | 158 | return $this->makeOperation( |
165 | 159 | static function (ExtendedCacheItemPoolInterface $pool) { |
166 | 160 | return $pool->commit(); |
@@ -33,8 +33,7 @@ discard block |
||
33 | 33 | * @param ExtendedCacheItemPoolInterface ...$driverPools |
34 | 34 | * @throws ReflectionException |
35 | 35 | */ |
36 | - public function __construct(string $clusterName, ExtendedCacheItemPoolInterface ...$driverPools) |
|
37 | - { |
|
36 | + public function __construct(string $clusterName, ExtendedCacheItemPoolInterface ...$driverPools) { |
|
38 | 37 | (new ReflectionMethod(\get_parent_class(\get_parent_class($this)), __FUNCTION__)) |
39 | 38 | ->invoke($this, $clusterName, ...$driverPools); |
40 | 39 | $randomPool = $driverPools[\random_int(0, \count($driverPools) - 1)]; |
@@ -52,8 +51,7 @@ discard block |
||
52 | 51 | * @param callable $operation |
53 | 52 | * @return mixed |
54 | 53 | */ |
55 | - protected function makeOperation(callable $operation) |
|
56 | - { |
|
54 | + protected function makeOperation(callable $operation) { |
|
57 | 55 | return $operation($this->getMasterPool()); |
58 | 56 | } |
59 | 57 | } |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | * @throws PhpfastcacheInvalidConfigurationException |
96 | 96 | * @throws ReflectionException |
97 | 97 | */ |
98 | - public function __construct(...$args) |
|
99 | - { |
|
98 | + public function __construct(...$args) { |
|
100 | 99 | parent::__construct(...$args); |
101 | 100 | $array =& $this->getArray(); |
102 | 101 | |
@@ -117,7 +116,8 @@ discard block |
||
117 | 116 | foreach (\get_object_vars($this) as $property => $value) { |
118 | 117 | if (\array_key_exists($property, $array)) { |
119 | 118 | $this->$property = &$array[$property]; |
120 | - } else { |
|
119 | + } |
|
120 | + else { |
|
121 | 121 | $array[$property] = &$this->$property; |
122 | 122 | } |
123 | 123 | } |
@@ -134,7 +134,8 @@ discard block |
||
134 | 134 | */ |
135 | 135 | $value = $this->{\lcfirst(\substr($method, 3))}; |
136 | 136 | $this->{$method}($value); |
137 | - } catch (TypeError $e) { |
|
137 | + } |
|
138 | + catch (TypeError $e) { |
|
138 | 139 | $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); |
139 | 140 | $reflectionMethod = new ReflectionMethod($this, $method); |
140 | 141 | $parameter = $reflectionMethod->getParameters()[0] ?? null; |
@@ -158,8 +159,7 @@ discard block |
||
158 | 159 | * @param string $optionName |
159 | 160 | * @return mixed|null |
160 | 161 | */ |
161 | - public function isValidOption(string $optionName) |
|
162 | - { |
|
162 | + public function isValidOption(string $optionName) { |
|
163 | 163 | return property_exists($this, $optionName); |
164 | 164 | } |
165 | 165 | |
@@ -220,8 +220,7 @@ discard block |
||
220 | 220 | /** |
221 | 221 | * @return Callable|string |
222 | 222 | */ |
223 | - public function getDefaultKeyHashFunction() |
|
224 | - { |
|
223 | + public function getDefaultKeyHashFunction() { |
|
225 | 224 | return $this->defaultKeyHashFunction; |
226 | 225 | } |
227 | 226 | |
@@ -242,8 +241,7 @@ discard block |
||
242 | 241 | /** |
243 | 242 | * @return Callable|string |
244 | 243 | */ |
245 | - public function getDefaultFileNameHashFunction() |
|
246 | - { |
|
244 | + public function getDefaultFileNameHashFunction() { |
|
247 | 245 | return $this->defaultFileNameHashFunction; |
248 | 246 | } |
249 | 247 |