9
9
10
10
namespace Nette \Bridges \CacheLatte \Nodes ;
11
11
12
- use Latte ;
13
12
use Latte \Compiler \Nodes \AreaNode ;
14
13
use Latte \Compiler \Nodes \Php \Expression \ArrayNode ;
15
14
use Latte \Compiler \Nodes \StatementNode ;
16
15
use Latte \Compiler \Position ;
17
16
use Latte \Compiler \PrintContext ;
18
17
use Latte \Compiler \Tag ;
19
- use Nette ;
20
- use Nette \Caching \Cache ;
21
18
22
19
23
20
/**
@@ -45,17 +42,18 @@ public function print(PrintContext $context): string
45
42
{
46
43
return $ context ->format (
47
44
<<<'XX'
48
- if (Nette\Bridges\CacheLatte\Nodes\CacheNode::createCache( $this->global->cacheStorage, %dump, $this->global->cacheStack , %node?)) %line
45
+ if ($this->global->cache->createCache(%dump , %node?)) %line
49
46
try {
50
47
%node
51
- Nette\Bridges\CacheLatte\Nodes\CacheNode::endCache( $this->global->cacheStack ) %line;
48
+ $this->global->cache->end( ) %line;
52
49
} catch (\Throwable $ʟ_e) {
53
- Nette\Bridges\CacheLatte\Nodes\CacheNode::rollback($this->global->cacheStack); throw $ʟ_e;
50
+ $this->global->cache->rollback();
51
+ throw $ʟ_e;
54
52
}
55
53
56
54
57
55
XX,
58
- Nette \ Utils \Random:: generate ( ),
56
+ base64_encode ( random_bytes ( 10 ) ),
59
57
$ this ->args ,
60
58
$ this ->position ,
61
59
$ this ->content ,
@@ -69,81 +67,4 @@ public function &getIterator(): \Generator
69
67
yield $ this ->args ;
70
68
yield $ this ->content ;
71
69
}
72
-
73
-
74
- /********************* run-time helpers ****************d*g**/
75
-
76
-
77
- public static function initRuntime (Latte \Runtime \Template $ template ): void
78
- {
79
- if (!empty ($ template ->global ->cacheStack )) {
80
- $ file = (new \ReflectionClass ($ template ))->getFileName ();
81
- if (@is_file ($ file )) { // @ - may trigger error
82
- end ($ template ->global ->cacheStack )->dependencies [Cache::Files][] = $ file ;
83
- }
84
- }
85
- }
86
-
87
-
88
- /**
89
- * Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
90
- * @return Nette\Caching\OutputHelper|\stdClass
91
- */
92
- public static function createCache (
93
- Nette \Caching \Storage $ cacheStorage ,
94
- string $ key ,
95
- ?array &$ parents ,
96
- ?array $ args = null ,
97
- ) {
98
- if ($ args ) {
99
- if (array_key_exists ('if ' , $ args ) && !$ args ['if ' ]) {
100
- return $ parents [] = new \stdClass ;
101
- }
102
-
103
- $ key = array_merge ([$ key ], array_intersect_key ($ args , range (0 , count ($ args ))));
104
- }
105
-
106
- if ($ parents ) {
107
- end ($ parents )->dependencies [Cache::Items][] = $ key ;
108
- }
109
-
110
- $ cache = new Cache ($ cacheStorage , 'Nette.Templating.Cache ' );
111
- if ($ helper = $ cache ->capture ($ key )) {
112
- $ parents [] = $ helper ;
113
-
114
- if (isset ($ args ['dependencies ' ])) {
115
- $ args += $ args ['dependencies ' ]();
116
- }
117
-
118
- $ helper ->dependencies [Cache::Tags] = $ args ['tags ' ] ?? null ;
119
- $ helper ->dependencies [Cache::Expire] = $ args ['expiration ' ] ?? $ args ['expire ' ] ?? '+ 7 days ' ;
120
- }
121
-
122
- return $ helper ;
123
- }
124
-
125
-
126
- /**
127
- * Ends the output cache.
128
- * @param Nette\Caching\OutputHelper[] $parents
129
- */
130
- public static function endCache (array &$ parents ): void
131
- {
132
- $ helper = array_pop ($ parents );
133
- if ($ helper instanceof Nette \Caching \OutputHelper) {
134
- $ helper ->end ();
135
- }
136
- }
137
-
138
-
139
- /**
140
- * @param Nette\Caching\OutputHelper[] $parents
141
- */
142
- public static function rollback (array &$ parents ): void
143
- {
144
- $ helper = array_pop ($ parents );
145
- if ($ helper instanceof Nette \Caching \OutputHelper) {
146
- $ helper ->rollback ();
147
- }
148
- }
149
70
}
0 commit comments