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

Commit 64a17cc

Browse files
committed
Added php7 strict support + Filename in profiler
1 parent 7c7d16a commit 64a17cc

File tree

13 files changed

+28
-11
lines changed

13 files changed

+28
-11
lines changed

src/Command/PhpfastcacheCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1414
*
1515
*/
16+
declare(strict_types=1);
1617

1718
namespace Phpfastcache\Bundle\Command;
1819

src/DataCollector/CacheCollector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1414
*
1515
*/
16+
declare(strict_types=1);
1617

1718
namespace Phpfastcache\Bundle\DataCollector;
1819

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1414
*
1515
*/
16+
declare(strict_types=1);
1617

1718
namespace Phpfastcache\Bundle\DependencyInjection;
1819

src/DependencyInjection/PhpfastcacheExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1414
*
1515
*/
16+
declare(strict_types=1);
1617

1718
namespace Phpfastcache\Bundle\DependencyInjection;
1819

src/PhpfastcacheBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1313
*
1414
*/
15+
declare(strict_types=1);
1516

1617
namespace Phpfastcache\Bundle;
1718

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
<thead>
232232
<tr>
233233
<th class="key" scope="col">Block ID</th>
234+
<th scope="col"><abbr title="The Twig file where the CACHE/ENDCACHE tags resides">File</abbr></th>
234235
<th scope="col"><abbr title="Displays if the data comes from the cache (Yes) or from the template itself (No)">Cache Hit</abbr></th>
235236
<th scope="col">Size</th>
236237
<th scope="col"><abbr title="In seconds">Time to Live (ttl)</abbr></th>
@@ -240,7 +241,8 @@
240241
<tbody>
241242
{% for key, block in collector.twigCacheBlocks %}
242243
<tr>
243-
<th>{{ key }}</th>
244+
<td><strong>{{ key }}</strong></td>
245+
<td><span>In </span><abbr><span title="{{ block.cacheFilePath }}">{{ block.cacheFileName }}</span></abbr></td>
244246
<th style="background-color: {{ block.cacheHit ? '#BBFEC9' : '#FEBBBB' }}">{{ block.cacheHit ? 'Yes' : 'No' }}</th>
245247
<td>{{ block.cacheSize|sizeFormat(1) }}</td>
246248
<td title="This cached block will expires at {{ profile.time|date_modify("+" ~ block.cacheTtl ~ " sec")|date('r') }}"><abbr>{{ block.cacheTtl }}</abbr></td>
@@ -249,7 +251,7 @@
249251
</tr>
250252
{% else %}
251253
<tr>
252-
<th colspan="5"><div style="text-align: center">No twig cache block found</div></th>
254+
<th colspan="6"><div style="text-align: center">No twig cache block found</div></th>
253255
</tr>
254256
{% endfor %}
255257
</tbody>

src/Service/Phpfastcache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1313
*
1414
*/
15+
declare(strict_types=1);
1516

1617
namespace Phpfastcache\Bundle\Service;
1718

src/Twig/CacheExtension/CacheProvider/PsrCacheAdapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1515
*
1616
*/
17+
declare(strict_types=1);
1718

1819
namespace Phpfastcache\Bundle\Twig\CacheExtension\CacheProvider;
1920

src/Twig/CacheExtension/CacheStrategy/LifetimeCacheStrategy.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1515
*
1616
*/
17+
declare(strict_types=1);
1718

1819
namespace Phpfastcache\Bundle\Twig\CacheExtension\CacheStrategy;
1920

@@ -68,19 +69,21 @@ public function __construct(CacheProviderInterface $cache, CacheCollector $cache
6869
/**
6970
* {@inheritDoc}
7071
*/
71-
public function fetchBlock($key)
72+
public function fetchBlock($key, \Twig_Source $sourceContext)
7273
{
73-
$generationTimeMc = microtime(true);
74+
$generationTimeMc = \microtime(true);
7475
$cacheData = $this->cache->fetch($key[ 'key' ]);
75-
$generationTime = microtime(true) - $generationTimeMc;
76-
$unprefixedKey = substr($key[ 'key' ], strlen($this->twigCachePrefix));
76+
$generationTime = \microtime(true) - $generationTimeMc;
77+
$unprefixedKey = \substr($key[ 'key' ], \strlen($this->twigCachePrefix));
7778

7879
if ($this->cacheCollector instanceof CacheCollector) {
7980
$this->cacheCollector->setTwigCacheBlock($unprefixedKey, [
8081
'cacheHit' => $cacheData !== null,
8182
'cacheTtl' => $key[ 'lifetime' ],
8283
'cacheSize' => mb_strlen((string)$cacheData),
8384
'cacheGenTime' => $generationTime,
85+
'cacheFileName' => $sourceContext->getName(),
86+
'cacheFilePath' => $sourceContext->getPath(),
8487
]);
8588
}
8689

@@ -109,7 +112,7 @@ public function generateKey($annotation, $value)
109112
/**
110113
* {@inheritDoc}
111114
*/
112-
public function saveBlock($key, $block, $generationTime)
115+
public function saveBlock($key, $block, $generationTime, \Twig_Source $sourceContext)
113116
{
114117
$unprefixedKey = \substr($key[ 'key' ], \strlen($this->twigCachePrefix));
115118

@@ -119,6 +122,8 @@ public function saveBlock($key, $block, $generationTime)
119122
'cacheTtl' => $key[ 'lifetime' ],
120123
'cacheSize' => \mb_strlen((string)$block),
121124
'cacheGenTime' => $generationTime,
125+
'cacheFileName' => $sourceContext->getName(),
126+
'cacheFilePath' => $sourceContext->getPath(),
122127
]);
123128
}
124129

src/Twig/CacheExtension/CacheStrategyInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface CacheStrategyInterface
3131
*
3232
* @return mixed
3333
*/
34-
public function fetchBlock($key);
34+
public function fetchBlock($key, \Twig_Source $sourceContext);
3535

3636
/**
3737
* Generate a key for the value.
@@ -52,5 +52,5 @@ public function generateKey($annotation, $value);
5252
*
5353
* @return mixed
5454
*/
55-
public function saveBlock($key, $block, $generationTime);
55+
public function saveBlock($key, $block, $generationTim, \Twig_Source $sourceContext);
5656
}

src/Twig/CacheExtension/Extension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1515
*
1616
*/
17+
declare(strict_types=1);
1718

1819
namespace Phpfastcache\Bundle\Twig\CacheExtension;
1920

src/Twig/CacheExtension/Node/CacheNode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1515
*
1616
*/
17+
declare(strict_types=1);
1718

1819
namespace Phpfastcache\Bundle\Twig\CacheExtension\Node;
1920

@@ -63,7 +64,7 @@ public function compile(\Twig_Compiler $compiler)
6364
->raw(", ")
6465
->subcompile($this->getNode('key_info'))
6566
->write(");\n")
66-
->write("\$phpfastcacheCacheBody".$i." = \$phpfastcacheCacheStrategy".$i."->fetchBlock(\$phpfastcacheKey".$i.");\n")
67+
->write("\$phpfastcacheCacheBody".$i." = \$phpfastcacheCacheStrategy".$i."->fetchBlock(\$phpfastcacheKey".$i.", \$this->getSourceContext());\n")
6768
->write("if (\$phpfastcacheCacheBody".$i." === false) {\n")
6869
->indent()
6970
->write("\\ob_start();\n")
@@ -74,7 +75,7 @@ public function compile(\Twig_Compiler $compiler)
7475
->write("\n")
7576
// ->write("sleep(2);\n") // For debug purpose
7677
->write("\$phpfastcacheCacheBody".$i." = \\ob_get_clean();\n")
77-
->write("\$phpfastcacheCacheStrategy".$i."->saveBlock(\$phpfastcacheKey".$i.", \$phpfastcacheCacheBody".$i.", \\microtime(true) - \$compileMc);\n")
78+
->write("\$phpfastcacheCacheStrategy".$i."->saveBlock(\$phpfastcacheKey".$i.", \$phpfastcacheCacheBody".$i.", \\microtime(true) - \$compileMc, \$this->getSourceContext());\n")
7879
->outdent()
7980
->write("}\n")
8081
->write("echo \$phpfastcacheCacheBody".$i.";\n")

src/Twig/CacheExtension/TokenParser/Cache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
1515
*
1616
*/
17+
declare(strict_types=1);
1718

1819
namespace Phpfastcache\Bundle\Twig\CacheExtension\TokenParser;
1920

0 commit comments

Comments
 (0)