@@ -31,7 +31,7 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
| 33 | 33 | { |
| 34 | - switch ($token->type) { |
|
| 34 | + switch ($token->type){ |
|
| 35 | 35 | case InlineGrammar::TYPE_OPEN_TAG: |
| 36 | 36 | $this->inline = new Inline(new Context($token, $parser->getPath())); |
| 37 | 37 | $asm->push($this->inline); |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
| 33 | 33 | { |
| 34 | - switch ($token->type) { |
|
| 34 | + switch ($token->type) |
|
| 35 | + { |
|
| 35 | 36 | case InlineGrammar::TYPE_OPEN_TAG: |
| 36 | 37 | $this->inline = new Inline(new Context($token, $parser->getPath())); |
| 37 | 38 | $asm->push($this->inline); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public function getStackPath(): string |
| 41 | 41 | { |
| 42 | 42 | $path = [$this->nodeName($this->node)]; |
| 43 | - foreach ($this->stack as $tuple) { |
|
| 43 | + foreach ($this->stack as $tuple){ |
|
| 44 | 44 | $path[] = $this->nodeName($tuple[0]); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | private function nodeName(NodeInterface $node): string |
| 73 | 73 | { |
| 74 | 74 | $r = new ReflectionClass($node); |
| 75 | - if (property_exists($node, 'name')) { |
|
| 76 | - return lcfirst($r->getShortName()) . "[{$node->name}]"; |
|
| 75 | + if (property_exists($node, 'name')){ |
|
| 76 | + return lcfirst($r->getShortName())."[{$node->name}]"; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return lcfirst($r->getShortName()); |
@@ -40,7 +40,8 @@ discard block |
||
| 40 | 40 | public function getStackPath(): string |
| 41 | 41 | { |
| 42 | 42 | $path = [$this->nodeName($this->node)]; |
| 43 | - foreach ($this->stack as $tuple) { |
|
| 43 | + foreach ($this->stack as $tuple) |
|
| 44 | + { |
|
| 44 | 45 | $path[] = $this->nodeName($tuple[0]); |
| 45 | 46 | } |
| 46 | 47 | |
@@ -72,7 +73,8 @@ discard block |
||
| 72 | 73 | private function nodeName(NodeInterface $node): string |
| 73 | 74 | { |
| 74 | 75 | $r = new ReflectionClass($node); |
| 75 | - if (property_exists($node, 'name')) { |
|
| 76 | + if (property_exists($node, 'name')) |
|
| 77 | + { |
|
| 76 | 78 | return lcfirst($r->getShortName()) . "[{$node->name}]"; |
| 77 | 79 | } |
| 78 | 80 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function __construct(array $visitors = []) |
| 31 | 31 | { |
| 32 | - foreach ($visitors as $visitor) { |
|
| 32 | + foreach ($visitors as $visitor){ |
|
| 33 | 33 | $this->addVisitor($visitor); |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public function removeVisitor(VisitorInterface $visitor): void |
| 46 | 46 | { |
| 47 | - foreach ($this->visitors as $index => $added) { |
|
| 48 | - if ($added === $visitor) { |
|
| 47 | + foreach ($this->visitors as $index => $added){ |
|
| 48 | + if ($added === $visitor){ |
|
| 49 | 49 | unset($this->visitors[$index]); |
| 50 | 50 | break; |
| 51 | 51 | } |
@@ -64,22 +64,22 @@ discard block |
||
| 64 | 64 | $context ??= new VisitorContext(); |
| 65 | 65 | |
| 66 | 66 | $ctx = clone $context; |
| 67 | - foreach ($nodes as $index => $node) { |
|
| 68 | - if ($this->stopTraversal) { |
|
| 67 | + foreach ($nodes as $index => $node){ |
|
| 68 | + if ($this->stopTraversal){ |
|
| 69 | 69 | break; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $traverseChildren = true; |
| 73 | 73 | $breakVisitorID = null; |
| 74 | 74 | |
| 75 | - if ($node instanceof NodeInterface) { |
|
| 75 | + if ($node instanceof NodeInterface){ |
|
| 76 | 76 | $ctx = $context->withNode($node); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 79 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 80 | 80 | $result = $visitor->enterNode($node, $ctx); |
| 81 | 81 | |
| 82 | - switch (true) { |
|
| 82 | + switch (true){ |
|
| 83 | 83 | case $result === null: |
| 84 | 84 | break; |
| 85 | 85 | |
@@ -103,23 +103,23 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | default: |
| 105 | 105 | throw new LogicException( |
| 106 | - 'enterNode() returned invalid value of type ' . gettype($result) |
|
| 106 | + 'enterNode() returned invalid value of type '.gettype($result) |
|
| 107 | 107 | ); |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // sub nodes |
| 112 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
| 112 | + if ($traverseChildren && $node instanceof NodeInterface){ |
|
| 113 | 113 | $nodes[$index] = $this->traverseNode($node, $ctx); |
| 114 | - if ($this->stopTraversal) { |
|
| 114 | + if ($this->stopTraversal){ |
|
| 115 | 115 | break; |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 119 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 120 | 120 | $result = $visitor->leaveNode($node, $ctx); |
| 121 | 121 | |
| 122 | - switch (true) { |
|
| 122 | + switch (true){ |
|
| 123 | 123 | case $result === null: |
| 124 | 124 | break; |
| 125 | 125 | |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | default: |
| 139 | 139 | throw new LogicException( |
| 140 | - 'leaveNode() returned invalid value of type ' . gettype($result) |
|
| 140 | + 'leaveNode() returned invalid value of type '.gettype($result) |
|
| 141 | 141 | ); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ($breakVisitorID === $visitorID) { |
|
| 144 | + if ($breakVisitorID === $visitorID){ |
|
| 145 | 145 | break; |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
| 157 | 157 | { |
| 158 | 158 | $ctx = clone $context; |
| 159 | - foreach ($node as $name => $_) { |
|
| 159 | + foreach ($node as $name => $_){ |
|
| 160 | 160 | $child = &$node->$name; |
| 161 | - if (is_array($child)) { |
|
| 161 | + if (is_array($child)){ |
|
| 162 | 162 | $child = $this->traverse($child, $ctx); |
| 163 | - if ($this->stopTraversal) { |
|
| 163 | + if ($this->stopTraversal){ |
|
| 164 | 164 | break; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | continue; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if (!$child instanceof NodeInterface) { |
|
| 170 | + if (!$child instanceof NodeInterface){ |
|
| 171 | 171 | continue; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | $traverseChildren = true; |
| 177 | 177 | $breakVisitorID = null; |
| 178 | 178 | |
| 179 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 179 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 180 | 180 | $result = $visitor->enterNode($child, $ctx); |
| 181 | - switch (true) { |
|
| 181 | + switch (true){ |
|
| 182 | 182 | case $result === null: |
| 183 | 183 | break; |
| 184 | 184 | |
@@ -201,22 +201,22 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | default: |
| 203 | 203 | throw new LogicException( |
| 204 | - 'enterNode() returned invalid value of type ' . gettype($result) |
|
| 204 | + 'enterNode() returned invalid value of type '.gettype($result) |
|
| 205 | 205 | ); |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if ($traverseChildren) { |
|
| 209 | + if ($traverseChildren){ |
|
| 210 | 210 | $child = $this->traverseNode($child, $ctx); |
| 211 | - if ($this->stopTraversal) { |
|
| 211 | + if ($this->stopTraversal){ |
|
| 212 | 212 | break; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 216 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 217 | 217 | $result = $visitor->leaveNode($child, $ctx); |
| 218 | 218 | |
| 219 | - switch (true) { |
|
| 219 | + switch (true){ |
|
| 220 | 220 | case $result === null: |
| 221 | 221 | break; |
| 222 | 222 | |
@@ -230,11 +230,11 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | default: |
| 232 | 232 | throw new LogicException( |
| 233 | - 'leaveNode() returned invalid value of type ' . gettype($result) |
|
| 233 | + 'leaveNode() returned invalid value of type '.gettype($result) |
|
| 234 | 234 | ); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ($breakVisitorID === $visitorID) { |
|
| 237 | + if ($breakVisitorID === $visitorID){ |
|
| 238 | 238 | break; |
| 239 | 239 | } |
| 240 | 240 | } |
@@ -29,7 +29,8 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function __construct(array $visitors = []) |
| 31 | 31 | { |
| 32 | - foreach ($visitors as $visitor) { |
|
| 32 | + foreach ($visitors as $visitor) |
|
| 33 | + { |
|
| 33 | 34 | $this->addVisitor($visitor); |
| 34 | 35 | } |
| 35 | 36 | } |
@@ -44,8 +45,10 @@ discard block |
||
| 44 | 45 | |
| 45 | 46 | public function removeVisitor(VisitorInterface $visitor): void |
| 46 | 47 | { |
| 47 | - foreach ($this->visitors as $index => $added) { |
|
| 48 | - if ($added === $visitor) { |
|
| 48 | + foreach ($this->visitors as $index => $added) |
|
| 49 | + { |
|
| 50 | + if ($added === $visitor) |
|
| 51 | + { |
|
| 49 | 52 | unset($this->visitors[$index]); |
| 50 | 53 | break; |
| 51 | 54 | } |
@@ -64,22 +67,27 @@ discard block |
||
| 64 | 67 | $context ??= new VisitorContext(); |
| 65 | 68 | |
| 66 | 69 | $ctx = clone $context; |
| 67 | - foreach ($nodes as $index => $node) { |
|
| 68 | - if ($this->stopTraversal) { |
|
| 70 | + foreach ($nodes as $index => $node) |
|
| 71 | + { |
|
| 72 | + if ($this->stopTraversal) |
|
| 73 | + { |
|
| 69 | 74 | break; |
| 70 | 75 | } |
| 71 | 76 | |
| 72 | 77 | $traverseChildren = true; |
| 73 | 78 | $breakVisitorID = null; |
| 74 | 79 | |
| 75 | - if ($node instanceof NodeInterface) { |
|
| 80 | + if ($node instanceof NodeInterface) |
|
| 81 | + { |
|
| 76 | 82 | $ctx = $context->withNode($node); |
| 77 | 83 | } |
| 78 | 84 | |
| 79 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 85 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 86 | + { |
|
| 80 | 87 | $result = $visitor->enterNode($node, $ctx); |
| 81 | 88 | |
| 82 | - switch (true) { |
|
| 89 | + switch (true) |
|
| 90 | + { |
|
| 83 | 91 | case $result === null: |
| 84 | 92 | break; |
| 85 | 93 | |
@@ -109,17 +117,21 @@ discard block |
||
| 109 | 117 | } |
| 110 | 118 | |
| 111 | 119 | // sub nodes |
| 112 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
| 120 | + if ($traverseChildren && $node instanceof NodeInterface) |
|
| 121 | + { |
|
| 113 | 122 | $nodes[$index] = $this->traverseNode($node, $ctx); |
| 114 | - if ($this->stopTraversal) { |
|
| 123 | + if ($this->stopTraversal) |
|
| 124 | + { |
|
| 115 | 125 | break; |
| 116 | 126 | } |
| 117 | 127 | } |
| 118 | 128 | |
| 119 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 129 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 130 | + { |
|
| 120 | 131 | $result = $visitor->leaveNode($node, $ctx); |
| 121 | 132 | |
| 122 | - switch (true) { |
|
| 133 | + switch (true) |
|
| 134 | + { |
|
| 123 | 135 | case $result === null: |
| 124 | 136 | break; |
| 125 | 137 | |
@@ -141,7 +153,8 @@ discard block |
||
| 141 | 153 | ); |
| 142 | 154 | } |
| 143 | 155 | |
| 144 | - if ($breakVisitorID === $visitorID) { |
|
| 156 | + if ($breakVisitorID === $visitorID) |
|
| 157 | + { |
|
| 145 | 158 | break; |
| 146 | 159 | } |
| 147 | 160 | } |
@@ -156,18 +169,22 @@ discard block |
||
| 156 | 169 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
| 157 | 170 | { |
| 158 | 171 | $ctx = clone $context; |
| 159 | - foreach ($node as $name => $_) { |
|
| 172 | + foreach ($node as $name => $_) |
|
| 173 | + { |
|
| 160 | 174 | $child = &$node->$name; |
| 161 | - if (is_array($child)) { |
|
| 175 | + if (is_array($child)) |
|
| 176 | + { |
|
| 162 | 177 | $child = $this->traverse($child, $ctx); |
| 163 | - if ($this->stopTraversal) { |
|
| 178 | + if ($this->stopTraversal) |
|
| 179 | + { |
|
| 164 | 180 | break; |
| 165 | 181 | } |
| 166 | 182 | |
| 167 | 183 | continue; |
| 168 | 184 | } |
| 169 | 185 | |
| 170 | - if (!$child instanceof NodeInterface) { |
|
| 186 | + if (!$child instanceof NodeInterface) |
|
| 187 | + { |
|
| 171 | 188 | continue; |
| 172 | 189 | } |
| 173 | 190 | |
@@ -176,9 +193,11 @@ discard block |
||
| 176 | 193 | $traverseChildren = true; |
| 177 | 194 | $breakVisitorID = null; |
| 178 | 195 | |
| 179 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 196 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 197 | + { |
|
| 180 | 198 | $result = $visitor->enterNode($child, $ctx); |
| 181 | - switch (true) { |
|
| 199 | + switch (true) |
|
| 200 | + { |
|
| 182 | 201 | case $result === null: |
| 183 | 202 | break; |
| 184 | 203 | |
@@ -206,17 +225,21 @@ discard block |
||
| 206 | 225 | } |
| 207 | 226 | } |
| 208 | 227 | |
| 209 | - if ($traverseChildren) { |
|
| 228 | + if ($traverseChildren) |
|
| 229 | + { |
|
| 210 | 230 | $child = $this->traverseNode($child, $ctx); |
| 211 | - if ($this->stopTraversal) { |
|
| 231 | + if ($this->stopTraversal) |
|
| 232 | + { |
|
| 212 | 233 | break; |
| 213 | 234 | } |
| 214 | 235 | } |
| 215 | 236 | |
| 216 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 237 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 238 | + { |
|
| 217 | 239 | $result = $visitor->leaveNode($child, $ctx); |
| 218 | 240 | |
| 219 | - switch (true) { |
|
| 241 | + switch (true) |
|
| 242 | + { |
|
| 220 | 243 | case $result === null: |
| 221 | 244 | break; |
| 222 | 245 | |
@@ -234,7 +257,8 @@ discard block |
||
| 234 | 257 | ); |
| 235 | 258 | } |
| 236 | 259 | |
| 237 | - if ($breakVisitorID === $visitorID) { |
|
| 260 | + if ($breakVisitorID === $visitorID) |
|
| 261 | + { |
|
| 238 | 262 | break; |
| 239 | 263 | } |
| 240 | 264 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 30 | 30 | { |
| 31 | - switch (true) { |
|
| 31 | + switch (true){ |
|
| 32 | 32 | case $node instanceof Tag: |
| 33 | 33 | $this->tag($compiler, $result, $node); |
| 34 | 34 | return true; |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $result->push(sprintf('<%s', $node->name), $node->getContext()); |
| 52 | 52 | |
| 53 | - foreach ($node->attrs as $attr) { |
|
| 54 | - if (!$attr instanceof Attribute) { |
|
| 53 | + foreach ($node->attrs as $attr){ |
|
| 54 | + if (!$attr instanceof Attribute){ |
|
| 55 | 55 | $compiler->compile($attr, $result); |
| 56 | 56 | continue; |
| 57 | 57 | } |
@@ -61,30 +61,30 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | $result->push(sprintf('%s>', $node->void ? '/' : ''), null); |
| 63 | 63 | |
| 64 | - foreach ($node->nodes as $child) { |
|
| 64 | + foreach ($node->nodes as $child){ |
|
| 65 | 65 | $compiler->compile($child, $result); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if (!$node->void) { |
|
| 68 | + if (!$node->void){ |
|
| 69 | 69 | $result->push(sprintf('</%s>', $node->name), null); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | private function attribute(Compiler $compiler, Result $result, Attr $node): void |
| 74 | 74 | { |
| 75 | - if ($node->name instanceof NodeInterface) { |
|
| 75 | + if ($node->name instanceof NodeInterface){ |
|
| 76 | 76 | $result->push(' ', null); |
| 77 | 77 | $compiler->compile($node->name, $result); |
| 78 | - } else { |
|
| 78 | + }else{ |
|
| 79 | 79 | $result->push(sprintf(' %s', $node->name), $node->getContext()); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $value = $node->value; |
| 83 | - if ($value instanceof Nil) { |
|
| 83 | + if ($value instanceof Nil){ |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if ($value instanceof NodeInterface) { |
|
| 87 | + if ($value instanceof NodeInterface){ |
|
| 88 | 88 | $result->push('=', null); |
| 89 | 89 | $compiler->compile($value, $result); |
| 90 | 90 | return; |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | private function verbatim(Compiler $compiler, Result $result, Verbatim $node): void |
| 97 | 97 | { |
| 98 | - foreach ($node->nodes as $child) { |
|
| 99 | - if (is_string($child)) { |
|
| 98 | + foreach ($node->nodes as $child){ |
|
| 99 | + if (is_string($child)){ |
|
| 100 | 100 | $result->push($child, null); |
| 101 | 101 | continue; |
| 102 | 102 | } |
@@ -28,7 +28,8 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 30 | 30 | { |
| 31 | - switch (true) { |
|
| 31 | + switch (true) |
|
| 32 | + { |
|
| 32 | 33 | case $node instanceof Tag: |
| 33 | 34 | $this->tag($compiler, $result, $node); |
| 34 | 35 | return true; |
@@ -50,8 +51,10 @@ discard block |
||
| 50 | 51 | { |
| 51 | 52 | $result->push(sprintf('<%s', $node->name), $node->getContext()); |
| 52 | 53 | |
| 53 | - foreach ($node->attrs as $attr) { |
|
| 54 | - if (!$attr instanceof Attribute) { |
|
| 54 | + foreach ($node->attrs as $attr) |
|
| 55 | + { |
|
| 56 | + if (!$attr instanceof Attribute) |
|
| 57 | + { |
|
| 55 | 58 | $compiler->compile($attr, $result); |
| 56 | 59 | continue; |
| 57 | 60 | } |
@@ -61,30 +64,37 @@ discard block |
||
| 61 | 64 | |
| 62 | 65 | $result->push(sprintf('%s>', $node->void ? '/' : ''), null); |
| 63 | 66 | |
| 64 | - foreach ($node->nodes as $child) { |
|
| 67 | + foreach ($node->nodes as $child) |
|
| 68 | + { |
|
| 65 | 69 | $compiler->compile($child, $result); |
| 66 | 70 | } |
| 67 | 71 | |
| 68 | - if (!$node->void) { |
|
| 72 | + if (!$node->void) |
|
| 73 | + { |
|
| 69 | 74 | $result->push(sprintf('</%s>', $node->name), null); |
| 70 | 75 | } |
| 71 | 76 | } |
| 72 | 77 | |
| 73 | 78 | private function attribute(Compiler $compiler, Result $result, Attr $node): void |
| 74 | 79 | { |
| 75 | - if ($node->name instanceof NodeInterface) { |
|
| 80 | + if ($node->name instanceof NodeInterface) |
|
| 81 | + { |
|
| 76 | 82 | $result->push(' ', null); |
| 77 | 83 | $compiler->compile($node->name, $result); |
| 78 | - } else { |
|
| 84 | + } |
|
| 85 | + else |
|
| 86 | + { |
|
| 79 | 87 | $result->push(sprintf(' %s', $node->name), $node->getContext()); |
| 80 | 88 | } |
| 81 | 89 | |
| 82 | 90 | $value = $node->value; |
| 83 | - if ($value instanceof Nil) { |
|
| 91 | + if ($value instanceof Nil) |
|
| 92 | + { |
|
| 84 | 93 | return; |
| 85 | 94 | } |
| 86 | 95 | |
| 87 | - if ($value instanceof NodeInterface) { |
|
| 96 | + if ($value instanceof NodeInterface) |
|
| 97 | + { |
|
| 88 | 98 | $result->push('=', null); |
| 89 | 99 | $compiler->compile($value, $result); |
| 90 | 100 | return; |
@@ -95,8 +105,10 @@ discard block |
||
| 95 | 105 | |
| 96 | 106 | private function verbatim(Compiler $compiler, Result $result, Verbatim $node): void |
| 97 | 107 | { |
| 98 | - foreach ($node->nodes as $child) { |
|
| 99 | - if (is_string($child)) { |
|
| 108 | + foreach ($node->nodes as $child) |
|
| 109 | + { |
|
| 110 | + if (is_string($child)) |
|
| 111 | + { |
|
| 100 | 112 | $result->push($child, null); |
| 101 | 113 | continue; |
| 102 | 114 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public function __construct( |
| 33 | 33 | DirectiveRendererInterface $directiveRenderer = null, |
| 34 | 34 | string $defaultFilter = self::DEFAULT_FILTER |
| 35 | - ) { |
|
| 35 | + ){ |
|
| 36 | 36 | $this->directiveRenderer = $directiveRenderer; |
| 37 | 37 | $this->defaultFilter = $defaultFilter; |
| 38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 44 | 44 | { |
| 45 | - switch (true) { |
|
| 45 | + switch (true){ |
|
| 46 | 46 | case $node instanceof Output: |
| 47 | 47 | $this->output($result, $node); |
| 48 | 48 | return true; |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | private function directive(Result $source, Directive $directive): void |
| 62 | 62 | { |
| 63 | - if ($this->directiveRenderer !== null) { |
|
| 63 | + if ($this->directiveRenderer !== null){ |
|
| 64 | 64 | $result = $this->directiveRenderer->render($directive); |
| 65 | - if ($result !== null) { |
|
| 65 | + if ($result !== null){ |
|
| 66 | 66 | $source->push($result, $directive->getContext()); |
| 67 | 67 | return; |
| 68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | private function output(Result $source, Output $output): void |
| 78 | 78 | { |
| 79 | - if ($output->rawOutput) { |
|
| 79 | + if ($output->rawOutput){ |
|
| 80 | 80 | $source->push(sprintf('<?php echo %s; ?>', trim($output->body)), $output->getContext()); |
| 81 | 81 | return; |
| 82 | 82 | } |
@@ -42,7 +42,8 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 44 | 44 | { |
| 45 | - switch (true) { |
|
| 45 | + switch (true) |
|
| 46 | + { |
|
| 46 | 47 | case $node instanceof Output: |
| 47 | 48 | $this->output($result, $node); |
| 48 | 49 | return true; |
@@ -60,9 +61,11 @@ discard block |
||
| 60 | 61 | */ |
| 61 | 62 | private function directive(Result $source, Directive $directive): void |
| 62 | 63 | { |
| 63 | - if ($this->directiveRenderer !== null) { |
|
| 64 | + if ($this->directiveRenderer !== null) |
|
| 65 | + { |
|
| 64 | 66 | $result = $this->directiveRenderer->render($directive); |
| 65 | - if ($result !== null) { |
|
| 67 | + if ($result !== null) |
|
| 68 | + { |
|
| 66 | 69 | $source->push($result, $directive->getContext()); |
| 67 | 70 | return; |
| 68 | 71 | } |
@@ -76,7 +79,8 @@ discard block |
||
| 76 | 79 | |
| 77 | 80 | private function output(Result $source, Output $output): void |
| 78 | 81 | { |
| 79 | - if ($output->rawOutput) { |
|
| 82 | + if ($output->rawOutput) |
|
| 83 | + { |
|
| 80 | 84 | $source->push(sprintf('<?php echo %s; ?>', trim($output->body)), $output->getContext()); |
| 81 | 85 | return; |
| 82 | 86 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | Result $result, |
| 33 | 33 | NodeInterface $node |
| 34 | 34 | ): bool { |
| 35 | - switch (true) { |
|
| 35 | + switch (true){ |
|
| 36 | 36 | case $node instanceof Hidden: |
| 37 | 37 | return true; |
| 38 | 38 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | $result->withinContext( |
| 41 | 41 | $node->getContext(), |
| 42 | 42 | function (Result $source) use ($node, $compiler): void { |
| 43 | - foreach ($node->nodes as $child) { |
|
| 43 | + foreach ($node->nodes as $child){ |
|
| 44 | 44 | $compiler->compile($child, $source); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | $result->withinContext( |
| 53 | 53 | $node->getContext(), |
| 54 | 54 | function (Result $source) use ($node, $compiler): void { |
| 55 | - foreach ($node->nodes as $child) { |
|
| 56 | - if (is_string($child)) { |
|
| 55 | + foreach ($node->nodes as $child){ |
|
| 56 | + if (is_string($child)){ |
|
| 57 | 57 | $source->push($child, null); |
| 58 | 58 | continue; |
| 59 | 59 | } |
@@ -32,7 +32,8 @@ discard block |
||
| 32 | 32 | Result $result, |
| 33 | 33 | NodeInterface $node |
| 34 | 34 | ): bool { |
| 35 | - switch (true) { |
|
| 35 | + switch (true) |
|
| 36 | + { |
|
| 36 | 37 | case $node instanceof Hidden: |
| 37 | 38 | return true; |
| 38 | 39 | |
@@ -40,7 +41,8 @@ discard block |
||
| 40 | 41 | $result->withinContext( |
| 41 | 42 | $node->getContext(), |
| 42 | 43 | function (Result $source) use ($node, $compiler): void { |
| 43 | - foreach ($node->nodes as $child) { |
|
| 44 | + foreach ($node->nodes as $child) |
|
| 45 | + { |
|
| 44 | 46 | $compiler->compile($child, $source); |
| 45 | 47 | } |
| 46 | 48 | } |
@@ -52,8 +54,10 @@ discard block |
||
| 52 | 54 | $result->withinContext( |
| 53 | 55 | $node->getContext(), |
| 54 | 56 | function (Result $source) use ($node, $compiler): void { |
| 55 | - foreach ($node->nodes as $child) { |
|
| 56 | - if (is_string($child)) { |
|
| 57 | + foreach ($node->nodes as $child) |
|
| 58 | + { |
|
| 59 | + if (is_string($child)) |
|
| 60 | + { |
|
| 57 | 61 | $source->push($child, null); |
| 58 | 62 | continue; |
| 59 | 63 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 26 | 26 | { |
| 27 | - if ($node instanceof PHP) { |
|
| 27 | + if ($node instanceof PHP){ |
|
| 28 | 28 | $result->push($node->content, $node->getContext()); |
| 29 | 29 | return true; |
| 30 | 30 | } |
@@ -24,7 +24,8 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 26 | 26 | { |
| 27 | - if ($node instanceof PHP) { |
|
| 27 | + if ($node instanceof PHP) |
|
| 28 | + { |
|
| 28 | 29 | $result->push($node->content, $node->getContext()); |
| 29 | 30 | return true; |
| 30 | 31 | } |
@@ -37,16 +37,16 @@ |
||
| 37 | 37 | { |
| 38 | 38 | $result ??= new Result(); |
| 39 | 39 | |
| 40 | - if (is_array($node)) { |
|
| 41 | - foreach ($node as $child) { |
|
| 40 | + if (is_array($node)){ |
|
| 41 | + foreach ($node as $child){ |
|
| 42 | 42 | $this->compile($child, $result); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | return $result; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - foreach ($this->renders as $renderer) { |
|
| 49 | - if ($renderer->render($this, $result, $node)) { |
|
| 48 | + foreach ($this->renders as $renderer){ |
|
| 49 | + if ($renderer->render($this, $result, $node)){ |
|
| 50 | 50 | return $result; |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -37,16 +37,20 @@ |
||
| 37 | 37 | { |
| 38 | 38 | $result ??= new Result(); |
| 39 | 39 | |
| 40 | - if (is_array($node)) { |
|
| 41 | - foreach ($node as $child) { |
|
| 40 | + if (is_array($node)) |
|
| 41 | + { |
|
| 42 | + foreach ($node as $child) |
|
| 43 | + { |
|
| 42 | 44 | $this->compile($child, $result); |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | return $result; |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - foreach ($this->renders as $renderer) { |
|
| 49 | - if ($renderer->render($this, $result, $node)) { |
|
| 50 | + foreach ($this->renders as $renderer) |
|
| 51 | + { |
|
| 52 | + if ($renderer->render($this, $result, $node)) |
|
| 53 | + { |
|
| 50 | 54 | return $result; |
| 51 | 55 | } |
| 52 | 56 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function enterNode($node, VisitorContext $ctx) |
| 49 | 49 | { |
| 50 | - if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) { |
|
| 50 | + if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0){ |
|
| 51 | 51 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -59,23 +59,23 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function leaveNode($node, VisitorContext $ctx) |
| 61 | 61 | { |
| 62 | - if (!$node instanceof Tag) { |
|
| 62 | + if (!$node instanceof Tag){ |
|
| 63 | 63 | return null; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $importCtx = ImportContext::on($ctx); |
| 67 | 67 | |
| 68 | 68 | // import definition |
| 69 | - if (\strpos($node->name, $this->useKeyword) === 0) { |
|
| 69 | + if (\strpos($node->name, $this->useKeyword) === 0){ |
|
| 70 | 70 | $importCtx->add($this->makeImport($node)); |
| 71 | 71 | |
| 72 | 72 | return self::REMOVE_NODE; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // imported tag |
| 76 | - try { |
|
| 76 | + try{ |
|
| 77 | 77 | $import = $importCtx->resolve($this->builder, $node->name); |
| 78 | - } catch (Throwable $e) { |
|
| 78 | + }catch (Throwable $e){ |
|
| 79 | 79 | throw new ImportException( |
| 80 | 80 | "Unable to resolve import `{$node->name}`", |
| 81 | 81 | $node->getContext(), |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | ); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ($import !== null) { |
|
| 86 | + if ($import !== null){ |
|
| 87 | 87 | $node = $this->merger->merge($import, $node); |
| 88 | 88 | |
| 89 | 89 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | private function makeImport(Tag $tag): ImportInterface |
| 101 | 101 | { |
| 102 | 102 | $options = []; |
| 103 | - foreach ($tag->attrs as $attr) { |
|
| 104 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
| 103 | + foreach ($tag->attrs as $attr){ |
|
| 104 | + if (!\is_string($attr->value) || !\is_string($attr->name)){ |
|
| 105 | 105 | continue; |
| 106 | 106 | } |
| 107 | 107 | $options[$attr->name] = trim($attr->value, '\'"'); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - switch (\strtolower($tag->name)) { |
|
| 110 | + switch (\strtolower($tag->name)){ |
|
| 111 | 111 | case 'use': |
| 112 | 112 | case 'use:element': |
| 113 | 113 | $this->assertHasOption('path', $options, $tag); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | private function assertHasOption(string $option, array $options, Tag $tag): void |
| 155 | 155 | { |
| 156 | - if (!isset($options[$option])) { |
|
| 156 | + if (!isset($options[$option])){ |
|
| 157 | 157 | throw new ImportException("Missing `{$option}` option", $tag->getContext()); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -47,7 +47,8 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function enterNode($node, VisitorContext $ctx) |
| 49 | 49 | { |
| 50 | - if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) { |
|
| 50 | + if ($node instanceof Tag && strpos($node->name, $this->useKeyword) === 0) |
|
| 51 | + { |
|
| 51 | 52 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
| 52 | 53 | } |
| 53 | 54 | |
@@ -59,23 +60,28 @@ discard block |
||
| 59 | 60 | */ |
| 60 | 61 | public function leaveNode($node, VisitorContext $ctx) |
| 61 | 62 | { |
| 62 | - if (!$node instanceof Tag) { |
|
| 63 | + if (!$node instanceof Tag) |
|
| 64 | + { |
|
| 63 | 65 | return null; |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | $importCtx = ImportContext::on($ctx); |
| 67 | 69 | |
| 68 | 70 | // import definition |
| 69 | - if (\strpos($node->name, $this->useKeyword) === 0) { |
|
| 71 | + if (\strpos($node->name, $this->useKeyword) === 0) |
|
| 72 | + { |
|
| 70 | 73 | $importCtx->add($this->makeImport($node)); |
| 71 | 74 | |
| 72 | 75 | return self::REMOVE_NODE; |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | // imported tag |
| 76 | - try { |
|
| 79 | + try |
|
| 80 | + { |
|
| 77 | 81 | $import = $importCtx->resolve($this->builder, $node->name); |
| 78 | - } catch (Throwable $e) { |
|
| 82 | + } |
|
| 83 | + catch (Throwable $e) |
|
| 84 | + { |
|
| 79 | 85 | throw new ImportException( |
| 80 | 86 | "Unable to resolve import `{$node->name}`", |
| 81 | 87 | $node->getContext(), |
@@ -83,7 +89,8 @@ discard block |
||
| 83 | 89 | ); |
| 84 | 90 | } |
| 85 | 91 | |
| 86 | - if ($import !== null) { |
|
| 92 | + if ($import !== null) |
|
| 93 | + { |
|
| 87 | 94 | $node = $this->merger->merge($import, $node); |
| 88 | 95 | |
| 89 | 96 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -100,14 +107,17 @@ discard block |
||
| 100 | 107 | private function makeImport(Tag $tag): ImportInterface |
| 101 | 108 | { |
| 102 | 109 | $options = []; |
| 103 | - foreach ($tag->attrs as $attr) { |
|
| 104 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
| 110 | + foreach ($tag->attrs as $attr) |
|
| 111 | + { |
|
| 112 | + if (!\is_string($attr->value) || !\is_string($attr->name)) |
|
| 113 | + { |
|
| 105 | 114 | continue; |
| 106 | 115 | } |
| 107 | 116 | $options[$attr->name] = trim($attr->value, '\'"'); |
| 108 | 117 | } |
| 109 | 118 | |
| 110 | - switch (\strtolower($tag->name)) { |
|
| 119 | + switch (\strtolower($tag->name)) |
|
| 120 | + { |
|
| 111 | 121 | case 'use': |
| 112 | 122 | case 'use:element': |
| 113 | 123 | $this->assertHasOption('path', $options, $tag); |
@@ -153,7 +163,8 @@ discard block |
||
| 153 | 163 | |
| 154 | 164 | private function assertHasOption(string $option, array $options, Tag $tag): void |
| 155 | 165 | { |
| 156 | - if (!isset($options[$option])) { |
|
| 166 | + if (!isset($options[$option])) |
|
| 167 | + { |
|
| 157 | 168 | throw new ImportException("Missing `{$option}` option", $tag->getContext()); |
| 158 | 169 | } |
| 159 | 170 | } |