@@ -24,7 +24,8 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
| 26 | 26 | { |
| 27 | - switch ($token->type) { |
|
| 27 | + switch ($token->type) |
|
| 28 | + { |
|
| 28 | 29 | case DynamicGrammar::TYPE_DIRECTIVE: |
| 29 | 30 | $this->directive = new Directive(new Context($token, $parser->getPath())); |
| 30 | 31 | $asm->push($this->directive); |
@@ -49,20 +50,23 @@ discard block |
||
| 49 | 50 | break; |
| 50 | 51 | |
| 51 | 52 | case DynamicGrammar::TYPE_KEYWORD: |
| 52 | - if ($this->directive !== null) { |
|
| 53 | + if ($this->directive !== null) |
|
| 54 | + { |
|
| 53 | 55 | $this->directive->name = $token->content; |
| 54 | 56 | } |
| 55 | 57 | break; |
| 56 | 58 | |
| 57 | 59 | case DynamicGrammar::TYPE_BODY: |
| 58 | - if ($this->directive !== null) { |
|
| 60 | + if ($this->directive !== null) |
|
| 61 | + { |
|
| 59 | 62 | $this->directive->body = $token->content; |
| 60 | 63 | $this->directive->values = $this->fetchValues($this->directive->body); |
| 61 | 64 | |
| 62 | 65 | $this->directive = null; |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | - if ($this->output !== null) { |
|
| 68 | + if ($this->output !== null) |
|
| 69 | + { |
|
| 66 | 70 | $this->output->body = $token->content; |
| 67 | 71 | } |
| 68 | 72 | |
@@ -80,31 +84,38 @@ discard block |
||
| 80 | 84 | |
| 81 | 85 | $src = new StringStream($body); |
| 82 | 86 | |
| 83 | - while ($n = $src->peak()) { |
|
| 84 | - if (\in_array($n, ['"', "'"], true)) { |
|
| 87 | + while ($n = $src->peak()) |
|
| 88 | + { |
|
| 89 | + if (\in_array($n, ['"', "'"], true)) |
|
| 90 | + { |
|
| 85 | 91 | $values[\count($values) - 1] .= $n; |
| 86 | - while (($nn = $src->peak()) !== null) { |
|
| 92 | + while (($nn = $src->peak()) !== null) |
|
| 93 | + { |
|
| 87 | 94 | $values[\count($values) - 1] .= $nn; |
| 88 | - if ($nn === $n) { |
|
| 95 | + if ($nn === $n) |
|
| 96 | + { |
|
| 89 | 97 | break; |
| 90 | 98 | } |
| 91 | 99 | } |
| 92 | 100 | continue; |
| 93 | 101 | } |
| 94 | 102 | |
| 95 | - if ($n === ',' && $level === 0) { |
|
| 103 | + if ($n === ',' && $level === 0) |
|
| 104 | + { |
|
| 96 | 105 | $values[] = ''; |
| 97 | 106 | continue; |
| 98 | 107 | } |
| 99 | 108 | |
| 100 | 109 | $values[\count($values) - 1] .= $n; |
| 101 | 110 | |
| 102 | - if ($n === '(' || $n === '[' || $n === '{') { |
|
| 111 | + if ($n === '(' || $n === '[' || $n === '{') |
|
| 112 | + { |
|
| 103 | 113 | $level++; |
| 104 | 114 | continue; |
| 105 | 115 | } |
| 106 | 116 | |
| 107 | - if ($n === ')' || $n === ']' || $n === '}') { |
|
| 117 | + if ($n === ')' || $n === ']' || $n === '}') |
|
| 118 | + { |
|
| 108 | 119 | $level--; |
| 109 | 120 | } |
| 110 | 121 | } |
@@ -56,7 +56,8 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
| 58 | 58 | { |
| 59 | - switch ($token->type) { |
|
| 59 | + switch ($token->type) |
|
| 60 | + { |
|
| 60 | 61 | case HTMLGrammar::TYPE_OPEN: |
| 61 | 62 | case HTMLGrammar::TYPE_OPEN_SHORT: |
| 62 | 63 | $this->node = new Tag(new Context($token, $parser->getPath())); |
@@ -65,12 +66,14 @@ discard block |
||
| 65 | 66 | break; |
| 66 | 67 | |
| 67 | 68 | case HTMLGrammar::TYPE_KEYWORD: |
| 68 | - if ($this->node->name === null) { |
|
| 69 | + if ($this->node->name === null) |
|
| 70 | + { |
|
| 69 | 71 | $this->node->name = $this->parseToken($parser, $token); |
| 70 | 72 | return; |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | - if ($this->attr !== null && !$this->attr->value instanceof Nil) { |
|
| 75 | + if ($this->attr !== null && !$this->attr->value instanceof Nil) |
|
| 76 | + { |
|
| 74 | 77 | $this->attr->value = $this->parseToken($parser, $token); |
| 75 | 78 | $this->attr = null; |
| 76 | 79 | break; |
@@ -86,7 +89,8 @@ discard block |
||
| 86 | 89 | break; |
| 87 | 90 | |
| 88 | 91 | case HTMLGrammar::TYPE_EQUAL: |
| 89 | - if ($this->attr === null) { |
|
| 92 | + if ($this->attr === null) |
|
| 93 | + { |
|
| 90 | 94 | throw new SyntaxException('unexpected attribute token', $token); |
| 91 | 95 | } |
| 92 | 96 | |
@@ -95,7 +99,8 @@ discard block |
||
| 95 | 99 | break; |
| 96 | 100 | |
| 97 | 101 | case HTMLGrammar::TYPE_ATTRIBUTE: |
| 98 | - if ($this->attr === null) { |
|
| 102 | + if ($this->attr === null) |
|
| 103 | + { |
|
| 99 | 104 | throw new SyntaxException('unexpected attribute token', $token); |
| 100 | 105 | } |
| 101 | 106 | |
@@ -107,7 +112,9 @@ discard block |
||
| 107 | 112 | ) |
| 108 | 113 | ) { |
| 109 | 114 | $this->attr->value = $this->parseVerbatim($parser, $token); |
| 110 | - } else { |
|
| 115 | + } |
|
| 116 | + else |
|
| 117 | + { |
|
| 111 | 118 | $this->attr->value = $this->parseToken($parser, $token); |
| 112 | 119 | } |
| 113 | 120 | |
@@ -121,8 +128,10 @@ discard block |
||
| 121 | 128 | break; |
| 122 | 129 | |
| 123 | 130 | case HTMLGrammar::TYPE_CLOSE: |
| 124 | - if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) { |
|
| 125 | - if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) { |
|
| 131 | + if ($this->token->type == HTMLGrammar::TYPE_OPEN_SHORT) |
|
| 132 | + { |
|
| 133 | + if (!$asm->getNode() instanceof Tag || $asm->getNode()->name !== $this->node->name) |
|
| 134 | + { |
|
| 126 | 135 | /** |
| 127 | 136 | * TODO issue #767 |
| 128 | 137 | * @link https://github.com/spiral/framework/issues/767 |
@@ -135,10 +144,14 @@ discard block |
||
| 135 | 144 | } |
| 136 | 145 | |
| 137 | 146 | $asm->close(); |
| 138 | - } elseif (\in_array($this->node->name, self::VOID_TAGS)) { |
|
| 147 | + } |
|
| 148 | + elseif (\in_array($this->node->name, self::VOID_TAGS)) |
|
| 149 | + { |
|
| 139 | 150 | $this->node->void = true; |
| 140 | 151 | $asm->push($this->node); |
| 141 | - } else { |
|
| 152 | + } |
|
| 153 | + else |
|
| 154 | + { |
|
| 142 | 155 | $asm->open($this->node, 'nodes'); |
| 143 | 156 | } |
| 144 | 157 | $this->flush(); |
@@ -150,9 +163,11 @@ discard block |
||
| 150 | 163 | break; |
| 151 | 164 | |
| 152 | 165 | default: |
| 153 | - if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) { |
|
| 166 | + if ($asm->getNode() instanceof Mixin || $asm->getNode() instanceof Verbatim) |
|
| 167 | + { |
|
| 154 | 168 | $node = $this->parseToken($parser, $token); |
| 155 | - if (\is_string($node)) { |
|
| 169 | + if (\is_string($node)) |
|
| 170 | + { |
|
| 156 | 171 | $node = new Raw($node, new Context($token, $parser->getPath())); |
| 157 | 172 | } |
| 158 | 173 | |
@@ -175,11 +190,15 @@ discard block |
||
| 175 | 190 | { |
| 176 | 191 | $verbatim = new Verbatim(new Context($token, $parser->getPath())); |
| 177 | 192 | |
| 178 | - if ($token->tokens === []) { |
|
| 179 | - if ($token->content) { |
|
| 193 | + if ($token->tokens === []) |
|
| 194 | + { |
|
| 195 | + if ($token->content) |
|
| 196 | + { |
|
| 180 | 197 | $verbatim->nodes[] = $token->content; |
| 181 | 198 | } |
| 182 | - } else { |
|
| 199 | + } |
|
| 200 | + else |
|
| 201 | + { |
|
| 183 | 202 | /** |
| 184 | 203 | * TODO issue #767 |
| 185 | 204 | * @link https://github.com/spiral/framework/issues/767 |
@@ -21,7 +21,8 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function handle(Parser $parser, Assembler $asm, Token $token): void |
| 23 | 23 | { |
| 24 | - switch ($token->type) { |
|
| 24 | + switch ($token->type) |
|
| 25 | + { |
|
| 25 | 26 | case InlineGrammar::TYPE_OPEN_TAG: |
| 26 | 27 | $this->inline = new Inline(new Context($token, $parser->getPath())); |
| 27 | 28 | $asm->push($this->inline); |
@@ -14,7 +14,8 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 16 | 16 | { |
| 17 | - if ($node instanceof PHP) { |
|
| 17 | + if ($node instanceof PHP) |
|
| 18 | + { |
|
| 18 | 19 | $result->push($node->content, $node->getContext()); |
| 19 | 20 | return true; |
| 20 | 21 | } |
@@ -17,7 +17,8 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 19 | 19 | { |
| 20 | - switch (true) { |
|
| 20 | + switch (true) |
|
| 21 | + { |
|
| 21 | 22 | case $node instanceof Tag: |
| 22 | 23 | $this->tag($compiler, $result, $node); |
| 23 | 24 | return true; |
@@ -36,8 +37,10 @@ discard block |
||
| 36 | 37 | { |
| 37 | 38 | $result->push(\sprintf('<%s', $node->name), $node->getContext()); |
| 38 | 39 | |
| 39 | - foreach ($node->attrs as $attr) { |
|
| 40 | - if (!$attr instanceof Attr) { |
|
| 40 | + foreach ($node->attrs as $attr) |
|
| 41 | + { |
|
| 42 | + if (!$attr instanceof Attr) |
|
| 43 | + { |
|
| 41 | 44 | $compiler->compile($attr, $result); |
| 42 | 45 | continue; |
| 43 | 46 | } |
@@ -47,30 +50,37 @@ discard block |
||
| 47 | 50 | |
| 48 | 51 | $result->push(\sprintf('%s>', $node->void ? '/' : ''), null); |
| 49 | 52 | |
| 50 | - foreach ($node->nodes as $child) { |
|
| 53 | + foreach ($node->nodes as $child) |
|
| 54 | + { |
|
| 51 | 55 | $compiler->compile($child, $result); |
| 52 | 56 | } |
| 53 | 57 | |
| 54 | - if (!$node->void) { |
|
| 58 | + if (!$node->void) |
|
| 59 | + { |
|
| 55 | 60 | $result->push(\sprintf('</%s>', $node->name), null); |
| 56 | 61 | } |
| 57 | 62 | } |
| 58 | 63 | |
| 59 | 64 | private function attribute(Compiler $compiler, Result $result, Attr $node): void |
| 60 | 65 | { |
| 61 | - if ($node->name instanceof NodeInterface) { |
|
| 66 | + if ($node->name instanceof NodeInterface) |
|
| 67 | + { |
|
| 62 | 68 | $result->push(' ', null); |
| 63 | 69 | $compiler->compile($node->name, $result); |
| 64 | - } else { |
|
| 70 | + } |
|
| 71 | + else |
|
| 72 | + { |
|
| 65 | 73 | $result->push(\sprintf(' %s', $node->name), $node->getContext()); |
| 66 | 74 | } |
| 67 | 75 | |
| 68 | 76 | $value = $node->value; |
| 69 | - if ($value instanceof Nil) { |
|
| 77 | + if ($value instanceof Nil) |
|
| 78 | + { |
|
| 70 | 79 | return; |
| 71 | 80 | } |
| 72 | 81 | |
| 73 | - if ($value instanceof NodeInterface) { |
|
| 82 | + if ($value instanceof NodeInterface) |
|
| 83 | + { |
|
| 74 | 84 | $result->push('=', null); |
| 75 | 85 | $compiler->compile($value, $result); |
| 76 | 86 | return; |
@@ -81,8 +91,10 @@ discard block |
||
| 81 | 91 | |
| 82 | 92 | private function verbatim(Compiler $compiler, Result $result, Verbatim $node): void |
| 83 | 93 | { |
| 84 | - foreach ($node->nodes as $child) { |
|
| 85 | - if (\is_string($child)) { |
|
| 94 | + foreach ($node->nodes as $child) |
|
| 95 | + { |
|
| 96 | + if (\is_string($child)) |
|
| 97 | + { |
|
| 86 | 98 | $result->push($child, null); |
| 87 | 99 | continue; |
| 88 | 100 | } |
@@ -22,7 +22,8 @@ discard block |
||
| 22 | 22 | Result $result, |
| 23 | 23 | NodeInterface $node |
| 24 | 24 | ): bool { |
| 25 | - switch (true) { |
|
| 25 | + switch (true) |
|
| 26 | + { |
|
| 26 | 27 | case $node instanceof Hidden: |
| 27 | 28 | return true; |
| 28 | 29 | |
@@ -30,7 +31,8 @@ discard block |
||
| 30 | 31 | $result->withinContext( |
| 31 | 32 | $node->getContext(), |
| 32 | 33 | function (Result $source) use ($node, $compiler): void { |
| 33 | - foreach ($node->nodes as $child) { |
|
| 34 | + foreach ($node->nodes as $child) |
|
| 35 | + { |
|
| 34 | 36 | $compiler->compile($child, $source); |
| 35 | 37 | } |
| 36 | 38 | } |
@@ -42,8 +44,10 @@ discard block |
||
| 42 | 44 | $result->withinContext( |
| 43 | 45 | $node->getContext(), |
| 44 | 46 | function (Result $source) use ($node, $compiler): void { |
| 45 | - foreach ($node->nodes as $child) { |
|
| 46 | - if (\is_string($child)) { |
|
| 47 | + foreach ($node->nodes as $child) |
|
| 48 | + { |
|
| 49 | + if (\is_string($child)) |
|
| 50 | + { |
|
| 47 | 51 | $source->push($child, null); |
| 48 | 52 | continue; |
| 49 | 53 | } |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function render(Compiler $compiler, Result $result, NodeInterface $node): bool |
| 28 | 28 | { |
| 29 | - switch (true) { |
|
| 29 | + switch (true) |
|
| 30 | + { |
|
| 30 | 31 | case $node instanceof Output: |
| 31 | 32 | $this->output($result, $node); |
| 32 | 33 | return true; |
@@ -43,9 +44,11 @@ discard block |
||
| 43 | 44 | */ |
| 44 | 45 | private function directive(Result $source, Directive $directive): void |
| 45 | 46 | { |
| 46 | - if ($this->directiveRenderer !== null) { |
|
| 47 | + if ($this->directiveRenderer !== null) |
|
| 48 | + { |
|
| 47 | 49 | $result = $this->directiveRenderer->render($directive); |
| 48 | - if ($result !== null) { |
|
| 50 | + if ($result !== null) |
|
| 51 | + { |
|
| 49 | 52 | $source->push($result, $directive->getContext()); |
| 50 | 53 | return; |
| 51 | 54 | } |
@@ -59,7 +62,8 @@ discard block |
||
| 59 | 62 | |
| 60 | 63 | private function output(Result $source, Output $output): void |
| 61 | 64 | { |
| 62 | - if ($output->rawOutput) { |
|
| 65 | + if ($output->rawOutput) |
|
| 66 | + { |
|
| 63 | 67 | $source->push(\sprintf('<?php echo %s; ?>', \trim($output->body)), $output->getContext()); |
| 64 | 68 | return; |
| 65 | 69 | } |
@@ -37,7 +37,8 @@ discard block |
||
| 37 | 37 | // Replaces alias with real pipeline name |
| 38 | 38 | $name = $this->config->getAliases()[$name] ?? $name; |
| 39 | 39 | |
| 40 | - if (!isset($this->pipelines[$name])) { |
|
| 40 | + if (!isset($this->pipelines[$name])) |
|
| 41 | + { |
|
| 41 | 42 | $this->pipelines[$name] = $this->resolveConnection($name); |
| 42 | 43 | } |
| 43 | 44 | |
@@ -52,18 +53,22 @@ discard block |
||
| 52 | 53 | { |
| 53 | 54 | $config = $this->config->getConnection($name); |
| 54 | 55 | |
| 55 | - try { |
|
| 56 | + try |
|
| 57 | + { |
|
| 56 | 58 | $driver = $this->factory->make($config['driver'], $config); |
| 57 | 59 | |
| 58 | 60 | $list = []; |
| 59 | - foreach ($this->config->getPushInterceptors() as $interceptor) { |
|
| 61 | + foreach ($this->config->getPushInterceptors() as $interceptor) |
|
| 62 | + { |
|
| 60 | 63 | $list[] = \is_string($interceptor) || $interceptor instanceof Autowire |
| 61 | 64 | ? $this->container->get($interceptor) |
| 62 | 65 | : $interceptor; |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | 68 | return new Queue($this->builder->withInterceptors(...$list)->build(new PushCore($driver))); |
| 66 | - } catch (ContainerException $e) { |
|
| 69 | + } |
|
| 70 | + catch (ContainerException $e) |
|
| 71 | + { |
|
| 67 | 72 | throw new NotSupportedDriverException( |
| 68 | 73 | \sprintf( |
| 69 | 74 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -61,7 +61,8 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function testMiddlewareProcessingEventShouldBeDispatched(): void |
| 63 | 63 | { |
| 64 | - $middleware = new class implements MiddlewareInterface { |
|
| 64 | + $middleware = new class implements MiddlewareInterface |
|
| 65 | + { |
|
| 65 | 66 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 66 | 67 | { |
| 67 | 68 | return (new ResponseFactory(new HttpConfig(['headers' => []])))->createResponse(200); |
@@ -90,7 +91,8 @@ discard block |
||
| 90 | 91 | $this->container->getBinder('http') |
| 91 | 92 | ->bind(ServerRequestInterface::class, static fn(CurrentRequest $cr) => $cr->get()); |
| 92 | 93 | |
| 93 | - $middleware = new class implements MiddlewareInterface { |
|
| 94 | + $middleware = new class implements MiddlewareInterface |
|
| 95 | + { |
|
| 94 | 96 | public function process( |
| 95 | 97 | ServerRequestInterface $request, |
| 96 | 98 | RequestHandlerInterface $handler, |
@@ -108,7 +110,8 @@ discard block |
||
| 108 | 110 | |
| 109 | 111 | $this->container->runScope( |
| 110 | 112 | new Scope(name: 'http'), |
| 111 | - function (ScopeInterface $c) use ($middleware) { |
|
| 113 | + function (ScopeInterface $c) use ($middleware) |
|
| 114 | + { |
|
| 112 | 115 | $request = new ServerRequest('GET', ''); |
| 113 | 116 | $handler = new CallableHandler(fn() => 'response', new ResponseFactory(new HttpConfig(['headers' => []]))); |
| 114 | 117 | |