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

Commit d6e6366

Browse files
committed
Fixed deprecated primitive array passed to CacheManager
1 parent eec9706 commit d6e6366

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"symfony/framework-bundle": "^3.4|^4.0",
3131
"symfony/console": "^3.4|^4.0",
3232
"symfony/dependency-injection": "^3.4|^4.0",
33-
"phpfastcache/phpfastcache": "^7.0"
33+
"phpfastcache/phpfastcache": "^7.0",
34+
"php": "^7.0"
3435
},
3536
"suggest": {
3637
"symfony/web-profiler-bundle": "To use the data collector."

src/DataCollector/CacheCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public function collect(Request $request, Response $response, \Exception $except
6666
$stats[ $instanceName ] = $cache->getStats();
6767
$instances[ $instanceName ] = [
6868
'driverName' => $cache->getDriverName(),
69-
'driverConfig' => $cache->getConfig()->toArray(),
69+
'configClassName' => \get_class( $cache->getConfig()),
70+
'driverConfig' => $cache->getConfig()->toArray()
7071
];
7172
$driverUsed[ $cache->getDriverName() ] = get_class($cache);
7273
}

src/Resources/views/Collector/cache.html.twig

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@
129129
<th title="The driver name with the namespace used">
130130
<abbr>Driver Name</abbr>
131131
</th>
132-
<td><strong>{{ collector.instances[name].driverName }}</strong> (
133-
<small><code>{{ collector.driverUsed[collector.instances[name].driverName] }}</code>
134-
</small>
135-
)
132+
<td><strong title="{{ collector.driverUsed[collector.instances[name].driverName] }}"><abbr>{{ collector.instances[name].driverName }}</abbr></strong>
136133
</td>
137134
</tr>
138135
<tr>
@@ -162,10 +159,20 @@
162159
<td>{{ dump(stat.rawData) }}</td>
163160
</tr>
164161
<tr>
162+
165163
<th title="The configuration that was used to setup the driver instance">
166-
<abbr>Driver Config</abbr>
164+
<abbr>Driver Configuration</abbr>
167165
</th>
168-
<td>{{ dump(collector.instances[name].driverConfig) }}</td>
166+
<td>
167+
<div>
168+
<strong>Class: </strong>
169+
<span>{{ collector.instances[name].configClassName }}</span>
170+
</div>
171+
<div>
172+
<strong>Values: </strong>
173+
<div>{{ dump(collector.instances[name].driverConfig) }}</div>
174+
</div>
175+
</td>
169176
</tr>
170177
</tbody>
171178
</table>

src/Service/Phpfastcache.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
1919
use Phpfastcache\CacheManager;
2020
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
21+
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
2122
use Symfony\Component\Stopwatch\Stopwatch;
2223

2324
/**
@@ -81,6 +82,7 @@ public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
8182
* @return \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface
8283
*
8384
* @throws \Phpfastcache\Exceptions\phpFastCacheDriverException
85+
* @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException
8486
*/
8587
public function get($name)
8688
{
@@ -90,11 +92,23 @@ public function get($name)
9092

9193
if (!array_key_exists($name, $this->cacheInstances)) {
9294
if (array_key_exists($name, $this->config[ 'drivers' ])) {
93-
/**
94-
* @todo Implement new config Object here
95-
*/
96-
$this->createInstance($name, CacheManager::getInstance($this->config[ 'drivers' ][ $name ][ 'type' ], $this->config[ 'drivers' ][ $name ][ 'parameters' ]));
97-
if (!$this->cacheInstances[ $name ] instanceof ExtendedCacheItemPoolInterface) {
95+
$driverClass = CacheManager::getDriverClass($this->config[ 'drivers' ][ $name ][ 'type' ]);
96+
if (is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)){
97+
$configClass = $driverClass::getConfigClass();
98+
if(\class_exists($configClass)){
99+
$this->createInstance(
100+
$name,
101+
CacheManager::getInstance(
102+
$this->config[ 'drivers' ][ $name ][ 'type' ],
103+
new $configClass($this->config[ 'drivers' ][ $name ][ 'parameters' ])
104+
)
105+
);
106+
}else{
107+
throw new PhpfastcacheInvalidConfigurationException('Invalid configuration class name: ' . $configClass);
108+
}
109+
}
110+
111+
if (!isset($this->cacheInstances[ $name ]) || !($this->cacheInstances[ $name ] instanceof ExtendedCacheItemPoolInterface)) {
98112
throw new PhpfastcacheDriverException("Cache instance '{$name}' does not implements ExtendedCacheItemPoolInterface");
99113
}
100114
} else {

0 commit comments

Comments
 (0)