@@ -5,7 +5,8 @@ |
||
| 5 | 5 | namespace Spiral\Core\Exception; |
| 6 | 6 | |
| 7 | 7 | // Load the original class to make an alias |
| 8 | -if (!\class_exists(\Spiral\Interceptors\Exception\InterceptorException::class)) { |
|
| 8 | +if (!\class_exists(\Spiral\Interceptors\Exception\InterceptorException::class)) |
|
| 9 | +{ |
|
| 9 | 10 | /** |
| 10 | 11 | * @deprecated will be removed in Spiral v4.0 |
| 11 | 12 | * Use {@see \Spiral\Interceptors\Exception\InterceptorException} instead. |
@@ -5,10 +5,10 @@ |
||
| 5 | 5 | namespace Spiral\Core\Exception; |
| 6 | 6 | |
| 7 | 7 | // Load the original class to make an alias |
| 8 | -if (!\class_exists(\Spiral\Interceptors\Exception\InterceptorException::class)) { |
|
| 8 | +if (!\class_exists(\Spiral\Interceptors\Exception\InterceptorException::class)){ |
|
| 9 | 9 | /** |
| 10 | 10 | * @deprecated will be removed in Spiral v4.0 |
| 11 | 11 | * Use {@see \Spiral\Interceptors\Exception\InterceptorException} instead. |
| 12 | 12 | */ |
| 13 | - class InterceptorException extends \RuntimeException {} |
|
| 13 | + class InterceptorException extends \RuntimeException{} |
|
| 14 | 14 | } |
@@ -65,7 +65,8 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | protected function resolveArguments(\ReflectionMethod $method, array $parameters): array |
| 67 | 67 | { |
| 68 | - foreach ($method->getParameters() as $parameter) { |
|
| 68 | + foreach ($method->getParameters() as $parameter) |
|
| 69 | + { |
|
| 69 | 70 | $name = $parameter->getName(); |
| 70 | 71 | if ( |
| 71 | 72 | \array_key_exists($name, $parameters) && |
@@ -86,9 +87,12 @@ discard block |
||
| 86 | 87 | */ |
| 87 | 88 | private function invoke(?object $object, string $class, \ReflectionMethod $method, array $arguments): mixed |
| 88 | 89 | { |
| 89 | - try { |
|
| 90 | + try |
|
| 91 | + { |
|
| 90 | 92 | $args = $this->resolveArguments($method, $arguments); |
| 91 | - } catch (ArgumentResolvingException | InvalidArgumentException $e) { |
|
| 93 | + } |
|
| 94 | + catch (ArgumentResolvingException | InvalidArgumentException $e) |
|
| 95 | + { |
|
| 92 | 96 | throw new ControllerException( |
| 93 | 97 | \sprintf( |
| 94 | 98 | 'Missing/invalid parameter %s of `%s`->`%s`', |
@@ -99,7 +103,9 @@ discard block |
||
| 99 | 103 | ControllerException::BAD_ARGUMENT, |
| 100 | 104 | $e, |
| 101 | 105 | ); |
| 102 | - } catch (ContainerExceptionInterface $e) { |
|
| 106 | + } |
|
| 107 | + catch (ContainerExceptionInterface $e) |
|
| 108 | + { |
|
| 103 | 109 | throw new ControllerException( |
| 104 | 110 | $e->getMessage(), |
| 105 | 111 | ControllerException::ERROR, |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | public function __construct( |
| 30 | 30 | /** @internal */ |
| 31 | 31 | #[Proxy] protected ContainerInterface $container, |
| 32 | - ) { |
|
| 32 | + ){ |
|
| 33 | 33 | // TODO: can we simplify this? |
| 34 | 34 | // resolver is usually the container itself |
| 35 | 35 | /** @psalm-suppress MixedAssignment */ |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ? $container |
| 38 | 38 | : $container |
| 39 | 39 | ->get(InvokerInterface::class) |
| 40 | - ->invoke(static fn(#[Proxy] ResolverInterface $resolver): ResolverInterface => $resolver); |
|
| 40 | + ->invoke(static fn(#[Proxy] ResolverInterface $resolver) : ResolverInterface => $resolver); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | protected function resolveArguments(\ReflectionMethod $method, array $parameters): array |
| 67 | 67 | { |
| 68 | - foreach ($method->getParameters() as $parameter) { |
|
| 68 | + foreach ($method->getParameters() as $parameter){ |
|
| 69 | 69 | $name = $parameter->getName(); |
| 70 | 70 | if ( |
| 71 | 71 | \array_key_exists($name, $parameters) && |
| 72 | 72 | $parameters[$name] === null && |
| 73 | 73 | $parameter->isDefaultValueAvailable() |
| 74 | - ) { |
|
| 74 | + ){ |
|
| 75 | 75 | /** @psalm-suppress MixedAssignment */ |
| 76 | 76 | $parameters[$name] = $parameter->getDefaultValue(); |
| 77 | 77 | } |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private function invoke(?object $object, string $class, \ReflectionMethod $method, array $arguments): mixed |
| 88 | 88 | { |
| 89 | - try { |
|
| 89 | + try{ |
|
| 90 | 90 | $args = $this->resolveArguments($method, $arguments); |
| 91 | - } catch (ArgumentResolvingException | InvalidArgumentException $e) { |
|
| 91 | + }catch (ArgumentResolvingException | InvalidArgumentException $e){ |
|
| 92 | 92 | throw new ControllerException( |
| 93 | 93 | \sprintf( |
| 94 | 94 | 'Missing/invalid parameter %s of `%s`->`%s`', |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | ControllerException::BAD_ARGUMENT, |
| 100 | 100 | $e, |
| 101 | 101 | ); |
| 102 | - } catch (ContainerExceptionInterface $e) { |
|
| 102 | + }catch (ContainerExceptionInterface $e){ |
|
| 103 | 103 | throw new ControllerException( |
| 104 | 104 | $e->getMessage(), |
| 105 | 105 | ControllerException::ERROR, |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | public function createHandler(array $definitions = []): AutowireHandler |
| 109 | 109 | { |
| 110 | 110 | $container = new Container(); |
| 111 | - foreach ($definitions as $id => $definition) { |
|
| 111 | + foreach ($definitions as $id => $definition){ |
|
| 112 | 112 | $container->bind($id, $definition); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -108,7 +108,8 @@ |
||
| 108 | 108 | public function createHandler(array $definitions = []): AutowireHandler |
| 109 | 109 | { |
| 110 | 110 | $container = new Container(); |
| 111 | - foreach ($definitions as $id => $definition) { |
|
| 111 | + foreach ($definitions as $id => $definition) |
|
| 112 | + { |
|
| 112 | 113 | $container->bind($id, $definition); |
| 113 | 114 | } |
| 114 | 115 | |
@@ -28,15 +28,18 @@ discard block |
||
| 28 | 28 | 'namespaces' => $config->getNamespaces(), |
| 29 | 29 | ]); |
| 30 | 30 | |
| 31 | - foreach ($this->config->getDependencies() as $dependency) { |
|
| 31 | + foreach ($this->config->getDependencies() as $dependency) |
|
| 32 | + { |
|
| 32 | 33 | $this->addDependency($dependency->resolve($factory)); |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | - foreach ($this->config->getEngines() as $engine) { |
|
| 36 | + foreach ($this->config->getEngines() as $engine) |
|
| 37 | + { |
|
| 36 | 38 | $this->addEngine($engine->resolve($factory)); |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | - if ($this->config->isCacheEnabled()) { |
|
| 41 | + if ($this->config->isCacheEnabled()) |
|
| 42 | + { |
|
| 40 | 43 | $this->cache = new ViewCache(); |
| 41 | 44 | } |
| 42 | 45 | } |
@@ -93,7 +96,8 @@ discard block |
||
| 93 | 96 | |
| 94 | 97 | // Rotate all possible context variants and warm up cache |
| 95 | 98 | $generator = new ContextGenerator($this->context); |
| 96 | - foreach ($generator->generate() as $context) { |
|
| 99 | + foreach ($generator->generate() as $context) |
|
| 100 | + { |
|
| 97 | 101 | $engine->reset($path, $context); |
| 98 | 102 | $engine->compile($path, $context); |
| 99 | 103 | } |
@@ -110,7 +114,8 @@ discard block |
||
| 110 | 114 | |
| 111 | 115 | // Rotate all possible context variants and warm up cache |
| 112 | 116 | $generator = new ContextGenerator($this->context); |
| 113 | - foreach ($generator->generate() as $context) { |
|
| 117 | + foreach ($generator->generate() as $context) |
|
| 118 | + { |
|
| 114 | 119 | $engine->reset($path, $context); |
| 115 | 120 | } |
| 116 | 121 | } |
@@ -122,7 +127,8 @@ discard block |
||
| 122 | 127 | */ |
| 123 | 128 | public function get(string $path): ViewInterface |
| 124 | 129 | { |
| 125 | - if ($this->cache?->has($this->context, $path)) { |
|
| 130 | + if ($this->cache?->has($this->context, $path)) |
|
| 131 | + { |
|
| 126 | 132 | return $this->cache->get($this->context, $path); |
| 127 | 133 | } |
| 128 | 134 | |
@@ -150,8 +156,10 @@ discard block |
||
| 150 | 156 | */ |
| 151 | 157 | private function findEngine(string $path): EngineInterface |
| 152 | 158 | { |
| 153 | - foreach ($this->engines as $engine) { |
|
| 154 | - if ($engine->getLoader()->exists($path)) { |
|
| 159 | + foreach ($this->engines as $engine) |
|
| 160 | + { |
|
| 161 | + if ($engine->getLoader()->exists($path)) |
|
| 162 | + { |
|
| 155 | 163 | return $engine; |
| 156 | 164 | } |
| 157 | 165 | } |
@@ -22,21 +22,21 @@ discard block |
||
| 22 | 22 | private readonly GlobalVariablesInterface $globalVariables, |
| 23 | 23 | FactoryInterface $factory, |
| 24 | 24 | ?ContextInterface $context = null, |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | $this->context = $context ?? new ViewContext(); |
| 27 | 27 | $this->loader = $factory->make(LoaderInterface::class, [ |
| 28 | 28 | 'namespaces' => $config->getNamespaces(), |
| 29 | 29 | ]); |
| 30 | 30 | |
| 31 | - foreach ($this->config->getDependencies() as $dependency) { |
|
| 31 | + foreach ($this->config->getDependencies() as $dependency){ |
|
| 32 | 32 | $this->addDependency($dependency->resolve($factory)); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - foreach ($this->config->getEngines() as $engine) { |
|
| 35 | + foreach ($this->config->getEngines() as $engine){ |
|
| 36 | 36 | $this->addEngine($engine->resolve($factory)); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if ($this->config->isCacheEnabled()) { |
|
| 39 | + if ($this->config->isCacheEnabled()){ |
|
| 40 | 40 | $this->cache = new ViewCache(); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | // Rotate all possible context variants and warm up cache |
| 94 | 94 | $generator = new ContextGenerator($this->context); |
| 95 | - foreach ($generator->generate() as $context) { |
|
| 95 | + foreach ($generator->generate() as $context){ |
|
| 96 | 96 | $engine->reset($path, $context); |
| 97 | 97 | $engine->compile($path, $context); |
| 98 | 98 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | // Rotate all possible context variants and warm up cache |
| 111 | 111 | $generator = new ContextGenerator($this->context); |
| 112 | - foreach ($generator->generate() as $context) { |
|
| 112 | + foreach ($generator->generate() as $context){ |
|
| 113 | 113 | $engine->reset($path, $context); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function get(string $path): ViewInterface |
| 123 | 123 | { |
| 124 | - if ($this->cache?->has($this->context, $path)) { |
|
| 124 | + if ($this->cache?->has($this->context, $path)){ |
|
| 125 | 125 | return $this->cache->get($this->context, $path); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | private function findEngine(string $path): EngineInterface |
| 150 | 150 | { |
| 151 | - foreach ($this->engines as $engine) { |
|
| 152 | - if ($engine->getLoader()->exists($path)) { |
|
| 151 | + foreach ($this->engines as $engine){ |
|
| 152 | + if ($engine->getLoader()->exists($path)){ |
|
| 153 | 153 | return $engine; |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | ResponseFactoryInterface $responseFactory, |
| 30 | 30 | BroadcastConfig $config, |
| 31 | 31 | ?EventDispatcherInterface $dispatcher = null, |
| 32 | - ): AuthorizationMiddleware => new AuthorizationMiddleware( |
|
| 32 | + ) : AuthorizationMiddleware => new AuthorizationMiddleware( |
|
| 33 | 33 | $broadcast, |
| 34 | 34 | $responseFactory, |
| 35 | 35 | $config->getAuthorizationPath(), |
@@ -55,17 +55,21 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
| 57 | 57 | { |
| 58 | - if ($node instanceof Output) { |
|
| 58 | + if ($node instanceof Output) |
|
| 59 | + { |
|
| 59 | 60 | return $this->output($node, $ctx); |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | - if ($node instanceof Directive) { |
|
| 63 | + if ($node instanceof Directive) |
|
| 64 | + { |
|
| 63 | 65 | return $this->directive($node); |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | - if ($node instanceof Template) { |
|
| 68 | + if ($node instanceof Template) |
|
| 69 | + { |
|
| 67 | 70 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
| 68 | - if ($extendsTag instanceof Tag) { |
|
| 71 | + if ($extendsTag instanceof Tag) |
|
| 72 | + { |
|
| 69 | 73 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
| 70 | 74 | } |
| 71 | 75 | } |
@@ -75,9 +79,11 @@ discard block |
||
| 75 | 79 | |
| 76 | 80 | private function directive(Directive $node): PHP |
| 77 | 81 | { |
| 78 | - foreach ($this->directives as $renderer) { |
|
| 82 | + foreach ($this->directives as $renderer) |
|
| 83 | + { |
|
| 79 | 84 | $result = $renderer->render($node); |
| 80 | - if ($result !== null) { |
|
| 85 | + if ($result !== null) |
|
| 86 | + { |
|
| 81 | 87 | return new PHP($result, \token_get_all($result), $node->getContext()); |
| 82 | 88 | } |
| 83 | 89 | } |
@@ -94,9 +100,12 @@ discard block |
||
| 94 | 100 | * In future this method can support context aware escaping based on tag location. |
| 95 | 101 | */ |
| 96 | 102 | |
| 97 | - if ($node->rawOutput) { |
|
| 103 | + if ($node->rawOutput) |
|
| 104 | + { |
|
| 98 | 105 | $result = \sprintf('<?php echo %s; ?>', \trim((string) $node->body)); |
| 99 | - } else { |
|
| 106 | + } |
|
| 107 | + else |
|
| 108 | + { |
|
| 100 | 109 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
| 101 | 110 | |
| 102 | 111 | $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string) $node->body)); |
@@ -114,22 +123,27 @@ discard block |
||
| 114 | 123 | // only "interesting" nodes |
| 115 | 124 | $context = []; |
| 116 | 125 | |
| 117 | - foreach (\array_reverse($ctx->getScope()) as $node) { |
|
| 118 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
| 126 | + foreach (\array_reverse($ctx->getScope()) as $node) |
|
| 127 | + { |
|
| 128 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) |
|
| 129 | + { |
|
| 119 | 130 | $context[] = $node; |
| 120 | 131 | } |
| 121 | 132 | |
| 122 | - if (\count($context) === 2) { |
|
| 133 | + if (\count($context) === 2) |
|
| 134 | + { |
|
| 123 | 135 | break; |
| 124 | 136 | } |
| 125 | 137 | } |
| 126 | 138 | |
| 127 | - if (\count($context) !== 2) { |
|
| 139 | + if (\count($context) !== 2) |
|
| 140 | + { |
|
| 128 | 141 | return $this->defaultFilter; |
| 129 | 142 | } |
| 130 | 143 | |
| 131 | 144 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
| 132 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
| 145 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') |
|
| 146 | + { |
|
| 133 | 147 | return \sprintf( |
| 134 | 148 | 'json_encode(%s, %s, %s)', |
| 135 | 149 | '%s', |
@@ -139,7 +153,8 @@ discard block |
||
| 139 | 153 | } |
| 140 | 154 | |
| 141 | 155 | // in on* and other attributes |
| 142 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
| 156 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') |
|
| 157 | + { |
|
| 143 | 158 | return \sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
| 144 | 159 | } |
| 145 | 160 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function __construct( |
| 36 | 36 | private readonly string $defaultFilter = self::DEFAULT_FILTER, |
| 37 | 37 | private array $directives = [], |
| 38 | - ) { |
|
| 38 | + ){ |
|
| 39 | 39 | $this->traverser = new Traverser(); |
| 40 | 40 | $this->traverser->addVisitor($this); |
| 41 | 41 | } |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
| 57 | 57 | { |
| 58 | - if ($node instanceof Output) { |
|
| 58 | + if ($node instanceof Output){ |
|
| 59 | 59 | return $this->output($node, $ctx); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ($node instanceof Directive) { |
|
| 62 | + if ($node instanceof Directive){ |
|
| 63 | 63 | return $this->directive($node); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ($node instanceof Template) { |
|
| 66 | + if ($node instanceof Template){ |
|
| 67 | 67 | $extendsTag = $node->getAttribute(ExtendsParent::class); |
| 68 | - if ($extendsTag instanceof Tag) { |
|
| 68 | + if ($extendsTag instanceof Tag){ |
|
| 69 | 69 | $extendsTag->attrs = $this->traverser->traverse($extendsTag->attrs); |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | private function directive(Directive $node): PHP |
| 77 | 77 | { |
| 78 | - foreach ($this->directives as $renderer) { |
|
| 78 | + foreach ($this->directives as $renderer){ |
|
| 79 | 79 | $result = $renderer->render($node); |
| 80 | - if ($result !== null) { |
|
| 80 | + if ($result !== null){ |
|
| 81 | 81 | return new PHP($result, \token_get_all($result), $node->getContext()); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -94,18 +94,18 @@ discard block |
||
| 94 | 94 | * In future this method can support context aware escaping based on tag location. |
| 95 | 95 | */ |
| 96 | 96 | |
| 97 | - if ($node->rawOutput) { |
|
| 98 | - $result = \sprintf('<?php echo %s; ?>', \trim((string) $node->body)); |
|
| 99 | - } else { |
|
| 97 | + if ($node->rawOutput){ |
|
| 98 | + $result = \sprintf('<?php echo %s; ?>', \trim((string)$node->body)); |
|
| 99 | + }else{ |
|
| 100 | 100 | $filter = $node->filter ?? $this->getFilterContext($ctx); |
| 101 | 101 | |
| 102 | - $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string) $node->body)); |
|
| 102 | + $result = \sprintf(\sprintf('<?php echo %s; ?>', $filter), \trim((string)$node->body)); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return new PHP( |
| 106 | 106 | $result, |
| 107 | 107 | \token_get_all($result), |
| 108 | - $node->getContext()->withValue(PHP::ORIGINAL_BODY, \trim((string) $node->body)), |
|
| 108 | + $node->getContext()->withValue(PHP::ORIGINAL_BODY, \trim((string)$node->body)), |
|
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -114,22 +114,22 @@ discard block |
||
| 114 | 114 | // only "interesting" nodes |
| 115 | 115 | $context = []; |
| 116 | 116 | |
| 117 | - foreach (\array_reverse($ctx->getScope()) as $node) { |
|
| 118 | - if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim) { |
|
| 117 | + foreach (\array_reverse($ctx->getScope()) as $node){ |
|
| 118 | + if ($node instanceof Attr || $node instanceof Tag || $node instanceof Verbatim){ |
|
| 119 | 119 | $context[] = $node; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if (\count($context) === 2) { |
|
| 122 | + if (\count($context) === 2){ |
|
| 123 | 123 | break; |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if (\count($context) !== 2) { |
|
| 127 | + if (\count($context) !== 2){ |
|
| 128 | 128 | return $this->defaultFilter; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // php {{ }} in javascript code (variable passing), use {! !} to bypass the filter |
| 132 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script') { |
|
| 132 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Tag && $context[1]->name === 'script'){ |
|
| 133 | 133 | return \sprintf( |
| 134 | 134 | 'json_encode(%s, %s, %s)', |
| 135 | 135 | '%s', |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // in on* and other attributes |
| 142 | - if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style') { |
|
| 142 | + if ($context[0] instanceof Verbatim && $context[1] instanceof Attr && $context[1]->name !== 'style'){ |
|
| 143 | 143 | return \sprintf("'%s', %s, '%s'", '"', $this->defaultFilter, '"'); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
| 24 | 24 | { |
| 25 | - if ($node instanceof Tag) { |
|
| 25 | + if ($node instanceof Tag){ |
|
| 26 | 26 | return $this->makeBlock($node); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ($node instanceof Inline) { |
|
| 29 | + if ($node instanceof Inline){ |
|
| 30 | 30 | $block = new Block($node->name, $node->getContext()); |
| 31 | - if ($node->value !== null) { |
|
| 31 | + if ($node->value !== null){ |
|
| 32 | 32 | $block->nodes[] = new Raw($node->value); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | private function makeBlock(Tag $node): ?NodeInterface |
| 50 | 50 | { |
| 51 | 51 | $name = null; |
| 52 | - foreach ($this->prefix as $prefix) { |
|
| 53 | - if (\str_starts_with($node->name, (string) $prefix)) { |
|
| 54 | - $name = \substr($node->name, \strlen((string) $prefix)); |
|
| 52 | + foreach ($this->prefix as $prefix){ |
|
| 53 | + if (\str_starts_with($node->name, (string)$prefix)){ |
|
| 54 | + $name = \substr($node->name, \strlen((string)$prefix)); |
|
| 55 | 55 | break; |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ($name === null) { |
|
| 59 | + if ($name === null){ |
|
| 60 | 60 | return null; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -22,13 +22,16 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
| 24 | 24 | { |
| 25 | - if ($node instanceof Tag) { |
|
| 25 | + if ($node instanceof Tag) |
|
| 26 | + { |
|
| 26 | 27 | return $this->makeBlock($node); |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | - if ($node instanceof Inline) { |
|
| 30 | + if ($node instanceof Inline) |
|
| 31 | + { |
|
| 30 | 32 | $block = new Block($node->name, $node->getContext()); |
| 31 | - if ($node->value !== null) { |
|
| 33 | + if ($node->value !== null) |
|
| 34 | + { |
|
| 32 | 35 | $block->nodes[] = new Raw($node->value); |
| 33 | 36 | } |
| 34 | 37 | |
@@ -49,14 +52,17 @@ discard block |
||
| 49 | 52 | private function makeBlock(Tag $node): ?NodeInterface |
| 50 | 53 | { |
| 51 | 54 | $name = null; |
| 52 | - foreach ($this->prefix as $prefix) { |
|
| 53 | - if (\str_starts_with($node->name, (string) $prefix)) { |
|
| 55 | + foreach ($this->prefix as $prefix) |
|
| 56 | + { |
|
| 57 | + if (\str_starts_with($node->name, (string) $prefix)) |
|
| 58 | + { |
|
| 54 | 59 | $name = \substr($node->name, \strlen((string) $prefix)); |
| 55 | 60 | break; |
| 56 | 61 | } |
| 57 | 62 | } |
| 58 | 63 | |
| 59 | - if ($name === null) { |
|
| 64 | + if ($name === null) |
|
| 65 | + { |
|
| 60 | 66 | return null; |
| 61 | 67 | } |
| 62 | 68 | |
@@ -67,13 +67,16 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function parse(Buffer $src): \Generator |
| 69 | 69 | { |
| 70 | - while ($n = $src->next()) { |
|
| 71 | - if (!$n instanceof Byte) { |
|
| 70 | + while ($n = $src->next()) |
|
| 71 | + { |
|
| 72 | + if (!$n instanceof Byte) |
|
| 73 | + { |
|
| 72 | 74 | yield $n; |
| 73 | 75 | continue; |
| 74 | 76 | } |
| 75 | 77 | |
| 76 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
| 78 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) |
|
| 79 | + { |
|
| 77 | 80 | if ( |
| 78 | 81 | $this->echo->nextToken($src) || |
| 79 | 82 | $this->raw->nextToken($src) || |
@@ -85,11 +88,15 @@ discard block |
||
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | $directive = new DirectiveGrammar(); |
| 88 | - if ($directive->parse($src, $n->offset)) { |
|
| 89 | - if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
| 91 | + if ($directive->parse($src, $n->offset)) |
|
| 92 | + { |
|
| 93 | + if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) |
|
| 94 | + { |
|
| 90 | 95 | // configure braces syntax |
| 91 | 96 | $this->declare($directive->getBody()); |
| 92 | - } else { |
|
| 97 | + } |
|
| 98 | + else |
|
| 99 | + { |
|
| 93 | 100 | if ( |
| 94 | 101 | $this->directiveRenderer !== null |
| 95 | 102 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
@@ -114,15 +121,20 @@ discard block |
||
| 114 | 121 | |
| 115 | 122 | /** @var BracesGrammar|null $braces */ |
| 116 | 123 | $braces = null; |
| 117 | - if ($this->echo->starts($src, $n)) { |
|
| 124 | + if ($this->echo->starts($src, $n)) |
|
| 125 | + { |
|
| 118 | 126 | $braces = clone $this->echo; |
| 119 | - } elseif ($this->raw->starts($src, $n)) { |
|
| 127 | + } |
|
| 128 | + elseif ($this->raw->starts($src, $n)) |
|
| 129 | + { |
|
| 120 | 130 | $braces = clone $this->raw; |
| 121 | 131 | } |
| 122 | 132 | |
| 123 | - if ($braces !== null) { |
|
| 133 | + if ($braces !== null) |
|
| 134 | + { |
|
| 124 | 135 | $echo = $braces->parse($src, $n); |
| 125 | - if ($echo !== null) { |
|
| 136 | + if ($echo !== null) |
|
| 137 | + { |
|
| 126 | 138 | yield from $echo; |
| 127 | 139 | continue; |
| 128 | 140 | } |
@@ -156,18 +168,22 @@ discard block |
||
| 156 | 168 | |
| 157 | 169 | private function declare(?string $body): void |
| 158 | 170 | { |
| 159 | - if ($body === null) { |
|
| 171 | + if ($body === null) |
|
| 172 | + { |
|
| 160 | 173 | return; |
| 161 | 174 | } |
| 162 | 175 | |
| 163 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
| 176 | + foreach ($this->fetchOptions($body) as $option => $value) |
|
| 177 | + { |
|
| 164 | 178 | $value = \trim((string) $value, '\'" '); |
| 165 | - switch ($option) { |
|
| 179 | + switch ($option) |
|
| 180 | + { |
|
| 166 | 181 | case 'syntax': |
| 167 | 182 | $this->echo->setActive($value !== 'off'); |
| 168 | 183 | $this->raw->setActive($value !== 'off'); |
| 169 | 184 | |
| 170 | - if ($value === 'default') { |
|
| 185 | + if ($value === 'default') |
|
| 186 | + { |
|
| 171 | 187 | $this->echo->setStartSequence('{{'); |
| 172 | 188 | $this->echo->setEndSequence('}}'); |
| 173 | 189 | $this->raw->setStartSequence('{!!'); |
@@ -204,10 +220,13 @@ discard block |
||
| 204 | 220 | $keyword = null; |
| 205 | 221 | |
| 206 | 222 | /** @var Token $token */ |
| 207 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
| 208 | - switch ($token->type) { |
|
| 223 | + foreach ($lexer->parse(new StringStream($body)) as $token) |
|
| 224 | + { |
|
| 225 | + switch ($token->type) |
|
| 226 | + { |
|
| 209 | 227 | case DeclareGrammar::TYPE_KEYWORD: |
| 210 | - if ($keyword !== null) { |
|
| 228 | + if ($keyword !== null) |
|
| 229 | + { |
|
| 211 | 230 | $options[$keyword] = $token->content; |
| 212 | 231 | $keyword = null; |
| 213 | 232 | break; |
@@ -215,7 +234,8 @@ discard block |
||
| 215 | 234 | $keyword = $token->content; |
| 216 | 235 | break; |
| 217 | 236 | case DeclareGrammar::TYPE_QUOTED: |
| 218 | - if ($keyword !== null) { |
|
| 237 | + if ($keyword !== null) |
|
| 238 | + { |
|
| 219 | 239 | $options[$keyword] = \trim($token->content, $token->content[0]); |
| 220 | 240 | $keyword = null; |
| 221 | 241 | break; |
@@ -224,7 +244,8 @@ discard block |
||
| 224 | 244 | $keyword = \trim($token->content, $token->content[0]); |
| 225 | 245 | break; |
| 226 | 246 | case DeclareGrammar::TYPE_COMMA: |
| 227 | - if ($keyword !== null) { |
|
| 247 | + if ($keyword !== null) |
|
| 248 | + { |
|
| 228 | 249 | $options[$keyword] = null; |
| 229 | 250 | $keyword = null; |
| 230 | 251 | break; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function __construct( |
| 48 | 48 | private readonly ?DirectiveRendererInterface $directiveRenderer = null, |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | $this->echo = new BracesGrammar( |
| 51 | 51 | '{{', |
| 52 | 52 | '}}', |
@@ -85,33 +85,33 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function parse(Buffer $src): \Generator |
| 87 | 87 | { |
| 88 | - while ($n = $src->next()) { |
|
| 89 | - if (!$n instanceof Byte) { |
|
| 88 | + while ($n = $src->next()){ |
|
| 89 | + if (!$n instanceof Byte){ |
|
| 90 | 90 | yield $n; |
| 91 | 91 | continue; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
| 94 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR){ |
|
| 95 | 95 | if ( |
| 96 | 96 | $this->echo->nextToken($src) || |
| 97 | 97 | $this->raw->nextToken($src) || |
| 98 | 98 | $src->lookaheadByte() === DirectiveGrammar::DIRECTIVE_CHAR |
| 99 | - ) { |
|
| 99 | + ){ |
|
| 100 | 100 | // escaped echo sequence, hide directive byte |
| 101 | 101 | yield $src->next(); |
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $directive = new DirectiveGrammar(); |
| 106 | - if ($directive->parse($src, $n->offset)) { |
|
| 107 | - if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
| 106 | + if ($directive->parse($src, $n->offset)){ |
|
| 107 | + if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE){ |
|
| 108 | 108 | // configure braces syntax |
| 109 | 109 | $this->declare($directive->getBody()); |
| 110 | - } else { |
|
| 110 | + }else{ |
|
| 111 | 111 | if ( |
| 112 | 112 | $this->directiveRenderer !== null |
| 113 | 113 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
| 114 | - ) { |
|
| 114 | + ){ |
|
| 115 | 115 | // directive opening char |
| 116 | 116 | yield $n; |
| 117 | 117 | |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | /** @var BracesGrammar|null $braces */ |
| 138 | 138 | $braces = null; |
| 139 | - if ($this->echo->starts($src, $n)) { |
|
| 139 | + if ($this->echo->starts($src, $n)){ |
|
| 140 | 140 | $braces = clone $this->echo; |
| 141 | - } elseif ($this->raw->starts($src, $n)) { |
|
| 141 | + } elseif ($this->raw->starts($src, $n)){ |
|
| 142 | 142 | $braces = clone $this->raw; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if ($braces !== null) { |
|
| 145 | + if ($braces !== null){ |
|
| 146 | 146 | $echo = $braces->parse($src, $n); |
| 147 | - if ($echo !== null) { |
|
| 147 | + if ($echo !== null){ |
|
| 148 | 148 | yield from $echo; |
| 149 | 149 | continue; |
| 150 | 150 | } |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | yield from $src; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - private function declare(?string $body): void |
|
| 161 | + private function declare(?string$body) : void |
|
| 162 | 162 | { |
| 163 | - if ($body === null) { |
|
| 163 | + if ($body === null){ |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
| 168 | - $value = \trim((string) $value, '\'" '); |
|
| 169 | - switch ($option) { |
|
| 167 | + foreach ($this->fetchOptions($body) as $option => $value){ |
|
| 168 | + $value = \trim((string)$value, '\'" '); |
|
| 169 | + switch ($option){ |
|
| 170 | 170 | case 'syntax': |
| 171 | 171 | $this->echo->setActive($value !== 'off'); |
| 172 | 172 | $this->raw->setActive($value !== 'off'); |
| 173 | 173 | |
| 174 | - if ($value === 'default') { |
|
| 174 | + if ($value === 'default'){ |
|
| 175 | 175 | $this->echo->setStartSequence('{{'); |
| 176 | 176 | $this->echo->setEndSequence('}}'); |
| 177 | 177 | $this->raw->setStartSequence('{!!'); |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | $keyword = null; |
| 209 | 209 | |
| 210 | 210 | /** @var Token $token */ |
| 211 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
| 212 | - switch ($token->type) { |
|
| 211 | + foreach ($lexer->parse(new StringStream($body)) as $token){ |
|
| 212 | + switch ($token->type){ |
|
| 213 | 213 | case DeclareGrammar::TYPE_KEYWORD: |
| 214 | - if ($keyword !== null) { |
|
| 214 | + if ($keyword !== null){ |
|
| 215 | 215 | $options[$keyword] = $token->content; |
| 216 | 216 | $keyword = null; |
| 217 | 217 | break; |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $keyword = $token->content; |
| 220 | 220 | break; |
| 221 | 221 | case DeclareGrammar::TYPE_QUOTED: |
| 222 | - if ($keyword !== null) { |
|
| 222 | + if ($keyword !== null){ |
|
| 223 | 223 | $options[$keyword] = \trim($token->content, $token->content[0]); |
| 224 | 224 | $keyword = null; |
| 225 | 225 | break; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $keyword = \trim($token->content, $token->content[0]); |
| 229 | 229 | break; |
| 230 | 230 | case DeclareGrammar::TYPE_COMMA: |
| 231 | - if ($keyword !== null) { |
|
| 231 | + if ($keyword !== null){ |
|
| 232 | 232 | $options[$keyword] = null; |
| 233 | 233 | $keyword = null; |
| 234 | 234 | break; |
@@ -39,14 +39,14 @@ |
||
| 39 | 39 | { |
| 40 | 40 | $declaration = $this->createDeclaration(CommandDeclaration::class, [ |
| 41 | 41 | 'description' => $this->description, |
| 42 | - 'alias' => $this->alias ?? \strtolower((string) \preg_replace('/(?<!^)[A-Z]/', ':$0', $this->name)), |
|
| 42 | + 'alias' => $this->alias ?? \strtolower((string)\preg_replace('/(?<!^)[A-Z]/', ':$0', $this->name)), |
|
| 43 | 43 | ]); |
| 44 | 44 | |
| 45 | - foreach ($this->arguments as $argument) { |
|
| 45 | + foreach ($this->arguments as $argument){ |
|
| 46 | 46 | $declaration->addArgument($argument); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - foreach ($this->options as $option) { |
|
| 49 | + foreach ($this->options as $option){ |
|
| 50 | 50 | $declaration->addOption($option); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -42,11 +42,13 @@ |
||
| 42 | 42 | 'alias' => $this->alias ?? \strtolower((string) \preg_replace('/(?<!^)[A-Z]/', ':$0', $this->name)), |
| 43 | 43 | ]); |
| 44 | 44 | |
| 45 | - foreach ($this->arguments as $argument) { |
|
| 45 | + foreach ($this->arguments as $argument) |
|
| 46 | + { |
|
| 46 | 47 | $declaration->addArgument($argument); |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | - foreach ($this->options as $option) { |
|
| 50 | + foreach ($this->options as $option) |
|
| 51 | + { |
|
| 50 | 52 | $declaration->addOption($option); |
| 51 | 53 | } |
| 52 | 54 | |