Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 9c40c03

Browse files
committed
Finished Opcache optimizations & short array fixes
1 parent 0e62dfc commit 9c40c03

File tree

7 files changed

+101
-88
lines changed

7 files changed

+101
-88
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"symfony/console": "^3.4|^4.0",
3232
"symfony/dependency-injection": "^3.4|^4.0",
3333
"phpfastcache/phpfastcache": "^7.0",
34-
"php": "^7.0"
34+
"php": "^7.0",
35+
"ext-mbstring": "*",
36+
"ext-json": "*"
3537
},
3638
"suggest": {
3739
"symfony/web-profiler-bundle": "To use the data collector."

composer.lock

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DataCollector/CacheCollector.php

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CacheCollector extends DataCollector
2929
/**
3030
* @var \Phpfastcache\Bundle\Service\Phpfastcache
3131
*/
32-
private $cache;
32+
private $phpfastcache;
3333

3434
/**
3535
* @var array
@@ -39,11 +39,11 @@ class CacheCollector extends DataCollector
3939
/**
4040
* CacheCollector constructor.
4141
*
42-
* @param \Phpfastcache\Bundle\Service\Phpfastcache $cache
42+
* @param \Phpfastcache\Bundle\Service\Phpfastcache $phpfastcache
4343
*/
44-
public function __construct(Phpfastcache $cache)
44+
public function __construct(Phpfastcache $phpfastcache)
4545
{
46-
$this->cache = $cache;
46+
$this->phpfastcache = $phpfastcache;
4747
}
4848

4949
/**
@@ -59,7 +59,7 @@ public function collect(Request $request, Response $response, \Exception $except
5959
$driverUsed = [];
6060

6161
/** @var $cache */
62-
foreach ($this->cache->getInstances() as $instanceName => $cache) {
62+
foreach ($this->phpfastcache->getInstances() as $instanceName => $cache) {
6363
if ($cache->getStats()->getSize()) {
6464
$size += $cache->getStats()->getSize();
6565
}
@@ -91,109 +91,109 @@ public function collect(Request $request, Response $response, \Exception $except
9191
'namespacePath (deprecated)' => CacheManager::getNamespacePath(),
9292
],
9393
'projectConfig' => [
94-
'twig_driver' => $this->cache->getConfig()['twig_driver'],
95-
'twig_block_debug' => $this->cache->getConfig()['twig_block_debug'],
94+
'twig_driver' => $this->phpfastcache->getConfig()['twig_driver'],
95+
'twig_block_debug' => $this->phpfastcache->getConfig()['twig_block_debug'],
9696
],
9797
];
9898
}
9999

100100
/**
101-
* @return mixed
101+
* @return array
102102
*/
103-
public function getStats()
103+
public function getStats(): array
104104
{
105-
return $this->data[ 'stats' ];
105+
return $this->data[ 'stats' ] ?? [];
106106
}
107107

108108
/**
109-
* @return mixed
109+
* @return array
110110
*/
111-
public function getInstances()
111+
public function getInstances(): array
112112
{
113113
return $this->data[ 'instances' ];
114114
}
115115

116116
/**
117-
* @return mixed
117+
* @return array
118118
*/
119-
public function getDriverUsed()
119+
public function getDriverUsed(): array
120120
{
121-
return $this->data[ 'driverUsed' ];
121+
return $this->data[ 'driverUsed' ] ?? [];
122122
}
123123

124124
/**
125-
* @return mixed
125+
* @return array
126126
*/
127-
public function getHits()
127+
public function getHits(): array
128128
{
129-
return $this->data[ 'hits' ];
129+
return $this->data[ 'hits' ] ?? [];
130130
}
131131

132132
/**
133-
* @return mixed
133+
* @return int
134134
*/
135-
public function getSize()
135+
public function getSize(): int
136136
{
137-
return $this->data[ 'size' ];
137+
return $this->data[ 'size' ] ?? 0;
138138
}
139139

140140
/**
141-
* @return mixed
141+
* @return array
142142
*/
143-
public function getCoreConfig()
143+
public function getCoreConfig(): array
144144
{
145-
return $this->data[ 'coreConfig' ];
145+
return $this->data[ 'coreConfig' ] ?? [];
146146
}
147147

148148
/**
149-
* @return mixed
149+
* @return array
150150
*/
151-
public function getProjectConfig()
151+
public function getProjectConfig(): array
152152
{
153-
return $this->data[ 'projectConfig' ];
153+
return $this->data[ 'projectConfig' ] ?? [];
154154
}
155155

156156
/**
157-
* @return mixed
157+
* @return string
158158
*/
159-
public function getApiVersion()
159+
public function getApiVersion(): string
160160
{
161161
return $this->data[ 'apiVersion' ];
162162
}
163163

164164
/**
165-
* @return mixed
165+
* @return string
166166
*/
167-
public function getPfcVersion()
167+
public function getPfcVersion(): string
168168
{
169169
return $this->data[ 'pfcVersion' ];
170170
}
171171

172172
/**
173-
* @return mixed
173+
* @return string
174174
*/
175-
public function getBundleVersion()
175+
public function getBundleVersion(): string
176176
{
177177
return $this->data[ 'bundleVersion' ];
178178
}
179179

180180
/**
181-
* @return mixed
181+
* @return string
182182
*/
183-
public function getApiChangelog()
183+
public function getApiChangelog(): string
184184
{
185-
return $this->data[ 'apiChangelog' ];
185+
return $this->data[ 'apiChangelog' ] ?? '';
186186
}
187187

188188
/**
189189
* @param string $blockName
190190
* @param array $cacheBlock
191191
* @return $this
192192
*/
193-
public function setTwigCacheBlock($blockName, array $cacheBlock)
193+
public function setTwigCacheBlock($blockName, array $cacheBlock): self
194194
{
195195
if(isset($this->twig_cache_blocks[$blockName])){
196-
$this->twig_cache_blocks[$blockName] = array_merge($this->twig_cache_blocks[$blockName], $cacheBlock);
196+
$this->twig_cache_blocks[$blockName] = \array_merge($this->twig_cache_blocks[$blockName], $cacheBlock);
197197
}else{
198198
$this->twig_cache_blocks[$blockName] = $cacheBlock;
199199
}
@@ -205,21 +205,25 @@ public function setTwigCacheBlock($blockName, array $cacheBlock)
205205
/**
206206
* @return array
207207
*/
208-
public function getTwigCacheBlocks()
208+
public function getTwigCacheBlocks(): array
209209
{
210-
return $this->data[ 'twigCacheBlocks' ];
210+
return $this->data[ 'twigCacheBlocks' ] ?? [];
211211
}
212212

213213
/**
214-
* @return string
214+
* @inheritdoc
215215
*/
216-
public function getName()
216+
public function getName(): string
217217
{
218218
return 'phpfastcache';
219219
}
220220

221+
/**
222+
* @inheritdoc
223+
*/
221224
public function reset()
222225
{
223-
// TODO: Implement reset() method.
226+
$this->data = [];
227+
$this->twig_cache_blocks = [];
224228
}
225229
}

src/Service/Phpfastcache.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ class Phpfastcache
5252
*
5353
* @throws \Phpfastcache\Exceptions\phpFastCacheDriverException
5454
*/
55-
public function __construct($config, Stopwatch $stopwatch = null)
55+
public function __construct(array $config, Stopwatch $stopwatch = null)
5656
{
57-
$this->config = (array) $config;
57+
$this->config = $config;
5858
$this->stopwatch = $stopwatch;
5959
}
6060

@@ -66,7 +66,7 @@ public function __construct($config, Stopwatch $stopwatch = null)
6666
*
6767
* @throws \Phpfastcache\Exceptions\phpFastCacheDriverException
6868
*/
69-
public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
69+
public function createInstance(string $name, ExtendedCacheItemPoolInterface $instance)
7070
{
7171
if (\array_key_exists($name, $this->cacheInstances) && $this->cacheInstances[ $name ] instanceof ExtendedCacheItemPoolInterface) {
7272
throw new PhpfastcacheDriverException("Cache instance '{$name}' already exists");
@@ -84,7 +84,7 @@ public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
8484
* @throws \Phpfastcache\Exceptions\phpFastCacheDriverException
8585
* @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException
8686
*/
87-
public function get($name): ExtendedCacheItemPoolInterface
87+
public function get(string $name): ExtendedCacheItemPoolInterface
8888
{
8989
if ($this->stopwatch) {
9090
$this->stopwatch->start(__METHOD__ . "('{$name}')");

0 commit comments

Comments
 (0)