@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | public function __construct( |
28 | 28 | private readonly Builder $builder, |
29 | 29 | private readonly Merger $merger = new Merger() |
30 | - ) { |
|
30 | + ){ |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
34 | 34 | { |
35 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)) { |
|
35 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)){ |
|
36 | 36 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
37 | 37 | } |
38 | 38 | |
@@ -41,23 +41,23 @@ discard block |
||
41 | 41 | |
42 | 42 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
43 | 43 | { |
44 | - if (!$node instanceof Tag) { |
|
44 | + if (!$node instanceof Tag){ |
|
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | |
48 | 48 | $importCtx = ImportContext::on($ctx); |
49 | 49 | |
50 | 50 | // import definition |
51 | - if (\str_starts_with($node->name, $this->useKeyword)) { |
|
51 | + if (\str_starts_with($node->name, $this->useKeyword)){ |
|
52 | 52 | $importCtx->add($this->makeImport($node)); |
53 | 53 | |
54 | 54 | return self::REMOVE_NODE; |
55 | 55 | } |
56 | 56 | |
57 | 57 | // imported tag |
58 | - try { |
|
58 | + try{ |
|
59 | 59 | $import = $importCtx->resolve($this->builder, $node->name); |
60 | - } catch (\Throwable $e) { |
|
60 | + }catch (\Throwable $e){ |
|
61 | 61 | throw new ImportException( |
62 | 62 | \sprintf('Unable to resolve import `%s`', $node->name), |
63 | 63 | $node->getContext(), |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - if ($import !== null) { |
|
68 | + if ($import !== null){ |
|
69 | 69 | $node = $this->merger->merge($import, $node); |
70 | 70 | |
71 | 71 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | private function makeImport(Tag $tag): ImportInterface |
82 | 82 | { |
83 | 83 | $options = []; |
84 | - foreach ($tag->attrs as $attr) { |
|
85 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
84 | + foreach ($tag->attrs as $attr){ |
|
85 | + if (!\is_string($attr->value) || !\is_string($attr->name)){ |
|
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | $options[$attr->name] = \trim($attr->value, '\'"'); |
89 | 89 | } |
90 | 90 | |
91 | - switch (\strtolower($tag->name)) { |
|
91 | + switch (\strtolower($tag->name)){ |
|
92 | 92 | case 'use': |
93 | 93 | case 'use:element': |
94 | 94 | $this->assertHasOption('path', $options, $tag); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | private function assertHasOption(string $option, array $options, Tag $tag): void |
136 | 136 | { |
137 | - if (!isset($options[$option])) { |
|
137 | + if (!isset($options[$option])){ |
|
138 | 138 | throw new ImportException(\sprintf('Missing `%s` option', $option), $tag->getContext()); |
139 | 139 | } |
140 | 140 | } |
@@ -32,7 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
34 | 34 | { |
35 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)) { |
|
35 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->useKeyword)) |
|
36 | + { |
|
36 | 37 | return self::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
37 | 38 | } |
38 | 39 | |
@@ -41,23 +42,28 @@ discard block |
||
41 | 42 | |
42 | 43 | public function leaveNode(mixed $node, VisitorContext $ctx): mixed |
43 | 44 | { |
44 | - if (!$node instanceof Tag) { |
|
45 | + if (!$node instanceof Tag) |
|
46 | + { |
|
45 | 47 | return null; |
46 | 48 | } |
47 | 49 | |
48 | 50 | $importCtx = ImportContext::on($ctx); |
49 | 51 | |
50 | 52 | // import definition |
51 | - if (\str_starts_with($node->name, $this->useKeyword)) { |
|
53 | + if (\str_starts_with($node->name, $this->useKeyword)) |
|
54 | + { |
|
52 | 55 | $importCtx->add($this->makeImport($node)); |
53 | 56 | |
54 | 57 | return self::REMOVE_NODE; |
55 | 58 | } |
56 | 59 | |
57 | 60 | // imported tag |
58 | - try { |
|
61 | + try |
|
62 | + { |
|
59 | 63 | $import = $importCtx->resolve($this->builder, $node->name); |
60 | - } catch (\Throwable $e) { |
|
64 | + } |
|
65 | + catch (\Throwable $e) |
|
66 | + { |
|
61 | 67 | throw new ImportException( |
62 | 68 | \sprintf('Unable to resolve import `%s`', $node->name), |
63 | 69 | $node->getContext(), |
@@ -65,7 +71,8 @@ discard block |
||
65 | 71 | ); |
66 | 72 | } |
67 | 73 | |
68 | - if ($import !== null) { |
|
74 | + if ($import !== null) |
|
75 | + { |
|
69 | 76 | $node = $this->merger->merge($import, $node); |
70 | 77 | |
71 | 78 | return $this->merger->isolateNodes($node, $import->getContext()->getPath()); |
@@ -81,14 +88,17 @@ discard block |
||
81 | 88 | private function makeImport(Tag $tag): ImportInterface |
82 | 89 | { |
83 | 90 | $options = []; |
84 | - foreach ($tag->attrs as $attr) { |
|
85 | - if (!\is_string($attr->value) || !\is_string($attr->name)) { |
|
91 | + foreach ($tag->attrs as $attr) |
|
92 | + { |
|
93 | + if (!\is_string($attr->value) || !\is_string($attr->name)) |
|
94 | + { |
|
86 | 95 | continue; |
87 | 96 | } |
88 | 97 | $options[$attr->name] = \trim($attr->value, '\'"'); |
89 | 98 | } |
90 | 99 | |
91 | - switch (\strtolower($tag->name)) { |
|
100 | + switch (\strtolower($tag->name)) |
|
101 | + { |
|
92 | 102 | case 'use': |
93 | 103 | case 'use:element': |
94 | 104 | $this->assertHasOption('path', $options, $tag); |
@@ -134,7 +144,8 @@ discard block |
||
134 | 144 | |
135 | 145 | private function assertHasOption(string $option, array $options, Tag $tag): void |
136 | 146 | { |
137 | - if (!isset($options[$option])) { |
|
147 | + if (!isset($options[$option])) |
|
148 | + { |
|
138 | 149 | throw new ImportException(\sprintf('Missing `%s` option', $option), $tag->getContext()); |
139 | 150 | } |
140 | 151 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | public function __construct( |
16 | 16 | private readonly array $blocks |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function has(string $name): bool |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | { |
24 | 24 | $blocks = [self::CONTEXT_KEY => []]; |
25 | 25 | |
26 | - foreach ($caller->attrs as $attr) { |
|
27 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
26 | + foreach ($caller->attrs as $attr){ |
|
27 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface){ |
|
28 | 28 | // ignore name when attribute is dynamic |
29 | 29 | $blocks[\sprintf('attr-%s', \count($blocks))] = $attr; |
30 | 30 | continue; |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | |
40 | - foreach ($caller->nodes as $node) { |
|
41 | - if ($node instanceof Block) { |
|
40 | + foreach ($caller->nodes as $node){ |
|
41 | + if ($node instanceof Block){ |
|
42 | 42 | $blocks[$node->name] = $node->nodes; |
43 | - } else { |
|
43 | + }else{ |
|
44 | 44 | \assert( |
45 | 45 | \is_array($blocks[self::CONTEXT_KEY]) || $blocks[self::CONTEXT_KEY] instanceof \ArrayAccess |
46 | 46 | ); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - if ($blocks[self::CONTEXT_KEY] === []) { |
|
52 | + if ($blocks[self::CONTEXT_KEY] === []){ |
|
53 | 53 | unset($blocks[self::CONTEXT_KEY]); |
54 | 54 | } |
55 | 55 |
@@ -23,8 +23,10 @@ discard block |
||
23 | 23 | { |
24 | 24 | $blocks = [self::CONTEXT_KEY => []]; |
25 | 25 | |
26 | - foreach ($caller->attrs as $attr) { |
|
27 | - if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) { |
|
26 | + foreach ($caller->attrs as $attr) |
|
27 | + { |
|
28 | + if (!$attr instanceof Attr || $attr->name instanceof NodeInterface) |
|
29 | + { |
|
28 | 30 | // ignore name when attribute is dynamic |
29 | 31 | $blocks[\sprintf('attr-%s', \count($blocks))] = $attr; |
30 | 32 | continue; |
@@ -37,10 +39,14 @@ discard block |
||
37 | 39 | } |
38 | 40 | |
39 | 41 | |
40 | - foreach ($caller->nodes as $node) { |
|
41 | - if ($node instanceof Block) { |
|
42 | + foreach ($caller->nodes as $node) |
|
43 | + { |
|
44 | + if ($node instanceof Block) |
|
45 | + { |
|
42 | 46 | $blocks[$node->name] = $node->nodes; |
43 | - } else { |
|
47 | + } |
|
48 | + else |
|
49 | + { |
|
44 | 50 | \assert( |
45 | 51 | \is_array($blocks[self::CONTEXT_KEY]) || $blocks[self::CONTEXT_KEY] instanceof \ArrayAccess |
46 | 52 | ); |
@@ -49,7 +55,8 @@ discard block |
||
49 | 55 | } |
50 | 56 | } |
51 | 57 | |
52 | - if ($blocks[self::CONTEXT_KEY] === []) { |
|
58 | + if ($blocks[self::CONTEXT_KEY] === []) |
|
59 | + { |
|
53 | 60 | unset($blocks[self::CONTEXT_KEY]); |
54 | 61 | } |
55 | 62 |
@@ -20,15 +20,15 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
23 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE){ |
|
24 | 24 | return null; |
25 | 25 | } |
26 | 26 | |
27 | - if ($node->value instanceof Nil) { |
|
27 | + if ($node->value instanceof Nil){ |
|
28 | 28 | return new Aggregate($node->getContext()); |
29 | 29 | } |
30 | 30 | |
31 | - if (!\is_string($node->value)) { |
|
31 | + if (!\is_string($node->value)){ |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 |
@@ -20,15 +20,18 @@ |
||
20 | 20 | |
21 | 21 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
22 | 22 | { |
23 | - if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) { |
|
23 | + if (!$node instanceof Attr || $node->name !== self::AGGREGATE_ATTRIBUTE) |
|
24 | + { |
|
24 | 25 | return null; |
25 | 26 | } |
26 | 27 | |
27 | - if ($node->value instanceof Nil) { |
|
28 | + if ($node->value instanceof Nil) |
|
29 | + { |
|
28 | 30 | return new Aggregate($node->getContext()); |
29 | 31 | } |
30 | 32 | |
31 | - if (!\is_string($node->value)) { |
|
33 | + if (!\is_string($node->value)) |
|
34 | + { |
|
32 | 35 | return null; |
33 | 36 | } |
34 | 37 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
21 | 21 | { |
22 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) { |
|
22 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)){ |
|
23 | 23 | return $this->registerAggregate(StackContext::on($ctx), $node); |
24 | 24 | } |
25 | 25 | |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | |
34 | - private function registerAggregate(StackContext $ctx, Tag $node): Aggregate|Tag |
|
34 | + private function registerAggregate(StackContext $ctx, Tag $node): Aggregate | Tag |
|
35 | 35 | { |
36 | 36 | $name = $this->stackName($node); |
37 | - if ($name === null) { |
|
37 | + if ($name === null){ |
|
38 | 38 | return $node; |
39 | 39 | } |
40 | 40 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | private function stackName(Tag $tag): ?string |
51 | 51 | { |
52 | 52 | $options = []; |
53 | - foreach ($tag->attrs as $attr) { |
|
54 | - if (\is_string($attr->value)) { |
|
53 | + foreach ($tag->attrs as $attr){ |
|
54 | + if (\is_string($attr->value)){ |
|
55 | 55 | $options[$attr->name] = \trim($attr->value, '\'"'); |
56 | 56 | } |
57 | 57 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | private function stackLevel(Tag $tag): int |
63 | 63 | { |
64 | 64 | $options = []; |
65 | - foreach ($tag->attrs as $attr) { |
|
66 | - if (\is_string($attr->value)) { |
|
65 | + foreach ($tag->attrs as $attr){ |
|
66 | + if (\is_string($attr->value)){ |
|
67 | 67 | $options[$attr->name] = \trim($attr->value, '\'"'); |
68 | 68 | } |
69 | 69 | } |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | |
20 | 20 | public function enterNode(mixed $node, VisitorContext $ctx): mixed |
21 | 21 | { |
22 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) { |
|
22 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->stackKeyword)) |
|
23 | + { |
|
23 | 24 | return $this->registerAggregate(StackContext::on($ctx), $node); |
24 | 25 | } |
25 | 26 | |
@@ -34,7 +35,8 @@ discard block |
||
34 | 35 | private function registerAggregate(StackContext $ctx, Tag $node): Aggregate|Tag |
35 | 36 | { |
36 | 37 | $name = $this->stackName($node); |
37 | - if ($name === null) { |
|
38 | + if ($name === null) |
|
39 | + { |
|
38 | 40 | return $node; |
39 | 41 | } |
40 | 42 | |
@@ -50,8 +52,10 @@ discard block |
||
50 | 52 | private function stackName(Tag $tag): ?string |
51 | 53 | { |
52 | 54 | $options = []; |
53 | - foreach ($tag->attrs as $attr) { |
|
54 | - if (\is_string($attr->value)) { |
|
55 | + foreach ($tag->attrs as $attr) |
|
56 | + { |
|
57 | + if (\is_string($attr->value)) |
|
58 | + { |
|
55 | 59 | $options[$attr->name] = \trim($attr->value, '\'"'); |
56 | 60 | } |
57 | 61 | } |
@@ -62,8 +66,10 @@ discard block |
||
62 | 66 | private function stackLevel(Tag $tag): int |
63 | 67 | { |
64 | 68 | $options = []; |
65 | - foreach ($tag->attrs as $attr) { |
|
66 | - if (\is_string($attr->value)) { |
|
69 | + foreach ($tag->attrs as $attr) |
|
70 | + { |
|
71 | + if (\is_string($attr->value)) |
|
72 | + { |
|
67 | 73 | $options[$attr->name] = \trim($attr->value, '\'"'); |
68 | 74 | } |
69 | 75 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | public function leaveNode(mixed $node, VisitorContext $ctx): ?Hidden |
23 | 23 | { |
24 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)) { |
|
24 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)){ |
|
25 | 25 | return new Hidden([$node]); |
26 | 26 | } |
27 | 27 |
@@ -21,7 +21,8 @@ |
||
21 | 21 | |
22 | 22 | public function leaveNode(mixed $node, VisitorContext $ctx): ?Hidden |
23 | 23 | { |
24 | - if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)) { |
|
24 | + if ($node instanceof Tag && \str_starts_with($node->name, $this->hiddenKeyword)) |
|
25 | + { |
|
25 | 26 | return new Hidden([$node]); |
26 | 27 | } |
27 | 28 |
@@ -29,19 +29,23 @@ |
||
29 | 29 | |
30 | 30 | public function resolve(Builder $builder, string $name): ?Template |
31 | 31 | { |
32 | - if ($this->template === null) { |
|
32 | + if ($this->template === null) |
|
33 | + { |
|
33 | 34 | $this->template = $builder->load($this->path); |
34 | 35 | } |
35 | 36 | |
36 | 37 | $path = $name; |
37 | - if ($this->prefix !== null) { |
|
38 | + if ($this->prefix !== null) |
|
39 | + { |
|
38 | 40 | $path = \substr($path, \strlen($this->prefix) + 1); |
39 | 41 | } |
40 | 42 | |
41 | 43 | /** @var ImportInterface $import */ |
42 | - foreach ($this->template->getAttribute(ImportContext::class, []) as $import) { |
|
44 | + foreach ($this->template->getAttribute(ImportContext::class, []) as $import) |
|
45 | + { |
|
43 | 46 | $tpl = $import->resolve($builder, $path); |
44 | - if ($tpl !== null) { |
|
47 | + if ($tpl !== null) |
|
48 | + { |
|
45 | 49 | return $tpl; |
46 | 50 | } |
47 | 51 | } |
@@ -23,25 +23,25 @@ |
||
23 | 23 | private string $path, |
24 | 24 | private ?string $prefix = null, |
25 | 25 | Context $context = null |
26 | - ) { |
|
26 | + ){ |
|
27 | 27 | $this->context = $context; |
28 | 28 | } |
29 | 29 | |
30 | 30 | public function resolve(Builder $builder, string $name): ?Template |
31 | 31 | { |
32 | - if ($this->template === null) { |
|
32 | + if ($this->template === null){ |
|
33 | 33 | $this->template = $builder->load($this->path); |
34 | 34 | } |
35 | 35 | |
36 | 36 | $path = $name; |
37 | - if ($this->prefix !== null) { |
|
37 | + if ($this->prefix !== null){ |
|
38 | 38 | $path = \substr($path, \strlen($this->prefix) + 1); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** @var ImportInterface $import */ |
42 | - foreach ($this->template->getAttribute(ImportContext::class, []) as $import) { |
|
42 | + foreach ($this->template->getAttribute(ImportContext::class, []) as $import){ |
|
43 | 43 | $tpl = $import->resolve($builder, $path); |
44 | - if ($tpl !== null) { |
|
44 | + if ($tpl !== null){ |
|
45 | 45 | return $tpl; |
46 | 46 | } |
47 | 47 | } |
@@ -20,13 +20,13 @@ |
||
20 | 20 | private readonly string $name, |
21 | 21 | private readonly array $nodes, |
22 | 22 | Context $context = null |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | $this->context = $context; |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function resolve(Builder $builder, string $name): ?Template |
28 | 28 | { |
29 | - if ($name !== $this->name) { |
|
29 | + if ($name !== $this->name){ |
|
30 | 30 | return null; |
31 | 31 | } |
32 | 32 |
@@ -26,7 +26,8 @@ |
||
26 | 26 | |
27 | 27 | public function resolve(Builder $builder, string $name): ?Template |
28 | 28 | { |
29 | - if ($name !== $this->name) { |
|
29 | + if ($name !== $this->name) |
|
30 | + { |
|
30 | 31 | return null; |
31 | 32 | } |
32 | 33 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public string $path, |
23 | 23 | ?string $prefix, |
24 | 24 | Context $context = null |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | $this->prefix = $prefix ?? \substr($path, \strrpos($path, '/') + 1); |
27 | 27 | $this->context = $context; |
28 | 28 | } |
@@ -32,6 +32,6 @@ discard block |
||
32 | 32 | $path = \substr($name, \strlen($this->prefix) + 1); |
33 | 33 | $path = \str_replace('.', DIRECTORY_SEPARATOR, $path); |
34 | 34 | |
35 | - return $builder->load($this->path . DIRECTORY_SEPARATOR . $path); |
|
35 | + return $builder->load($this->path.DIRECTORY_SEPARATOR.$path); |
|
36 | 36 | } |
37 | 37 | } |