@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | declare(strict_types=1); |
10 | 10 | |
11 | -if (!function_exists('inject')) { |
|
11 | +if (!function_exists('inject')){ |
|
12 | 12 | /** |
13 | 13 | * Macro function to be replaced by the injected value. |
14 | 14 | * |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | -if (!function_exists('injected')) { |
|
25 | +if (!function_exists('injected')){ |
|
26 | 26 | /** |
27 | 27 | * Return true if block value has been defined. |
28 | 28 | * |
@@ -8,7 +8,8 @@ discard block |
||
8 | 8 | */ |
9 | 9 | declare(strict_types=1); |
10 | 10 | |
11 | -if (!function_exists('inject')) { |
|
11 | +if (!function_exists('inject')) |
|
12 | +{ |
|
12 | 13 | /** |
13 | 14 | * Macro function to be replaced by the injected value. |
14 | 15 | * |
@@ -22,7 +23,8 @@ discard block |
||
22 | 23 | } |
23 | 24 | } |
24 | 25 | |
25 | -if (!function_exists('injected')) { |
|
26 | +if (!function_exists('injected')) |
|
27 | +{ |
|
26 | 28 | /** |
27 | 29 | * Return true if block value has been defined. |
28 | 30 | * |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function compileTemplate(Template $tpl): Result |
120 | 120 | { |
121 | - try { |
|
122 | - if (isset($this->visitors[self::STAGE_COMPILE])) { |
|
121 | + try{ |
|
122 | + if (isset($this->visitors[self::STAGE_COMPILE])){ |
|
123 | 123 | $traverser = new Traverser($this->visitors[self::STAGE_COMPILE]); |
124 | 124 | $tpl = $traverser->traverse([$tpl])[0]; |
125 | 125 | } |
126 | 126 | |
127 | 127 | return $this->compiler->compile($tpl); |
128 | - } catch (CompilerException $e) { |
|
128 | + }catch (CompilerException $e){ |
|
129 | 129 | throw $this->mapException($e); |
130 | 130 | } |
131 | 131 | } |
@@ -141,21 +141,21 @@ discard block |
||
141 | 141 | $source = $this->loader->load($path); |
142 | 142 | $stream = new StringStream($source->getContent()); |
143 | 143 | |
144 | - try { |
|
144 | + try{ |
|
145 | 145 | $tpl = $this->parser->withPath($path)->parse($stream); |
146 | 146 | $tpl->setContext(new Context( |
147 | 147 | new Token(Token::TYPE_RAW, 0, ''), |
148 | 148 | $path |
149 | 149 | )); |
150 | - } catch (ParserException $e) { |
|
150 | + }catch (ParserException $e){ |
|
151 | 151 | throw $this->mapException($e); |
152 | 152 | } |
153 | 153 | |
154 | - try { |
|
154 | + try{ |
|
155 | 155 | return $this->process($tpl); |
156 | - } catch (ContextExceptionInterface $e) { |
|
156 | + }catch (ContextExceptionInterface $e){ |
|
157 | 157 | throw $this->mapException($e); |
158 | - } catch (\Throwable $e) { |
|
158 | + }catch (\Throwable $e){ |
|
159 | 159 | throw $e; |
160 | 160 | } |
161 | 161 | } |
@@ -168,17 +168,17 @@ discard block |
||
168 | 168 | */ |
169 | 169 | private function process(Template $template): Template |
170 | 170 | { |
171 | - if (isset($this->visitors[self::STAGE_PREPARE])) { |
|
171 | + if (isset($this->visitors[self::STAGE_PREPARE])){ |
|
172 | 172 | $traverser = new Traverser($this->visitors[self::STAGE_PREPARE]); |
173 | 173 | $template = $traverser->traverse([$template])[0]; |
174 | 174 | } |
175 | 175 | |
176 | - if (isset($this->visitors[self::STAGE_TRANSFORM])) { |
|
176 | + if (isset($this->visitors[self::STAGE_TRANSFORM])){ |
|
177 | 177 | $traverser = new Traverser($this->visitors[self::STAGE_TRANSFORM]); |
178 | 178 | $template = $traverser->traverse([$template])[0]; |
179 | 179 | } |
180 | 180 | |
181 | - if (isset($this->visitors[self::STAGE_FINALIZE])) { |
|
181 | + if (isset($this->visitors[self::STAGE_FINALIZE])){ |
|
182 | 182 | $traverser = new Traverser($this->visitors[self::STAGE_FINALIZE]); |
183 | 183 | $template = $traverser->traverse([$template])[0]; |
184 | 184 | } |
@@ -194,17 +194,17 @@ discard block |
||
194 | 194 | */ |
195 | 195 | private function mapException(ContextExceptionInterface $e): ContextExceptionInterface |
196 | 196 | { |
197 | - if ($e->getContext()->getPath() === null) { |
|
197 | + if ($e->getContext()->getPath() === null){ |
|
198 | 198 | return $e; |
199 | 199 | } |
200 | 200 | |
201 | - try { |
|
201 | + try{ |
|
202 | 202 | $source = $this->loader->load($e->getContext()->getPath()); |
203 | - } catch (LoaderException $te) { |
|
203 | + }catch (LoaderException $te){ |
|
204 | 204 | return $e; |
205 | 205 | } |
206 | 206 | |
207 | - if ($source->getFilename() === null) { |
|
207 | + if ($source->getFilename() === null){ |
|
208 | 208 | return $e; |
209 | 209 | } |
210 | 210 |
@@ -118,14 +118,18 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function compileTemplate(Template $tpl): Result |
120 | 120 | { |
121 | - try { |
|
122 | - if (isset($this->visitors[self::STAGE_COMPILE])) { |
|
121 | + try |
|
122 | + { |
|
123 | + if (isset($this->visitors[self::STAGE_COMPILE])) |
|
124 | + { |
|
123 | 125 | $traverser = new Traverser($this->visitors[self::STAGE_COMPILE]); |
124 | 126 | $tpl = $traverser->traverse([$tpl])[0]; |
125 | 127 | } |
126 | 128 | |
127 | 129 | return $this->compiler->compile($tpl); |
128 | - } catch (CompilerException $e) { |
|
130 | + } |
|
131 | + catch (CompilerException $e) |
|
132 | + { |
|
129 | 133 | throw $this->mapException($e); |
130 | 134 | } |
131 | 135 | } |
@@ -141,21 +145,29 @@ discard block |
||
141 | 145 | $source = $this->loader->load($path); |
142 | 146 | $stream = new StringStream($source->getContent()); |
143 | 147 | |
144 | - try { |
|
148 | + try |
|
149 | + { |
|
145 | 150 | $tpl = $this->parser->withPath($path)->parse($stream); |
146 | 151 | $tpl->setContext(new Context( |
147 | 152 | new Token(Token::TYPE_RAW, 0, ''), |
148 | 153 | $path |
149 | 154 | )); |
150 | - } catch (ParserException $e) { |
|
155 | + } |
|
156 | + catch (ParserException $e) |
|
157 | + { |
|
151 | 158 | throw $this->mapException($e); |
152 | 159 | } |
153 | 160 | |
154 | - try { |
|
161 | + try |
|
162 | + { |
|
155 | 163 | return $this->process($tpl); |
156 | - } catch (ContextExceptionInterface $e) { |
|
164 | + } |
|
165 | + catch (ContextExceptionInterface $e) |
|
166 | + { |
|
157 | 167 | throw $this->mapException($e); |
158 | - } catch (\Throwable $e) { |
|
168 | + } |
|
169 | + catch (\Throwable $e) |
|
170 | + { |
|
159 | 171 | throw $e; |
160 | 172 | } |
161 | 173 | } |
@@ -168,17 +180,20 @@ discard block |
||
168 | 180 | */ |
169 | 181 | private function process(Template $template): Template |
170 | 182 | { |
171 | - if (isset($this->visitors[self::STAGE_PREPARE])) { |
|
183 | + if (isset($this->visitors[self::STAGE_PREPARE])) |
|
184 | + { |
|
172 | 185 | $traverser = new Traverser($this->visitors[self::STAGE_PREPARE]); |
173 | 186 | $template = $traverser->traverse([$template])[0]; |
174 | 187 | } |
175 | 188 | |
176 | - if (isset($this->visitors[self::STAGE_TRANSFORM])) { |
|
189 | + if (isset($this->visitors[self::STAGE_TRANSFORM])) |
|
190 | + { |
|
177 | 191 | $traverser = new Traverser($this->visitors[self::STAGE_TRANSFORM]); |
178 | 192 | $template = $traverser->traverse([$template])[0]; |
179 | 193 | } |
180 | 194 | |
181 | - if (isset($this->visitors[self::STAGE_FINALIZE])) { |
|
195 | + if (isset($this->visitors[self::STAGE_FINALIZE])) |
|
196 | + { |
|
182 | 197 | $traverser = new Traverser($this->visitors[self::STAGE_FINALIZE]); |
183 | 198 | $template = $traverser->traverse([$template])[0]; |
184 | 199 | } |
@@ -194,17 +209,22 @@ discard block |
||
194 | 209 | */ |
195 | 210 | private function mapException(ContextExceptionInterface $e): ContextExceptionInterface |
196 | 211 | { |
197 | - if ($e->getContext()->getPath() === null) { |
|
212 | + if ($e->getContext()->getPath() === null) |
|
213 | + { |
|
198 | 214 | return $e; |
199 | 215 | } |
200 | 216 | |
201 | - try { |
|
217 | + try |
|
218 | + { |
|
202 | 219 | $source = $this->loader->load($e->getContext()->getPath()); |
203 | - } catch (LoaderException $te) { |
|
220 | + } |
|
221 | + catch (LoaderException $te) |
|
222 | + { |
|
204 | 223 | return $e; |
205 | 224 | } |
206 | 225 | |
207 | - if ($source->getFilename() === null) { |
|
226 | + if ($source->getFilename() === null) |
|
227 | + { |
|
208 | 228 | return $e; |
209 | 229 | } |
210 | 230 |
@@ -41,16 +41,16 @@ |
||
41 | 41 | { |
42 | 42 | $result = $result ?? new Result(); |
43 | 43 | |
44 | - if (is_array($node)) { |
|
45 | - foreach ($node as $child) { |
|
44 | + if (is_array($node)){ |
|
45 | + foreach ($node as $child){ |
|
46 | 46 | $this->compile($child, $result); |
47 | 47 | } |
48 | 48 | |
49 | 49 | return $result; |
50 | 50 | } |
51 | 51 | |
52 | - foreach ($this->renders as $renderer) { |
|
53 | - if ($renderer->render($this, $result, $node)) { |
|
52 | + foreach ($this->renders as $renderer){ |
|
53 | + if ($renderer->render($this, $result, $node)){ |
|
54 | 54 | return $result; |
55 | 55 | } |
56 | 56 | } |
@@ -41,16 +41,20 @@ |
||
41 | 41 | { |
42 | 42 | $result = $result ?? new Result(); |
43 | 43 | |
44 | - if (is_array($node)) { |
|
45 | - foreach ($node as $child) { |
|
44 | + if (is_array($node)) |
|
45 | + { |
|
46 | + foreach ($node as $child) |
|
47 | + { |
|
46 | 48 | $this->compile($child, $result); |
47 | 49 | } |
48 | 50 | |
49 | 51 | return $result; |
50 | 52 | } |
51 | 53 | |
52 | - foreach ($this->renders as $renderer) { |
|
53 | - if ($renderer->render($this, $result, $node)) { |
|
54 | + foreach ($this->renders as $renderer) |
|
55 | + { |
|
56 | + if ($renderer->render($this, $result, $node)) |
|
57 | + { |
|
54 | 58 | return $result; |
55 | 59 | } |
56 | 60 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function renderBreak(Directive $directive): string |
62 | 62 | { |
63 | - if (isset($directive->values[0])) { |
|
63 | + if (isset($directive->values[0])){ |
|
64 | 64 | return sprintf('<?php break %s; ?>', $directive->values[0]); |
65 | 65 | } |
66 | 66 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function renderContinue(Directive $directive): string |
75 | 75 | { |
76 | - if (isset($directive->values[0])) { |
|
76 | + if (isset($directive->values[0])){ |
|
77 | 77 | return sprintf('<?php continue %s; ?>', $directive->values[0]); |
78 | 78 | } |
79 | 79 |
@@ -60,7 +60,8 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function renderBreak(Directive $directive): string |
62 | 62 | { |
63 | - if (isset($directive->values[0])) { |
|
63 | + if (isset($directive->values[0])) |
|
64 | + { |
|
64 | 65 | return sprintf('<?php break %s; ?>', $directive->values[0]); |
65 | 66 | } |
66 | 67 | |
@@ -73,7 +74,8 @@ discard block |
||
73 | 74 | */ |
74 | 75 | public function renderContinue(Directive $directive): string |
75 | 76 | { |
76 | - if (isset($directive->values[0])) { |
|
77 | + if (isset($directive->values[0])) |
|
78 | + { |
|
77 | 79 | return sprintf('<?php continue %s; ?>', $directive->values[0]); |
78 | 80 | } |
79 | 81 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function renderCase(Directive $directive): string |
130 | 130 | { |
131 | - if ($this->firstSwitchCase) { |
|
131 | + if ($this->firstSwitchCase){ |
|
132 | 132 | $this->firstSwitchCase = false; |
133 | 133 | |
134 | 134 | return sprintf('case (%s): ?>', $directive->body); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function renderDefault(Directive $directive): string |
145 | 145 | { |
146 | - if ($this->firstSwitchCase) { |
|
146 | + if ($this->firstSwitchCase){ |
|
147 | 147 | $this->firstSwitchCase = false; |
148 | 148 | |
149 | 149 | return 'default: ?>'; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function renderBreak(Directive $directive): string |
169 | 169 | { |
170 | - if (isset($directive->values[0])) { |
|
170 | + if (isset($directive->values[0])){ |
|
171 | 171 | return sprintf('<?php break %s; ?>', $directive->values[0]); |
172 | 172 | } |
173 | 173 |
@@ -128,7 +128,8 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function renderCase(Directive $directive): string |
130 | 130 | { |
131 | - if ($this->firstSwitchCase) { |
|
131 | + if ($this->firstSwitchCase) |
|
132 | + { |
|
132 | 133 | $this->firstSwitchCase = false; |
133 | 134 | |
134 | 135 | return sprintf('case (%s): ?>', $directive->body); |
@@ -143,7 +144,8 @@ discard block |
||
143 | 144 | */ |
144 | 145 | public function renderDefault(Directive $directive): string |
145 | 146 | { |
146 | - if ($this->firstSwitchCase) { |
|
147 | + if ($this->firstSwitchCase) |
|
148 | + { |
|
147 | 149 | $this->firstSwitchCase = false; |
148 | 150 | |
149 | 151 | return 'default: ?>'; |
@@ -167,7 +169,8 @@ discard block |
||
167 | 169 | */ |
168 | 170 | public function renderBreak(Directive $directive): string |
169 | 171 | { |
170 | - if (isset($directive->values[0])) { |
|
172 | + if (isset($directive->values[0])) |
|
173 | + { |
|
171 | 174 | return sprintf('<?php break %s; ?>', $directive->values[0]); |
172 | 175 | } |
173 | 176 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function hasDirective(string $name): bool |
38 | 38 | { |
39 | - return $this->r->hasMethod('render' . ucfirst($name)); |
|
39 | + return $this->r->hasMethod('render'.ucfirst($name)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function render(Directive $directive): ?string |
47 | 47 | { |
48 | - if (!$this->hasDirective($directive->name)) { |
|
48 | + if (!$this->hasDirective($directive->name)){ |
|
49 | 49 | return null; |
50 | 50 | } |
51 | 51 | |
52 | - return call_user_func([$this, 'render' . ucfirst($directive->name)], $directive); |
|
52 | + return call_user_func([$this, 'render'.ucfirst($directive->name)], $directive); |
|
53 | 53 | } |
54 | 54 | } |
@@ -45,7 +45,8 @@ |
||
45 | 45 | */ |
46 | 46 | public function render(Directive $directive): ?string |
47 | 47 | { |
48 | - if (!$this->hasDirective($directive->name)) { |
|
48 | + if (!$this->hasDirective($directive->name)) |
|
49 | + { |
|
49 | 50 | return null; |
50 | 51 | } |
51 | 52 |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function hasDirective(string $name): bool |
44 | 44 | { |
45 | - foreach ($this->directives as $directiveRenderer) { |
|
46 | - if ($directiveRenderer->hasDirective($name)) { |
|
45 | + foreach ($this->directives as $directiveRenderer){ |
|
46 | + if ($directiveRenderer->hasDirective($name)){ |
|
47 | 47 | return true; |
48 | 48 | } |
49 | 49 | } |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function render(Directive $directive): ?string |
59 | 59 | { |
60 | - foreach ($this->directives as $directiveRenderer) { |
|
61 | - if ($directiveRenderer->hasDirective($directive->name)) { |
|
60 | + foreach ($this->directives as $directiveRenderer){ |
|
61 | + if ($directiveRenderer->hasDirective($directive->name)){ |
|
62 | 62 | return $directiveRenderer->render($directive); |
63 | 63 | } |
64 | 64 | } |
@@ -42,8 +42,10 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function hasDirective(string $name): bool |
44 | 44 | { |
45 | - foreach ($this->directives as $directiveRenderer) { |
|
46 | - if ($directiveRenderer->hasDirective($name)) { |
|
45 | + foreach ($this->directives as $directiveRenderer) |
|
46 | + { |
|
47 | + if ($directiveRenderer->hasDirective($name)) |
|
48 | + { |
|
47 | 49 | return true; |
48 | 50 | } |
49 | 51 | } |
@@ -57,8 +59,10 @@ discard block |
||
57 | 59 | */ |
58 | 60 | public function render(Directive $directive): ?string |
59 | 61 | { |
60 | - foreach ($this->directives as $directiveRenderer) { |
|
61 | - if ($directiveRenderer->hasDirective($directive->name)) { |
|
62 | + foreach ($this->directives as $directiveRenderer) |
|
63 | + { |
|
64 | + if ($directiveRenderer->hasDirective($directive->name)) |
|
65 | + { |
|
62 | 66 | return $directiveRenderer->render($directive); |
63 | 67 | } |
64 | 68 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | { |
35 | 35 | protected function compile(string $source, array $visitors = [], LoaderInterface $loader = null) |
36 | 36 | { |
37 | - if ($loader === null) { |
|
37 | + if ($loader === null){ |
|
38 | 38 | $loader = new StringLoader(); |
39 | 39 | $loader->set('root', $source); |
40 | 40 | } |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup())); |
70 | 70 | $builder->getCompiler()->addRenderer(new HTMLRenderer()); |
71 | 71 | |
72 | - foreach ($this->getVisitors() as $visitor) { |
|
72 | + foreach ($this->getVisitors() as $visitor){ |
|
73 | 73 | $builder->addVisitor($visitor); |
74 | 74 | } |
75 | 75 | |
76 | - foreach ($visitors as $visitor) { |
|
76 | + foreach ($visitors as $visitor){ |
|
77 | 77 | $builder->addVisitor($visitor); |
78 | 78 | } |
79 | 79 | |
@@ -90,6 +90,6 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function getFixtureLoader(): LoaderInterface |
92 | 92 | { |
93 | - return new DirectoryLoader(__DIR__ . '/../fixtures'); |
|
93 | + return new DirectoryLoader(__DIR__.'/../fixtures'); |
|
94 | 94 | } |
95 | 95 | } |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | { |
35 | 35 | protected function compile(string $source, array $visitors = [], LoaderInterface $loader = null) |
36 | 36 | { |
37 | - if ($loader === null) { |
|
37 | + if ($loader === null) |
|
38 | + { |
|
38 | 39 | $loader = new StringLoader(); |
39 | 40 | $loader->set('root', $source); |
40 | 41 | } |
@@ -69,11 +70,13 @@ discard block |
||
69 | 70 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup())); |
70 | 71 | $builder->getCompiler()->addRenderer(new HTMLRenderer()); |
71 | 72 | |
72 | - foreach ($this->getVisitors() as $visitor) { |
|
73 | + foreach ($this->getVisitors() as $visitor) |
|
74 | + { |
|
73 | 75 | $builder->addVisitor($visitor); |
74 | 76 | } |
75 | 77 | |
76 | - foreach ($visitors as $visitor) { |
|
78 | + foreach ($visitors as $visitor) |
|
79 | + { |
|
77 | 80 | $builder->addVisitor($visitor); |
78 | 81 | } |
79 | 82 |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function testVerbatim4(): void |
105 | 105 | { |
106 | 106 | $this->assertSame( |
107 | - '<script>alert(<?php echo json_encode' . |
|
107 | + '<script>alert(<?php echo json_encode'. |
|
108 | 108 | '("hello\' \'world", JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, 512); ?>)</script>', |
109 | 109 | $res = $this->compile('<script>alert({{ "hello\' \'world" }})</script>')->getContent() |
110 | 110 | ); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | ob_start(); |
129 | 129 | |
130 | - eval('?>' . $body); |
|
130 | + eval('?>'.$body); |
|
131 | 131 | |
132 | 132 | return ob_get_clean(); |
133 | 133 | } |