@@ -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,15 +59,15 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function bindSingleton(string $alias, mixed $resolver): void |
61 | 61 | { |
62 | - if (isset($this->state->singletons[$alias])) { |
|
62 | + if (isset($this->state->singletons[$alias])){ |
|
63 | 63 | throw new SingletonOverloadException( |
64 | 64 | \sprintf('Can\'t overload the singleton `%s` because it\'s already used.', $alias) |
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - try { |
|
68 | + try{ |
|
69 | 69 | $config = $this->makeConfig($resolver, true); |
70 | - } catch (\Throwable $e) { |
|
70 | + }catch (\Throwable $e){ |
|
71 | 71 | throw $this->invalidBindingException($alias, $e); |
72 | 72 | } |
73 | 73 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | $bindings = &$this->state->bindings; |
80 | 80 | |
81 | 81 | $flags = []; |
82 | - while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) { |
|
82 | + while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class){ |
|
83 | 83 | //Checking alias tree |
84 | - if ($flags[$binding->alias] ?? false) { |
|
84 | + if ($flags[$binding->alias] ?? false){ |
|
85 | 85 | return $binding->alias === $alias ?: throw new Exception('Circular alias detected'); |
86 | 86 | } |
87 | 87 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function removeInjector(string $class): void |
107 | 107 | { |
108 | 108 | unset($this->state->injectors[$class]); |
109 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
109 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class){ |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | unset($this->state->bindings[$class]); |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | |
115 | 115 | public function hasInjector(string $class): bool |
116 | 116 | { |
117 | - try { |
|
117 | + try{ |
|
118 | 118 | $reflection = new \ReflectionClass($class); |
119 | - } catch (\ReflectionException $e) { |
|
119 | + }catch (\ReflectionException $e){ |
|
120 | 120 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
121 | 121 | } |
122 | 122 | |
123 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
123 | + if (\array_key_exists($class, $this->state->injectors)){ |
|
124 | 124 | return true; |
125 | 125 | } |
126 | 126 | |
127 | 127 | if ( |
128 | 128 | $reflection->implementsInterface(InjectableInterface::class) |
129 | 129 | && $reflection->hasConstant('INJECTOR') |
130 | - ) { |
|
130 | + ){ |
|
131 | 131 | $const = $reflection->getConstant('INJECTOR'); |
132 | 132 | $this->bindInjector($class, $const); |
133 | 133 | |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | } |
136 | 136 | |
137 | 137 | // check interfaces |
138 | - foreach ($this->state->injectors as $target => $injector) { |
|
138 | + foreach ($this->state->injectors as $target => $injector){ |
|
139 | 139 | if ( |
140 | 140 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
141 | 141 | || |
142 | 142 | (\interface_exists($target, true) && $reflection->implementsInterface($target)) |
143 | - ) { |
|
143 | + ){ |
|
144 | 144 | $this->state->bindings[$class] = new Injectable($injector); |
145 | 145 | |
146 | 146 | return true; |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | |
168 | 168 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
169 | 169 | { |
170 | - if (\is_callable($resolver)) { |
|
170 | + if (\is_callable($resolver)){ |
|
171 | 171 | return new Factory($resolver, $singleton); |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Validate lazy invokable array |
175 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
175 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === ''){ |
|
176 | 176 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
177 | 177 | } |
178 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
178 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === ''){ |
|
179 | 179 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
180 | 180 | } |
181 | 181 |
@@ -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,15 +63,19 @@ discard block |
||
59 | 63 | */ |
60 | 64 | public function bindSingleton(string $alias, mixed $resolver): void |
61 | 65 | { |
62 | - if (isset($this->state->singletons[$alias])) { |
|
66 | + if (isset($this->state->singletons[$alias])) |
|
67 | + { |
|
63 | 68 | throw new SingletonOverloadException( |
64 | 69 | \sprintf('Can\'t overload the singleton `%s` because it\'s already used.', $alias) |
65 | 70 | ); |
66 | 71 | } |
67 | 72 | |
68 | - try { |
|
73 | + try |
|
74 | + { |
|
69 | 75 | $config = $this->makeConfig($resolver, true); |
70 | - } catch (\Throwable $e) { |
|
76 | + } |
|
77 | + catch (\Throwable $e) |
|
78 | + { |
|
71 | 79 | throw $this->invalidBindingException($alias, $e); |
72 | 80 | } |
73 | 81 | |
@@ -79,9 +87,11 @@ discard block |
||
79 | 87 | $bindings = &$this->state->bindings; |
80 | 88 | |
81 | 89 | $flags = []; |
82 | - while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) { |
|
90 | + while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) |
|
91 | + { |
|
83 | 92 | //Checking alias tree |
84 | - if ($flags[$binding->alias] ?? false) { |
|
93 | + if ($flags[$binding->alias] ?? false) |
|
94 | + { |
|
85 | 95 | return $binding->alias === $alias ?: throw new Exception('Circular alias detected'); |
86 | 96 | } |
87 | 97 | |
@@ -106,7 +116,8 @@ discard block |
||
106 | 116 | public function removeInjector(string $class): void |
107 | 117 | { |
108 | 118 | unset($this->state->injectors[$class]); |
109 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
119 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) |
|
120 | + { |
|
110 | 121 | return; |
111 | 122 | } |
112 | 123 | unset($this->state->bindings[$class]); |
@@ -114,13 +125,17 @@ discard block |
||
114 | 125 | |
115 | 126 | public function hasInjector(string $class): bool |
116 | 127 | { |
117 | - try { |
|
128 | + try |
|
129 | + { |
|
118 | 130 | $reflection = new \ReflectionClass($class); |
119 | - } catch (\ReflectionException $e) { |
|
131 | + } |
|
132 | + catch (\ReflectionException $e) |
|
133 | + { |
|
120 | 134 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
121 | 135 | } |
122 | 136 | |
123 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
137 | + if (\array_key_exists($class, $this->state->injectors)) |
|
138 | + { |
|
124 | 139 | return true; |
125 | 140 | } |
126 | 141 | |
@@ -135,7 +150,8 @@ discard block |
||
135 | 150 | } |
136 | 151 | |
137 | 152 | // check interfaces |
138 | - foreach ($this->state->injectors as $target => $injector) { |
|
153 | + foreach ($this->state->injectors as $target => $injector) |
|
154 | + { |
|
139 | 155 | if ( |
140 | 156 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
141 | 157 | || |
@@ -167,15 +183,18 @@ discard block |
||
167 | 183 | |
168 | 184 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
169 | 185 | { |
170 | - if (\is_callable($resolver)) { |
|
186 | + if (\is_callable($resolver)) |
|
187 | + { |
|
171 | 188 | return new Factory($resolver, $singleton); |
172 | 189 | } |
173 | 190 | |
174 | 191 | // Validate lazy invokable array |
175 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
192 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') |
|
193 | + { |
|
176 | 194 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
177 | 195 | } |
178 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
196 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') |
|
197 | + { |
|
179 | 198 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
180 | 199 | } |
181 | 200 |
@@ -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 |