@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | { |
28 | 28 | $grid = $this->table(['Name:', 'Verbs:', 'Pattern:', 'Target:', 'Group:']); |
29 | 29 | |
30 | - foreach ($router->getRoutes() as $name => $route) { |
|
31 | - if ($route instanceof Route) { |
|
30 | + foreach ($router->getRoutes() as $name => $route){ |
|
31 | + if ($route instanceof Route){ |
|
32 | 32 | $grid->addRow( |
33 | 33 | [ |
34 | 34 | $name, |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | private function getRouteGroups(GroupRegistry $registry, string $routeName): array |
53 | 53 | { |
54 | 54 | $groups = []; |
55 | - foreach ($registry as $groupName => $group) { |
|
56 | - if ($group->hasRoute($routeName)) { |
|
55 | + foreach ($registry as $groupName => $group){ |
|
56 | + if ($group->hasRoute($routeName)){ |
|
57 | 57 | $groups[] = $groupName; |
58 | 58 | } |
59 | 59 | } |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | |
64 | 64 | private function getVerbs(Route $route): string |
65 | 65 | { |
66 | - if ($route->getVerbs() === Route::VERBS) { |
|
66 | + if ($route->getVerbs() === Route::VERBS){ |
|
67 | 67 | return '*'; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $result = []; |
71 | - foreach ($route->getVerbs() as $verb) { |
|
71 | + foreach ($route->getVerbs() as $verb){ |
|
72 | 72 | $result[] = match (\strtolower($verb)) { |
73 | 73 | 'get' => '<fg=green>GET</>', |
74 | 74 | 'post' => '<fg=blue>POST</>', |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $pattern = \preg_replace_callback( |
96 | 96 | '/<([^>]*)>/', |
97 | 97 | static fn ($m) => \sprintf('<fg=magenta>%s</>', $m[0]), |
98 | - !empty($prefix) ? $prefix . '/' . \trim($pattern, '/') : $pattern |
|
98 | + !empty($prefix) ? $prefix.'/'.\trim($pattern, '/') : $pattern |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | return $pattern; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | private function getTarget(Route $route, KernelInterface $kernel): string |
109 | 109 | { |
110 | 110 | $target = $this->getValue($route, 'target'); |
111 | - switch (true) { |
|
111 | + switch (true){ |
|
112 | 112 | case $target instanceof \Closure: |
113 | 113 | $reflection = new \ReflectionFunction($target); |
114 | 114 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | case $target instanceof Group: |
135 | 135 | $result = []; |
136 | - foreach ($this->getValue($target, 'controllers') as $alias => $class) { |
|
136 | + foreach ($this->getValue($target, 'controllers') as $alias => $class){ |
|
137 | 137 | $result[] = \sprintf('%s => %s', $alias, $this->relativeClass($class, $kernel)); |
138 | 138 | } |
139 | 139 | |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | |
153 | 153 | private function getValue(object $object, string $property): mixed |
154 | 154 | { |
155 | - try { |
|
155 | + try{ |
|
156 | 156 | $r = new \ReflectionObject($object); |
157 | 157 | $prop = $r->getProperty($property); |
158 | - } catch (\Throwable $e) { |
|
158 | + }catch (\Throwable $e){ |
|
159 | 159 | return $e->getMessage(); |
160 | 160 | } |
161 | 161 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | { |
167 | 167 | $r = new \ReflectionObject($kernel); |
168 | 168 | |
169 | - if (\str_starts_with($class, $r->getNamespaceName())) { |
|
169 | + if (\str_starts_with($class, $r->getNamespaceName())){ |
|
170 | 170 | return \substr($class, \strlen($r->getNamespaceName()) + 1); |
171 | 171 | } |
172 | 172 |
@@ -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,9 +73,9 @@ 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 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public function removeInjector(string $class): void |
101 | 101 | { |
102 | 102 | unset($this->state->injectors[$class]); |
103 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
103 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class){ |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | unset($this->state->bindings[$class]); |
@@ -108,20 +108,20 @@ discard block |
||
108 | 108 | |
109 | 109 | public function hasInjector(string $class): bool |
110 | 110 | { |
111 | - try { |
|
111 | + try{ |
|
112 | 112 | $reflection = new \ReflectionClass($class); |
113 | - } catch (\ReflectionException $e) { |
|
113 | + }catch (\ReflectionException $e){ |
|
114 | 114 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
115 | 115 | } |
116 | 116 | |
117 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
117 | + if (\array_key_exists($class, $this->state->injectors)){ |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
121 | 121 | if ( |
122 | 122 | $reflection->implementsInterface(InjectableInterface::class) |
123 | 123 | && $reflection->hasConstant('INJECTOR') |
124 | - ) { |
|
124 | + ){ |
|
125 | 125 | $const = $reflection->getConstant('INJECTOR'); |
126 | 126 | $this->bindInjector($class, $const); |
127 | 127 | |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | } |
130 | 130 | |
131 | 131 | // check interfaces |
132 | - foreach ($this->state->injectors as $target => $injector) { |
|
132 | + foreach ($this->state->injectors as $target => $injector){ |
|
133 | 133 | if ( |
134 | 134 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
135 | 135 | || |
136 | 136 | (\interface_exists($target, true) && $reflection->implementsInterface($target)) |
137 | - ) { |
|
137 | + ){ |
|
138 | 138 | $this->state->bindings[$class] = new Injectable($injector); |
139 | 139 | |
140 | 140 | return true; |
@@ -161,15 +161,15 @@ discard block |
||
161 | 161 | |
162 | 162 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
163 | 163 | { |
164 | - if (\is_callable($resolver)) { |
|
164 | + if (\is_callable($resolver)){ |
|
165 | 165 | return new Factory($resolver, $singleton); |
166 | 166 | } |
167 | 167 | |
168 | 168 | // Validate lazy invokable array |
169 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
169 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === ''){ |
|
170 | 170 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
171 | 171 | } |
172 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
172 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === ''){ |
|
173 | 173 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
174 | 174 | } |
175 | 175 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | private function setBinding(string $alias, Binding $config): void |
189 | 189 | { |
190 | - if (isset($this->state->singletons[$alias])) { |
|
190 | + if (isset($this->state->singletons[$alias])){ |
|
191 | 191 | throw new SingletonOverloadException($alias); |
192 | 192 | } |
193 | 193 |
@@ -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,9 +80,11 @@ 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 | |
@@ -100,7 +109,8 @@ discard block |
||
100 | 109 | public function removeInjector(string $class): void |
101 | 110 | { |
102 | 111 | unset($this->state->injectors[$class]); |
103 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
112 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) |
|
113 | + { |
|
104 | 114 | return; |
105 | 115 | } |
106 | 116 | unset($this->state->bindings[$class]); |
@@ -108,13 +118,17 @@ discard block |
||
108 | 118 | |
109 | 119 | public function hasInjector(string $class): bool |
110 | 120 | { |
111 | - try { |
|
121 | + try |
|
122 | + { |
|
112 | 123 | $reflection = new \ReflectionClass($class); |
113 | - } catch (\ReflectionException $e) { |
|
124 | + } |
|
125 | + catch (\ReflectionException $e) |
|
126 | + { |
|
114 | 127 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
115 | 128 | } |
116 | 129 | |
117 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
130 | + if (\array_key_exists($class, $this->state->injectors)) |
|
131 | + { |
|
118 | 132 | return true; |
119 | 133 | } |
120 | 134 | |
@@ -129,7 +143,8 @@ discard block |
||
129 | 143 | } |
130 | 144 | |
131 | 145 | // check interfaces |
132 | - foreach ($this->state->injectors as $target => $injector) { |
|
146 | + foreach ($this->state->injectors as $target => $injector) |
|
147 | + { |
|
133 | 148 | if ( |
134 | 149 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
135 | 150 | || |
@@ -161,15 +176,18 @@ discard block |
||
161 | 176 | |
162 | 177 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
163 | 178 | { |
164 | - if (\is_callable($resolver)) { |
|
179 | + if (\is_callable($resolver)) |
|
180 | + { |
|
165 | 181 | return new Factory($resolver, $singleton); |
166 | 182 | } |
167 | 183 | |
168 | 184 | // Validate lazy invokable array |
169 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
185 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') |
|
186 | + { |
|
170 | 187 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
171 | 188 | } |
172 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
189 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') |
|
190 | + { |
|
173 | 191 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
174 | 192 | } |
175 | 193 | |
@@ -187,7 +205,8 @@ discard block |
||
187 | 205 | |
188 | 206 | private function setBinding(string $alias, Binding $config): void |
189 | 207 | { |
190 | - if (isset($this->state->singletons[$alias])) { |
|
208 | + if (isset($this->state->singletons[$alias])) |
|
209 | + { |
|
191 | 210 | throw new SingletonOverloadException($alias); |
192 | 211 | } |
193 | 212 |