Skip to content

Commit df36802

Browse files
committed
CacheMacros: uses Latte provider 'cacheStorage' (and 'cacheStack')
1 parent 81eb48e commit df36802

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function initialize()
4040
public function finalize()
4141
{
4242
if ($this->used) {
43-
return ['Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this, $this->global);'];
43+
return ['Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this);'];
4444
}
4545
}
4646

@@ -57,7 +57,7 @@ public function nodeOpened(Latte\MacroNode $node)
5757
$this->used = TRUE;
5858
$node->isEmpty = FALSE;
5959
$node->openingCode = Latte\PhpWriter::using($node)
60-
->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, %var, $this->global->caches, %node.array?)) { ?>',
60+
->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>',
6161
Nette\Utils\Random::generate()
6262
);
6363
}
@@ -69,7 +69,7 @@ public function nodeOpened(Latte\MacroNode $node)
6969
*/
7070
public function nodeClosed(Latte\MacroNode $node)
7171
{
72-
$node->closingCode = '<?php $_tmp = array_pop($this->global->caches); if (!$_tmp instanceof stdClass) $_tmp->end(); } ?>';
72+
$node->closingCode = '<?php $_tmp = array_pop($this->global->cacheStack); if (!$_tmp instanceof stdClass) $_tmp->end(); } ?>';
7373
}
7474

7575

@@ -79,12 +79,12 @@ public function nodeClosed(Latte\MacroNode $node)
7979
/**
8080
* @return void
8181
*/
82-
public static function initRuntime(Latte\Template $template, $global)
82+
public static function initRuntime(Latte\Template $template)
8383
{
84-
if (!empty($global->caches)) {
84+
if (!empty($template->global->cacheStack)) {
8585
$file = (new \ReflectionClass($template))->getFileName();
8686
if (@is_file($file)) { // @ - may trigger error
87-
end($global->caches)->dependencies[Cache::FILES][] = $file;
87+
end($template->global->cacheStack)->dependencies[Cache::FILES][] = $file;
8888
}
8989
}
9090
}

tests/Bridges.DI/CacheExtension.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ test(function () {
1616
$compiler = new DI\Compiler;
1717
$compiler->addExtension('cache', new CacheExtension(TEMP_DIR));
1818

19-
eval($compiler->compile([], 'Container1'));
19+
eval($compiler->compile());
2020

21-
$container = new Container1;
21+
$container = new Container;
2222
$container->initialize();
2323

2424
$journal = $container->getService('cache.journal');

tests/Bridges.Latte/CacheMacro.cache.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require __DIR__ . '/../bootstrap.php';
1414
$latte = new Latte\Engine;
1515
$latte->setTempDirectory(TEMP_DIR);
1616
$latte->addMacro('cache', new CacheMacro($latte->getCompiler()));
17+
$latte->addProvider('cacheStorage', new Nette\Caching\Storages\DevNullStorage);
1718

18-
$params['netteCacheStorage'] = new Nette\Caching\Storages\DevNullStorage;
1919
$params['title'] = 'Hello';
2020
$params['id'] = 456;
2121

tests/Bridges.Latte/expected/CacheMacro.cache.inc.phtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ class Template%a% extends Latte\Template
88
{
99
%A%
1010
// prolog Nette\Bridges\CacheLatte\CacheMacro
11-
Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this, $this->global);
11+
Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this);
1212

1313
%A%
14-
if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, '%[\w]+%', $this->global->caches)) {
14+
if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, '%[\w]+%', $this->global->cacheStack)) {
1515
?> <?php echo %a% ?>
1616

1717
<?php
18-
$_tmp = array_pop($this->global->caches);
18+
$_tmp = array_pop($this->global->cacheStack);
1919
if (!$_tmp instanceof stdClass) $_tmp->end();
2020
}
2121

tests/Bridges.Latte/expected/CacheMacro.cache.phtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ class Template%a% extends Latte\Template
88
{
99
%A%
1010
// prolog Nette\Bridges\CacheLatte\CacheMacro
11-
Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this, $this->global);
11+
Nette\Bridges\CacheLatte\CacheMacro::initRuntime($this);
1212

1313
%A%
1414
Noncached content
1515

1616
%A%
17-
if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, '%[\w]+%', $this->global->caches, [$id, 'tags' => 'mytag'])) {
17+
if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, '%[\w]+%', $this->global->cacheStack, [$id, 'tags' => 'mytag'])) {
1818
?>
1919

2020
<h1><?php echo %a% ?></h1>
2121

22-
<?php $this->createTemplate('include.cache.latte', ['localvar' => 11] + $this->params, "include", 'html')->render() ?>
22+
<?php $this->createTemplate('include.cache.latte', ['localvar' => 11] + $this->params, "include")->renderToContentType('html') ?>
2323

2424
<?php
25-
$_tmp = array_pop($this->global->caches);
25+
$_tmp = array_pop($this->global->cacheStack);
2626
if (!$_tmp instanceof stdClass) $_tmp->end();
2727
}
2828

0 commit comments

Comments
 (0)