@@ -28,7 +28,7 @@ |
||
28 | 28 | public function getFilters() |
29 | 29 | { |
30 | 30 | return [ |
31 | - new \Twig_SimpleFilter('sizeFormat', [$this, 'size_format']), |
|
31 | + new \Twig_SimpleFilter('sizeFormat', [$this, 'size_format']), |
|
32 | 32 | ]; |
33 | 33 | } |
34 | 34 |
@@ -42,11 +42,11 @@ |
||
42 | 42 | */ |
43 | 43 | public function size_format($bytes, $decimals = 2, $octetFormat = false, $separator = '') |
44 | 44 | { |
45 | - $bytes = (int)$bytes; |
|
45 | + $bytes = (int) $bytes; |
|
46 | 46 | $sz = 'BKMGTP'; |
47 | 47 | $factor = floor((\strlen($bytes) - 1) / 3); |
48 | 48 | |
49 | - return sprintf("%.{$decimals}f", $bytes / (1024 ** $factor)) . $separator . @$sz[ $factor ] . ($factor ? ($octetFormat ? 'O' : 'B') : ''); |
|
49 | + return sprintf("%.{$decimals}f", $bytes / (1024 ** $factor)) . $separator . @$sz[$factor] . ($factor ? ($octetFormat ? 'O' : 'B') : ''); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -36,9 +36,9 @@ |
||
36 | 36 | public function __construct(\Twig_Node_Expression $annotation, \Twig_Node_Expression $keyInfo, \Twig_Node $body, $lineno, $tag = null) |
37 | 37 | { |
38 | 38 | parent::__construct([ |
39 | - 'key_info' => $keyInfo, |
|
40 | - 'body' => $body, |
|
41 | - 'annotation' => $annotation |
|
39 | + 'key_info' => $keyInfo, |
|
40 | + 'body' => $body, |
|
41 | + 'annotation' => $annotation |
|
42 | 42 | ], [], $lineno, $tag); |
43 | 43 | } |
44 | 44 |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | |
78 | 78 | if ($this->cacheCollector instanceof CacheCollector) { |
79 | 79 | $this->cacheCollector->setTwigCacheBlock($unprefixedKey, [ |
80 | - 'cacheHit' => $cacheData !== null, |
|
81 | - 'cacheTtl' => $key[ 'lifetime' ], |
|
82 | - 'cacheSize' => mb_strlen((string)$cacheData), |
|
83 | - 'cacheGenTime' => $generationTime, |
|
80 | + 'cacheHit' => $cacheData !== null, |
|
81 | + 'cacheTtl' => $key[ 'lifetime' ], |
|
82 | + 'cacheSize' => mb_strlen((string)$cacheData), |
|
83 | + 'cacheGenTime' => $generationTime, |
|
84 | 84 | ]); |
85 | 85 | } |
86 | 86 | |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | return [ |
104 | - 'lifetime' => $value, |
|
105 | - 'key' => $this->twigCachePrefix . $annotation, |
|
104 | + 'lifetime' => $value, |
|
105 | + 'key' => $this->twigCachePrefix . $annotation, |
|
106 | 106 | ]; |
107 | 107 | } |
108 | 108 | |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | |
116 | 116 | if ($this->cacheCollector instanceof CacheCollector) { |
117 | 117 | $this->cacheCollector->setTwigCacheBlock($unprefixedKey, [ |
118 | - 'cacheHit' => false, |
|
119 | - 'cacheTtl' => $key[ 'lifetime' ], |
|
120 | - 'cacheSize' => \mb_strlen((string)$block), |
|
121 | - 'cacheGenTime' => $generationTime, |
|
118 | + 'cacheHit' => false, |
|
119 | + 'cacheTtl' => $key[ 'lifetime' ], |
|
120 | + 'cacheSize' => \mb_strlen((string)$block), |
|
121 | + 'cacheGenTime' => $generationTime, |
|
122 | 122 | ]); |
123 | 123 | } |
124 | 124 |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | public function fetchBlock($key) |
72 | 72 | { |
73 | 73 | $generationTimeMc = microtime(true); |
74 | - $cacheData = $this->cache->fetch($key[ 'key' ]); |
|
74 | + $cacheData = $this->cache->fetch($key['key']); |
|
75 | 75 | $generationTime = microtime(true) - $generationTimeMc; |
76 | - $unprefixedKey = substr($key[ 'key' ], strlen($this->twigCachePrefix)); |
|
76 | + $unprefixedKey = substr($key['key'], strlen($this->twigCachePrefix)); |
|
77 | 77 | |
78 | 78 | if ($this->cacheCollector instanceof CacheCollector) { |
79 | 79 | $this->cacheCollector->setTwigCacheBlock($unprefixedKey, [ |
80 | 80 | 'cacheHit' => $cacheData !== null, |
81 | - 'cacheTtl' => $key[ 'lifetime' ], |
|
82 | - 'cacheSize' => mb_strlen((string)$cacheData), |
|
81 | + 'cacheTtl' => $key['lifetime'], |
|
82 | + 'cacheSize' => mb_strlen((string) $cacheData), |
|
83 | 83 | 'cacheGenTime' => $generationTime, |
84 | 84 | ]); |
85 | 85 | } |
86 | 86 | |
87 | - if (!empty($cacheData) && $this->config[ 'twig_block_debug' ]) { |
|
87 | + if (!empty($cacheData) && $this->config['twig_block_debug']) { |
|
88 | 88 | return "<!-- BEGIN CACHE BLOCK OUTPUT '{$unprefixedKey}' -->\n{$cacheData}\n<!-- // END CACHE BLOCK OUTPUT '{$unprefixedKey}' -->"; |
89 | 89 | } |
90 | 90 | |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function saveBlock($key, $block, $generationTime) |
113 | 113 | { |
114 | - $unprefixedKey = \substr($key[ 'key' ], \strlen($this->twigCachePrefix)); |
|
114 | + $unprefixedKey = \substr($key['key'], \strlen($this->twigCachePrefix)); |
|
115 | 115 | |
116 | 116 | if ($this->cacheCollector instanceof CacheCollector) { |
117 | 117 | $this->cacheCollector->setTwigCacheBlock($unprefixedKey, [ |
118 | 118 | 'cacheHit' => false, |
119 | - 'cacheTtl' => $key[ 'lifetime' ], |
|
120 | - 'cacheSize' => \mb_strlen((string)$block), |
|
119 | + 'cacheTtl' => $key['lifetime'], |
|
120 | + 'cacheSize' => \mb_strlen((string) $block), |
|
121 | 121 | 'cacheGenTime' => $generationTime, |
122 | 122 | ]); |
123 | 123 | } |
124 | 124 | |
125 | - return $this->cache->save($key[ 'key' ], $block, $key[ 'lifetime' ]); |
|
125 | + return $this->cache->save($key['key'], $block, $key['lifetime']); |
|
126 | 126 | } |
127 | 127 | } |
@@ -65,35 +65,35 @@ |
||
65 | 65 | } |
66 | 66 | $stats[ $instanceName ] = $cache->getStats(); |
67 | 67 | $instances[ $instanceName ] = [ |
68 | - 'driverName' => $cache->getDriverName(), |
|
69 | - 'configClassName' => \get_class( $cache->getConfig()), |
|
70 | - 'driverConfig' => $cache->getConfig()->toArray() |
|
68 | + 'driverName' => $cache->getDriverName(), |
|
69 | + 'configClassName' => \get_class( $cache->getConfig()), |
|
70 | + 'driverConfig' => $cache->getConfig()->toArray() |
|
71 | 71 | ]; |
72 | 72 | $driverUsed[ $cache->getDriverName() ] = \get_class($cache); |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->data = [ |
76 | - 'twigCacheBlocks' => $this->twig_cache_blocks, |
|
77 | - 'apiVersion' => PhpfastcacheApi::getVersion(), |
|
78 | - 'pfcVersion' => PhpfastcacheApi::getPhpFastCacheVersion(), |
|
79 | - 'bundleVersion' => phpFastCacheBundle::VERSION, |
|
80 | - 'apiChangelog' => PhpfastcacheApi::getChangelog(), |
|
81 | - 'driverUsed' => $driverUsed, |
|
82 | - 'instances' => $instances, |
|
83 | - 'stats' => $stats, |
|
84 | - 'size' => $size, |
|
85 | - 'hits' => [ |
|
76 | + 'twigCacheBlocks' => $this->twig_cache_blocks, |
|
77 | + 'apiVersion' => PhpfastcacheApi::getVersion(), |
|
78 | + 'pfcVersion' => PhpfastcacheApi::getPhpFastCacheVersion(), |
|
79 | + 'bundleVersion' => phpFastCacheBundle::VERSION, |
|
80 | + 'apiChangelog' => PhpfastcacheApi::getChangelog(), |
|
81 | + 'driverUsed' => $driverUsed, |
|
82 | + 'instances' => $instances, |
|
83 | + 'stats' => $stats, |
|
84 | + 'size' => $size, |
|
85 | + 'hits' => [ |
|
86 | 86 | 'read' => (int) CacheManager::$ReadHits, |
87 | 87 | 'write' => (int) CacheManager::$WriteHits, |
88 | - ], |
|
89 | - 'coreConfig' => [ |
|
88 | + ], |
|
89 | + 'coreConfig' => [ |
|
90 | 90 | 'driverList' => CacheManager::getDriverList(true), |
91 | 91 | 'namespacePath (deprecated)' => CacheManager::getNamespacePath(), |
92 | - ], |
|
93 | - 'projectConfig' => [ |
|
92 | + ], |
|
93 | + 'projectConfig' => [ |
|
94 | 94 | 'twig_driver' => $this->phpfastcache->getConfig()['twig_driver'], |
95 | 95 | 'twig_block_debug' => $this->phpfastcache->getConfig()['twig_block_debug'], |
96 | - ], |
|
96 | + ], |
|
97 | 97 | ]; |
98 | 98 | } |
99 | 99 |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | if ($cache->getStats()->getSize()) { |
64 | 64 | $size += $cache->getStats()->getSize(); |
65 | 65 | } |
66 | - $stats[ $instanceName ] = $cache->getStats(); |
|
67 | - $instances[ $instanceName ] = [ |
|
66 | + $stats[$instanceName] = $cache->getStats(); |
|
67 | + $instances[$instanceName] = [ |
|
68 | 68 | 'driverName' => $cache->getDriverName(), |
69 | - 'configClassName' => \get_class( $cache->getConfig()), |
|
69 | + 'configClassName' => \get_class($cache->getConfig()), |
|
70 | 70 | 'driverConfig' => $cache->getConfig()->toArray() |
71 | 71 | ]; |
72 | - $driverUsed[ $cache->getDriverName() ] = \get_class($cache); |
|
72 | + $driverUsed[$cache->getDriverName()] = \get_class($cache); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->data = [ |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function getStats(): array |
104 | 104 | { |
105 | - return $this->data[ 'stats' ] ?? []; |
|
105 | + return $this->data['stats'] ?? []; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getInstances(): array |
112 | 112 | { |
113 | - return $this->data[ 'instances' ]; |
|
113 | + return $this->data['instances']; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function getDriverUsed(): array |
120 | 120 | { |
121 | - return $this->data[ 'driverUsed' ] ?? []; |
|
121 | + return $this->data['driverUsed'] ?? []; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getHits(): array |
128 | 128 | { |
129 | - return $this->data[ 'hits' ] ?? []; |
|
129 | + return $this->data['hits'] ?? []; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function getSize(): int |
136 | 136 | { |
137 | - return $this->data[ 'size' ] ?? 0; |
|
137 | + return $this->data['size'] ?? 0; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function getCoreConfig(): array |
144 | 144 | { |
145 | - return $this->data[ 'coreConfig' ] ?? []; |
|
145 | + return $this->data['coreConfig'] ?? []; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function getProjectConfig(): array |
152 | 152 | { |
153 | - return $this->data[ 'projectConfig' ] ?? []; |
|
153 | + return $this->data['projectConfig'] ?? []; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function getApiVersion(): string |
160 | 160 | { |
161 | - return $this->data[ 'apiVersion' ]; |
|
161 | + return $this->data['apiVersion']; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function getPfcVersion(): string |
168 | 168 | { |
169 | - return $this->data[ 'pfcVersion' ]; |
|
169 | + return $this->data['pfcVersion']; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getBundleVersion(): string |
176 | 176 | { |
177 | - return $this->data[ 'bundleVersion' ]; |
|
177 | + return $this->data['bundleVersion']; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function getApiChangelog(): string |
184 | 184 | { |
185 | - return $this->data[ 'apiChangelog' ] ?? ''; |
|
185 | + return $this->data['apiChangelog'] ?? ''; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function setTwigCacheBlock($blockName, array $cacheBlock): self |
194 | 194 | { |
195 | - if(isset($this->twig_cache_blocks[$blockName])){ |
|
195 | + if (isset($this->twig_cache_blocks[$blockName])) { |
|
196 | 196 | $this->twig_cache_blocks[$blockName] = \array_merge($this->twig_cache_blocks[$blockName], $cacheBlock); |
197 | - }else{ |
|
197 | + } else { |
|
198 | 198 | $this->twig_cache_blocks[$blockName] = $cacheBlock; |
199 | 199 | } |
200 | 200 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function getTwigCacheBlocks(): array |
209 | 209 | { |
210 | - return $this->data[ 'twigCacheBlocks' ] ?? []; |
|
210 | + return $this->data['twigCacheBlocks'] ?? []; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -194,7 +194,7 @@ |
||
194 | 194 | { |
195 | 195 | if(isset($this->twig_cache_blocks[$blockName])){ |
196 | 196 | $this->twig_cache_blocks[$blockName] = \array_merge($this->twig_cache_blocks[$blockName], $cacheBlock); |
197 | - }else{ |
|
197 | + } else{ |
|
198 | 198 | $this->twig_cache_blocks[$blockName] = $cacheBlock; |
199 | 199 | } |
200 | 200 |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function createInstance(string $name, ExtendedCacheItemPoolInterface $instance) |
70 | 70 | { |
71 | - if (\array_key_exists($name, $this->cacheInstances) && $this->cacheInstances[ $name ] instanceof ExtendedCacheItemPoolInterface) { |
|
71 | + if (\array_key_exists($name, $this->cacheInstances) && $this->cacheInstances[$name] instanceof ExtendedCacheItemPoolInterface) { |
|
72 | 72 | throw new PhpfastcacheDriverException("Cache instance '{$name}' already exists"); |
73 | 73 | } |
74 | - $this->cacheInstances[ $name ] = $instance; |
|
74 | + $this->cacheInstances[$name] = $instance; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | if (!\array_key_exists($name, $this->cacheInstances)) { |
94 | - if (\array_key_exists($name, $this->config[ 'drivers' ])) { |
|
95 | - $driverClass = CacheManager::getDriverClass($this->config[ 'drivers' ][ $name ][ 'type' ]); |
|
96 | - if (\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)){ |
|
94 | + if (\array_key_exists($name, $this->config['drivers'])) { |
|
95 | + $driverClass = CacheManager::getDriverClass($this->config['drivers'][$name]['type']); |
|
96 | + if (\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) { |
|
97 | 97 | $configClass = $driverClass::getConfigClass(); |
98 | - if(\class_exists($configClass)){ |
|
98 | + if (\class_exists($configClass)) { |
|
99 | 99 | $this->createInstance( |
100 | 100 | $name, |
101 | 101 | CacheManager::getInstance( |
102 | - $this->config[ 'drivers' ][ $name ][ 'type' ], |
|
103 | - new $configClass($this->config[ 'drivers' ][ $name ][ 'parameters' ]) |
|
102 | + $this->config['drivers'][$name]['type'], |
|
103 | + new $configClass($this->config['drivers'][$name]['parameters']) |
|
104 | 104 | ) |
105 | 105 | ); |
106 | - }else{ |
|
106 | + } else { |
|
107 | 107 | throw new PhpfastcacheInvalidConfigurationException('Invalid configuration class name: ' . $configClass); |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - if (!isset($this->cacheInstances[ $name ]) || !($this->cacheInstances[ $name ] instanceof ExtendedCacheItemPoolInterface)) { |
|
111 | + if (!isset($this->cacheInstances[$name]) || !($this->cacheInstances[$name] instanceof ExtendedCacheItemPoolInterface)) { |
|
112 | 112 | throw new PhpfastcacheDriverException("Cache instance '{$name}' does not implements ExtendedCacheItemPoolInterface"); |
113 | 113 | } |
114 | 114 | } else { |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | if ($this->stopwatch) { |
120 | 120 | $this->stopwatch->stop(__METHOD__ . "('{$name}')"); |
121 | 121 | } |
122 | - return $this->cacheInstances[ $name ]; |
|
122 | + return $this->cacheInstances[$name]; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function getTwigCacheInstance(): ExtendedCacheItemPoolInterface |
129 | 129 | { |
130 | - return $this->get($this->config[ 'twig_driver' ]); |
|
130 | + return $this->get($this->config['twig_driver']); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |