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

Commit ec40779

Browse files
committed
More Opcache optimizations...
1 parent e2eaf16 commit ec40779

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/Command/PhpfastcacheCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070
$caches = $this->getContainer()->getParameter('phpfastcache');
7171

7272
if($driver) {
73-
if(array_key_exists($driver, $caches['drivers'])){
73+
if(\array_key_exists($driver, $caches['drivers'])){
7474
$callback($driver);
75-
if(!count($failedInstances)){
75+
if(!\count($failedInstances)){
7676
$io->success("Cache instance {$driver} cleared");
7777
}else{
7878
$io->error("Cache instance {$driver} not cleared");
@@ -84,10 +84,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484
foreach($caches['drivers'] as $name => $parameters) {
8585
$callback($name);
8686
}
87-
if(!count($failedInstances)){
87+
if(!\count($failedInstances)){
8888
$io->success('All caches instances got cleared');
8989
}else{
90-
$io->success('Almost all caches instances got cleared, except these: ' . implode(', ', $failedInstances));
90+
$io->success('Almost all caches instances got cleared, except these: ' . \implode(', ', $failedInstances));
9191
}
9292
}
9393
}

src/DataCollector/CacheCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function collect(Request $request, Response $response, \Exception $except
6969
'configClassName' => \get_class( $cache->getConfig()),
7070
'driverConfig' => $cache->getConfig()->toArray()
7171
];
72-
$driverUsed[ $cache->getDriverName() ] = get_class($cache);
72+
$driverUsed[ $cache->getDriverName() ] = \get_class($cache);
7373
}
7474

7575
$this->data = [

src/Service/Phpfastcache.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __construct($config, Stopwatch $stopwatch = null)
6868
*/
6969
public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
7070
{
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) {
7272
throw new PhpfastcacheDriverException("Cache instance '{$name}' already exists");
7373
}
7474
$this->cacheInstances[ $name ] = $instance;
@@ -79,21 +79,21 @@ public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
7979
*
8080
* @param string $name Name of configured driver
8181
*
82-
* @return \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface
82+
* @return ExtendedCacheItemPoolInterface
8383
*
8484
* @throws \Phpfastcache\Exceptions\phpFastCacheDriverException
8585
* @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException
8686
*/
87-
public function get($name)
87+
public function get($name): ExtendedCacheItemPoolInterface
8888
{
8989
if ($this->stopwatch) {
9090
$this->stopwatch->start(__METHOD__ . "('{$name}')");
9191
}
9292

93-
if (!array_key_exists($name, $this->cacheInstances)) {
94-
if (array_key_exists($name, $this->config[ 'drivers' ])) {
93+
if (!\array_key_exists($name, $this->cacheInstances)) {
94+
if (\array_key_exists($name, $this->config[ 'drivers' ])) {
9595
$driverClass = CacheManager::getDriverClass($this->config[ 'drivers' ][ $name ][ 'type' ]);
96-
if (is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)){
96+
if (\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)){
9797
$configClass = $driverClass::getConfigClass();
9898
if(\class_exists($configClass)){
9999
$this->createInstance(
@@ -125,7 +125,7 @@ public function get($name)
125125
/**
126126
* @return \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface
127127
*/
128-
public function getTwigCacheInstance()
128+
public function getTwigCacheInstance(): ExtendedCacheItemPoolInterface
129129
{
130130
return $this->get($this->config[ 'twig_driver' ]);
131131
}
@@ -135,7 +135,7 @@ public function getTwigCacheInstance()
135135
*
136136
* @return array
137137
*/
138-
public function getConfig()
138+
public function getConfig(): array
139139
{
140140
return $this->config;
141141
}
@@ -145,7 +145,7 @@ public function getConfig()
145145
*
146146
* @return \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface[]
147147
*/
148-
public function getInstances()
148+
public function getInstances(): array
149149
{
150150
return $this->cacheInstances;
151151
}

src/Twig/CacheExtension/Extension.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function getCacheStrategy()
4747
*/
4848
public function getName()
4949
{
50-
if (version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) {
51-
return get_class($this);
50+
if (\version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) {
51+
return \get_class($this);
5252
}
5353
return 'phpfastcache_cache';
5454
}
@@ -58,8 +58,8 @@ public function getName()
5858
*/
5959
public function getTokenParsers()
6060
{
61-
return array(
62-
new TokenParser\Cache(),
63-
);
61+
return [
62+
new TokenParser\Cache(),
63+
];
6464
}
6565
}

src/Twig/CacheExtension/Node/CacheNode.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function compile(\Twig_Compiler $compiler)
4545
{
4646
$i = self::$cacheCount++;
4747

48-
if (version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) {
48+
if (\version_compare(\Twig_Environment::VERSION, '1.26.0', '>=')) {
4949
$extension = \Phpfastcache\Bundle\Twig\CacheExtension\Extension::class;
5050
} else {
5151
$extension = 'phpfastcache_cache';
@@ -62,15 +62,15 @@ public function compile(\Twig_Compiler $compiler)
6262
->write("\$phpfastcacheCacheBody".$i." = \$phpfastcacheCacheStrategy".$i."->fetchBlock(\$phpfastcacheKey".$i.");\n")
6363
->write("if (\$phpfastcacheCacheBody".$i." === false) {\n")
6464
->indent()
65-
->write("ob_start();\n")
66-
->write("\$compileMc = microtime(true);\n")
65+
->write("\\ob_start();\n")
66+
->write("\$compileMc = \\microtime(true);\n")
6767
->indent()
6868
->subcompile($this->getNode('body'))
6969
->outdent()
7070
->write("\n")
7171
// ->write("sleep(2);\n") // For debug purpose
72-
->write("\$phpfastcacheCacheBody".$i." = ob_get_clean();\n")
73-
->write("\$phpfastcacheCacheStrategy".$i."->saveBlock(\$phpfastcacheKey".$i.", \$phpfastcacheCacheBody".$i.", microtime(true) - \$compileMc);\n")
72+
->write("\$phpfastcacheCacheBody".$i." = \\ob_get_clean();\n")
73+
->write("\$phpfastcacheCacheStrategy".$i."->saveBlock(\$phpfastcacheKey".$i.", \$phpfastcacheCacheBody".$i.", \\microtime(true) - \$compileMc);\n")
7474
->outdent()
7575
->write("}\n")
7676
->write("echo \$phpfastcacheCacheBody".$i.";\n")

0 commit comments

Comments
 (0)