@@ -15,7 +15,7 @@ |
||
15 | 15 | { |
16 | 16 | public function __construct( |
17 | 17 | private readonly InvokerInterface $invoker, |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | public function __construct( |
34 | 34 | protected readonly State $state, |
35 | - ) { |
|
35 | + ){ |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function bind(string $alias, mixed $resolver): void |
42 | 42 | { |
43 | - if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) { |
|
43 | + if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))){ |
|
44 | 44 | $this->state->inflectors[$alias][] = $resolver; |
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | - try { |
|
48 | + try{ |
|
49 | 49 | $config = $this->makeConfig($resolver, false); |
50 | - } catch (\Throwable $e) { |
|
50 | + }catch (\Throwable $e){ |
|
51 | 51 | throw $this->invalidBindingException($alias, $e); |
52 | 52 | } |
53 | 53 | |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function bindSingleton(string $alias, mixed $resolver): void |
61 | 61 | { |
62 | - try { |
|
62 | + try{ |
|
63 | 63 | $config = $this->makeConfig($resolver, true); |
64 | - } catch (\Throwable $e) { |
|
64 | + }catch (\Throwable $e){ |
|
65 | 65 | throw $this->invalidBindingException($alias, $e); |
66 | 66 | } |
67 | 67 | |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | $bindings = &$this->state->bindings; |
74 | 74 | |
75 | 75 | $flags = []; |
76 | - while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) { |
|
76 | + while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class){ |
|
77 | 77 | //Checking alias tree |
78 | - if ($flags[$binding->alias] ?? false) { |
|
78 | + if ($flags[$binding->alias] ?? false){ |
|
79 | 79 | return $binding->alias === $alias ?: throw new Exception('Circular alias detected'); |
80 | 80 | } |
81 | 81 | |
82 | - if (\array_key_exists($alias, $this->state->singletons)) { |
|
82 | + if (\array_key_exists($alias, $this->state->singletons)){ |
|
83 | 83 | return true; |
84 | 84 | } |
85 | 85 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function removeInjector(string $class): void |
105 | 105 | { |
106 | 106 | unset($this->state->injectors[$class]); |
107 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
107 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class){ |
|
108 | 108 | return; |
109 | 109 | } |
110 | 110 | unset($this->state->bindings[$class]); |
@@ -112,20 +112,20 @@ discard block |
||
112 | 112 | |
113 | 113 | public function hasInjector(string $class): bool |
114 | 114 | { |
115 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
115 | + if (\array_key_exists($class, $this->state->injectors)){ |
|
116 | 116 | return true; |
117 | 117 | } |
118 | 118 | |
119 | - try { |
|
119 | + try{ |
|
120 | 120 | $reflection = new \ReflectionClass($class); |
121 | - } catch (\ReflectionException $e) { |
|
121 | + }catch (\ReflectionException $e){ |
|
122 | 122 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
123 | 123 | } |
124 | 124 | |
125 | 125 | if ( |
126 | 126 | $reflection->implementsInterface(InjectableInterface::class) |
127 | 127 | && $reflection->hasConstant('INJECTOR') |
128 | - ) { |
|
128 | + ){ |
|
129 | 129 | $const = $reflection->getConstant('INJECTOR'); |
130 | 130 | $this->bindInjector($class, $const); |
131 | 131 | |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | // check interfaces |
136 | - foreach ($this->state->injectors as $target => $injector) { |
|
136 | + foreach ($this->state->injectors as $target => $injector){ |
|
137 | 137 | if ( |
138 | 138 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
139 | 139 | || |
140 | 140 | (\interface_exists($target, true) && $reflection->implementsInterface($target)) |
141 | - ) { |
|
141 | + ){ |
|
142 | 142 | $this->state->bindings[$class] = new Injectable($injector); |
143 | 143 | |
144 | 144 | return true; |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | |
166 | 166 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
167 | 167 | { |
168 | - if (\is_callable($resolver)) { |
|
168 | + if (\is_callable($resolver)){ |
|
169 | 169 | return new Factory($resolver, $singleton); |
170 | 170 | } |
171 | 171 | |
172 | 172 | // Validate lazy invokable array |
173 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
173 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === ''){ |
|
174 | 174 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
175 | 175 | } |
176 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
176 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === ''){ |
|
177 | 177 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
178 | 178 | } |
179 | 179 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | private function setBinding(string $alias, Binding $config): void |
193 | 193 | { |
194 | - if (isset($this->state->singletons[$alias])) { |
|
194 | + if (isset($this->state->singletons[$alias])){ |
|
195 | 195 | throw new SingletonOverloadException($alias); |
196 | 196 | } |
197 | 197 |
@@ -40,14 +40,18 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function bind(string $alias, mixed $resolver): void |
42 | 42 | { |
43 | - if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) { |
|
43 | + if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) |
|
44 | + { |
|
44 | 45 | $this->state->inflectors[$alias][] = $resolver; |
45 | 46 | return; |
46 | 47 | } |
47 | 48 | |
48 | - try { |
|
49 | + try |
|
50 | + { |
|
49 | 51 | $config = $this->makeConfig($resolver, false); |
50 | - } catch (\Throwable $e) { |
|
52 | + } |
|
53 | + catch (\Throwable $e) |
|
54 | + { |
|
51 | 55 | throw $this->invalidBindingException($alias, $e); |
52 | 56 | } |
53 | 57 | |
@@ -59,9 +63,12 @@ discard block |
||
59 | 63 | */ |
60 | 64 | public function bindSingleton(string $alias, mixed $resolver): void |
61 | 65 | { |
62 | - try { |
|
66 | + try |
|
67 | + { |
|
63 | 68 | $config = $this->makeConfig($resolver, true); |
64 | - } catch (\Throwable $e) { |
|
69 | + } |
|
70 | + catch (\Throwable $e) |
|
71 | + { |
|
65 | 72 | throw $this->invalidBindingException($alias, $e); |
66 | 73 | } |
67 | 74 | |
@@ -73,13 +80,16 @@ discard block |
||
73 | 80 | $bindings = &$this->state->bindings; |
74 | 81 | |
75 | 82 | $flags = []; |
76 | - while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) { |
|
83 | + while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) |
|
84 | + { |
|
77 | 85 | //Checking alias tree |
78 | - if ($flags[$binding->alias] ?? false) { |
|
86 | + if ($flags[$binding->alias] ?? false) |
|
87 | + { |
|
79 | 88 | return $binding->alias === $alias ?: throw new Exception('Circular alias detected'); |
80 | 89 | } |
81 | 90 | |
82 | - if (\array_key_exists($alias, $this->state->singletons)) { |
|
91 | + if (\array_key_exists($alias, $this->state->singletons)) |
|
92 | + { |
|
83 | 93 | return true; |
84 | 94 | } |
85 | 95 | |
@@ -104,7 +114,8 @@ discard block |
||
104 | 114 | public function removeInjector(string $class): void |
105 | 115 | { |
106 | 116 | unset($this->state->injectors[$class]); |
107 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
117 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) |
|
118 | + { |
|
108 | 119 | return; |
109 | 120 | } |
110 | 121 | unset($this->state->bindings[$class]); |
@@ -112,13 +123,17 @@ discard block |
||
112 | 123 | |
113 | 124 | public function hasInjector(string $class): bool |
114 | 125 | { |
115 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
126 | + if (\array_key_exists($class, $this->state->injectors)) |
|
127 | + { |
|
116 | 128 | return true; |
117 | 129 | } |
118 | 130 | |
119 | - try { |
|
131 | + try |
|
132 | + { |
|
120 | 133 | $reflection = new \ReflectionClass($class); |
121 | - } catch (\ReflectionException $e) { |
|
134 | + } |
|
135 | + catch (\ReflectionException $e) |
|
136 | + { |
|
122 | 137 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
123 | 138 | } |
124 | 139 | |
@@ -133,7 +148,8 @@ discard block |
||
133 | 148 | } |
134 | 149 | |
135 | 150 | // check interfaces |
136 | - foreach ($this->state->injectors as $target => $injector) { |
|
151 | + foreach ($this->state->injectors as $target => $injector) |
|
152 | + { |
|
137 | 153 | if ( |
138 | 154 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
139 | 155 | || |
@@ -165,15 +181,18 @@ discard block |
||
165 | 181 | |
166 | 182 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
167 | 183 | { |
168 | - if (\is_callable($resolver)) { |
|
184 | + if (\is_callable($resolver)) |
|
185 | + { |
|
169 | 186 | return new Factory($resolver, $singleton); |
170 | 187 | } |
171 | 188 | |
172 | 189 | // Validate lazy invokable array |
173 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
190 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') |
|
191 | + { |
|
174 | 192 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
175 | 193 | } |
176 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
194 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') |
|
195 | + { |
|
177 | 196 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
178 | 197 | } |
179 | 198 | |
@@ -191,7 +210,8 @@ discard block |
||
191 | 210 | |
192 | 211 | private function setBinding(string $alias, Binding $config): void |
193 | 212 | { |
194 | - if (isset($this->state->singletons[$alias])) { |
|
213 | + if (isset($this->state->singletons[$alias])) |
|
214 | + { |
|
195 | 215 | throw new SingletonOverloadException($alias); |
196 | 216 | } |
197 | 217 |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | { |
29 | 29 | $grid = $this->table(['Name:', 'Verbs:', 'Pattern:', 'Target:', 'Group:']); |
30 | 30 | |
31 | - foreach ($router->getRoutes() as $name => $route) { |
|
32 | - if ($route instanceof RouteInterface) { |
|
31 | + foreach ($router->getRoutes() as $name => $route){ |
|
32 | + if ($route instanceof RouteInterface){ |
|
33 | 33 | $grid->addRow( |
34 | 34 | [ |
35 | 35 | $name, |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | private function getRouteGroups(GroupRegistry $registry, string $routeName): array |
54 | 54 | { |
55 | 55 | $groups = []; |
56 | - foreach ($registry as $groupName => $group) { |
|
57 | - if ($group->hasRoute($routeName)) { |
|
56 | + foreach ($registry as $groupName => $group){ |
|
57 | + if ($group->hasRoute($routeName)){ |
|
58 | 58 | $groups[] = $groupName; |
59 | 59 | } |
60 | 60 | } |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | |
65 | 65 | private function getVerbs(RouteInterface $route): string |
66 | 66 | { |
67 | - if ($route->getVerbs() === RouteInterface::VERBS) { |
|
67 | + if ($route->getVerbs() === RouteInterface::VERBS){ |
|
68 | 68 | return '*'; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $result = []; |
72 | - foreach ($route->getVerbs() as $verb) { |
|
72 | + foreach ($route->getVerbs() as $verb){ |
|
73 | 73 | $result[] = match (\strtolower($verb)) { |
74 | 74 | 'get' => '<fg=green>GET</>', |
75 | 75 | 'head' => '<fg=bright-green>HEAD</>', |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $pattern = \preg_replace_callback( |
99 | 99 | '/<([^>]*)>/', |
100 | 100 | static fn ($m) => \sprintf('<fg=magenta>%s</>', $m[0]), |
101 | - !empty($prefix) ? $prefix . '/' . \trim($pattern, '/') : $pattern |
|
101 | + !empty($prefix) ? $prefix.'/'.\trim($pattern, '/') : $pattern |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | return $pattern; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | private function getTarget(RouteInterface $route, KernelInterface $kernel): string |
112 | 112 | { |
113 | 113 | $target = $this->getValue($route, 'target'); |
114 | - switch (true) { |
|
114 | + switch (true){ |
|
115 | 115 | case $target instanceof \Closure: |
116 | 116 | $reflection = new \ReflectionFunction($target); |
117 | 117 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | case $target instanceof Group: |
138 | 138 | $result = []; |
139 | - foreach ($this->getValue($target, 'controllers') as $alias => $class) { |
|
139 | + foreach ($this->getValue($target, 'controllers') as $alias => $class){ |
|
140 | 140 | $result[] = \sprintf('%s => %s', $alias, $this->relativeClass($class, $kernel)); |
141 | 141 | } |
142 | 142 | |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | |
156 | 156 | private function getValue(object $object, string $property): mixed |
157 | 157 | { |
158 | - try { |
|
158 | + try{ |
|
159 | 159 | $r = new \ReflectionObject($object); |
160 | 160 | $prop = $r->getProperty($property); |
161 | - } catch (\Throwable $e) { |
|
161 | + }catch (\Throwable $e){ |
|
162 | 162 | return $e->getMessage(); |
163 | 163 | } |
164 | 164 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $r = new \ReflectionObject($kernel); |
171 | 171 | |
172 | - if (\str_starts_with($class, $r->getNamespaceName())) { |
|
172 | + if (\str_starts_with($class, $r->getNamespaceName())){ |
|
173 | 173 | return \substr($class, \strlen($r->getNamespaceName()) + 1); |
174 | 174 | } |
175 | 175 |
@@ -28,8 +28,10 @@ discard block |
||
28 | 28 | { |
29 | 29 | $grid = $this->table(['Name:', 'Verbs:', 'Pattern:', 'Target:', 'Group:']); |
30 | 30 | |
31 | - foreach ($router->getRoutes() as $name => $route) { |
|
32 | - if ($route instanceof RouteInterface) { |
|
31 | + foreach ($router->getRoutes() as $name => $route) |
|
32 | + { |
|
33 | + if ($route instanceof RouteInterface) |
|
34 | + { |
|
33 | 35 | $grid->addRow( |
34 | 36 | [ |
35 | 37 | $name, |
@@ -53,8 +55,10 @@ discard block |
||
53 | 55 | private function getRouteGroups(GroupRegistry $registry, string $routeName): array |
54 | 56 | { |
55 | 57 | $groups = []; |
56 | - foreach ($registry as $groupName => $group) { |
|
57 | - if ($group->hasRoute($routeName)) { |
|
58 | + foreach ($registry as $groupName => $group) |
|
59 | + { |
|
60 | + if ($group->hasRoute($routeName)) |
|
61 | + { |
|
58 | 62 | $groups[] = $groupName; |
59 | 63 | } |
60 | 64 | } |
@@ -64,12 +68,14 @@ discard block |
||
64 | 68 | |
65 | 69 | private function getVerbs(RouteInterface $route): string |
66 | 70 | { |
67 | - if ($route->getVerbs() === RouteInterface::VERBS) { |
|
71 | + if ($route->getVerbs() === RouteInterface::VERBS) |
|
72 | + { |
|
68 | 73 | return '*'; |
69 | 74 | } |
70 | 75 | |
71 | 76 | $result = []; |
72 | - foreach ($route->getVerbs() as $verb) { |
|
77 | + foreach ($route->getVerbs() as $verb) |
|
78 | + { |
|
73 | 79 | $result[] = match (\strtolower($verb)) { |
74 | 80 | 'get' => '<fg=green>GET</>', |
75 | 81 | 'head' => '<fg=bright-green>HEAD</>', |
@@ -111,7 +117,8 @@ discard block |
||
111 | 117 | private function getTarget(RouteInterface $route, KernelInterface $kernel): string |
112 | 118 | { |
113 | 119 | $target = $this->getValue($route, 'target'); |
114 | - switch (true) { |
|
120 | + switch (true) |
|
121 | + { |
|
115 | 122 | case $target instanceof \Closure: |
116 | 123 | $reflection = new \ReflectionFunction($target); |
117 | 124 | |
@@ -136,7 +143,8 @@ discard block |
||
136 | 143 | |
137 | 144 | case $target instanceof Group: |
138 | 145 | $result = []; |
139 | - foreach ($this->getValue($target, 'controllers') as $alias => $class) { |
|
146 | + foreach ($this->getValue($target, 'controllers') as $alias => $class) |
|
147 | + { |
|
140 | 148 | $result[] = \sprintf('%s => %s', $alias, $this->relativeClass($class, $kernel)); |
141 | 149 | } |
142 | 150 | |
@@ -155,10 +163,13 @@ discard block |
||
155 | 163 | |
156 | 164 | private function getValue(object $object, string $property): mixed |
157 | 165 | { |
158 | - try { |
|
166 | + try |
|
167 | + { |
|
159 | 168 | $r = new \ReflectionObject($object); |
160 | 169 | $prop = $r->getProperty($property); |
161 | - } catch (\Throwable $e) { |
|
170 | + } |
|
171 | + catch (\Throwable $e) |
|
172 | + { |
|
162 | 173 | return $e->getMessage(); |
163 | 174 | } |
164 | 175 | |
@@ -169,7 +180,8 @@ discard block |
||
169 | 180 | { |
170 | 181 | $r = new \ReflectionObject($kernel); |
171 | 182 | |
172 | - if (\str_starts_with($class, $r->getNamespaceName())) { |
|
183 | + if (\str_starts_with($class, $r->getNamespaceName())) |
|
184 | + { |
|
173 | 185 | return \substr($class, \strlen($r->getNamespaceName()) + 1); |
174 | 186 | } |
175 | 187 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | private readonly bool $useAnnotations = false, |
30 | 30 | private readonly bool $namedArguments = true, |
31 | 31 | private readonly bool $scanParents = false, |
32 | - ) { |
|
32 | + ){ |
|
33 | 33 | parent::__construct($scope); |
34 | 34 | } |
35 | 35 | |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | ? (new Factory())->create() |
46 | 46 | : new AttributeReader($this->namedArguments ? new NamedArgumentsInstantiator() : null); |
47 | 47 | |
48 | - if ($attribute === null) { |
|
48 | + if ($attribute === null){ |
|
49 | 49 | return; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $attribute = $attribute->newInstance(); |
53 | 53 | |
54 | - foreach ($classes as $class) { |
|
54 | + foreach ($classes as $class){ |
|
55 | 55 | // If attribute is defined on class level and class has target attribute |
56 | 56 | // then we can add it to the list of classes |
57 | - if ($attribute->flags & \Attribute::TARGET_CLASS) { |
|
58 | - if ($reader->firstClassMetadata($class, $target->getName())) { |
|
57 | + if ($attribute->flags & \Attribute::TARGET_CLASS){ |
|
58 | + if ($reader->firstClassMetadata($class, $target->getName())){ |
|
59 | 59 | yield $class->getName(); |
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | - if ($this->scanParents) { |
|
63 | + if ($this->scanParents){ |
|
64 | 64 | // Interfaces |
65 | - foreach ($class->getInterfaces() as $interface) { |
|
66 | - if ($reader->firstClassMetadata($interface, $target->getName())) { |
|
65 | + foreach ($class->getInterfaces() as $interface){ |
|
66 | + if ($reader->firstClassMetadata($interface, $target->getName())){ |
|
67 | 67 | yield $class->getName(); |
68 | 68 | continue 2; |
69 | 69 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | |
72 | 72 | // Parents |
73 | 73 | $parent = $class->getParentClass(); |
74 | - while ($parent !== false) { |
|
75 | - if ($reader->firstClassMetadata($parent, $target->getName())) { |
|
74 | + while ($parent !== false){ |
|
75 | + if ($reader->firstClassMetadata($parent, $target->getName())){ |
|
76 | 76 | yield $class->getName(); |
77 | 77 | continue 2; |
78 | 78 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | |
84 | 84 | // If attribute is defined on method level and class methods has target attribute |
85 | 85 | // then we can add it to the list of classes |
86 | - if ($attribute->flags & \Attribute::TARGET_METHOD) { |
|
87 | - foreach ($class->getMethods() as $method) { |
|
88 | - if ($reader->firstFunctionMetadata($method, $target->getName())) { |
|
86 | + if ($attribute->flags & \Attribute::TARGET_METHOD){ |
|
87 | + foreach ($class->getMethods() as $method){ |
|
88 | + if ($reader->firstFunctionMetadata($method, $target->getName())){ |
|
89 | 89 | yield $class->getName(); |
90 | 90 | continue 2; |
91 | 91 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | |
95 | 95 | // If attribute is defined on property level and class properties has target attribute |
96 | 96 | // then we can add it to the list of classes |
97 | - if ($attribute->flags & \Attribute::TARGET_PROPERTY) { |
|
98 | - foreach ($class->getProperties() as $property) { |
|
99 | - if ($reader->firstPropertyMetadata($property, $target->getName())) { |
|
97 | + if ($attribute->flags & \Attribute::TARGET_PROPERTY){ |
|
98 | + foreach ($class->getProperties() as $property){ |
|
99 | + if ($reader->firstPropertyMetadata($property, $target->getName())){ |
|
100 | 100 | yield $class->getName(); |
101 | 101 | continue 2; |
102 | 102 | } |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | |
107 | 107 | // If attribute is defined on constant level and class constants has target attribute |
108 | 108 | // then we can add it to the list of classes |
109 | - if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT) { |
|
110 | - foreach ($class->getReflectionConstants() as $constant) { |
|
111 | - if ($reader->firstConstantMetadata($constant, $target->getName())) { |
|
109 | + if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT){ |
|
110 | + foreach ($class->getReflectionConstants() as $constant){ |
|
111 | + if ($reader->firstConstantMetadata($constant, $target->getName())){ |
|
112 | 112 | yield $class->getName(); |
113 | 113 | continue 2; |
114 | 114 | } |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | |
119 | 119 | // If attribute is defined on method parameters level and class method parameter has target attribute |
120 | 120 | // then we can add it to the list of classes |
121 | - if ($attribute->flags & \Attribute::TARGET_PARAMETER) { |
|
122 | - foreach ($class->getMethods() as $method) { |
|
123 | - foreach ($method->getParameters() as $parameter) { |
|
124 | - if ($reader->firstParameterMetadata($parameter, $target->getName())) { |
|
121 | + if ($attribute->flags & \Attribute::TARGET_PARAMETER){ |
|
122 | + foreach ($class->getMethods() as $method){ |
|
123 | + foreach ($method->getParameters() as $parameter){ |
|
124 | + if ($reader->firstParameterMetadata($parameter, $target->getName())){ |
|
125 | 125 | yield $class->getName(); |
126 | 126 | continue 3; |
127 | 127 | } |
@@ -45,25 +45,32 @@ discard block |
||
45 | 45 | ? (new Factory())->create() |
46 | 46 | : new AttributeReader($this->namedArguments ? new NamedArgumentsInstantiator() : null); |
47 | 47 | |
48 | - if ($attribute === null) { |
|
48 | + if ($attribute === null) |
|
49 | + { |
|
49 | 50 | return; |
50 | 51 | } |
51 | 52 | |
52 | 53 | $attribute = $attribute->newInstance(); |
53 | 54 | |
54 | - foreach ($classes as $class) { |
|
55 | + foreach ($classes as $class) |
|
56 | + { |
|
55 | 57 | // If attribute is defined on class level and class has target attribute |
56 | 58 | // then we can add it to the list of classes |
57 | - if ($attribute->flags & \Attribute::TARGET_CLASS) { |
|
58 | - if ($reader->firstClassMetadata($class, $target->getName())) { |
|
59 | + if ($attribute->flags & \Attribute::TARGET_CLASS) |
|
60 | + { |
|
61 | + if ($reader->firstClassMetadata($class, $target->getName())) |
|
62 | + { |
|
59 | 63 | yield $class->getName(); |
60 | 64 | continue; |
61 | 65 | } |
62 | 66 | |
63 | - if ($this->scanParents) { |
|
67 | + if ($this->scanParents) |
|
68 | + { |
|
64 | 69 | // Interfaces |
65 | - foreach ($class->getInterfaces() as $interface) { |
|
66 | - if ($reader->firstClassMetadata($interface, $target->getName())) { |
|
70 | + foreach ($class->getInterfaces() as $interface) |
|
71 | + { |
|
72 | + if ($reader->firstClassMetadata($interface, $target->getName())) |
|
73 | + { |
|
67 | 74 | yield $class->getName(); |
68 | 75 | continue 2; |
69 | 76 | } |
@@ -71,8 +78,10 @@ discard block |
||
71 | 78 | |
72 | 79 | // Parents |
73 | 80 | $parent = $class->getParentClass(); |
74 | - while ($parent !== false) { |
|
75 | - if ($reader->firstClassMetadata($parent, $target->getName())) { |
|
81 | + while ($parent !== false) |
|
82 | + { |
|
83 | + if ($reader->firstClassMetadata($parent, $target->getName())) |
|
84 | + { |
|
76 | 85 | yield $class->getName(); |
77 | 86 | continue 2; |
78 | 87 | } |
@@ -83,9 +92,12 @@ discard block |
||
83 | 92 | |
84 | 93 | // If attribute is defined on method level and class methods has target attribute |
85 | 94 | // then we can add it to the list of classes |
86 | - if ($attribute->flags & \Attribute::TARGET_METHOD) { |
|
87 | - foreach ($class->getMethods() as $method) { |
|
88 | - if ($reader->firstFunctionMetadata($method, $target->getName())) { |
|
95 | + if ($attribute->flags & \Attribute::TARGET_METHOD) |
|
96 | + { |
|
97 | + foreach ($class->getMethods() as $method) |
|
98 | + { |
|
99 | + if ($reader->firstFunctionMetadata($method, $target->getName())) |
|
100 | + { |
|
89 | 101 | yield $class->getName(); |
90 | 102 | continue 2; |
91 | 103 | } |
@@ -94,9 +106,12 @@ discard block |
||
94 | 106 | |
95 | 107 | // If attribute is defined on property level and class properties has target attribute |
96 | 108 | // then we can add it to the list of classes |
97 | - if ($attribute->flags & \Attribute::TARGET_PROPERTY) { |
|
98 | - foreach ($class->getProperties() as $property) { |
|
99 | - if ($reader->firstPropertyMetadata($property, $target->getName())) { |
|
109 | + if ($attribute->flags & \Attribute::TARGET_PROPERTY) |
|
110 | + { |
|
111 | + foreach ($class->getProperties() as $property) |
|
112 | + { |
|
113 | + if ($reader->firstPropertyMetadata($property, $target->getName())) |
|
114 | + { |
|
100 | 115 | yield $class->getName(); |
101 | 116 | continue 2; |
102 | 117 | } |
@@ -106,9 +121,12 @@ discard block |
||
106 | 121 | |
107 | 122 | // If attribute is defined on constant level and class constants has target attribute |
108 | 123 | // then we can add it to the list of classes |
109 | - if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT) { |
|
110 | - foreach ($class->getReflectionConstants() as $constant) { |
|
111 | - if ($reader->firstConstantMetadata($constant, $target->getName())) { |
|
124 | + if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT) |
|
125 | + { |
|
126 | + foreach ($class->getReflectionConstants() as $constant) |
|
127 | + { |
|
128 | + if ($reader->firstConstantMetadata($constant, $target->getName())) |
|
129 | + { |
|
112 | 130 | yield $class->getName(); |
113 | 131 | continue 2; |
114 | 132 | } |
@@ -118,10 +136,14 @@ discard block |
||
118 | 136 | |
119 | 137 | // If attribute is defined on method parameters level and class method parameter has target attribute |
120 | 138 | // then we can add it to the list of classes |
121 | - if ($attribute->flags & \Attribute::TARGET_PARAMETER) { |
|
122 | - foreach ($class->getMethods() as $method) { |
|
123 | - foreach ($method->getParameters() as $parameter) { |
|
124 | - if ($reader->firstParameterMetadata($parameter, $target->getName())) { |
|
139 | + if ($attribute->flags & \Attribute::TARGET_PARAMETER) |
|
140 | + { |
|
141 | + foreach ($class->getMethods() as $method) |
|
142 | + { |
|
143 | + foreach ($method->getParameters() as $parameter) |
|
144 | + { |
|
145 | + if ($reader->firstParameterMetadata($parameter, $target->getName())) |
|
146 | + { |
|
125 | 147 | yield $class->getName(); |
126 | 148 | continue 3; |
127 | 149 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | public function __construct( |
22 | 22 | private readonly ContainerInterface $container, |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | array $interceptors, |
31 | 31 | ?EventDispatcherInterface $eventDispatcher = null, |
32 | 32 | ?PipelineBuilderInterface $pipelineBuilder = null, |
33 | - ): CoreInterface|HandlerInterface { |
|
33 | + ): CoreInterface | HandlerInterface { |
|
34 | 34 | /** @var CommandCore $core */ |
35 | 35 | $core = $this->container->get(CommandCore::class); |
36 | 36 | $pipelineBuilder ??= new CompatiblePipelineBuilder($eventDispatcher); |
37 | 37 | |
38 | 38 | $resolved = []; |
39 | - foreach ($interceptors as $interceptor) { |
|
39 | + foreach ($interceptors as $interceptor){ |
|
40 | 40 | $resolved[] = $this->container->get($interceptor); |
41 | 41 | } |
42 | 42 |
@@ -36,7 +36,8 @@ |
||
36 | 36 | $pipelineBuilder ??= new CompatiblePipelineBuilder($eventDispatcher); |
37 | 37 | |
38 | 38 | $resolved = []; |
39 | - foreach ($interceptors as $interceptor) { |
|
39 | + foreach ($interceptors as $interceptor) |
|
40 | + { |
|
40 | 41 | $resolved[] = $this->container->get($interceptor); |
41 | 42 | } |
42 | 43 |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function execute(InputInterface $input, OutputInterface $output): int |
85 | 85 | { |
86 | - if ($this->container === null) { |
|
86 | + if ($this->container === null){ |
|
87 | 87 | throw new ScopeException('Container is not set'); |
88 | 88 | } |
89 | 89 | |
90 | 90 | $method = method_exists($this, 'perform') ? 'perform' : '__invoke'; |
91 | 91 | |
92 | - try { |
|
92 | + try{ |
|
93 | 93 | [$this->input, $this->output] = [$this->prepareInput($input), $this->prepareOutput($input, $output)]; |
94 | 94 | |
95 | 95 | $this->eventDispatcher?->dispatch(new CommandStarting($this, $this->input, $this->output)); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $this->eventDispatcher?->dispatch(new CommandFinished($this, $code, $this->input, $this->output)); |
123 | 123 | |
124 | 124 | return $code; |
125 | - } finally { |
|
125 | + }finally{ |
|
126 | 126 | [$this->input, $this->output] = [null, null]; |
127 | 127 | } |
128 | 128 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | /** |
131 | 131 | * @deprecated This method will be removed in v4.0. |
132 | 132 | */ |
133 | - protected function buildCore(): CoreInterface|HandlerInterface |
|
133 | + protected function buildCore(): CoreInterface | HandlerInterface |
|
134 | 134 | { |
135 | 135 | /** @var InvokerInterface $invoker */ |
136 | 136 | $invoker = $this->container->get(InvokerInterface::class); |
@@ -83,13 +83,15 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function execute(InputInterface $input, OutputInterface $output): int |
85 | 85 | { |
86 | - if ($this->container === null) { |
|
86 | + if ($this->container === null) |
|
87 | + { |
|
87 | 88 | throw new ScopeException('Container is not set'); |
88 | 89 | } |
89 | 90 | |
90 | 91 | $method = method_exists($this, 'perform') ? 'perform' : '__invoke'; |
91 | 92 | |
92 | - try { |
|
93 | + try |
|
94 | + { |
|
93 | 95 | [$this->input, $this->output] = [$this->prepareInput($input), $this->prepareOutput($input, $output)]; |
94 | 96 | |
95 | 97 | $this->eventDispatcher?->dispatch(new CommandStarting($this, $this->input, $this->output)); |
@@ -122,7 +124,9 @@ discard block |
||
122 | 124 | $this->eventDispatcher?->dispatch(new CommandFinished($this, $code, $this->input, $this->output)); |
123 | 125 | |
124 | 126 | return $code; |
125 | - } finally { |
|
127 | + } |
|
128 | + finally |
|
129 | + { |
|
126 | 130 | [$this->input, $this->output] = [null, null]; |
127 | 131 | } |
128 | 132 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | private readonly FactoryInterface $factory, |
27 | 27 | ?EventDispatcherInterface $dispatcher = null, |
28 | 28 | ?PipelineBuilderInterface $builder = null, |
29 | - ) { |
|
29 | + ){ |
|
30 | 30 | $this->builder = $builder ?? new CompatiblePipelineBuilder($dispatcher); |
31 | 31 | } |
32 | 32 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | // Replaces alias with real pipeline name |
37 | 37 | $name = $this->config->getAliases()[$name] ?? $name; |
38 | 38 | |
39 | - if (!isset($this->pipelines[$name])) { |
|
39 | + if (!isset($this->pipelines[$name])){ |
|
40 | 40 | $this->pipelines[$name] = $this->resolveConnection($name); |
41 | 41 | } |
42 | 42 | |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | { |
52 | 52 | $config = $this->config->getConnection($name); |
53 | 53 | |
54 | - try { |
|
54 | + try{ |
|
55 | 55 | $driver = $this->factory->make($config['driver'], $config); |
56 | 56 | |
57 | 57 | $list = []; |
58 | - foreach ($this->config->getPushInterceptors() as $interceptor) { |
|
58 | + foreach ($this->config->getPushInterceptors() as $interceptor){ |
|
59 | 59 | $list[] = \is_string($interceptor) || $interceptor instanceof Autowire |
60 | 60 | ? $this->container->get($interceptor) |
61 | 61 | : $interceptor; |
62 | 62 | } |
63 | 63 | |
64 | 64 | return new Queue($this->builder->withInterceptors(...$list)->build(new PushCore($driver))); |
65 | - } catch (ContainerException $e) { |
|
65 | + }catch (ContainerException $e){ |
|
66 | 66 | throw new Exception\NotSupportedDriverException( |
67 | 67 | \sprintf( |
68 | 68 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | // Replaces alias with real pipeline name |
37 | 37 | $name = $this->config->getAliases()[$name] ?? $name; |
38 | 38 | |
39 | - if (!isset($this->pipelines[$name])) { |
|
39 | + if (!isset($this->pipelines[$name])) |
|
40 | + { |
|
40 | 41 | $this->pipelines[$name] = $this->resolveConnection($name); |
41 | 42 | } |
42 | 43 | |
@@ -51,18 +52,22 @@ discard block |
||
51 | 52 | { |
52 | 53 | $config = $this->config->getConnection($name); |
53 | 54 | |
54 | - try { |
|
55 | + try |
|
56 | + { |
|
55 | 57 | $driver = $this->factory->make($config['driver'], $config); |
56 | 58 | |
57 | 59 | $list = []; |
58 | - foreach ($this->config->getPushInterceptors() as $interceptor) { |
|
60 | + foreach ($this->config->getPushInterceptors() as $interceptor) |
|
61 | + { |
|
59 | 62 | $list[] = \is_string($interceptor) || $interceptor instanceof Autowire |
60 | 63 | ? $this->container->get($interceptor) |
61 | 64 | : $interceptor; |
62 | 65 | } |
63 | 66 | |
64 | 67 | return new Queue($this->builder->withInterceptors(...$list)->build(new PushCore($driver))); |
65 | - } catch (ContainerException $e) { |
|
68 | + } |
|
69 | + catch (ContainerException $e) |
|
70 | + { |
|
66 | 71 | throw new Exception\NotSupportedDriverException( |
67 | 72 | \sprintf( |
68 | 73 | 'Driver `%s` is not supported. Connection `%s` cannot be created. Reason: `%s`', |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function __construct( |
57 | 57 | private readonly ConfiguratorInterface $config, |
58 | - ) { |
|
58 | + ){ |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function init( |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | $registry = $container->get(QueueRegistry::class); |
74 | 74 | $config = $container->get(QueueConfig::class); |
75 | 75 | |
76 | - foreach ($config->getRegistryHandlers() as $jobType => $handler) { |
|
76 | + foreach ($config->getRegistryHandlers() as $jobType => $handler){ |
|
77 | 77 | $registry->setHandler($jobType, $handler); |
78 | 78 | } |
79 | 79 | |
80 | - foreach ($config->getRegistrySerializers() as $jobType => $serializer) { |
|
80 | + foreach ($config->getRegistrySerializers() as $jobType => $serializer){ |
|
81 | 81 | $registry->setSerializer($jobType, $serializer); |
82 | 82 | } |
83 | 83 | }); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * @param class-string<CoreInterceptorInterface>|CoreInterceptorInterface|Autowire $interceptor |
97 | 97 | */ |
98 | - public function addConsumeInterceptor(string|CoreInterceptorInterface|Autowire $interceptor): void |
|
98 | + public function addConsumeInterceptor(string | CoreInterceptorInterface | Autowire $interceptor): void |
|
99 | 99 | { |
100 | 100 | $this->config->modify( |
101 | 101 | QueueConfig::CONFIG, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | /** |
107 | 107 | * @param class-string<CoreInterceptorInterface>|CoreInterceptorInterface|Autowire $interceptor |
108 | 108 | */ |
109 | - public function addPushInterceptor(string|CoreInterceptorInterface|Autowire $interceptor): void |
|
109 | + public function addPushInterceptor(string | CoreInterceptorInterface | Autowire $interceptor): void |
|
110 | 110 | { |
111 | 111 | $this->config->modify( |
112 | 112 | QueueConfig::CONFIG, |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ContainerInterface $container, |
132 | 132 | FactoryInterface $factory, |
133 | 133 | ContainerRegistry $registry, |
134 | - ) { |
|
134 | + ){ |
|
135 | 135 | return new QueueRegistry($container, $factory, $registry); |
136 | 136 | } |
137 | 137 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | $builder ??= new CompatiblePipelineBuilder($dispatcher); |
148 | 148 | |
149 | 149 | $list = []; |
150 | - foreach ($config->getConsumeInterceptors() as $interceptor) { |
|
151 | - if (\is_string($interceptor)) { |
|
150 | + foreach ($config->getConsumeInterceptors() as $interceptor){ |
|
151 | + if (\is_string($interceptor)){ |
|
152 | 152 | $list[] = $container->get($interceptor); |
153 | - } elseif ($interceptor instanceof Autowire) { |
|
153 | + } elseif ($interceptor instanceof Autowire){ |
|
154 | 154 | $list[] = $interceptor->resolve($factory); |
155 | 155 | } |
156 | 156 | } |
@@ -73,11 +73,13 @@ discard block |
||
73 | 73 | $registry = $container->get(QueueRegistry::class); |
74 | 74 | $config = $container->get(QueueConfig::class); |
75 | 75 | |
76 | - foreach ($config->getRegistryHandlers() as $jobType => $handler) { |
|
76 | + foreach ($config->getRegistryHandlers() as $jobType => $handler) |
|
77 | + { |
|
77 | 78 | $registry->setHandler($jobType, $handler); |
78 | 79 | } |
79 | 80 | |
80 | - foreach ($config->getRegistrySerializers() as $jobType => $serializer) { |
|
81 | + foreach ($config->getRegistrySerializers() as $jobType => $serializer) |
|
82 | + { |
|
81 | 83 | $registry->setSerializer($jobType, $serializer); |
82 | 84 | } |
83 | 85 | }); |
@@ -147,10 +149,14 @@ discard block |
||
147 | 149 | $builder ??= new CompatiblePipelineBuilder($dispatcher); |
148 | 150 | |
149 | 151 | $list = []; |
150 | - foreach ($config->getConsumeInterceptors() as $interceptor) { |
|
151 | - if (\is_string($interceptor)) { |
|
152 | + foreach ($config->getConsumeInterceptors() as $interceptor) |
|
153 | + { |
|
154 | + if (\is_string($interceptor)) |
|
155 | + { |
|
152 | 156 | $list[] = $container->get($interceptor); |
153 | - } elseif ($interceptor instanceof Autowire) { |
|
157 | + } |
|
158 | + elseif ($interceptor instanceof Autowire) |
|
159 | + { |
|
154 | 160 | $list[] = $interceptor->resolve($factory); |
155 | 161 | } |
156 | 162 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | $builder = new CompatiblePipelineBuilder($dispatcher); |
33 | 33 | |
34 | 34 | $list = []; |
35 | - foreach (static::defineInterceptors() as $interceptor) { |
|
35 | + foreach (static::defineInterceptors() as $interceptor){ |
|
36 | 36 | $list[] = $interceptor instanceof CoreInterceptorInterface || $interceptor instanceof InterceptorInterface |
37 | 37 | ? $interceptor |
38 | 38 | : $container->get($interceptor); |
@@ -32,7 +32,8 @@ |
||
32 | 32 | $builder = new CompatiblePipelineBuilder($dispatcher); |
33 | 33 | |
34 | 34 | $list = []; |
35 | - foreach (static::defineInterceptors() as $interceptor) { |
|
35 | + foreach (static::defineInterceptors() as $interceptor) |
|
36 | + { |
|
36 | 37 | $list[] = $interceptor instanceof CoreInterceptorInterface || $interceptor instanceof InterceptorInterface |
37 | 38 | ? $interceptor |
38 | 39 | : $container->get($interceptor); |