-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathCacheNode.php
More file actions
70 lines (56 loc) · 1.39 KB
/
CacheNode.php
File metadata and controls
70 lines (56 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* This file is part of the Latte (https://latte.nette.org)
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Bridges\CacheLatte\Nodes;
use Latte\Compiler\Nodes\AreaNode;
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
use Latte\Compiler\Nodes\StatementNode;
use Latte\Compiler\Position;
use Latte\Compiler\PrintContext;
use Latte\Compiler\Tag;
/**
* {cache} ... {/cache}
*/
class CacheNode extends StatementNode
{
public ArrayNode $args;
public AreaNode $content;
public ?Position $endLine;
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static> */
public static function create(Tag $tag): \Generator
{
$node = $tag->node = new static;
$node->args = $tag->parser->parseArguments();
[$node->content, $endTag] = yield;
$node->endLine = $endTag?->position;
return $node;
}
public function print(PrintContext $context): string
{
return $context->format(
<<<'XX'
if ($this->global->cache->createCache(%dump, %node?)) %line
try {
%node
$this->global->cache->end() %line;
} catch (\Throwable $ʟ_e) {
$this->global->cache->rollback();
throw $ʟ_e;
}
XX,
base64_encode(random_bytes(10)),
$this->args,
$this->position,
$this->content,
$this->endLine,
);
}
public function &getIterator(): \Generator
{
yield $this->args;
yield $this->content;
}
}