@@ -7,11 +7,11 @@ |
||
7 | 7 | final class Context implements ContextInterface |
8 | 8 | { |
9 | 9 | public function __construct( |
10 | - public \Stringable|string|null $value, |
|
11 | - ) { |
|
10 | + public \Stringable | string | null $value, |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | - public function getValue(): \Stringable|string|null |
|
14 | + public function getValue(): \Stringable | string | null |
|
15 | 15 | { |
16 | 16 | return $this->value; |
17 | 17 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | |
7 | 7 | interface ContextInterface |
8 | 8 | { |
9 | - public function getValue(): \Stringable|string|null; |
|
9 | + public function getValue(): \Stringable | string | null; |
|
10 | 10 | } |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | $root = new Container(); |
24 | 24 | $root->bind(LoggerInterface::class, KVLogger::class); |
25 | 25 | |
26 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
26 | + $root->runScope(new Scope(), static function (Container $c1){ |
|
27 | 27 | $c1->bind(LoggerInterface::class, FileLogger::class); |
28 | 28 | |
29 | - $c1->runScope(new Scope(), static function (LoggerCarrier $carrier, LoggerInterface $logger) { |
|
29 | + $c1->runScope(new Scope(), static function (LoggerCarrier $carrier, LoggerInterface $logger){ |
|
30 | 30 | // from the $root container |
31 | 31 | self::assertInstanceOf(KVLogger::class, $carrier->logger); |
32 | 32 | // from the $c1 container |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $root = new Container(); |
41 | 41 | $root->bind(LoggerInterface::class, KVLogger::class); |
42 | 42 | |
43 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
43 | + $root->runScope(new Scope(), static function (Container $c1){ |
|
44 | 44 | $c1->bind(LoggerInterface::class, FileLogger::class); |
45 | 45 | |
46 | 46 | self::assertInstanceOf( |
@@ -23,10 +23,12 @@ discard block |
||
23 | 23 | $root = new Container(); |
24 | 24 | $root->bind(LoggerInterface::class, KVLogger::class); |
25 | 25 | |
26 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
26 | + $root->runScope(new Scope(), static function (Container $c1) |
|
27 | + { |
|
27 | 28 | $c1->bind(LoggerInterface::class, FileLogger::class); |
28 | 29 | |
29 | - $c1->runScope(new Scope(), static function (LoggerCarrier $carrier, LoggerInterface $logger) { |
|
30 | + $c1->runScope(new Scope(), static function (LoggerCarrier $carrier, LoggerInterface $logger) |
|
31 | + { |
|
30 | 32 | // from the $root container |
31 | 33 | self::assertInstanceOf(KVLogger::class, $carrier->logger); |
32 | 34 | // from the $c1 container |
@@ -40,7 +42,8 @@ discard block |
||
40 | 42 | $root = new Container(); |
41 | 43 | $root->bind(LoggerInterface::class, KVLogger::class); |
42 | 44 | |
43 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
45 | + $root->runScope(new Scope(), static function (Container $c1) |
|
46 | + { |
|
44 | 47 | $c1->bind(LoggerInterface::class, FileLogger::class); |
45 | 48 | |
46 | 49 | self::assertInstanceOf( |
@@ -12,6 +12,6 @@ |
||
12 | 12 | trait ProxyTrait |
13 | 13 | { |
14 | 14 | private static string $__container_proxy_alias; |
15 | - private \Stringable|string|null $__container_proxy_context = null; |
|
15 | + private \Stringable | string | null $__container_proxy_context = null; |
|
16 | 16 | private ?ContainerInterface $__container_proxy_container = null; |
17 | 17 | } |
@@ -31,6 +31,6 @@ |
||
31 | 31 | public bool $proxyOverloads = false; |
32 | 32 | |
33 | 33 | public function __construct( |
34 | - ) { |
|
34 | + ){ |
|
35 | 35 | } |
36 | 36 | } |
@@ -32,7 +32,8 @@ discard block |
||
32 | 32 | $root->invoke(static function ( |
33 | 33 | #[Proxy] MockInterface $mock, |
34 | 34 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
35 | - ) use ($var) { |
|
35 | + ) use ($var) |
|
36 | + { |
|
36 | 37 | /** @var MockInterfaceImpl $proxy */ |
37 | 38 | $proxy = $$var; |
38 | 39 | $proxy->bar(name: 'foo'); // Possible to run |
@@ -49,7 +50,8 @@ discard block |
||
49 | 50 | |
50 | 51 | self::expectExceptionMessageMatches('/Call to undefined method/i'); |
51 | 52 | |
52 | - $root->invoke(static function (#[Proxy] EmptyInterface $proxy) { |
|
53 | + $root->invoke(static function (#[Proxy] EmptyInterface $proxy) |
|
54 | + { |
|
53 | 55 | $proxy->bar(name: 'foo'); // Possible to run |
54 | 56 | }); |
55 | 57 | } |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | $root->invoke(static function ( |
67 | 69 | #[Proxy] MockInterface $mock, |
68 | 70 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
69 | - ) use ($var) { |
|
71 | + ) use ($var) |
|
72 | + { |
|
70 | 73 | /** @var MockInterfaceImpl $proxy */ |
71 | 74 | $proxy = $$var; |
72 | 75 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extra('foo', 'bar', 'baz', 69)); |
@@ -88,7 +91,8 @@ discard block |
||
88 | 91 | $root->invoke(static function ( |
89 | 92 | #[Proxy] MockInterface $mock, |
90 | 93 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
91 | - ) use ($var) { |
|
94 | + ) use ($var) |
|
95 | + { |
|
92 | 96 | /** @var MockInterfaceImpl $proxy */ |
93 | 97 | $proxy = $$var; |
94 | 98 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
@@ -112,7 +116,8 @@ discard block |
||
112 | 116 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
113 | 117 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
114 | 118 | |
115 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
119 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
120 | + { |
|
116 | 121 | /** @var MockInterfaceImpl $proxy */ |
117 | 122 | $proxy = $$var; |
118 | 123 | $str = 'bar'; |
@@ -134,7 +139,8 @@ discard block |
||
134 | 139 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
135 | 140 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
136 | 141 | |
137 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
142 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
143 | + { |
|
138 | 144 | /** @var MockInterfaceImpl $proxy */ |
139 | 145 | $proxy = $$var; |
140 | 146 | |
@@ -159,7 +165,8 @@ discard block |
||
159 | 165 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
160 | 166 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
161 | 167 | |
162 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
168 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
169 | + { |
|
163 | 170 | /** @var MockInterfaceImpl $proxy */ |
164 | 171 | $proxy = $$var; |
165 | 172 | $str1 = 'bar'; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | self::expectExceptionMessageMatches('/Call to undefined method/i'); |
51 | 51 | |
52 | - $root->invoke(static function (#[Proxy] EmptyInterface $proxy) { |
|
52 | + $root->invoke(static function (#[Proxy] EmptyInterface $proxy){ |
|
53 | 53 | $proxy->bar(name: 'foo'); // Possible to run |
54 | 54 | }); |
55 | 55 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $proxy = $$var; |
94 | 94 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
95 | 95 | self::assertSame( |
96 | - ['foo' => 'foo','zap' => 'bar', 'gas' => 69], |
|
96 | + ['foo' => 'foo', 'zap' => 'bar', 'gas' => 69], |
|
97 | 97 | $proxy->extraVariadic(foo: 'foo', zap: 'bar', gas: 69), |
98 | 98 | ); |
99 | 99 | }); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
185 | 185 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
186 | 186 | |
187 | - $mock = $root->invoke(static fn(#[Proxy] MockInterface|EmptyInterface $mock) => $mock); |
|
187 | + $mock = $root->invoke(static fn(#[Proxy] MockInterface | EmptyInterface $mock) => $mock); |
|
188 | 188 | |
189 | 189 | self::assertInstanceOf(MockInterfaceImpl::class, $mock); |
190 | 190 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ): array { |
54 | 54 | $state = new ResolvingState($reflection, $parameters); |
55 | 55 | |
56 | - foreach ($reflection->getParameters() as $parameter) { |
|
56 | + foreach ($reflection->getParameters() as $parameter){ |
|
57 | 57 | $this->resolveParameter($parameter, $state, $validate) |
58 | 58 | or |
59 | 59 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -67,47 +67,47 @@ discard block |
||
67 | 67 | $positional = true; |
68 | 68 | $variadic = false; |
69 | 69 | $parameters = $reflection->getParameters(); |
70 | - if (\count($parameters) === 0) { |
|
70 | + if (\count($parameters) === 0){ |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $parameter = null; |
75 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
75 | + while (\count($parameters) > 0 || \count($arguments) > 0){ |
|
76 | 76 | // get related argument value |
77 | 77 | $key = \key($arguments); |
78 | 78 | |
79 | 79 | // For a variadic parameter it's no sense - named or positional argument will be sent |
80 | 80 | // But you can't send positional argument after named in any case |
81 | - if (\is_int($key) && !$positional) { |
|
81 | + if (\is_int($key) && !$positional){ |
|
82 | 82 | throw new PositionalArgumentException($reflection, $key); |
83 | 83 | } |
84 | 84 | |
85 | 85 | $positional = $positional && \is_int($key); |
86 | 86 | |
87 | - if (!$variadic) { |
|
87 | + if (!$variadic){ |
|
88 | 88 | $parameter = \array_shift($parameters); |
89 | 89 | $variadic = $parameter?->isVariadic() ?? false; |
90 | 90 | } |
91 | 91 | |
92 | - if ($parameter === null) { |
|
92 | + if ($parameter === null){ |
|
93 | 93 | throw new UnknownParameterException($reflection, $key); |
94 | 94 | } |
95 | 95 | $name = $parameter->getName(); |
96 | 96 | |
97 | - if (($positional || $variadic) && $key !== null) { |
|
97 | + if (($positional || $variadic) && $key !== null){ |
|
98 | 98 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
99 | 99 | $value = \array_shift($arguments); |
100 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
101 | - if ($parameter->isOptional()) { |
|
100 | + } elseif ($key === null || !\array_key_exists($name, $arguments)){ |
|
101 | + if ($parameter->isOptional()){ |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | throw new MissingRequiredArgumentException($reflection, $name); |
105 | - } else { |
|
105 | + }else{ |
|
106 | 106 | $value = &$arguments[$name]; |
107 | 107 | unset($arguments[$name]); |
108 | 108 | } |
109 | 109 | |
110 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
110 | + if (!$this->validateValueToParameter($parameter, $value)){ |
|
111 | 111 | throw new InvalidArgumentException($reflection, $name); |
112 | 112 | } |
113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
117 | 117 | { |
118 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
118 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)){ |
|
119 | 119 | return true; |
120 | 120 | } |
121 | 121 | $type = $parameter->getType(); |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
127 | 127 | }; |
128 | 128 | |
129 | - foreach ($types as $t) { |
|
129 | + foreach ($types as $t){ |
|
130 | 130 | \assert($t instanceof ReflectionNamedType); |
131 | - if (!$this->validateValueNamedType($t, $value)) { |
|
131 | + if (!$this->validateValueNamedType($t, $value)){ |
|
132 | 132 | // If it is TypeIntersection |
133 | - if ($or) { |
|
133 | + if ($or){ |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | // If it is not type intersection then we can skip that value after first successful check |
139 | - if ($or) { |
|
139 | + if ($or){ |
|
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | { |
152 | 152 | $name = $type->getName(); |
153 | 153 | |
154 | - if ($type->isBuiltin()) { |
|
154 | + if ($type->isBuiltin()){ |
|
155 | 155 | return match ($name) { |
156 | 156 | 'mixed' => true, |
157 | 157 | 'string' => \is_string($value), |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | |
185 | 185 | // Try to resolve parameter by name |
186 | 186 | $res = $state->resolveParameterByNameOrPosition($param, $isVariadic); |
187 | - if ($res !== [] || $isVariadic) { |
|
187 | + if ($res !== [] || $isVariadic){ |
|
188 | 188 | // validate |
189 | - if ($isVariadic) { |
|
190 | - foreach ($res as $k => &$v) { |
|
191 | - $this->processArgument($state, $v, validateWith: $validate ? $param : null, key: $k); |
|
189 | + if ($isVariadic){ |
|
190 | + foreach ($res as $k => &$v){ |
|
191 | + $this->processArgument($state, $v, validateWith: $validate ? $param : null, key : $k); |
|
192 | 192 | } |
193 | - } else { |
|
193 | + }else{ |
|
194 | 194 | $this->processArgument($state, $res[0], validateWith: $validate ? $param : null); |
195 | 195 | } |
196 | 196 | |
@@ -198,18 +198,18 @@ discard block |
||
198 | 198 | } |
199 | 199 | |
200 | 200 | $error = null; |
201 | - while ($hasType) { |
|
201 | + while ($hasType){ |
|
202 | 202 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $refType */ |
203 | 203 | $refType = $param->getType(); |
204 | 204 | |
205 | - if ($refType::class === ReflectionNamedType::class) { |
|
206 | - if ($refType->isBuiltin()) { |
|
205 | + if ($refType::class === ReflectionNamedType::class){ |
|
206 | + if ($refType->isBuiltin()){ |
|
207 | 207 | break; |
208 | 208 | } |
209 | 209 | |
210 | 210 | if (\interface_exists($refType->getName()) && !empty( |
211 | 211 | $attrs = $param->getAttributes(ProxyAttribute::class) |
212 | - )) { |
|
212 | + )){ |
|
213 | 213 | $proxy = Proxy::create( |
214 | 214 | new \ReflectionClass($refType->getName()), |
215 | 215 | $param, |
@@ -219,23 +219,23 @@ discard block |
||
219 | 219 | return true; |
220 | 220 | } |
221 | 221 | |
222 | - try { |
|
223 | - if ($this->resolveObject($state, $refType, $param, $validate)) { |
|
222 | + try{ |
|
223 | + if ($this->resolveObject($state, $refType, $param, $validate)){ |
|
224 | 224 | return true; |
225 | 225 | } |
226 | - } catch (Throwable $e) { |
|
226 | + }catch (Throwable $e){ |
|
227 | 227 | $error = $e; |
228 | 228 | } |
229 | 229 | break; |
230 | 230 | } |
231 | 231 | |
232 | - if ($refType::class === ReflectionUnionType::class) { |
|
233 | - foreach ($refType->getTypes() as $namedType) { |
|
234 | - try { |
|
235 | - if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) { |
|
232 | + if ($refType::class === ReflectionUnionType::class){ |
|
233 | + foreach ($refType->getTypes() as $namedType){ |
|
234 | + try{ |
|
235 | + if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)){ |
|
236 | 236 | return true; |
237 | 237 | } |
238 | - } catch (Throwable $e) { |
|
238 | + }catch (Throwable $e){ |
|
239 | 239 | $error = $e; |
240 | 240 | } |
241 | 241 | } |
@@ -245,19 +245,19 @@ discard block |
||
245 | 245 | throw new UnsupportedTypeException($param->getDeclaringFunction(), $param->getName()); |
246 | 246 | } |
247 | 247 | |
248 | - if ($param->isDefaultValueAvailable()) { |
|
248 | + if ($param->isDefaultValueAvailable()){ |
|
249 | 249 | $argument = $param->getDefaultValue(); |
250 | 250 | $this->processArgument($state, $argument); |
251 | 251 | return true; |
252 | 252 | } |
253 | 253 | |
254 | - if ($hasType && $param->allowsNull()) { |
|
254 | + if ($hasType && $param->allowsNull()){ |
|
255 | 255 | $argument = null; |
256 | 256 | $this->processArgument($state, $argument); |
257 | 257 | return true; |
258 | 258 | } |
259 | 259 | |
260 | - if ($error === null) { |
|
260 | + if ($error === null){ |
|
261 | 261 | return false; |
262 | 262 | } |
263 | 263 | |
@@ -295,15 +295,15 @@ discard block |
||
295 | 295 | ResolvingState $state, |
296 | 296 | mixed &$value, |
297 | 297 | ReflectionParameter $validateWith = null, |
298 | - int|string $key = null |
|
298 | + int | string $key = null |
|
299 | 299 | ): void { |
300 | 300 | // Resolve Autowire objects |
301 | - if ($value instanceof Autowire) { |
|
301 | + if ($value instanceof Autowire){ |
|
302 | 302 | $value = $value->resolve($this->factory); |
303 | 303 | } |
304 | 304 | |
305 | 305 | // Validation |
306 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
306 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){ |
|
307 | 307 | throw new InvalidArgumentException( |
308 | 308 | $validateWith->getDeclaringFunction(), |
309 | 309 | $validateWith->getName() |
@@ -53,7 +53,8 @@ discard block |
||
53 | 53 | ): array { |
54 | 54 | $state = new ResolvingState($reflection, $parameters); |
55 | 55 | |
56 | - foreach ($reflection->getParameters() as $parameter) { |
|
56 | + foreach ($reflection->getParameters() as $parameter) |
|
57 | + { |
|
57 | 58 | $this->resolveParameter($parameter, $state, $validate) |
58 | 59 | or |
59 | 60 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -67,47 +68,59 @@ discard block |
||
67 | 68 | $positional = true; |
68 | 69 | $variadic = false; |
69 | 70 | $parameters = $reflection->getParameters(); |
70 | - if (\count($parameters) === 0) { |
|
71 | + if (\count($parameters) === 0) |
|
72 | + { |
|
71 | 73 | return; |
72 | 74 | } |
73 | 75 | |
74 | 76 | $parameter = null; |
75 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
77 | + while (\count($parameters) > 0 || \count($arguments) > 0) |
|
78 | + { |
|
76 | 79 | // get related argument value |
77 | 80 | $key = \key($arguments); |
78 | 81 | |
79 | 82 | // For a variadic parameter it's no sense - named or positional argument will be sent |
80 | 83 | // But you can't send positional argument after named in any case |
81 | - if (\is_int($key) && !$positional) { |
|
84 | + if (\is_int($key) && !$positional) |
|
85 | + { |
|
82 | 86 | throw new PositionalArgumentException($reflection, $key); |
83 | 87 | } |
84 | 88 | |
85 | 89 | $positional = $positional && \is_int($key); |
86 | 90 | |
87 | - if (!$variadic) { |
|
91 | + if (!$variadic) |
|
92 | + { |
|
88 | 93 | $parameter = \array_shift($parameters); |
89 | 94 | $variadic = $parameter?->isVariadic() ?? false; |
90 | 95 | } |
91 | 96 | |
92 | - if ($parameter === null) { |
|
97 | + if ($parameter === null) |
|
98 | + { |
|
93 | 99 | throw new UnknownParameterException($reflection, $key); |
94 | 100 | } |
95 | 101 | $name = $parameter->getName(); |
96 | 102 | |
97 | - if (($positional || $variadic) && $key !== null) { |
|
103 | + if (($positional || $variadic) && $key !== null) |
|
104 | + { |
|
98 | 105 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
99 | 106 | $value = \array_shift($arguments); |
100 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
101 | - if ($parameter->isOptional()) { |
|
107 | + } |
|
108 | + elseif ($key === null || !\array_key_exists($name, $arguments)) |
|
109 | + { |
|
110 | + if ($parameter->isOptional()) |
|
111 | + { |
|
102 | 112 | continue; |
103 | 113 | } |
104 | 114 | throw new MissingRequiredArgumentException($reflection, $name); |
105 | - } else { |
|
115 | + } |
|
116 | + else |
|
117 | + { |
|
106 | 118 | $value = &$arguments[$name]; |
107 | 119 | unset($arguments[$name]); |
108 | 120 | } |
109 | 121 | |
110 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
122 | + if (!$this->validateValueToParameter($parameter, $value)) |
|
123 | + { |
|
111 | 124 | throw new InvalidArgumentException($reflection, $name); |
112 | 125 | } |
113 | 126 | } |
@@ -115,7 +128,8 @@ discard block |
||
115 | 128 | |
116 | 129 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
117 | 130 | { |
118 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
131 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) |
|
132 | + { |
|
119 | 133 | return true; |
120 | 134 | } |
121 | 135 | $type = $parameter->getType(); |
@@ -126,17 +140,21 @@ discard block |
||
126 | 140 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
127 | 141 | }; |
128 | 142 | |
129 | - foreach ($types as $t) { |
|
143 | + foreach ($types as $t) |
|
144 | + { |
|
130 | 145 | \assert($t instanceof ReflectionNamedType); |
131 | - if (!$this->validateValueNamedType($t, $value)) { |
|
146 | + if (!$this->validateValueNamedType($t, $value)) |
|
147 | + { |
|
132 | 148 | // If it is TypeIntersection |
133 | - if ($or) { |
|
149 | + if ($or) |
|
150 | + { |
|
134 | 151 | continue; |
135 | 152 | } |
136 | 153 | return false; |
137 | 154 | } |
138 | 155 | // If it is not type intersection then we can skip that value after first successful check |
139 | - if ($or) { |
|
156 | + if ($or) |
|
157 | + { |
|
140 | 158 | return true; |
141 | 159 | } |
142 | 160 | } |
@@ -151,7 +169,8 @@ discard block |
||
151 | 169 | { |
152 | 170 | $name = $type->getName(); |
153 | 171 | |
154 | - if ($type->isBuiltin()) { |
|
172 | + if ($type->isBuiltin()) |
|
173 | + { |
|
155 | 174 | return match ($name) { |
156 | 175 | 'mixed' => true, |
157 | 176 | 'string' => \is_string($value), |
@@ -184,13 +203,18 @@ discard block |
||
184 | 203 | |
185 | 204 | // Try to resolve parameter by name |
186 | 205 | $res = $state->resolveParameterByNameOrPosition($param, $isVariadic); |
187 | - if ($res !== [] || $isVariadic) { |
|
206 | + if ($res !== [] || $isVariadic) |
|
207 | + { |
|
188 | 208 | // validate |
189 | - if ($isVariadic) { |
|
190 | - foreach ($res as $k => &$v) { |
|
209 | + if ($isVariadic) |
|
210 | + { |
|
211 | + foreach ($res as $k => &$v) |
|
212 | + { |
|
191 | 213 | $this->processArgument($state, $v, validateWith: $validate ? $param : null, key: $k); |
192 | 214 | } |
193 | - } else { |
|
215 | + } |
|
216 | + else |
|
217 | + { |
|
194 | 218 | $this->processArgument($state, $res[0], validateWith: $validate ? $param : null); |
195 | 219 | } |
196 | 220 | |
@@ -198,18 +222,22 @@ discard block |
||
198 | 222 | } |
199 | 223 | |
200 | 224 | $error = null; |
201 | - while ($hasType) { |
|
225 | + while ($hasType) |
|
226 | + { |
|
202 | 227 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $refType */ |
203 | 228 | $refType = $param->getType(); |
204 | 229 | |
205 | - if ($refType::class === ReflectionNamedType::class) { |
|
206 | - if ($refType->isBuiltin()) { |
|
230 | + if ($refType::class === ReflectionNamedType::class) |
|
231 | + { |
|
232 | + if ($refType->isBuiltin()) |
|
233 | + { |
|
207 | 234 | break; |
208 | 235 | } |
209 | 236 | |
210 | 237 | if (\interface_exists($refType->getName()) && !empty( |
211 | 238 | $attrs = $param->getAttributes(ProxyAttribute::class) |
212 | - )) { |
|
239 | + )) |
|
240 | + { |
|
213 | 241 | $proxy = Proxy::create( |
214 | 242 | new \ReflectionClass($refType->getName()), |
215 | 243 | $param, |
@@ -219,23 +247,33 @@ discard block |
||
219 | 247 | return true; |
220 | 248 | } |
221 | 249 | |
222 | - try { |
|
223 | - if ($this->resolveObject($state, $refType, $param, $validate)) { |
|
250 | + try |
|
251 | + { |
|
252 | + if ($this->resolveObject($state, $refType, $param, $validate)) |
|
253 | + { |
|
224 | 254 | return true; |
225 | 255 | } |
226 | - } catch (Throwable $e) { |
|
256 | + } |
|
257 | + catch (Throwable $e) |
|
258 | + { |
|
227 | 259 | $error = $e; |
228 | 260 | } |
229 | 261 | break; |
230 | 262 | } |
231 | 263 | |
232 | - if ($refType::class === ReflectionUnionType::class) { |
|
233 | - foreach ($refType->getTypes() as $namedType) { |
|
234 | - try { |
|
235 | - if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) { |
|
264 | + if ($refType::class === ReflectionUnionType::class) |
|
265 | + { |
|
266 | + foreach ($refType->getTypes() as $namedType) |
|
267 | + { |
|
268 | + try |
|
269 | + { |
|
270 | + if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) |
|
271 | + { |
|
236 | 272 | return true; |
237 | 273 | } |
238 | - } catch (Throwable $e) { |
|
274 | + } |
|
275 | + catch (Throwable $e) |
|
276 | + { |
|
239 | 277 | $error = $e; |
240 | 278 | } |
241 | 279 | } |
@@ -245,19 +283,22 @@ discard block |
||
245 | 283 | throw new UnsupportedTypeException($param->getDeclaringFunction(), $param->getName()); |
246 | 284 | } |
247 | 285 | |
248 | - if ($param->isDefaultValueAvailable()) { |
|
286 | + if ($param->isDefaultValueAvailable()) |
|
287 | + { |
|
249 | 288 | $argument = $param->getDefaultValue(); |
250 | 289 | $this->processArgument($state, $argument); |
251 | 290 | return true; |
252 | 291 | } |
253 | 292 | |
254 | - if ($hasType && $param->allowsNull()) { |
|
293 | + if ($hasType && $param->allowsNull()) |
|
294 | + { |
|
255 | 295 | $argument = null; |
256 | 296 | $this->processArgument($state, $argument); |
257 | 297 | return true; |
258 | 298 | } |
259 | 299 | |
260 | - if ($error === null) { |
|
300 | + if ($error === null) |
|
301 | + { |
|
261 | 302 | return false; |
262 | 303 | } |
263 | 304 | |
@@ -298,12 +339,14 @@ discard block |
||
298 | 339 | int|string $key = null |
299 | 340 | ): void { |
300 | 341 | // Resolve Autowire objects |
301 | - if ($value instanceof Autowire) { |
|
342 | + if ($value instanceof Autowire) |
|
343 | + { |
|
302 | 344 | $value = $value->resolve($this->factory); |
303 | 345 | } |
304 | 346 | |
305 | 347 | // Validation |
306 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
348 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) |
|
349 | + { |
|
307 | 350 | throw new InvalidArgumentException( |
308 | 351 | $validateWith->getDeclaringFunction(), |
309 | 352 | $validateWith->getName() |
@@ -15,17 +15,17 @@ |
||
15 | 15 | { |
16 | 16 | public static function resolve( |
17 | 17 | string $alias, |
18 | - \Stringable|string|null $context = null, |
|
18 | + \Stringable | string | null $context = null, |
|
19 | 19 | ?ContainerInterface $c = null |
20 | 20 | ): object { |
21 | 21 | $c ??= ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.'); |
22 | 22 | |
23 | - try { |
|
23 | + try{ |
|
24 | 24 | /** @psalm-suppress TooManyArguments */ |
25 | 25 | $result = $c->get($alias, $context) ?? throw new ContainerException( |
26 | 26 | 'Resolved `null` from the container.', |
27 | 27 | ); |
28 | - } catch (\Throwable $e) { |
|
28 | + }catch (\Throwable $e){ |
|
29 | 29 | throw new ContainerException( |
30 | 30 | \sprintf('Unable to resolve `%s` in a Proxy.', $alias), |
31 | 31 | previous: $e, |
@@ -20,12 +20,15 @@ |
||
20 | 20 | ): object { |
21 | 21 | $c ??= ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.'); |
22 | 22 | |
23 | - try { |
|
23 | + try |
|
24 | + { |
|
24 | 25 | /** @psalm-suppress TooManyArguments */ |
25 | 26 | $result = $c->get($alias, $context) ?? throw new ContainerException( |
26 | 27 | 'Resolved `null` from the container.', |
27 | 28 | ); |
28 | - } catch (\Throwable $e) { |
|
29 | + } |
|
30 | + catch (\Throwable $e) |
|
31 | + { |
|
29 | 32 | throw new ContainerException( |
30 | 33 | \sprintf('Unable to resolve `%s` in a Proxy.', $alias), |
31 | 34 | previous: $e, |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public static function create( |
24 | 24 | \ReflectionClass $type, |
25 | - \Stringable|string|null $context, |
|
25 | + \Stringable | string | null $context, |
|
26 | 26 | \Spiral\Core\Attribute\Proxy $attribute, |
27 | 27 | ): object { |
28 | 28 | $interface = $type->getName(); |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | $attribute->proxyOverloads ? '[magic-calls]' : '', |
38 | 38 | ); |
39 | 39 | |
40 | - if (!\array_key_exists($cacheKey, self::$classes)) { |
|
40 | + if (!\array_key_exists($cacheKey, self::$classes)){ |
|
41 | 41 | $n = 0; |
42 | - do { |
|
42 | + do{ |
|
43 | 43 | $className = \sprintf( |
44 | 44 | '%s\%s SCOPED PROXY%s', |
45 | 45 | $type->getNamespaceName(), |
46 | 46 | $type->getShortName(), |
47 | 47 | $n++ > 0 ? " {$n}" : '' |
48 | 48 | ); |
49 | - } while (\class_exists($className)); |
|
49 | + }while (\class_exists($className)); |
|
50 | 50 | |
51 | 51 | /** @var class-string<TClass> $className */ |
52 | - try { |
|
52 | + try{ |
|
53 | 53 | $classString = ProxyClassRenderer::renderClass( |
54 | 54 | $type, |
55 | 55 | $className, |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | eval($classString); |
61 | - } catch (\Throwable $e) { |
|
61 | + }catch (\Throwable $e){ |
|
62 | 62 | throw new \Error("Unable to create proxy for `{$interface}`: {$e->getMessage()}", 0, $e); |
63 | 63 | } |
64 | 64 | |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | |
68 | 68 | // Store in cache without context |
69 | 69 | self::$classes[$cacheKey] = $className; |
70 | - } else { |
|
70 | + }else{ |
|
71 | 71 | /** @var TClass $instance */ |
72 | 72 | $instance = new (self::$classes[$cacheKey])(); |
73 | 73 | } |
74 | 74 | |
75 | - if ($context !== null || $attachContainer) { |
|
75 | + if ($context !== null || $attachContainer){ |
|
76 | 76 | (static function () use ($instance, $context, $attachContainer): void { |
77 | 77 | // Set the Current Context |
78 | 78 | /** @see \Spiral\Core\Internal\Proxy\ProxyTrait::$__container_proxy_context */ |
@@ -37,9 +37,11 @@ discard block |
||
37 | 37 | $attribute->proxyOverloads ? '[magic-calls]' : '', |
38 | 38 | ); |
39 | 39 | |
40 | - if (!\array_key_exists($cacheKey, self::$classes)) { |
|
40 | + if (!\array_key_exists($cacheKey, self::$classes)) |
|
41 | + { |
|
41 | 42 | $n = 0; |
42 | - do { |
|
43 | + do |
|
44 | + { |
|
43 | 45 | $className = \sprintf( |
44 | 46 | '%s\%s SCOPED PROXY%s', |
45 | 47 | $type->getNamespaceName(), |
@@ -49,7 +51,8 @@ discard block |
||
49 | 51 | } while (\class_exists($className)); |
50 | 52 | |
51 | 53 | /** @var class-string<TClass> $className */ |
52 | - try { |
|
54 | + try |
|
55 | + { |
|
53 | 56 | $classString = ProxyClassRenderer::renderClass( |
54 | 57 | $type, |
55 | 58 | $className, |
@@ -58,7 +61,9 @@ discard block |
||
58 | 61 | ); |
59 | 62 | |
60 | 63 | eval($classString); |
61 | - } catch (\Throwable $e) { |
|
64 | + } |
|
65 | + catch (\Throwable $e) |
|
66 | + { |
|
62 | 67 | throw new \Error("Unable to create proxy for `{$interface}`: {$e->getMessage()}", 0, $e); |
63 | 68 | } |
64 | 69 | |
@@ -67,12 +72,15 @@ discard block |
||
67 | 72 | |
68 | 73 | // Store in cache without context |
69 | 74 | self::$classes[$cacheKey] = $className; |
70 | - } else { |
|
75 | + } |
|
76 | + else |
|
77 | + { |
|
71 | 78 | /** @var TClass $instance */ |
72 | 79 | $instance = new (self::$classes[$cacheKey])(); |
73 | 80 | } |
74 | 81 | |
75 | - if ($context !== null || $attachContainer) { |
|
82 | + if ($context !== null || $attachContainer) |
|
83 | + { |
|
76 | 84 | (static function () use ($instance, $context, $attachContainer): void { |
77 | 85 | // Set the Current Context |
78 | 86 | /** @see \Spiral\Core\Internal\Proxy\ProxyTrait::$__container_proxy_context */ |