@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | public function testScope(): void |
54 | 54 | { |
55 | 55 | $core = $this->httpCore([CookiesMiddleware::class]); |
56 | - $core->setHandler(function ($r) { |
|
56 | + $core->setHandler(function ($r){ |
|
57 | 57 | $this->assertInstanceOf( |
58 | 58 | CookieQueue::class, |
59 | 59 | ContainerScope::getContainer()->get(ServerRequestInterface::class) |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public function testSetEncryptedCookie(): void |
78 | 78 | { |
79 | 79 | $core = $this->httpCore([CookiesMiddleware::class]); |
80 | - $core->setHandler(function ($r) { |
|
80 | + $core->setHandler(function ($r){ |
|
81 | 81 | ContainerScope::getContainer()->get(ServerRequestInterface::class) |
82 | 82 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
83 | 83 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | public function testSetNotProtectedCookie(): void |
100 | 100 | { |
101 | 101 | $core = $this->httpCore([CookiesMiddleware::class]); |
102 | - $core->setHandler(function ($r) { |
|
102 | + $core->setHandler(function ($r){ |
|
103 | 103 | ContainerScope::getContainer()->get(ServerRequestInterface::class) |
104 | 104 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('PHPSESSID', 'value'); |
105 | 105 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | public function testDecrypt(): void |
119 | 119 | { |
120 | 120 | $core = $this->httpCore([CookiesMiddleware::class]); |
121 | - $core->setHandler(function ($r) { |
|
121 | + $core->setHandler(function ($r){ |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @var ServerRequest $r |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | public function testDecryptArray(): void |
137 | 137 | { |
138 | 138 | $core = $this->httpCore([CookiesMiddleware::class]); |
139 | - $core->setHandler(function ($r) { |
|
139 | + $core->setHandler(function ($r){ |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @var ServerRequest $r |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | public function testDecryptBroken(): void |
155 | 155 | { |
156 | 156 | $core = $this->httpCore([CookiesMiddleware::class]); |
157 | - $core->setHandler(function ($r) { |
|
157 | + $core->setHandler(function ($r){ |
|
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @var ServerRequest $r |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | return $r->getCookieParams()['name']; |
163 | 163 | }); |
164 | 164 | |
165 | - $value = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value') . 'BROKEN'; |
|
165 | + $value = $this->container->get(EncrypterInterface::class)->encrypt('cookie-value').'BROKEN'; |
|
166 | 166 | |
167 | 167 | $response = $this->get($core, '/', [], [], ['name' => $value]); |
168 | 168 | $this->assertSame(200, $response->getStatusCode()); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public function testDelete(): void |
173 | 173 | { |
174 | 174 | $core = $this->httpCore([CookiesMiddleware::class]); |
175 | - $core->setHandler(function ($r) { |
|
175 | + $core->setHandler(function ($r){ |
|
176 | 176 | ContainerScope::getContainer()->get(ServerRequestInterface::class) |
177 | 177 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
178 | 178 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | ])); |
201 | 201 | |
202 | 202 | $core = $this->httpCore([CookiesMiddleware::class]); |
203 | - $core->setHandler(function ($r) { |
|
203 | + $core->setHandler(function ($r){ |
|
204 | 204 | ContainerScope::getContainer()->get(ServerRequestInterface::class) |
205 | 205 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
206 | 206 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | ])); |
226 | 226 | |
227 | 227 | $core = $this->httpCore([CookiesMiddleware::class]); |
228 | - $core->setHandler(function ($r) { |
|
228 | + $core->setHandler(function ($r){ |
|
229 | 229 | |
230 | 230 | /** |
231 | 231 | * @var ServerRequest $r |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | ])); |
250 | 250 | |
251 | 251 | $core = $this->httpCore([CookiesMiddleware::class]); |
252 | - $core->setHandler(function ($r) { |
|
252 | + $core->setHandler(function ($r){ |
|
253 | 253 | ContainerScope::getContainer()->get(ServerRequestInterface::class) |
254 | 254 | ->getAttribute(CookieQueue::ATTRIBUTE)->set('name', 'value'); |
255 | 255 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $cookies = $this->fetchCookies($response); |
264 | 264 | $this->assertArrayHasKey('name', $cookies); |
265 | 265 | |
266 | - $core->setHandler(function ($r) { |
|
266 | + $core->setHandler(function ($r){ |
|
267 | 267 | return $r->getCookieParams()['name']; |
268 | 268 | }); |
269 | 269 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | { |
319 | 319 | $result = []; |
320 | 320 | |
321 | - foreach ($response->getHeaders() as $line) { |
|
321 | + foreach ($response->getHeaders() as $line){ |
|
322 | 322 | $cookie = explode('=', implode('', $line)); |
323 | 323 | $result[$cookie[0]] = rawurldecode(substr( |
324 | 324 | (string)$cookie[1], |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | { |
46 | 46 | $core = $this->getCore(); |
47 | 47 | |
48 | - $core->setHandler(function () { |
|
48 | + $core->setHandler(function (){ |
|
49 | 49 | return 'hello world'; |
50 | 50 | }); |
51 | 51 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $core = $this->getCore(); |
69 | 69 | $core->setHandler( |
70 | - new CallableHandler(function () { |
|
70 | + new CallableHandler(function (){ |
|
71 | 71 | return 'hello world'; |
72 | 72 | }, new ResponseFactory(new HttpConfig(['headers' => []]))) |
73 | 73 | ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | { |
81 | 81 | $core = $this->getCore(); |
82 | 82 | |
83 | - $core->setHandler(function ($req, $resp) { |
|
83 | + $core->setHandler(function ($req, $resp){ |
|
84 | 84 | return $resp->withAddedHeader('hello', 'value'); |
85 | 85 | }); |
86 | 86 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | { |
94 | 94 | $core = $this->getCore(); |
95 | 95 | |
96 | - $core->setHandler(function ($req, $resp) { |
|
96 | + $core->setHandler(function ($req, $resp){ |
|
97 | 97 | echo 'hello!'; |
98 | 98 | |
99 | 99 | return $resp->withAddedHeader('hello', 'value'); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | { |
110 | 110 | $core = $this->getCore(); |
111 | 111 | |
112 | - $core->setHandler(function ($req, $resp) { |
|
112 | + $core->setHandler(function ($req, $resp){ |
|
113 | 113 | echo 'hello!'; |
114 | 114 | $resp->getBody()->write('world '); |
115 | 115 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | $core = $this->getCore(); |
128 | 128 | |
129 | - $core->setHandler(function () { |
|
129 | + $core->setHandler(function (){ |
|
130 | 130 | ob_start(); |
131 | 131 | ob_start(); |
132 | 132 | echo 'hello!'; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | $core = $this->getCore(); |
149 | 149 | |
150 | - $core->setHandler(function () { |
|
150 | + $core->setHandler(function (){ |
|
151 | 151 | return [ |
152 | 152 | 'status' => 404, |
153 | 153 | 'message' => 'not found', |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | { |
164 | 164 | $core = $this->getCore(); |
165 | 165 | |
166 | - $core->setHandler(function () { |
|
166 | + $core->setHandler(function (){ |
|
167 | 167 | return new Json([ |
168 | 168 | 'status' => 404, |
169 | 169 | 'message' => 'not found', |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | { |
180 | 180 | $core = $this->getCore([HeaderMiddleware::class]); |
181 | 181 | |
182 | - $core->setHandler(function () { |
|
182 | + $core->setHandler(function (){ |
|
183 | 183 | return 'hello?'; |
184 | 184 | }); |
185 | 185 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $core->getPipeline()->pushMiddleware(new Header2Middleware()); |
197 | 197 | $core->getPipeline()->riseMiddleware(new HeaderMiddleware()); |
198 | 198 | |
199 | - $core->setHandler(function () { |
|
199 | + $core->setHandler(function (){ |
|
200 | 200 | return 'hello?'; |
201 | 201 | }); |
202 | 202 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $core->getPipeline()->pushMiddleware(new HeaderMiddleware()); |
214 | 214 | $core->getPipeline()->riseMiddleware(new Header2Middleware()); |
215 | 215 | |
216 | - $core->setHandler(function () { |
|
216 | + $core->setHandler(function (){ |
|
217 | 217 | return 'hello?'; |
218 | 218 | }); |
219 | 219 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | $core = $this->getCore(); |
229 | 229 | |
230 | - $core->setHandler(function () { |
|
230 | + $core->setHandler(function (){ |
|
231 | 231 | $this->assertTrue(ContainerScope::getContainer()->has(ServerRequestInterface::class)); |
232 | 232 | |
233 | 233 | return 'OK'; |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | $dispatcher |
261 | 261 | ->expects(self::exactly(2)) |
262 | 262 | ->method('dispatch') |
263 | - ->with($this->callback(static fn(RequestReceived|RequestHandled $event): bool => true)); |
|
263 | + ->with($this->callback(static fn(RequestReceived | RequestHandled $event): bool => true)); |
|
264 | 264 | $this->container->bind(EventDispatcherInterface::class, $dispatcher); |
265 | 265 | |
266 | 266 | $core = $this->getCore(); |
267 | 267 | |
268 | - $core->setHandler(function () { |
|
268 | + $core->setHandler(function (){ |
|
269 | 269 | return 'hello world'; |
270 | 270 | }); |
271 | 271 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | $tracerFactory = m::mock(TracerFactoryInterface::class), |
287 | 287 | ); |
288 | 288 | |
289 | - $http->setHandler(function () { |
|
289 | + $http->setHandler(function (){ |
|
290 | 290 | return 'hello world'; |
291 | 291 | }); |
292 | 292 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | public function hasInstance(string $alias): bool |
30 | 30 | { |
31 | - if (!$this->container->has($alias)) { |
|
31 | + if (!$this->container->has($alias)){ |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | return parent::hasInstance($alias); |
@@ -12,6 +12,6 @@ |
||
12 | 12 | public ?string $parameter = null, |
13 | 13 | public ?bool $singleton = null, |
14 | 14 | public ?\ReflectionClass $reflection = null, |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | } |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | { |
19 | 19 | public function __construct( |
20 | 20 | protected readonly State $state, |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @param TResolver|object $resolver |
26 | 26 | */ |
27 | - public function bind(string $alias, string|array|callable|object $resolver): void |
|
27 | + public function bind(string $alias, string | array | callable | object $resolver): void |
|
28 | 28 | { |
29 | - if (\is_array($resolver) || $resolver instanceof \Closure || $resolver instanceof Autowire) { |
|
29 | + if (\is_array($resolver) || $resolver instanceof \Closure || $resolver instanceof Autowire){ |
|
30 | 30 | // array means = execute me, false = not singleton |
31 | 31 | $this->state->bindings[$alias] = [$resolver, false]; |
32 | 32 | |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @param TResolver|object $resolver |
41 | 41 | */ |
42 | - public function bindSingleton(string $alias, string|array|callable|object $resolver): void |
|
42 | + public function bindSingleton(string $alias, string | array | callable | object $resolver): void |
|
43 | 43 | { |
44 | - if (\is_object($resolver) && !$resolver instanceof \Closure && !$resolver instanceof Autowire) { |
|
44 | + if (\is_object($resolver) && !$resolver instanceof \Closure && !$resolver instanceof Autowire){ |
|
45 | 45 | // direct binding to an instance |
46 | 46 | $this->state->bindings[$alias] = $resolver; |
47 | 47 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $bindings = &$this->state->bindings; |
57 | 57 | |
58 | - while (\is_string($bindings[$alias] ?? null)) { |
|
58 | + while (\is_string($bindings[$alias] ?? null)){ |
|
59 | 59 | //Checking alias tree |
60 | 60 | $alias = $bindings[$alias]; |
61 | 61 | } |
@@ -80,31 +80,31 @@ discard block |
||
80 | 80 | |
81 | 81 | public function hasInjector(string $class): bool |
82 | 82 | { |
83 | - try { |
|
83 | + try{ |
|
84 | 84 | $reflection = new \ReflectionClass($class); |
85 | - } catch (\ReflectionException $e) { |
|
85 | + }catch (\ReflectionException $e){ |
|
86 | 86 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
87 | 87 | } |
88 | 88 | |
89 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
89 | + if (\array_key_exists($class, $this->state->injectors)){ |
|
90 | 90 | return $this->state->injectors[$class] !== null; |
91 | 91 | } |
92 | 92 | |
93 | 93 | if ( |
94 | 94 | $reflection->implementsInterface(InjectableInterface::class) |
95 | 95 | && $reflection->hasConstant('INJECTOR') |
96 | - ) { |
|
96 | + ){ |
|
97 | 97 | $this->state->injectors[$class] = $reflection->getConstant('INJECTOR'); |
98 | 98 | |
99 | 99 | return true; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // check interfaces |
103 | - foreach ($this->state->injectors as $target => $injector) { |
|
103 | + foreach ($this->state->injectors as $target => $injector){ |
|
104 | 104 | if ( |
105 | 105 | \class_exists($target, true) |
106 | 106 | && $reflection->isSubclassOf($target) |
107 | - ) { |
|
107 | + ){ |
|
108 | 108 | $this->state->injectors[$class] = $injector; |
109 | 109 | |
110 | 110 | return true; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | if ( |
114 | 114 | \interface_exists($target, true) |
115 | 115 | && $reflection->implementsInterface($target) |
116 | - ) { |
|
116 | + ){ |
|
117 | 117 | $this->state->injectors[$class] = $injector; |
118 | 118 | |
119 | 119 | return true; |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
66 | 66 | { |
67 | - if (!isset($this->state->bindings[$alias])) { |
|
67 | + if (!isset($this->state->bindings[$alias])){ |
|
68 | 68 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
69 | 69 | } |
70 | 70 | |
71 | 71 | $avoidCache = $parameters !== []; |
72 | 72 | $binding = $this->state->bindings[$alias]; |
73 | - try { |
|
73 | + try{ |
|
74 | 74 | $this->tracer->push( |
75 | 75 | false, |
76 | 76 | action: 'resolve from binding', |
@@ -81,22 +81,22 @@ discard block |
||
81 | 81 | ); |
82 | 82 | $this->tracer->push(true); |
83 | 83 | |
84 | - if (\is_object($binding)) { |
|
85 | - if ($binding::class === WeakReference::class) { |
|
84 | + if (\is_object($binding)){ |
|
85 | + if ($binding::class === WeakReference::class){ |
|
86 | 86 | return $this->resolveWeakReference($binding, $alias, $context, $parameters); |
87 | 87 | } |
88 | 88 | |
89 | 89 | // When binding is instance, assuming singleton |
90 | 90 | return $avoidCache |
91 | 91 | ? $this->createInstance( |
92 | - new Ctx(alias: $alias, class: $binding::class, parameter: $context), |
|
92 | + new Ctx(alias : $alias, class : $binding::class, parameter : $context), |
|
93 | 93 | $parameters, |
94 | 94 | ) |
95 | 95 | : $binding; |
96 | 96 | } |
97 | 97 | |
98 | 98 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
99 | - if (\is_string($binding)) { |
|
99 | + if (\is_string($binding)){ |
|
100 | 100 | $ctx->class = $binding; |
101 | 101 | return $binding === $alias |
102 | 102 | ? $this->autowire($ctx, $parameters) |
@@ -104,19 +104,19 @@ discard block |
||
104 | 104 | : $this->make($binding, $parameters, $context); |
105 | 105 | } |
106 | 106 | |
107 | - if ($binding[1] === true) { |
|
107 | + if ($binding[1] === true){ |
|
108 | 108 | $ctx->singleton = true; |
109 | 109 | } |
110 | 110 | unset($this->state->bindings[$alias]); |
111 | - try { |
|
111 | + try{ |
|
112 | 112 | return $binding[0] === $alias |
113 | 113 | ? $this->autowire($ctx, $parameters) |
114 | 114 | : $this->evaluateBinding($ctx, $binding[0], $parameters); |
115 | - } finally { |
|
115 | + }finally{ |
|
116 | 116 | /** @psalm-var class-string $alias */ |
117 | 117 | $this->state->bindings[$alias] ??= $binding; |
118 | 118 | } |
119 | - } finally { |
|
119 | + }finally{ |
|
120 | 120 | $this->tracer->pop(true); |
121 | 121 | $this->tracer->pop(false); |
122 | 122 | } |
@@ -130,18 +130,18 @@ discard block |
||
130 | 130 | ): ?object { |
131 | 131 | $avoidCache = $parameters !== []; |
132 | 132 | |
133 | - if (($avoidCache || $binding->get() === null) && \class_exists($alias)) { |
|
134 | - try { |
|
133 | + if (($avoidCache || $binding->get() === null) && \class_exists($alias)){ |
|
134 | + try{ |
|
135 | 135 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
136 | 136 | $object = $this->createInstance( |
137 | 137 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
138 | 138 | $parameters, |
139 | 139 | ); |
140 | - if ($avoidCache) { |
|
140 | + if ($avoidCache){ |
|
141 | 141 | return $object; |
142 | 142 | } |
143 | 143 | $binding = $this->state->bindings[$alias] = WeakReference::create($object); |
144 | - } catch (\Throwable) { |
|
144 | + }catch (\Throwable){ |
|
145 | 145 | throw new ContainerException( |
146 | 146 | $this->tracer->combineTraceMessage( |
147 | 147 | \sprintf( |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | ) |
152 | 152 | ) |
153 | 153 | ); |
154 | - } finally { |
|
154 | + }finally{ |
|
155 | 155 | $this->tracer->pop(); |
156 | 156 | } |
157 | 157 | } |
@@ -163,18 +163,18 @@ discard block |
||
163 | 163 | { |
164 | 164 | $parent = $this->scope->getParent(); |
165 | 165 | |
166 | - if ($parent !== null) { |
|
167 | - try { |
|
166 | + if ($parent !== null){ |
|
167 | + try{ |
|
168 | 168 | $this->tracer->push(false, ...[ |
169 | 169 | 'current scope' => $this->scope->getScopeName(), |
170 | 170 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
171 | 171 | ]); |
172 | 172 | return $parent->make($alias, $parameters, $context); |
173 | - } catch (BadScopeException $e) { |
|
174 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
173 | + }catch (BadScopeException $e){ |
|
174 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
175 | 175 | throw $e; |
176 | 176 | } |
177 | - } catch (ContainerExceptionInterface $e) { |
|
177 | + }catch (ContainerExceptionInterface $e){ |
|
178 | 178 | $className = match (true) { |
179 | 179 | $e instanceof NotFoundException => NotFoundException::class, |
180 | 180 | default => ContainerException::class, |
@@ -183,19 +183,19 @@ discard block |
||
183 | 183 | 'Can\'t resolve `%s`.', |
184 | 184 | $alias, |
185 | 185 | )), previous: $e); |
186 | - } finally { |
|
186 | + }finally{ |
|
187 | 187 | $this->tracer->pop(false); |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | 191 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
192 | - try { |
|
192 | + try{ |
|
193 | 193 | //No direct instructions how to construct class, make is automatically |
194 | 194 | return $this->autowire( |
195 | 195 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
196 | 196 | $parameters, |
197 | 197 | ); |
198 | - } finally { |
|
198 | + }finally{ |
|
199 | 199 | $this->tracer->pop(false); |
200 | 200 | } |
201 | 201 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | && |
217 | 217 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
218 | 218 | )) |
219 | - ) { |
|
219 | + ){ |
|
220 | 220 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
221 | 221 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
222 | 222 | $this->tracer->getRootAlias(), |
@@ -244,16 +244,16 @@ discard block |
||
244 | 244 | mixed $target, |
245 | 245 | array $arguments, |
246 | 246 | ): mixed { |
247 | - if (\is_string($target)) { |
|
247 | + if (\is_string($target)){ |
|
248 | 248 | // Reference |
249 | 249 | $instance = $this->make($target, $arguments, $ctx->parameter); |
250 | - } else { |
|
251 | - if ($target instanceof Autowire) { |
|
250 | + }else{ |
|
251 | + if ($target instanceof Autowire){ |
|
252 | 252 | $instance = $target->resolve($this, $arguments); |
253 | - } else { |
|
254 | - try { |
|
253 | + }else{ |
|
254 | + try{ |
|
255 | 255 | $instance = $this->invoker->invoke($target, $arguments); |
256 | - } catch (NotCallableException $e) { |
|
256 | + }catch (NotCallableException $e){ |
|
257 | 257 | throw new ContainerException( |
258 | 258 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
259 | 259 | $e->getCode(), |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | // Check scope name |
266 | - if (\is_object($instance)) { |
|
266 | + if (\is_object($instance)){ |
|
267 | 267 | $ctx->reflection = new \ReflectionClass($instance); |
268 | 268 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
269 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
269 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
270 | 270 | throw new BadScopeException($scopeName, $instance::class); |
271 | 271 | } |
272 | 272 | } |
@@ -295,26 +295,26 @@ discard block |
||
295 | 295 | array $parameters, |
296 | 296 | ): object { |
297 | 297 | $class = $ctx->class; |
298 | - try { |
|
298 | + try{ |
|
299 | 299 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
300 | - } catch (\ReflectionException $e) { |
|
300 | + }catch (\ReflectionException $e){ |
|
301 | 301 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
302 | 302 | } |
303 | 303 | |
304 | 304 | // Check scope name |
305 | 305 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
306 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
306 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
307 | 307 | throw new BadScopeException($scope, $class); |
308 | 308 | } |
309 | 309 | |
310 | 310 | //We have to construct class using external injector when we know exact context |
311 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
311 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
312 | 312 | $injector = $this->state->injectors[$reflection->getName()]; |
313 | 313 | |
314 | - try { |
|
314 | + try{ |
|
315 | 315 | $injectorInstance = $this->container->get($injector); |
316 | 316 | |
317 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
317 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
318 | 318 | throw new InjectionException( |
319 | 319 | \sprintf( |
320 | 320 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @psalm-suppress RedundantCondition |
330 | 330 | */ |
331 | 331 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
332 | - if (!$reflection->isInstance($instance)) { |
|
332 | + if (!$reflection->isInstance($instance)){ |
|
333 | 333 | throw new InjectionException( |
334 | 334 | \sprintf( |
335 | 335 | "Invalid injection response for '%s'.", |
@@ -339,12 +339,12 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | return $instance; |
342 | - } finally { |
|
342 | + }finally{ |
|
343 | 343 | $this->state->injectors[$reflection->getName()] = $injector; |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - if (!$reflection->isInstantiable()) { |
|
347 | + if (!$reflection->isInstantiable()){ |
|
348 | 348 | $itIs = match (true) { |
349 | 349 | $reflection->isEnum() => 'Enum', |
350 | 350 | $reflection->isAbstract() => 'Abstract class', |
@@ -357,12 +357,12 @@ discard block |
||
357 | 357 | |
358 | 358 | $constructor = $reflection->getConstructor(); |
359 | 359 | |
360 | - if ($constructor !== null) { |
|
361 | - try { |
|
360 | + if ($constructor !== null){ |
|
361 | + try{ |
|
362 | 362 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
363 | 363 | $this->tracer->push(true); |
364 | 364 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
365 | - } catch (ValidationException $e) { |
|
365 | + }catch (ValidationException $e){ |
|
366 | 366 | throw new ContainerException( |
367 | 367 | $this->tracer->combineTraceMessage( |
368 | 368 | \sprintf( |
@@ -372,22 +372,22 @@ discard block |
||
372 | 372 | ) |
373 | 373 | ), |
374 | 374 | ); |
375 | - } finally { |
|
375 | + }finally{ |
|
376 | 376 | $this->tracer->pop(true); |
377 | 377 | $this->tracer->pop(false); |
378 | 378 | } |
379 | - try { |
|
379 | + try{ |
|
380 | 380 | // Using constructor with resolved arguments |
381 | 381 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
382 | 382 | $this->tracer->push(true); |
383 | 383 | $instance = new $class(...$arguments); |
384 | - } catch (\TypeError $e) { |
|
384 | + }catch (\TypeError $e){ |
|
385 | 385 | throw new WrongTypeException($constructor, $e); |
386 | - } finally { |
|
386 | + }finally{ |
|
387 | 387 | $this->tracer->pop(true); |
388 | 388 | $this->tracer->pop(false); |
389 | 389 | } |
390 | - } else { |
|
390 | + }else{ |
|
391 | 391 | // No constructor specified |
392 | 392 | $instance = $reflection->newInstance(); |
393 | 393 | } |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | $ctx->reflection ??= new \ReflectionClass($instance); |
412 | 412 | |
413 | 413 | //Declarative singletons |
414 | - if ($this->isSingleton($ctx)) { |
|
414 | + if ($this->isSingleton($ctx)){ |
|
415 | 415 | $this->state->bindings[$ctx->alias] = $instance; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Register finalizer |
419 | 419 | $finalizer = $this->getFinalizer($ctx, $instance); |
420 | - if ($finalizer !== null) { |
|
420 | + if ($finalizer !== null){ |
|
421 | 421 | $this->state->finalizers[] = $finalizer; |
422 | 422 | } |
423 | 423 | |
@@ -429,11 +429,11 @@ discard block |
||
429 | 429 | */ |
430 | 430 | private function isSingleton(Ctx $ctx): bool |
431 | 431 | { |
432 | - if ($ctx->singleton === true) { |
|
432 | + if ($ctx->singleton === true){ |
|
433 | 433 | return true; |
434 | 434 | } |
435 | 435 | |
436 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
436 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
437 | 437 | return true; |
438 | 438 | } |
439 | 439 | |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | { |
445 | 445 | /** @var Finalize|null $attribute */ |
446 | 446 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
447 | - if ($attribute === null) { |
|
447 | + if ($attribute === null){ |
|
448 | 448 | return null; |
449 | 449 | } |
450 | 450 |
@@ -34,22 +34,22 @@ |
||
34 | 34 | { |
35 | 35 | [$previous, self::$container] = [self::$container, $container]; |
36 | 36 | |
37 | - try { |
|
38 | - if (Fiber::getCurrent() === null) { |
|
37 | + try{ |
|
38 | + if (Fiber::getCurrent() === null){ |
|
39 | 39 | return $scope(self::$container); |
40 | 40 | } |
41 | 41 | |
42 | 42 | // Wrap scope into fiber |
43 | 43 | $fiber = new Fiber(static fn () => $scope(self::$container)); |
44 | 44 | $value = $fiber->start(); |
45 | - while (!$fiber->isTerminated()) { |
|
45 | + while (!$fiber->isTerminated()){ |
|
46 | 46 | self::$container = $previous; |
47 | 47 | $resume = Fiber::suspend($value); |
48 | 48 | self::$container = $container; |
49 | 49 | $value = $fiber->resume($resume); |
50 | 50 | } |
51 | 51 | return $fiber->getReturn(); |
52 | - } finally { |
|
52 | + }finally{ |
|
53 | 53 | self::$container = $previous; |
54 | 54 | } |
55 | 55 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | { |
13 | 13 | public function __construct( |
14 | 14 | public string $method, |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | { |
13 | 13 | public function __construct( |
14 | 14 | public string $name, |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | } |