99
1010namespace Nette \Bridges \CacheLatte \Nodes ;
1111
12- use Latte ;
1312use Latte \Compiler \Nodes \AreaNode ;
1413use Latte \Compiler \Nodes \Php \Expression \ArrayNode ;
1514use Latte \Compiler \Nodes \StatementNode ;
1615use Latte \Compiler \Position ;
1716use Latte \Compiler \PrintContext ;
1817use Latte \Compiler \Tag ;
19- use Nette ;
20- use Nette \Caching \Cache ;
2118
2219
2320/**
@@ -45,17 +42,18 @@ public function print(PrintContext $context): string
4542 {
4643 return $ context ->format (
4744 <<<'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
4946 try {
5047 %node
51- Nette\Bridges\CacheLatte\Nodes\CacheNode::endCache( $this->global->cacheStack ) %line;
48+ $this->global->cache->end( ) %line;
5249 } catch (\Throwable $ʟ_e) {
53- Nette\Bridges\CacheLatte\Nodes\CacheNode::rollback($this->global->cacheStack); throw $ʟ_e;
50+ $this->global->cache->rollback();
51+ throw $ʟ_e;
5452 }
5553
5654
5755 XX,
58- Nette \ Utils \Random:: generate ( ),
56+ base64_encode ( random_bytes ( 10 ) ),
5957 $ this ->args ,
6058 $ this ->position ,
6159 $ this ->content ,
@@ -69,81 +67,4 @@ public function &getIterator(): \Generator
6967 yield $ this ->args ;
7068 yield $ this ->content ;
7169 }
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- }
14970}
0 commit comments