@@ -56,7 +56,7 @@ |
||
56 | 56 | */ |
57 | 57 | public function load(string $path): Source |
58 | 58 | { |
59 | - if ($this->context === null) { |
|
59 | + if ($this->context === null){ |
|
60 | 60 | throw new EngineException('Unable to use StemplerLoader without given context.'); |
61 | 61 | } |
62 | 62 |
@@ -56,7 +56,8 @@ |
||
56 | 56 | */ |
57 | 57 | public function load(string $path): Source |
58 | 58 | { |
59 | - if ($this->context === null) { |
|
59 | + if ($this->context === null) |
|
60 | + { |
|
60 | 61 | throw new EngineException('Unable to use StemplerLoader without given context.'); |
61 | 62 | } |
62 | 63 |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ContainerInterface $container, |
71 | 71 | StemplerConfig $config, |
72 | 72 | StemplerCache $cache = null |
73 | - ) { |
|
73 | + ){ |
|
74 | 74 | $this->container = $container; |
75 | 75 | $this->config = $config; |
76 | 76 | $this->cache = $cache; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function getLoader(): LoaderInterface |
103 | 103 | { |
104 | - if ($this->loader === null) { |
|
104 | + if ($this->loader === null){ |
|
105 | 105 | throw new EngineException('No associated loader found'); |
106 | 106 | } |
107 | 107 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function getBuilder(ContextInterface $context): Builder |
118 | 118 | { |
119 | - if ($this->builder === null) { |
|
119 | + if ($this->builder === null){ |
|
120 | 120 | throw new EngineException('No associated builder found'); |
121 | 121 | } |
122 | 122 | |
@@ -140,25 +140,25 @@ discard block |
||
140 | 140 | // cache key |
141 | 141 | $key = $this->cacheKey($view, $context); |
142 | 142 | |
143 | - if ($this->cache !== null && $this->cache->isFresh($key)) { |
|
143 | + if ($this->cache !== null && $this->cache->isFresh($key)){ |
|
144 | 144 | $this->cache->load($key); |
145 | - } elseif (!class_exists($class)) { |
|
146 | - try { |
|
145 | + } elseif (!class_exists($class)){ |
|
146 | + try{ |
|
147 | 147 | $builder = $this->getBuilder($context); |
148 | 148 | |
149 | 149 | $result = $builder->compile($path); |
150 | - } catch (Throwable $e) { |
|
150 | + }catch (Throwable $e){ |
|
151 | 151 | throw new CompileException($e); |
152 | 152 | } |
153 | 153 | |
154 | 154 | $compiled = $this->compileClass($class, $result); |
155 | 155 | |
156 | - if ($this->cache !== null) { |
|
156 | + if ($this->cache !== null){ |
|
157 | 157 | $this->cache->write( |
158 | 158 | $key, |
159 | 159 | $compiled, |
160 | 160 | array_map( |
161 | - function ($path) { |
|
161 | + function ($path){ |
|
162 | 162 | return $this->getLoader()->load($path)->getFilename(); |
163 | 163 | }, |
164 | 164 | $result->getPaths() |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | $this->cache->load($key); |
169 | 169 | } |
170 | 170 | |
171 | - if (!class_exists($class)) { |
|
171 | + if (!class_exists($class)){ |
|
172 | 172 | // runtime initialization |
173 | - eval('?>' . $compiled); |
|
173 | + eval('?>'.$compiled); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | - if (!class_exists($class)) { |
|
177 | + if (!class_exists($class)){ |
|
178 | 178 | throw new EngineException("Unable to load `{$path}`, cache might be corrupted"); |
179 | 179 | } |
180 | 180 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function reset(string $path, ContextInterface $context): void |
188 | 188 | { |
189 | - if ($this->cache === null) { |
|
189 | + if ($this->cache === null){ |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
@@ -212,12 +212,12 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function makeSourceMap(string $path, ContextInterface $context): ?SourceMap |
214 | 214 | { |
215 | - try { |
|
215 | + try{ |
|
216 | 216 | $builder = $this->getBuilder($context); |
217 | 217 | |
218 | 218 | // there is no need to cache sourcemaps since they are used during the exception only |
219 | 219 | return $builder->compile($path)->getSourceMap($builder->getLoader()); |
220 | - } catch (Throwable $e) { |
|
220 | + }catch (Throwable $e){ |
|
221 | 221 | return null; |
222 | 222 | } |
223 | 223 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | */ |
261 | 261 | private function className(ViewSource $source, ContextInterface $context): string |
262 | 262 | { |
263 | - return $this->classPrefix . $this->cacheKey($source, $context); |
|
263 | + return $this->classPrefix.$this->cacheKey($source, $context); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $builder = new Builder($loader); |
290 | 290 | |
291 | 291 | $directivesGroup = new DirectiveGroup(); |
292 | - foreach ($this->getDirectives() as $directive) { |
|
292 | + foreach ($this->getDirectives() as $directive){ |
|
293 | 293 | $directivesGroup->addDirective($directive); |
294 | 294 | } |
295 | 295 | |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup($this->getDirectives()))); |
321 | 321 | |
322 | 322 | // ATS modifications |
323 | - foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor) { |
|
323 | + foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor){ |
|
324 | 324 | $builder->addVisitor($visitor, Builder::STAGE_PREPARE); |
325 | 325 | } |
326 | 326 | |
@@ -333,15 +333,15 @@ discard block |
||
333 | 333 | $builder->addVisitor(new ResolveImports($builder), Builder::STAGE_TRANSFORM); |
334 | 334 | $builder->addVisitor(new ExtendsParent($builder), Builder::STAGE_TRANSFORM); |
335 | 335 | |
336 | - foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor) { |
|
336 | + foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor){ |
|
337 | 337 | $builder->addVisitor($visitor, Builder::STAGE_TRANSFORM); |
338 | 338 | } |
339 | 339 | |
340 | - foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor) { |
|
340 | + foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor){ |
|
341 | 341 | $builder->addVisitor($visitor, Builder::STAGE_FINALIZE); |
342 | 342 | } |
343 | 343 | |
344 | - foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor) { |
|
344 | + foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor){ |
|
345 | 345 | $builder->addVisitor($visitor, Builder::STAGE_COMPILE); |
346 | 346 | } |
347 | 347 | |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | private function getVisitors(int $stage): iterable |
356 | 356 | { |
357 | 357 | $result = []; |
358 | - foreach ($this->config->getVisitors($stage) as $visitor) { |
|
359 | - if ($visitor instanceof Autowire) { |
|
358 | + foreach ($this->config->getVisitors($stage) as $visitor){ |
|
359 | + if ($visitor instanceof Autowire){ |
|
360 | 360 | $result[] = $visitor->resolve($this->container->get(FactoryInterface::class)); |
361 | 361 | continue; |
362 | 362 | } |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | private function getProcessors(): iterable |
374 | 374 | { |
375 | 375 | $result = []; |
376 | - foreach ($this->config->getProcessors() as $processor) { |
|
377 | - if ($processor instanceof Autowire) { |
|
376 | + foreach ($this->config->getProcessors() as $processor){ |
|
377 | + if ($processor instanceof Autowire){ |
|
378 | 378 | $result[] = $processor->resolve($this->container->get(FactoryInterface::class)); |
379 | 379 | continue; |
380 | 380 | } |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | private function getDirectives(): iterable |
392 | 392 | { |
393 | 393 | $result = []; |
394 | - foreach ($this->config->getDirectives() as $directive) { |
|
395 | - if ($directive instanceof Autowire) { |
|
394 | + foreach ($this->config->getDirectives() as $directive){ |
|
395 | + if ($directive instanceof Autowire){ |
|
396 | 396 | $result[] = $directive->resolve($this->container->get(FactoryInterface::class)); |
397 | 397 | continue; |
398 | 398 | } |
@@ -101,7 +101,8 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function getLoader(): LoaderInterface |
103 | 103 | { |
104 | - if ($this->loader === null) { |
|
104 | + if ($this->loader === null) |
|
105 | + { |
|
105 | 106 | throw new EngineException('No associated loader found'); |
106 | 107 | } |
107 | 108 | |
@@ -116,7 +117,8 @@ discard block |
||
116 | 117 | */ |
117 | 118 | public function getBuilder(ContextInterface $context): Builder |
118 | 119 | { |
119 | - if ($this->builder === null) { |
|
120 | + if ($this->builder === null) |
|
121 | + { |
|
120 | 122 | throw new EngineException('No associated builder found'); |
121 | 123 | } |
122 | 124 | |
@@ -140,25 +142,33 @@ discard block |
||
140 | 142 | // cache key |
141 | 143 | $key = $this->cacheKey($view, $context); |
142 | 144 | |
143 | - if ($this->cache !== null && $this->cache->isFresh($key)) { |
|
145 | + if ($this->cache !== null && $this->cache->isFresh($key)) |
|
146 | + { |
|
144 | 147 | $this->cache->load($key); |
145 | - } elseif (!class_exists($class)) { |
|
146 | - try { |
|
148 | + } |
|
149 | + elseif (!class_exists($class)) |
|
150 | + { |
|
151 | + try |
|
152 | + { |
|
147 | 153 | $builder = $this->getBuilder($context); |
148 | 154 | |
149 | 155 | $result = $builder->compile($path); |
150 | - } catch (Throwable $e) { |
|
156 | + } |
|
157 | + catch (Throwable $e) |
|
158 | + { |
|
151 | 159 | throw new CompileException($e); |
152 | 160 | } |
153 | 161 | |
154 | 162 | $compiled = $this->compileClass($class, $result); |
155 | 163 | |
156 | - if ($this->cache !== null) { |
|
164 | + if ($this->cache !== null) |
|
165 | + { |
|
157 | 166 | $this->cache->write( |
158 | 167 | $key, |
159 | 168 | $compiled, |
160 | 169 | array_map( |
161 | - function ($path) { |
|
170 | + function ($path) |
|
171 | + { |
|
162 | 172 | return $this->getLoader()->load($path)->getFilename(); |
163 | 173 | }, |
164 | 174 | $result->getPaths() |
@@ -168,13 +178,15 @@ discard block |
||
168 | 178 | $this->cache->load($key); |
169 | 179 | } |
170 | 180 | |
171 | - if (!class_exists($class)) { |
|
181 | + if (!class_exists($class)) |
|
182 | + { |
|
172 | 183 | // runtime initialization |
173 | 184 | eval('?>' . $compiled); |
174 | 185 | } |
175 | 186 | } |
176 | 187 | |
177 | - if (!class_exists($class)) { |
|
188 | + if (!class_exists($class)) |
|
189 | + { |
|
178 | 190 | throw new EngineException("Unable to load `{$path}`, cache might be corrupted"); |
179 | 191 | } |
180 | 192 | |
@@ -186,7 +198,8 @@ discard block |
||
186 | 198 | */ |
187 | 199 | public function reset(string $path, ContextInterface $context): void |
188 | 200 | { |
189 | - if ($this->cache === null) { |
|
201 | + if ($this->cache === null) |
|
202 | + { |
|
190 | 203 | return; |
191 | 204 | } |
192 | 205 | |
@@ -212,12 +225,15 @@ discard block |
||
212 | 225 | */ |
213 | 226 | public function makeSourceMap(string $path, ContextInterface $context): ?SourceMap |
214 | 227 | { |
215 | - try { |
|
228 | + try |
|
229 | + { |
|
216 | 230 | $builder = $this->getBuilder($context); |
217 | 231 | |
218 | 232 | // there is no need to cache sourcemaps since they are used during the exception only |
219 | 233 | return $builder->compile($path)->getSourceMap($builder->getLoader()); |
220 | - } catch (Throwable $e) { |
|
234 | + } |
|
235 | + catch (Throwable $e) |
|
236 | + { |
|
221 | 237 | return null; |
222 | 238 | } |
223 | 239 | } |
@@ -289,7 +305,8 @@ discard block |
||
289 | 305 | $builder = new Builder($loader); |
290 | 306 | |
291 | 307 | $directivesGroup = new DirectiveGroup(); |
292 | - foreach ($this->getDirectives() as $directive) { |
|
308 | + foreach ($this->getDirectives() as $directive) |
|
309 | + { |
|
293 | 310 | $directivesGroup->addDirective($directive); |
294 | 311 | } |
295 | 312 | |
@@ -320,7 +337,8 @@ discard block |
||
320 | 337 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup($this->getDirectives()))); |
321 | 338 | |
322 | 339 | // ATS modifications |
323 | - foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor) { |
|
340 | + foreach ($this->getVisitors(Builder::STAGE_PREPARE) as $visitor) |
|
341 | + { |
|
324 | 342 | $builder->addVisitor($visitor, Builder::STAGE_PREPARE); |
325 | 343 | } |
326 | 344 | |
@@ -333,15 +351,18 @@ discard block |
||
333 | 351 | $builder->addVisitor(new ResolveImports($builder), Builder::STAGE_TRANSFORM); |
334 | 352 | $builder->addVisitor(new ExtendsParent($builder), Builder::STAGE_TRANSFORM); |
335 | 353 | |
336 | - foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor) { |
|
354 | + foreach ($this->getVisitors(Builder::STAGE_TRANSFORM) as $visitor) |
|
355 | + { |
|
337 | 356 | $builder->addVisitor($visitor, Builder::STAGE_TRANSFORM); |
338 | 357 | } |
339 | 358 | |
340 | - foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor) { |
|
359 | + foreach ($this->getVisitors(Builder::STAGE_FINALIZE) as $visitor) |
|
360 | + { |
|
341 | 361 | $builder->addVisitor($visitor, Builder::STAGE_FINALIZE); |
342 | 362 | } |
343 | 363 | |
344 | - foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor) { |
|
364 | + foreach ($this->getVisitors(Builder::STAGE_COMPILE) as $visitor) |
|
365 | + { |
|
345 | 366 | $builder->addVisitor($visitor, Builder::STAGE_COMPILE); |
346 | 367 | } |
347 | 368 | |
@@ -355,8 +376,10 @@ discard block |
||
355 | 376 | private function getVisitors(int $stage): iterable |
356 | 377 | { |
357 | 378 | $result = []; |
358 | - foreach ($this->config->getVisitors($stage) as $visitor) { |
|
359 | - if ($visitor instanceof Autowire) { |
|
379 | + foreach ($this->config->getVisitors($stage) as $visitor) |
|
380 | + { |
|
381 | + if ($visitor instanceof Autowire) |
|
382 | + { |
|
360 | 383 | $result[] = $visitor->resolve($this->container->get(FactoryInterface::class)); |
361 | 384 | continue; |
362 | 385 | } |
@@ -373,8 +396,10 @@ discard block |
||
373 | 396 | private function getProcessors(): iterable |
374 | 397 | { |
375 | 398 | $result = []; |
376 | - foreach ($this->config->getProcessors() as $processor) { |
|
377 | - if ($processor instanceof Autowire) { |
|
399 | + foreach ($this->config->getProcessors() as $processor) |
|
400 | + { |
|
401 | + if ($processor instanceof Autowire) |
|
402 | + { |
|
378 | 403 | $result[] = $processor->resolve($this->container->get(FactoryInterface::class)); |
379 | 404 | continue; |
380 | 405 | } |
@@ -391,8 +416,10 @@ discard block |
||
391 | 416 | private function getDirectives(): iterable |
392 | 417 | { |
393 | 418 | $result = []; |
394 | - foreach ($this->config->getDirectives() as $directive) { |
|
395 | - if ($directive instanceof Autowire) { |
|
419 | + foreach ($this->config->getDirectives() as $directive) |
|
420 | + { |
|
421 | + if ($directive instanceof Autowire) |
|
422 | + { |
|
396 | 423 | $result[] = $directive->resolve($this->container->get(FactoryInterface::class)); |
397 | 424 | continue; |
398 | 425 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | $this->context |
60 | 60 | ); |
61 | 61 | |
62 | - if ($sourcemap === null) { |
|
62 | + if ($sourcemap === null){ |
|
63 | 63 | return $e; |
64 | 64 | } |
65 | 65 |
@@ -59,7 +59,8 @@ |
||
59 | 59 | $this->context |
60 | 60 | ); |
61 | 61 | |
62 | - if ($sourcemap === null) { |
|
62 | + if ($sourcemap === null) |
|
63 | + { |
|
63 | 64 | return $e; |
64 | 65 | } |
65 | 66 |
@@ -40,30 +40,30 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function enterNode($node, VisitorContext $ctx) |
42 | 42 | { |
43 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
43 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag){ |
|
44 | 44 | return null; |
45 | 45 | } |
46 | 46 | |
47 | - if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) { |
|
47 | + if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)){ |
|
48 | 48 | // raw nodes |
49 | 49 | return null; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $level = $this->getLevel($ctx); |
53 | - if ($level === null) { |
|
53 | + if ($level === null){ |
|
54 | 54 | // not available in some contexts |
55 | 55 | return null; |
56 | 56 | } |
57 | 57 | |
58 | - foreach ($node->nodes as $i => $child) { |
|
59 | - if (!$child instanceof Raw) { |
|
58 | + foreach ($node->nodes as $i => $child){ |
|
59 | + if (!$child instanceof Raw){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $position = self::BETWEEN_TAGS; |
64 | - if (!isset($node->nodes[$i + 1])) { |
|
64 | + if (!isset($node->nodes[$i + 1])){ |
|
65 | 65 | $position = self::BEFORE_CLOSE; |
66 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
66 | + } elseif ($node->nodes[$i + 1] instanceof PHP){ |
|
67 | 67 | $position = self::BEFORE_PHP; |
68 | 68 | } |
69 | 69 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS) |
92 | 92 | { |
93 | - if (strpos($content, "\n") === false) { |
|
93 | + if (strpos($content, "\n") === false){ |
|
94 | 94 | // no need to do anything |
95 | 95 | return $content; |
96 | 96 | } |
@@ -98,44 +98,44 @@ discard block |
||
98 | 98 | // we have to apply special rules to the first and the last lines |
99 | 99 | $lines = explode("\n", $content); |
100 | 100 | |
101 | - foreach ($lines as $i => $line) { |
|
102 | - if (trim($line) === '' && $i !== 0) { |
|
101 | + foreach ($lines as $i => $line){ |
|
102 | + if (trim($line) === '' && $i !== 0){ |
|
103 | 103 | unset($lines[$i]); |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | 107 | $lines = array_values($lines); |
108 | - if (count($lines) === 0) { |
|
108 | + if (count($lines) === 0){ |
|
109 | 109 | $lines[] = ''; |
110 | 110 | } |
111 | 111 | |
112 | 112 | $result = ''; |
113 | - foreach ($lines as $i => $line) { |
|
114 | - if (trim($line) !== '') { |
|
115 | - if ($i === 0) { |
|
113 | + foreach ($lines as $i => $line){ |
|
114 | + if (trim($line) !== ''){ |
|
115 | + if ($i === 0){ |
|
116 | 116 | $line = rtrim($line); |
117 | - } else { |
|
117 | + }else{ |
|
118 | 118 | $line = trim($line); |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - if ($i !== (count($lines) - 1)) { |
|
123 | - $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
|
122 | + if ($i !== (count($lines) - 1)){ |
|
123 | + $result .= $line."\n".str_repeat(self::INDENT, $level); |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // working with last line |
128 | - if ($position === self::BEFORE_PHP) { |
|
129 | - $result .= $line . "\n"; |
|
128 | + if ($position === self::BEFORE_PHP){ |
|
129 | + $result .= $line."\n"; |
|
130 | 130 | break; |
131 | 131 | } |
132 | 132 | |
133 | - if ($position === self::BEFORE_CLOSE) { |
|
134 | - $result .= $line . "\n" . str_repeat(self::INDENT, max($level - 1, 0)); |
|
133 | + if ($position === self::BEFORE_CLOSE){ |
|
134 | + $result .= $line."\n".str_repeat(self::INDENT, max($level - 1, 0)); |
|
135 | 135 | break; |
136 | 136 | } |
137 | 137 | |
138 | - $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
|
138 | + $result .= $line."\n".str_repeat(self::INDENT, $level); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | return $result; |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | private function getLevel(VisitorContext $ctx): ?int |
149 | 149 | { |
150 | 150 | $level = 0; |
151 | - foreach ($ctx->getScope() as $node) { |
|
152 | - if ($node instanceof Attr) { |
|
151 | + foreach ($ctx->getScope() as $node){ |
|
152 | + if ($node instanceof Attr){ |
|
153 | 153 | return null; |
154 | 154 | } |
155 | 155 | |
156 | - if ($node instanceof Block || $node instanceof Template) { |
|
156 | + if ($node instanceof Block || $node instanceof Template){ |
|
157 | 157 | continue; |
158 | 158 | } |
159 | 159 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
175 | 175 | { |
176 | - if (!$joinMultiple) { |
|
176 | + if (!$joinMultiple){ |
|
177 | 177 | return str_replace("\r\n", "\n", $string); |
178 | 178 | } |
179 | 179 |
@@ -40,30 +40,38 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function enterNode($node, VisitorContext $ctx) |
42 | 42 | { |
43 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
43 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) |
|
44 | + { |
|
44 | 45 | return null; |
45 | 46 | } |
46 | 47 | |
47 | - if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) { |
|
48 | + if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) |
|
49 | + { |
|
48 | 50 | // raw nodes |
49 | 51 | return null; |
50 | 52 | } |
51 | 53 | |
52 | 54 | $level = $this->getLevel($ctx); |
53 | - if ($level === null) { |
|
55 | + if ($level === null) |
|
56 | + { |
|
54 | 57 | // not available in some contexts |
55 | 58 | return null; |
56 | 59 | } |
57 | 60 | |
58 | - foreach ($node->nodes as $i => $child) { |
|
59 | - if (!$child instanceof Raw) { |
|
61 | + foreach ($node->nodes as $i => $child) |
|
62 | + { |
|
63 | + if (!$child instanceof Raw) |
|
64 | + { |
|
60 | 65 | continue; |
61 | 66 | } |
62 | 67 | |
63 | 68 | $position = self::BETWEEN_TAGS; |
64 | - if (!isset($node->nodes[$i + 1])) { |
|
69 | + if (!isset($node->nodes[$i + 1])) |
|
70 | + { |
|
65 | 71 | $position = self::BEFORE_CLOSE; |
66 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
72 | + } |
|
73 | + elseif ($node->nodes[$i + 1] instanceof PHP) |
|
74 | + { |
|
67 | 75 | $position = self::BEFORE_PHP; |
68 | 76 | } |
69 | 77 | |
@@ -90,7 +98,8 @@ discard block |
||
90 | 98 | */ |
91 | 99 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS) |
92 | 100 | { |
93 | - if (strpos($content, "\n") === false) { |
|
101 | + if (strpos($content, "\n") === false) |
|
102 | + { |
|
94 | 103 | // no need to do anything |
95 | 104 | return $content; |
96 | 105 | } |
@@ -98,39 +107,50 @@ discard block |
||
98 | 107 | // we have to apply special rules to the first and the last lines |
99 | 108 | $lines = explode("\n", $content); |
100 | 109 | |
101 | - foreach ($lines as $i => $line) { |
|
102 | - if (trim($line) === '' && $i !== 0) { |
|
110 | + foreach ($lines as $i => $line) |
|
111 | + { |
|
112 | + if (trim($line) === '' && $i !== 0) |
|
113 | + { |
|
103 | 114 | unset($lines[$i]); |
104 | 115 | } |
105 | 116 | } |
106 | 117 | |
107 | 118 | $lines = array_values($lines); |
108 | - if (count($lines) === 0) { |
|
119 | + if (count($lines) === 0) |
|
120 | + { |
|
109 | 121 | $lines[] = ''; |
110 | 122 | } |
111 | 123 | |
112 | 124 | $result = ''; |
113 | - foreach ($lines as $i => $line) { |
|
114 | - if (trim($line) !== '') { |
|
115 | - if ($i === 0) { |
|
125 | + foreach ($lines as $i => $line) |
|
126 | + { |
|
127 | + if (trim($line) !== '') |
|
128 | + { |
|
129 | + if ($i === 0) |
|
130 | + { |
|
116 | 131 | $line = rtrim($line); |
117 | - } else { |
|
132 | + } |
|
133 | + else |
|
134 | + { |
|
118 | 135 | $line = trim($line); |
119 | 136 | } |
120 | 137 | } |
121 | 138 | |
122 | - if ($i !== (count($lines) - 1)) { |
|
139 | + if ($i !== (count($lines) - 1)) |
|
140 | + { |
|
123 | 141 | $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
124 | 142 | continue; |
125 | 143 | } |
126 | 144 | |
127 | 145 | // working with last line |
128 | - if ($position === self::BEFORE_PHP) { |
|
146 | + if ($position === self::BEFORE_PHP) |
|
147 | + { |
|
129 | 148 | $result .= $line . "\n"; |
130 | 149 | break; |
131 | 150 | } |
132 | 151 | |
133 | - if ($position === self::BEFORE_CLOSE) { |
|
152 | + if ($position === self::BEFORE_CLOSE) |
|
153 | + { |
|
134 | 154 | $result .= $line . "\n" . str_repeat(self::INDENT, max($level - 1, 0)); |
135 | 155 | break; |
136 | 156 | } |
@@ -148,12 +168,15 @@ discard block |
||
148 | 168 | private function getLevel(VisitorContext $ctx): ?int |
149 | 169 | { |
150 | 170 | $level = 0; |
151 | - foreach ($ctx->getScope() as $node) { |
|
152 | - if ($node instanceof Attr) { |
|
171 | + foreach ($ctx->getScope() as $node) |
|
172 | + { |
|
173 | + if ($node instanceof Attr) |
|
174 | + { |
|
153 | 175 | return null; |
154 | 176 | } |
155 | 177 | |
156 | - if ($node instanceof Block || $node instanceof Template) { |
|
178 | + if ($node instanceof Block || $node instanceof Template) |
|
179 | + { |
|
157 | 180 | continue; |
158 | 181 | } |
159 | 182 | |
@@ -173,7 +196,8 @@ discard block |
||
173 | 196 | */ |
174 | 197 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
175 | 198 | { |
176 | - if (!$joinMultiple) { |
|
199 | + if (!$joinMultiple) |
|
200 | + { |
|
177 | 201 | return str_replace("\r\n", "\n", $string); |
178 | 202 | } |
179 | 203 |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function enterNode($node, VisitorContext $ctx): void |
34 | 34 | { |
35 | - if (!$node instanceof Tag) { |
|
35 | + if (!$node instanceof Tag){ |
|
36 | 36 | return; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $flatten = []; |
40 | - foreach ($node->nodes as $child) { |
|
41 | - if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) { |
|
42 | - foreach ($child->nodes as $childNode) { |
|
40 | + foreach ($node->nodes as $child){ |
|
41 | + if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate){ |
|
42 | + foreach ($child->nodes as $childNode){ |
|
43 | 43 | $flatten[] = $childNode; |
44 | 44 | } |
45 | 45 | continue; |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | private function mergeRaw(array $nodes): array |
66 | 66 | { |
67 | 67 | $result = []; |
68 | - foreach ($nodes as $node) { |
|
68 | + foreach ($nodes as $node){ |
|
69 | 69 | if ( |
70 | 70 | $node instanceof Raw |
71 | 71 | && isset($result[count($result) - 1]) |
72 | 72 | && $result[count($result) - 1] instanceof Raw |
73 | - ) { |
|
73 | + ){ |
|
74 | 74 | $result[count($result) - 1]->content .= $node->content; |
75 | 75 | continue; |
76 | 76 | } |
@@ -32,14 +32,18 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function enterNode($node, VisitorContext $ctx): void |
34 | 34 | { |
35 | - if (!$node instanceof Tag) { |
|
35 | + if (!$node instanceof Tag) |
|
36 | + { |
|
36 | 37 | return; |
37 | 38 | } |
38 | 39 | |
39 | 40 | $flatten = []; |
40 | - foreach ($node->nodes as $child) { |
|
41 | - if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) { |
|
42 | - foreach ($child->nodes as $childNode) { |
|
41 | + foreach ($node->nodes as $child) |
|
42 | + { |
|
43 | + if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) |
|
44 | + { |
|
45 | + foreach ($child->nodes as $childNode) |
|
46 | + { |
|
43 | 47 | $flatten[] = $childNode; |
44 | 48 | } |
45 | 49 | continue; |
@@ -65,7 +69,8 @@ discard block |
||
65 | 69 | private function mergeRaw(array $nodes): array |
66 | 70 | { |
67 | 71 | $result = []; |
68 | - foreach ($nodes as $node) { |
|
72 | + foreach ($nodes as $node) |
|
73 | + { |
|
69 | 74 | if ( |
70 | 75 | $node instanceof Raw |
71 | 76 | && isset($result[count($result) - 1]) |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function renderRoute(Directive $directive): string |
43 | 43 | { |
44 | - if (count($directive->values) < 1) { |
|
44 | + if (count($directive->values) < 1){ |
|
45 | 45 | throw new DirectiveException( |
46 | 46 | 'Unable to call @route directive, at least 1 value is required', |
47 | 47 | $directive->getContext() |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | { |
66 | 66 | $vars = []; |
67 | 67 | $restore = []; |
68 | - foreach ($params as $key => $value) { |
|
69 | - if (is_string($value) && preg_match('/\{.*\}/', $value)) { |
|
68 | + foreach ($params as $key => $value){ |
|
69 | + if (is_string($value) && preg_match('/\{.*\}/', $value)){ |
|
70 | 70 | $restore[sprintf('__%s__', $key)] = $value; |
71 | 71 | $value = sprintf('__%s__', $key); |
72 | 72 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | $vars[$key] = $value; |
75 | 75 | } |
76 | 76 | |
77 | - try { |
|
77 | + try{ |
|
78 | 78 | return strtr( |
79 | 79 | $this->container->get(RouterInterface::class)->uri($route, $vars)->__toString(), |
80 | 80 | $restore |
81 | 81 | ); |
82 | - } catch (UndefinedRouteException $e) { |
|
82 | + }catch (UndefinedRouteException $e){ |
|
83 | 83 | throw new RouterException("No such route {$route}", $e->getCode(), $e); |
84 | 84 | } |
85 | 85 | } |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function renderRoute(Directive $directive): string |
43 | 43 | { |
44 | - if (count($directive->values) < 1) { |
|
44 | + if (count($directive->values) < 1) |
|
45 | + { |
|
45 | 46 | throw new DirectiveException( |
46 | 47 | 'Unable to call @route directive, at least 1 value is required', |
47 | 48 | $directive->getContext() |
@@ -65,8 +66,10 @@ discard block |
||
65 | 66 | { |
66 | 67 | $vars = []; |
67 | 68 | $restore = []; |
68 | - foreach ($params as $key => $value) { |
|
69 | - if (is_string($value) && preg_match('/\{.*\}/', $value)) { |
|
69 | + foreach ($params as $key => $value) |
|
70 | + { |
|
71 | + if (is_string($value) && preg_match('/\{.*\}/', $value)) |
|
72 | + { |
|
70 | 73 | $restore[sprintf('__%s__', $key)] = $value; |
71 | 74 | $value = sprintf('__%s__', $key); |
72 | 75 | } |
@@ -74,12 +77,15 @@ discard block |
||
74 | 77 | $vars[$key] = $value; |
75 | 78 | } |
76 | 79 | |
77 | - try { |
|
80 | + try |
|
81 | + { |
|
78 | 82 | return strtr( |
79 | 83 | $this->container->get(RouterInterface::class)->uri($route, $vars)->__toString(), |
80 | 84 | $restore |
81 | 85 | ); |
82 | - } catch (UndefinedRouteException $e) { |
|
86 | + } |
|
87 | + catch (UndefinedRouteException $e) |
|
88 | + { |
|
83 | 89 | throw new RouterException("No such route {$route}", $e->getCode(), $e); |
84 | 90 | } |
85 | 91 | } |
@@ -27,14 +27,14 @@ |
||
27 | 27 | */ |
28 | 28 | public function renderInject(Directive $directive): string |
29 | 29 | { |
30 | - if (count($directive->values) < 2 || strlen($directive->values[0]) === 0) { |
|
30 | + if (count($directive->values) < 2 || strlen($directive->values[0]) === 0){ |
|
31 | 31 | throw new DirectiveException( |
32 | 32 | 'Unable to call @inject directive, 2 values required', |
33 | 33 | $directive->getContext() |
34 | 34 | ); |
35 | 35 | } |
36 | 36 | |
37 | - if ($directive->values[0][0] === '$') { |
|
37 | + if ($directive->values[0][0] === '$'){ |
|
38 | 38 | return sprintf( |
39 | 39 | '<?php %s = $this->container->get(%s); ?>', |
40 | 40 | $directive->values[0], |
@@ -27,14 +27,16 @@ |
||
27 | 27 | */ |
28 | 28 | public function renderInject(Directive $directive): string |
29 | 29 | { |
30 | - if (count($directive->values) < 2 || strlen($directive->values[0]) === 0) { |
|
30 | + if (count($directive->values) < 2 || strlen($directive->values[0]) === 0) |
|
31 | + { |
|
31 | 32 | throw new DirectiveException( |
32 | 33 | 'Unable to call @inject directive, 2 values required', |
33 | 34 | $directive->getContext() |
34 | 35 | ); |
35 | 36 | } |
36 | 37 | |
37 | - if ($directive->values[0][0] === '$') { |
|
38 | + if ($directive->values[0][0] === '$') |
|
39 | + { |
|
38 | 40 | return sprintf( |
39 | 41 | '<?php %s = $this->container->get(%s); ?>', |
40 | 42 | $directive->values[0], |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | public function getDirectives(): array |
33 | 33 | { |
34 | 34 | $directives = []; |
35 | - foreach ($this->config['directives'] as $directive) { |
|
36 | - if (is_object($directive) && !$directive instanceof Autowire) { |
|
35 | + foreach ($this->config['directives'] as $directive){ |
|
36 | + if (is_object($directive) && !$directive instanceof Autowire){ |
|
37 | 37 | $directives[] = $directive; |
38 | 38 | continue; |
39 | 39 | } |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | public function getProcessors(): array |
51 | 51 | { |
52 | 52 | $processors = []; |
53 | - foreach ($this->config['processors'] as $processor) { |
|
54 | - if (is_object($processor) && !$processor instanceof Autowire) { |
|
53 | + foreach ($this->config['processors'] as $processor){ |
|
54 | + if (is_object($processor) && !$processor instanceof Autowire){ |
|
55 | 55 | $processors[] = $processor; |
56 | 56 | continue; |
57 | 57 | } |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | public function getVisitors(int $stage): array |
70 | 70 | { |
71 | 71 | $visitors = []; |
72 | - foreach ($this->config['visitors'][$stage] ?? [] as $visitor) { |
|
73 | - if (is_object($visitor) && !$visitor instanceof Autowire) { |
|
72 | + foreach ($this->config['visitors'][$stage] ?? [] as $visitor){ |
|
73 | + if (is_object($visitor) && !$visitor instanceof Autowire){ |
|
74 | 74 | $visitors[] = $visitor; |
75 | 75 | continue; |
76 | 76 | } |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function wire($item): Autowire |
91 | 91 | { |
92 | - if ($item instanceof Autowire) { |
|
92 | + if ($item instanceof Autowire){ |
|
93 | 93 | return $item; |
94 | 94 | } |
95 | 95 | |
96 | - if (is_string($item)) { |
|
96 | + if (is_string($item)){ |
|
97 | 97 | return new Autowire($item); |
98 | 98 | } |
99 | 99 |
@@ -32,8 +32,10 @@ discard block |
||
32 | 32 | public function getDirectives(): array |
33 | 33 | { |
34 | 34 | $directives = []; |
35 | - foreach ($this->config['directives'] as $directive) { |
|
36 | - if (is_object($directive) && !$directive instanceof Autowire) { |
|
35 | + foreach ($this->config['directives'] as $directive) |
|
36 | + { |
|
37 | + if (is_object($directive) && !$directive instanceof Autowire) |
|
38 | + { |
|
37 | 39 | $directives[] = $directive; |
38 | 40 | continue; |
39 | 41 | } |
@@ -50,8 +52,10 @@ discard block |
||
50 | 52 | public function getProcessors(): array |
51 | 53 | { |
52 | 54 | $processors = []; |
53 | - foreach ($this->config['processors'] as $processor) { |
|
54 | - if (is_object($processor) && !$processor instanceof Autowire) { |
|
55 | + foreach ($this->config['processors'] as $processor) |
|
56 | + { |
|
57 | + if (is_object($processor) && !$processor instanceof Autowire) |
|
58 | + { |
|
55 | 59 | $processors[] = $processor; |
56 | 60 | continue; |
57 | 61 | } |
@@ -69,8 +73,10 @@ discard block |
||
69 | 73 | public function getVisitors(int $stage): array |
70 | 74 | { |
71 | 75 | $visitors = []; |
72 | - foreach ($this->config['visitors'][$stage] ?? [] as $visitor) { |
|
73 | - if (is_object($visitor) && !$visitor instanceof Autowire) { |
|
76 | + foreach ($this->config['visitors'][$stage] ?? [] as $visitor) |
|
77 | + { |
|
78 | + if (is_object($visitor) && !$visitor instanceof Autowire) |
|
79 | + { |
|
74 | 80 | $visitors[] = $visitor; |
75 | 81 | continue; |
76 | 82 | } |
@@ -89,11 +95,13 @@ discard block |
||
89 | 95 | */ |
90 | 96 | private function wire($item): Autowire |
91 | 97 | { |
92 | - if ($item instanceof Autowire) { |
|
98 | + if ($item instanceof Autowire) |
|
99 | + { |
|
93 | 100 | return $item; |
94 | 101 | } |
95 | 102 | |
96 | - if (is_string($item)) { |
|
103 | + if (is_string($item)) |
|
104 | + { |
|
97 | 105 | return new Autowire($item); |
98 | 106 | } |
99 | 107 |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | public function isFresh(string $key): bool |
68 | 68 | { |
69 | 69 | $mapFilename = $this->mapFilename($key); |
70 | - if (!$this->files->exists($mapFilename)) { |
|
70 | + if (!$this->files->exists($mapFilename)){ |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $time = $this->files->time($this->filename($key)); |
75 | 75 | |
76 | 76 | $files = (array)include $mapFilename; |
77 | - foreach ($files as $file) { |
|
78 | - if ($this->files->time($file) > $time) { |
|
77 | + foreach ($files as $file){ |
|
78 | + if ($this->files->time($file) > $time){ |
|
79 | 79 | // some partial has changed |
80 | 80 | return false; |
81 | 81 | } |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | public function delete(string $key): void |
93 | 93 | { |
94 | 94 | $filename = $this->filename($key); |
95 | - if ($this->files->exists($filename)) { |
|
95 | + if ($this->files->exists($filename)){ |
|
96 | 96 | $this->files->delete($filename); |
97 | 97 | } |
98 | 98 | |
99 | 99 | $mapFilename = $this->mapFilename($key); |
100 | - if ($this->files->exists($mapFilename)) { |
|
100 | + if ($this->files->exists($mapFilename)){ |
|
101 | 101 | $this->files->delete($mapFilename); |
102 | 102 | } |
103 | 103 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function load(string $key): void |
111 | 111 | { |
112 | 112 | $filename = $this->filename($key); |
113 | - if ($this->files->exists($filename)) { |
|
113 | + if ($this->files->exists($filename)){ |
|
114 | 114 | include_once $filename; |
115 | 115 | } |
116 | 116 | } |
@@ -67,15 +67,18 @@ discard block |
||
67 | 67 | public function isFresh(string $key): bool |
68 | 68 | { |
69 | 69 | $mapFilename = $this->mapFilename($key); |
70 | - if (!$this->files->exists($mapFilename)) { |
|
70 | + if (!$this->files->exists($mapFilename)) |
|
71 | + { |
|
71 | 72 | return false; |
72 | 73 | } |
73 | 74 | |
74 | 75 | $time = $this->files->time($this->filename($key)); |
75 | 76 | |
76 | 77 | $files = (array)include $mapFilename; |
77 | - foreach ($files as $file) { |
|
78 | - if ($this->files->time($file) > $time) { |
|
78 | + foreach ($files as $file) |
|
79 | + { |
|
80 | + if ($this->files->time($file) > $time) |
|
81 | + { |
|
79 | 82 | // some partial has changed |
80 | 83 | return false; |
81 | 84 | } |
@@ -92,12 +95,14 @@ discard block |
||
92 | 95 | public function delete(string $key): void |
93 | 96 | { |
94 | 97 | $filename = $this->filename($key); |
95 | - if ($this->files->exists($filename)) { |
|
98 | + if ($this->files->exists($filename)) |
|
99 | + { |
|
96 | 100 | $this->files->delete($filename); |
97 | 101 | } |
98 | 102 | |
99 | 103 | $mapFilename = $this->mapFilename($key); |
100 | - if ($this->files->exists($mapFilename)) { |
|
104 | + if ($this->files->exists($mapFilename)) |
|
105 | + { |
|
101 | 106 | $this->files->delete($mapFilename); |
102 | 107 | } |
103 | 108 | } |
@@ -110,7 +115,8 @@ discard block |
||
110 | 115 | public function load(string $key): void |
111 | 116 | { |
112 | 117 | $filename = $this->filename($key); |
113 | - if ($this->files->exists($filename)) { |
|
118 | + if ($this->files->exists($filename)) |
|
119 | + { |
|
114 | 120 | include_once $filename; |
115 | 121 | } |
116 | 122 | } |