@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | self::runInFiber( |
32 | 32 | self::functionScopedTestDataIterator(), |
33 | - static function (mixed $suspendValue) { |
|
33 | + static function (mixed $suspendValue){ |
|
34 | 34 | self::assertNull(ContainerScope::getContainer()); |
35 | 35 | self::assertTrue(\in_array($suspendValue, self::TEST_DATA, true)); |
36 | 36 | }, |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ); |
64 | 64 | |
65 | 65 | self::assertCount(5, $result); |
66 | - foreach ($result as $suspendValue) { |
|
66 | + foreach ($result as $suspendValue){ |
|
67 | 67 | self::assertSame(self::TEST_DATA, $suspendValue); |
68 | 68 | } |
69 | 69 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | ); |
82 | 82 | |
83 | 83 | self::assertCount(2, $result); |
84 | - foreach ($result as $suspendValue) { |
|
84 | + foreach ($result as $suspendValue){ |
|
85 | 85 | self::assertSame(self::TEST_DATA, $suspendValue); |
86 | 86 | } |
87 | 87 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $this->expectExceptionMessage('test'); |
93 | 93 | |
94 | 94 | self::runInFiber( |
95 | - static function () { |
|
95 | + static function (){ |
|
96 | 96 | return (new Container())->runScoped( |
97 | 97 | function (): string { |
98 | 98 | $result = ''; |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | public function testCatchThrownException(): void |
115 | 115 | { |
116 | 116 | $result = self::runInFiber( |
117 | - static function () { |
|
117 | + static function (){ |
|
118 | 118 | return (new Container())->runScoped( |
119 | 119 | function (): string { |
120 | 120 | $result = ''; |
121 | 121 | $result .= Fiber::suspend('foo'); |
122 | 122 | $result .= Fiber::suspend('bar'); |
123 | - try { |
|
123 | + try{ |
|
124 | 124 | $result .= Fiber::suspend('error'); |
125 | - } catch (\Throwable $e) { |
|
125 | + }catch (\Throwable $e){ |
|
126 | 126 | $result .= $e->getMessage(); |
127 | 127 | } |
128 | 128 | $result .= Fiber::suspend('baz'); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ?callable $load = null, |
153 | 153 | ?Container $container = null, |
154 | 154 | ): callable { |
155 | - return static function () use ($load, $container): array { |
|
155 | + return static function () use ($load, $container) : array { |
|
156 | 156 | // The function should be called in a fiber |
157 | 157 | self::assertNotNull(Fiber::getCurrent()); |
158 | 158 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $resource = $c3->get('resource'); |
174 | 174 | self::assertInstanceOf(DateTimeImmutable::class, $c3->get('bar')); |
175 | 175 | self::assertInstanceOf(stdClass::class, $resource); |
176 | - foreach (self::TEST_DATA as $key => $value) { |
|
176 | + foreach (self::TEST_DATA as $key => $value){ |
|
177 | 177 | $resource->$key = $value; |
178 | 178 | $load === null or $load(); |
179 | 179 | Fiber::suspend($value); |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | }, ['foo' => new DateTime()]); |
187 | 187 | self::assertFalse($c1->has('foo')); |
188 | 188 | |
189 | - self::assertSame(self::TEST_DATA, (array) $result); |
|
190 | - return (array) $result; |
|
189 | + self::assertSame(self::TEST_DATA, (array)$result); |
|
190 | + return (array)$result; |
|
191 | 191 | }; |
192 | 192 | } |
193 | 193 | |
@@ -204,11 +204,11 @@ discard block |
||
204 | 204 | { |
205 | 205 | $fiber = new Fiber($callable); |
206 | 206 | $value = $fiber->start(); |
207 | - while (!$fiber->isTerminated()) { |
|
208 | - if ($check !== null) { |
|
209 | - try { |
|
207 | + while (!$fiber->isTerminated()){ |
|
208 | + if ($check !== null){ |
|
209 | + try{ |
|
210 | 210 | $value = $check($value); |
211 | - } catch (\Throwable $e) { |
|
211 | + }catch (\Throwable $e){ |
|
212 | 212 | $value = $fiber->throw($e); |
213 | 213 | continue; |
214 | 214 | } |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | /** Values that were suspended by the fiber. */ |
233 | 233 | $suspends = []; |
234 | 234 | $results = []; |
235 | - foreach ($callables as $key => $callable) { |
|
235 | + foreach ($callables as $key => $callable){ |
|
236 | 236 | $fiberGenerators[$key] = (static function () use ($callable) { |
237 | 237 | $fiber = new Fiber($callable); |
238 | 238 | // Get ready |
239 | 239 | yield null; |
240 | 240 | |
241 | 241 | $value = yield $fiber->start(); |
242 | - while (!$fiber->isTerminated()) { |
|
242 | + while (!$fiber->isTerminated()){ |
|
243 | 243 | $value = yield $fiber->resume($value); |
244 | 244 | } |
245 | 245 | return $fiber->getReturn(); |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | |
252 | - while ($fiberGenerators !== []) { |
|
253 | - foreach ($fiberGenerators as $key => $generator) { |
|
254 | - try { |
|
252 | + while ($fiberGenerators !== []){ |
|
253 | + foreach ($fiberGenerators as $key => $generator){ |
|
254 | + try{ |
|
255 | 255 | $suspends[$key] = $generator->send($suspends[$key]); |
256 | - if (!$generator->valid()) { |
|
256 | + if (!$generator->valid()){ |
|
257 | 257 | $results[$key] = $generator->getReturn(); |
258 | 258 | unset($fiberGenerators[$key]); |
259 | 259 | } |
260 | - } catch (\Throwable $e) { |
|
260 | + }catch (\Throwable $e){ |
|
261 | 261 | unset($fiberGenerators[$key]); |
262 | 262 | $results[$key] = $e; |
263 | 263 | } |
@@ -30,7 +30,8 @@ discard block |
||
30 | 30 | |
31 | 31 | self::runInFiber( |
32 | 32 | self::functionScopedTestDataIterator(), |
33 | - static function (mixed $suspendValue) { |
|
33 | + static function (mixed $suspendValue) |
|
34 | + { |
|
34 | 35 | self::assertNull(ContainerScope::getContainer()); |
35 | 36 | self::assertTrue(\in_array($suspendValue, self::TEST_DATA, true)); |
36 | 37 | }, |
@@ -63,7 +64,8 @@ discard block |
||
63 | 64 | ); |
64 | 65 | |
65 | 66 | self::assertCount(5, $result); |
66 | - foreach ($result as $suspendValue) { |
|
67 | + foreach ($result as $suspendValue) |
|
68 | + { |
|
67 | 69 | self::assertSame(self::TEST_DATA, $suspendValue); |
68 | 70 | } |
69 | 71 | } |
@@ -81,7 +83,8 @@ discard block |
||
81 | 83 | ); |
82 | 84 | |
83 | 85 | self::assertCount(2, $result); |
84 | - foreach ($result as $suspendValue) { |
|
86 | + foreach ($result as $suspendValue) |
|
87 | + { |
|
85 | 88 | self::assertSame(self::TEST_DATA, $suspendValue); |
86 | 89 | } |
87 | 90 | } |
@@ -92,7 +95,8 @@ discard block |
||
92 | 95 | $this->expectExceptionMessage('test'); |
93 | 96 | |
94 | 97 | self::runInFiber( |
95 | - static function () { |
|
98 | + static function () |
|
99 | + { |
|
96 | 100 | return (new Container())->runScoped( |
97 | 101 | function (): string { |
98 | 102 | $result = ''; |
@@ -114,15 +118,19 @@ discard block |
||
114 | 118 | public function testCatchThrownException(): void |
115 | 119 | { |
116 | 120 | $result = self::runInFiber( |
117 | - static function () { |
|
121 | + static function () |
|
122 | + { |
|
118 | 123 | return (new Container())->runScoped( |
119 | 124 | function (): string { |
120 | 125 | $result = ''; |
121 | 126 | $result .= Fiber::suspend('foo'); |
122 | 127 | $result .= Fiber::suspend('bar'); |
123 | - try { |
|
128 | + try |
|
129 | + { |
|
124 | 130 | $result .= Fiber::suspend('error'); |
125 | - } catch (\Throwable $e) { |
|
131 | + } |
|
132 | + catch (\Throwable $e) |
|
133 | + { |
|
126 | 134 | $result .= $e->getMessage(); |
127 | 135 | } |
128 | 136 | $result .= Fiber::suspend('baz'); |
@@ -160,20 +168,23 @@ discard block |
||
160 | 168 | $c1 = $container ?? new Container(); |
161 | 169 | $c1->bindSingleton('resource', new stdClass()); |
162 | 170 | |
163 | - $result = $c1->runScoped(static function (Container $c2) use ($load) { |
|
171 | + $result = $c1->runScoped(static function (Container $c2) use ($load) |
|
172 | + { |
|
164 | 173 | // check local binding |
165 | 174 | self::assertTrue($c2->has('foo')); |
166 | 175 | self::assertInstanceOf(DateTime::class, $c2->get('foo')); |
167 | 176 | |
168 | 177 | return $c2->runScoped( |
169 | - static function (ContainerInterface $c3) use ($load) { |
|
178 | + static function (ContainerInterface $c3) use ($load) |
|
179 | + { |
|
170 | 180 | // check local binding |
171 | 181 | self::assertTrue($c3->has('bar')); |
172 | 182 | |
173 | 183 | $resource = $c3->get('resource'); |
174 | 184 | self::assertInstanceOf(DateTimeImmutable::class, $c3->get('bar')); |
175 | 185 | self::assertInstanceOf(stdClass::class, $resource); |
176 | - foreach (self::TEST_DATA as $key => $value) { |
|
186 | + foreach (self::TEST_DATA as $key => $value) |
|
187 | + { |
|
177 | 188 | $resource->$key = $value; |
178 | 189 | $load === null or $load(); |
179 | 190 | Fiber::suspend($value); |
@@ -204,11 +215,16 @@ discard block |
||
204 | 215 | { |
205 | 216 | $fiber = new Fiber($callable); |
206 | 217 | $value = $fiber->start(); |
207 | - while (!$fiber->isTerminated()) { |
|
208 | - if ($check !== null) { |
|
209 | - try { |
|
218 | + while (!$fiber->isTerminated()) |
|
219 | + { |
|
220 | + if ($check !== null) |
|
221 | + { |
|
222 | + try |
|
223 | + { |
|
210 | 224 | $value = $check($value); |
211 | - } catch (\Throwable $e) { |
|
225 | + } |
|
226 | + catch (\Throwable $e) |
|
227 | + { |
|
212 | 228 | $value = $fiber->throw($e); |
213 | 229 | continue; |
214 | 230 | } |
@@ -232,14 +248,17 @@ discard block |
||
232 | 248 | /** Values that were suspended by the fiber. */ |
233 | 249 | $suspends = []; |
234 | 250 | $results = []; |
235 | - foreach ($callables as $key => $callable) { |
|
236 | - $fiberGenerators[$key] = (static function () use ($callable) { |
|
251 | + foreach ($callables as $key => $callable) |
|
252 | + { |
|
253 | + $fiberGenerators[$key] = (static function () use ($callable) |
|
254 | + { |
|
237 | 255 | $fiber = new Fiber($callable); |
238 | 256 | // Get ready |
239 | 257 | yield null; |
240 | 258 | |
241 | 259 | $value = yield $fiber->start(); |
242 | - while (!$fiber->isTerminated()) { |
|
260 | + while (!$fiber->isTerminated()) |
|
261 | + { |
|
243 | 262 | $value = yield $fiber->resume($value); |
244 | 263 | } |
245 | 264 | return $fiber->getReturn(); |
@@ -249,15 +268,21 @@ discard block |
||
249 | 268 | } |
250 | 269 | |
251 | 270 | |
252 | - while ($fiberGenerators !== []) { |
|
253 | - foreach ($fiberGenerators as $key => $generator) { |
|
254 | - try { |
|
271 | + while ($fiberGenerators !== []) |
|
272 | + { |
|
273 | + foreach ($fiberGenerators as $key => $generator) |
|
274 | + { |
|
275 | + try |
|
276 | + { |
|
255 | 277 | $suspends[$key] = $generator->send($suspends[$key]); |
256 | - if (!$generator->valid()) { |
|
278 | + if (!$generator->valid()) |
|
279 | + { |
|
257 | 280 | $results[$key] = $generator->getReturn(); |
258 | 281 | unset($fiberGenerators[$key]); |
259 | 282 | } |
260 | - } catch (\Throwable $e) { |
|
283 | + } |
|
284 | + catch (\Throwable $e) |
|
285 | + { |
|
261 | 286 | unset($fiberGenerators[$key]); |
262 | 287 | $results[$key] = $e; |
263 | 288 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | $root = new Container(); |
23 | 23 | $root->bind(LoggerInterface::class, KVLogger::class); |
24 | 24 | |
25 | - $root->runScoped(static function (Container $c1) { |
|
25 | + $root->runScoped(static function (Container $c1){ |
|
26 | 26 | $c1->bind(LoggerInterface::class, FileLogger::class); |
27 | 27 | |
28 | - $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger) { |
|
28 | + $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger){ |
|
29 | 29 | // from the $root container |
30 | 30 | self::assertInstanceOf(KVLogger::class, $carrier->logger); |
31 | 31 | // from the $c1 container |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $root = new Container(); |
40 | 40 | $root->bind(LoggerInterface::class, KVLogger::class); |
41 | 41 | |
42 | - $root->runScoped(static function (Container $c1) { |
|
42 | + $root->runScoped(static function (Container $c1){ |
|
43 | 43 | $c1->bind(LoggerInterface::class, FileLogger::class); |
44 | 44 | |
45 | 45 | self::assertInstanceOf( |
@@ -22,10 +22,12 @@ discard block |
||
22 | 22 | $root = new Container(); |
23 | 23 | $root->bind(LoggerInterface::class, KVLogger::class); |
24 | 24 | |
25 | - $root->runScoped(static function (Container $c1) { |
|
25 | + $root->runScoped(static function (Container $c1) |
|
26 | + { |
|
26 | 27 | $c1->bind(LoggerInterface::class, FileLogger::class); |
27 | 28 | |
28 | - $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger) { |
|
29 | + $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger) |
|
30 | + { |
|
29 | 31 | // from the $root container |
30 | 32 | self::assertInstanceOf(KVLogger::class, $carrier->logger); |
31 | 33 | // from the $c1 container |
@@ -39,7 +41,8 @@ discard block |
||
39 | 41 | $root = new Container(); |
40 | 42 | $root->bind(LoggerInterface::class, KVLogger::class); |
41 | 43 | |
42 | - $root->runScoped(static function (Container $c1) { |
|
44 | + $root->runScoped(static function (Container $c1) |
|
45 | + { |
|
43 | 46 | $c1->bind(LoggerInterface::class, FileLogger::class); |
44 | 47 | |
45 | 48 | self::assertInstanceOf( |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | { |
22 | 22 | $root = new Container(); |
23 | 23 | |
24 | - $obj = $root->runScoped(static function (Container $c1) { |
|
25 | - $obj = $c1->runScoped(static function (Container $c2) { |
|
24 | + $obj = $root->runScoped(static function (Container $c1){ |
|
25 | + $obj = $c1->runScoped(static function (Container $c2){ |
|
26 | 26 | $obj = $c2->get(AttrScopeFooFinalize::class); |
27 | 27 | |
28 | 28 | self::assertFalse($obj->finalized); |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | self::expectException(FinalizersException::class); |
125 | 125 | self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`'); |
126 | 126 | |
127 | - try { |
|
128 | - $root->runScoped(static function (Container $c1) { |
|
127 | + try{ |
|
128 | + $root->runScoped(static function (Container $c1){ |
|
129 | 129 | $obj = $c1->get(AttrScopeFooFinalize::class); |
130 | 130 | $obj->throwException = true; |
131 | 131 | }, name: 'foo'); |
132 | - } catch (FinalizersException $e) { |
|
132 | + }catch (FinalizersException $e){ |
|
133 | 133 | self::assertSame('foo', $e->getScope()); |
134 | 134 | self::assertCount(1, $e->getExceptions()); |
135 | 135 | // Contains the message from the inner exception. |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | self::expectException(FinalizersException::class); |
154 | 154 | self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`'); |
155 | 155 | |
156 | - try { |
|
157 | - $root->runScoped(static function (Container $c1) { |
|
156 | + try{ |
|
157 | + $root->runScoped(static function (Container $c1){ |
|
158 | 158 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
159 | 159 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
160 | 160 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
161 | 161 | }, name: 'foo'); |
162 | - } catch (FinalizersException $e) { |
|
162 | + }catch (FinalizersException $e){ |
|
163 | 163 | self::assertSame('foo', $e->getScope()); |
164 | 164 | self::assertCount(3, $e->getExceptions()); |
165 | 165 | // Contains the message from the inner exception. |
@@ -21,8 +21,10 @@ discard block |
||
21 | 21 | { |
22 | 22 | $root = new Container(); |
23 | 23 | |
24 | - $obj = $root->runScoped(static function (Container $c1) { |
|
25 | - $obj = $c1->runScoped(static function (Container $c2) { |
|
24 | + $obj = $root->runScoped(static function (Container $c1) |
|
25 | + { |
|
26 | + $obj = $c1->runScoped(static function (Container $c2) |
|
27 | + { |
|
26 | 28 | $obj = $c2->get(AttrScopeFooFinalize::class); |
27 | 29 | |
28 | 30 | self::assertFalse($obj->finalized); |
@@ -46,8 +48,10 @@ discard block |
||
46 | 48 | $root->bindSingleton(LoggerInterface::class, FileLogger::class); |
47 | 49 | |
48 | 50 | $obj2 = null; |
49 | - $obj = $root->runScoped(static function (Container $c1) use (&$obj2) { |
|
50 | - $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) { |
|
51 | + $obj = $root->runScoped(static function (Container $c1) use (&$obj2) |
|
52 | + { |
|
53 | + $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) |
|
54 | + { |
|
51 | 55 | $obj = $c2->get(AttrScopeFooFinalize::class); |
52 | 56 | $obj2 = $c2->get(AttrScopeFooFinalize::class); |
53 | 57 | |
@@ -77,8 +81,10 @@ discard block |
||
77 | 81 | $root->bindSingleton(LoggerInterface::class, FileLogger::class); |
78 | 82 | |
79 | 83 | $obj2 = null; |
80 | - $obj = $root->runScoped(static function (Container $c1) use (&$obj2) { |
|
81 | - $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) { |
|
84 | + $obj = $root->runScoped(static function (Container $c1) use (&$obj2) |
|
85 | + { |
|
86 | + $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) |
|
87 | + { |
|
82 | 88 | $obj = $c2->get(AttrFinalize::class); |
83 | 89 | $obj2 = $c2->get(AttrFinalize::class); |
84 | 90 | |
@@ -124,12 +130,16 @@ discard block |
||
124 | 130 | self::expectException(FinalizersException::class); |
125 | 131 | self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`'); |
126 | 132 | |
127 | - try { |
|
128 | - $root->runScoped(static function (Container $c1) { |
|
133 | + try |
|
134 | + { |
|
135 | + $root->runScoped(static function (Container $c1) |
|
136 | + { |
|
129 | 137 | $obj = $c1->get(AttrScopeFooFinalize::class); |
130 | 138 | $obj->throwException = true; |
131 | 139 | }, name: 'foo'); |
132 | - } catch (FinalizersException $e) { |
|
140 | + } |
|
141 | + catch (FinalizersException $e) |
|
142 | + { |
|
133 | 143 | self::assertSame('foo', $e->getScope()); |
134 | 144 | self::assertCount(1, $e->getExceptions()); |
135 | 145 | // Contains the message from the inner exception. |
@@ -153,13 +163,17 @@ discard block |
||
153 | 163 | self::expectException(FinalizersException::class); |
154 | 164 | self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`'); |
155 | 165 | |
156 | - try { |
|
157 | - $root->runScoped(static function (Container $c1) { |
|
166 | + try |
|
167 | + { |
|
168 | + $root->runScoped(static function (Container $c1) |
|
169 | + { |
|
158 | 170 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
159 | 171 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
160 | 172 | $c1->get(AttrScopeFooFinalize::class)->throwException = true; |
161 | 173 | }, name: 'foo'); |
162 | - } catch (FinalizersException $e) { |
|
174 | + } |
|
175 | + catch (FinalizersException $e) |
|
176 | + { |
|
163 | 177 | self::assertSame('foo', $e->getScope()); |
164 | 178 | self::assertCount(3, $e->getExceptions()); |
165 | 179 | // Contains the message from the inner exception. |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | |
21 | 21 | $container = new Container(); |
22 | 22 | |
23 | - $container->runScoped(static function (Container $c1) { |
|
24 | - try { |
|
23 | + $container->runScoped(static function (Container $c1){ |
|
24 | + try{ |
|
25 | 25 | $c1->get(ExceptionConstructor::class); |
26 | 26 | self::fail('Exception should be thrown'); |
27 | - } catch (\Throwable $e) { |
|
27 | + }catch (\Throwable $e){ |
|
28 | 28 | // self::assertInstanceOf(\InvalidArgumentException::class, $e); |
29 | 29 | throw $e; |
30 | 30 | } |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | |
39 | 39 | $container = new Container(); |
40 | 40 | |
41 | - $container->runScoped(static function (Container $c1) { |
|
42 | - try { |
|
41 | + $container->runScoped(static function (Container $c1){ |
|
42 | + try{ |
|
43 | 43 | $c1->get(ExceptionConstructor::class); |
44 | 44 | self::fail('Exception should be thrown'); |
45 | - } catch (\Throwable $e) { |
|
45 | + }catch (\Throwable $e){ |
|
46 | 46 | // self::assertInstanceOf(\InvalidArgumentException::class, $e); |
47 | 47 | throw $e; |
48 | 48 | } |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | |
57 | 57 | $container = new Container(); |
58 | 58 | |
59 | - $container->runScoped(static function (Container $c1) { |
|
60 | - try { |
|
59 | + $container->runScoped(static function (Container $c1){ |
|
60 | + try{ |
|
61 | 61 | $c1->get(DatetimeCarrier::class); |
62 | 62 | self::fail('Exception should be thrown'); |
63 | - } catch (\Throwable $e) { |
|
63 | + }catch (\Throwable $e){ |
|
64 | 64 | self::assertInstanceOf(NotFoundException::class, $e); |
65 | 65 | self::assertInstanceOf(NotFoundException::class, $e->getPrevious()); |
66 | 66 | self::assertStringContainsString( |
@@ -20,11 +20,15 @@ discard block |
||
20 | 20 | |
21 | 21 | $container = new Container(); |
22 | 22 | |
23 | - $container->runScoped(static function (Container $c1) { |
|
24 | - try { |
|
23 | + $container->runScoped(static function (Container $c1) |
|
24 | + { |
|
25 | + try |
|
26 | + { |
|
25 | 27 | $c1->get(ExceptionConstructor::class); |
26 | 28 | self::fail('Exception should be thrown'); |
27 | - } catch (\Throwable $e) { |
|
29 | + } |
|
30 | + catch (\Throwable $e) |
|
31 | + { |
|
28 | 32 | // self::assertInstanceOf(\InvalidArgumentException::class, $e); |
29 | 33 | throw $e; |
30 | 34 | } |
@@ -38,11 +42,15 @@ discard block |
||
38 | 42 | |
39 | 43 | $container = new Container(); |
40 | 44 | |
41 | - $container->runScoped(static function (Container $c1) { |
|
42 | - try { |
|
45 | + $container->runScoped(static function (Container $c1) |
|
46 | + { |
|
47 | + try |
|
48 | + { |
|
43 | 49 | $c1->get(ExceptionConstructor::class); |
44 | 50 | self::fail('Exception should be thrown'); |
45 | - } catch (\Throwable $e) { |
|
51 | + } |
|
52 | + catch (\Throwable $e) |
|
53 | + { |
|
46 | 54 | // self::assertInstanceOf(\InvalidArgumentException::class, $e); |
47 | 55 | throw $e; |
48 | 56 | } |
@@ -56,11 +64,15 @@ discard block |
||
56 | 64 | |
57 | 65 | $container = new Container(); |
58 | 66 | |
59 | - $container->runScoped(static function (Container $c1) { |
|
60 | - try { |
|
67 | + $container->runScoped(static function (Container $c1) |
|
68 | + { |
|
69 | + try |
|
70 | + { |
|
61 | 71 | $c1->get(DatetimeCarrier::class); |
62 | 72 | self::fail('Exception should be thrown'); |
63 | - } catch (\Throwable $e) { |
|
73 | + } |
|
74 | + catch (\Throwable $e) |
|
75 | + { |
|
64 | 76 | self::assertInstanceOf(NotFoundException::class, $e); |
65 | 77 | self::assertInstanceOf(NotFoundException::class, $e->getPrevious()); |
66 | 78 | self::assertStringContainsString( |
@@ -23,7 +23,7 @@ |
||
23 | 23 | $root = new Container(); |
24 | 24 | $root->bind('foo', SampleClass::class); |
25 | 25 | |
26 | - $root->runScoped(function (ContainerInterface $c1) { |
|
26 | + $root->runScoped(function (ContainerInterface $c1){ |
|
27 | 27 | $c1->get('foo'); |
28 | 28 | }, bindings: ['foo' => SampleClass::class]); |
29 | 29 |
@@ -23,7 +23,8 @@ discard block |
||
23 | 23 | $root = new Container(); |
24 | 24 | $root->bind('foo', SampleClass::class); |
25 | 25 | |
26 | - $root->runScoped(function (ContainerInterface $c1) { |
|
26 | + $root->runScoped(function (ContainerInterface $c1) |
|
27 | + { |
|
27 | 28 | $c1->get('foo'); |
28 | 29 | }, bindings: ['foo' => SampleClass::class]); |
29 | 30 | |
@@ -54,7 +55,8 @@ discard block |
||
54 | 55 | { |
55 | 56 | $root = new Container(); |
56 | 57 | |
57 | - $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) { |
|
58 | + $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) |
|
59 | + { |
|
58 | 60 | $obj1 = $c1->get($alias); |
59 | 61 | $obj2 = $c1->get($alias); |
60 | 62 | |
@@ -79,14 +81,16 @@ discard block |
||
79 | 81 | { |
80 | 82 | $root = new Container(); |
81 | 83 | |
82 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
84 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
85 | + { |
|
83 | 86 | $obj1 = $c1->get('foo'); |
84 | 87 | $this->weakMap->offsetSet($obj1, true); |
85 | 88 | |
86 | 89 | self::assertNotSame($root, $c1); |
87 | 90 | self::assertInstanceOf(stdClass::class, $obj1); |
88 | 91 | |
89 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) { |
|
92 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) |
|
93 | + { |
|
90 | 94 | $obj2 = $c2->get('foo'); |
91 | 95 | $this->weakMap->offsetSet($obj2, true); |
92 | 96 | |
@@ -115,14 +119,16 @@ discard block |
||
115 | 119 | $root->bindSingleton('bar', [Factory::class, 'makeStdClass']); |
116 | 120 | $root->bind(stdClass::class, new stdClass()); |
117 | 121 | |
118 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
122 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
123 | + { |
|
119 | 124 | $obj1 = $c1->get('foo'); |
120 | 125 | $this->weakMap->offsetSet($obj1, true); |
121 | 126 | |
122 | 127 | self::assertInstanceOf(stdClass::class, $obj1); |
123 | 128 | // Singleton must be the same |
124 | 129 | self::assertSame($c1->get('bar'), $root->get('bar')); |
125 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) { |
|
130 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) |
|
131 | + { |
|
126 | 132 | $obj2 = $c2->get('foo'); |
127 | 133 | |
128 | 134 | self::assertInstanceOf(stdClass::class, $obj2); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | $root = new Container(); |
35 | 35 | |
36 | - $root->runScoped(static function (Container $c1) { |
|
36 | + $root->runScoped(static function (Container $c1){ |
|
37 | 37 | $c1->runScoped(static function (Container $c2) use ($c1) { |
38 | 38 | $obj1 = $c1->get(AttrScopeFooSingleton::class); |
39 | 39 | $obj2 = $c2->get(AttrScopeFooSingleton::class); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | $root = new Container(); |
57 | 57 | $root->bind('foo', self::makeFooScopeObject(...)); |
58 | 58 | |
59 | - $root->runScoped(static function (Container $c1) { |
|
60 | - $c1->runScoped(static function (Container $c2) { |
|
59 | + $root->runScoped(static function (Container $c1){ |
|
60 | + $c1->runScoped(static function (Container $c2){ |
|
61 | 61 | $c2->get('foo'); |
62 | 62 | }, name: 'foo'); |
63 | 63 | }); |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | $root = new Container(); |
76 | 76 | $root->bind('foo', self::makeFooScopeObject(...)); |
77 | 77 | |
78 | - $root->runScoped(static function (Container $c1) { |
|
79 | - $c1->runScoped(static function (Container $c2) { |
|
78 | + $root->runScoped(static function (Container $c1){ |
|
79 | + $c1->runScoped(static function (Container $c2){ |
|
80 | 80 | $c2->get('foo'); |
81 | 81 | }); |
82 | 82 | }); |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | |
95 | 95 | $root = new Container(); |
96 | 96 | |
97 | - try { |
|
98 | - $root->runScoped(static function (Container $c1) { |
|
99 | - $c1->runScoped(static function (Container $c2) { |
|
100 | - $c2->runScoped(static function (Container $c3) { |
|
97 | + try{ |
|
98 | + $root->runScoped(static function (Container $c1){ |
|
99 | + $c1->runScoped(static function (Container $c2){ |
|
100 | + $c2->runScoped(static function (Container $c3){ |
|
101 | 101 | // do nothing |
102 | 102 | }, name: 'root'); |
103 | 103 | }); |
104 | 104 | }); |
105 | - } catch (NamedScopeDuplicationException $e) { |
|
105 | + }catch (NamedScopeDuplicationException $e){ |
|
106 | 106 | self::assertSame('root', $e->getScope()); |
107 | 107 | throw $e; |
108 | 108 | } |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | { |
118 | 118 | self::expectException(BadScopeException::class); |
119 | 119 | |
120 | - try { |
|
120 | + try{ |
|
121 | 121 | $root = new Container(); |
122 | - $root->runScoped(static function (Container $c1) { |
|
123 | - $c1->runScoped(static function (Container $c2) { |
|
122 | + $root->runScoped(static function (Container $c1){ |
|
123 | + $c1->runScoped(static function (Container $c2){ |
|
124 | 124 | $c2->get(AttrScopeFoo::class); |
125 | 125 | }); |
126 | 126 | }, name: 'bar'); |
127 | - } catch (BadScopeException $e) { |
|
127 | + }catch (BadScopeException $e){ |
|
128 | 128 | self::assertSame('foo', $e->getScope()); |
129 | 129 | throw $e; |
130 | 130 | } |
@@ -33,8 +33,10 @@ discard block |
||
33 | 33 | { |
34 | 34 | $root = new Container(); |
35 | 35 | |
36 | - $root->runScoped(static function (Container $c1) { |
|
37 | - $c1->runScoped(static function (Container $c2) use ($c1) { |
|
36 | + $root->runScoped(static function (Container $c1) |
|
37 | + { |
|
38 | + $c1->runScoped(static function (Container $c2) use ($c1) |
|
39 | + { |
|
38 | 40 | $obj1 = $c1->get(AttrScopeFooSingleton::class); |
39 | 41 | $obj2 = $c2->get(AttrScopeFooSingleton::class); |
40 | 42 | |
@@ -56,8 +58,10 @@ discard block |
||
56 | 58 | $root = new Container(); |
57 | 59 | $root->bind('foo', self::makeFooScopeObject(...)); |
58 | 60 | |
59 | - $root->runScoped(static function (Container $c1) { |
|
60 | - $c1->runScoped(static function (Container $c2) { |
|
61 | + $root->runScoped(static function (Container $c1) |
|
62 | + { |
|
63 | + $c1->runScoped(static function (Container $c2) |
|
64 | + { |
|
61 | 65 | $c2->get('foo'); |
62 | 66 | }, name: 'foo'); |
63 | 67 | }); |
@@ -75,8 +79,10 @@ discard block |
||
75 | 79 | $root = new Container(); |
76 | 80 | $root->bind('foo', self::makeFooScopeObject(...)); |
77 | 81 | |
78 | - $root->runScoped(static function (Container $c1) { |
|
79 | - $c1->runScoped(static function (Container $c2) { |
|
82 | + $root->runScoped(static function (Container $c1) |
|
83 | + { |
|
84 | + $c1->runScoped(static function (Container $c2) |
|
85 | + { |
|
80 | 86 | $c2->get('foo'); |
81 | 87 | }); |
82 | 88 | }); |
@@ -94,15 +100,21 @@ discard block |
||
94 | 100 | |
95 | 101 | $root = new Container(); |
96 | 102 | |
97 | - try { |
|
98 | - $root->runScoped(static function (Container $c1) { |
|
99 | - $c1->runScoped(static function (Container $c2) { |
|
100 | - $c2->runScoped(static function (Container $c3) { |
|
103 | + try |
|
104 | + { |
|
105 | + $root->runScoped(static function (Container $c1) |
|
106 | + { |
|
107 | + $c1->runScoped(static function (Container $c2) |
|
108 | + { |
|
109 | + $c2->runScoped(static function (Container $c3) |
|
110 | + { |
|
101 | 111 | // do nothing |
102 | 112 | }, name: 'root'); |
103 | 113 | }); |
104 | 114 | }); |
105 | - } catch (NamedScopeDuplicationException $e) { |
|
115 | + } |
|
116 | + catch (NamedScopeDuplicationException $e) |
|
117 | + { |
|
106 | 118 | self::assertSame('root', $e->getScope()); |
107 | 119 | throw $e; |
108 | 120 | } |
@@ -117,14 +129,19 @@ discard block |
||
117 | 129 | { |
118 | 130 | self::expectException(BadScopeException::class); |
119 | 131 | |
120 | - try { |
|
132 | + try |
|
133 | + { |
|
121 | 134 | $root = new Container(); |
122 | - $root->runScoped(static function (Container $c1) { |
|
123 | - $c1->runScoped(static function (Container $c2) { |
|
135 | + $root->runScoped(static function (Container $c1) |
|
136 | + { |
|
137 | + $c1->runScoped(static function (Container $c2) |
|
138 | + { |
|
124 | 139 | $c2->get(AttrScopeFoo::class); |
125 | 140 | }); |
126 | 141 | }, name: 'bar'); |
127 | - } catch (BadScopeException $e) { |
|
142 | + } |
|
143 | + catch (BadScopeException $e) |
|
144 | + { |
|
128 | 145 | self::assertSame('foo', $e->getScope()); |
129 | 146 | throw $e; |
130 | 147 | } |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
48 | 48 | |
49 | 49 | private Internal\State $state; |
50 | - private ResolverInterface|Internal\Resolver $resolver; |
|
51 | - private FactoryInterface|Internal\Factory $factory; |
|
52 | - private ContainerInterface|Internal\Container $container; |
|
53 | - private BinderInterface|Internal\Binder $binder; |
|
54 | - private InvokerInterface|Internal\Invoker $invoker; |
|
50 | + private ResolverInterface | Internal\Resolver $resolver; |
|
51 | + private FactoryInterface | Internal\Factory $factory; |
|
52 | + private ContainerInterface | Internal\Container $container; |
|
53 | + private BinderInterface | Internal\Binder $binder; |
|
54 | + private InvokerInterface | Internal\Invoker $invoker; |
|
55 | 55 | private Internal\Scope $scope; |
56 | 56 | |
57 | 57 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | public function __construct( |
61 | 61 | private Config $config = new Config(), |
62 | 62 | ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
63 | - ) { |
|
63 | + ){ |
|
64 | 64 | $this->initServices($this, $scopeName); |
65 | 65 | |
66 | 66 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @psalm-suppress InvalidArgument, InvalidCast |
139 | 139 | */ |
140 | - public function get(string|Autowire $id, string $context = null): mixed |
|
140 | + public function get(string | Autowire $id, string $context = null): mixed |
|
141 | 141 | { |
142 | 142 | /** @psalm-suppress TooManyArguments */ |
143 | 143 | return $this->container->get($id, $context); |
@@ -164,26 +164,26 @@ discard block |
||
164 | 164 | { |
165 | 165 | $binds = &$this->state->bindings; |
166 | 166 | $cleanup = $previous = []; |
167 | - foreach ($bindings as $alias => $resolver) { |
|
168 | - if (isset($binds[$alias])) { |
|
167 | + foreach ($bindings as $alias => $resolver){ |
|
168 | + if (isset($binds[$alias])){ |
|
169 | 169 | $previous[$alias] = $binds[$alias]; |
170 | - } else { |
|
170 | + }else{ |
|
171 | 171 | $cleanup[] = $alias; |
172 | 172 | } |
173 | 173 | |
174 | 174 | $this->binder->bind($alias, $resolver); |
175 | 175 | } |
176 | 176 | |
177 | - try { |
|
177 | + try{ |
|
178 | 178 | return ContainerScope::getContainer() !== $this |
179 | 179 | ? ContainerScope::runScope($this, $scope) |
180 | 180 | : $scope($this); |
181 | - } finally { |
|
182 | - foreach ($previous as $alias => $resolver) { |
|
181 | + }finally{ |
|
182 | + foreach ($previous as $alias => $resolver){ |
|
183 | 183 | $binds[$alias] = $resolver; |
184 | 184 | } |
185 | 185 | |
186 | - foreach ($cleanup as $alias) { |
|
186 | + foreach ($cleanup as $alias){ |
|
187 | 187 | unset($binds[$alias]); |
188 | 188 | } |
189 | 189 | } |
@@ -197,32 +197,32 @@ discard block |
||
197 | 197 | // Open scope |
198 | 198 | $container = new self($this->config, $name); |
199 | 199 | |
200 | - try { |
|
200 | + try{ |
|
201 | 201 | // Configure scope |
202 | 202 | $container->scope->setParent($this, $this->scope); |
203 | 203 | |
204 | 204 | // Add specific bindings |
205 | - foreach ($bindings as $alias => $resolver) { |
|
205 | + foreach ($bindings as $alias => $resolver){ |
|
206 | 206 | $container->binder->bind($alias, $resolver); |
207 | 207 | } |
208 | 208 | |
209 | 209 | return ContainerScope::runScope( |
210 | 210 | $container, |
211 | 211 | static function (self $container) use ($autowire, $closure): mixed { |
212 | - try { |
|
212 | + try{ |
|
213 | 213 | return $autowire |
214 | 214 | ? $container->invoke($closure) |
215 | 215 | : $closure($container); |
216 | - } finally { |
|
216 | + }finally{ |
|
217 | 217 | $container->closeScope(); |
218 | 218 | } |
219 | 219 | } |
220 | 220 | ); |
221 | - } finally { |
|
221 | + }finally{ |
|
222 | 222 | // Check the container has not been leaked |
223 | 223 | $link = \WeakReference::create($container); |
224 | 224 | unset($container); |
225 | - if ($link->get() !== null) { |
|
225 | + if ($link->get() !== null){ |
|
226 | 226 | throw new ScopeContainerLeakedException($name, $this->scope->getParentScopeNames()); |
227 | 227 | } |
228 | 228 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * for each method call), function array or Closure (executed every call). Only object resolvers |
239 | 239 | * supported by this method. |
240 | 240 | */ |
241 | - public function bind(string $alias, string|array|callable|object $resolver): void |
|
241 | + public function bind(string $alias, string | array | callable | object $resolver): void |
|
242 | 242 | { |
243 | 243 | $this->binder->bind($alias, $resolver); |
244 | 244 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @psalm-param TResolver $resolver |
251 | 251 | */ |
252 | - public function bindSingleton(string $alias, string|array|callable|object $resolver): void |
|
252 | + public function bindSingleton(string $alias, string | array | callable | object $resolver): void |
|
253 | 253 | { |
254 | 254 | $this->binder->bindSingleton($alias, $resolver); |
255 | 255 | } |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | ]); |
320 | 320 | |
321 | 321 | // Create container services |
322 | - foreach ($container->config as $property => $class) { |
|
323 | - if (\property_exists($container, $property)) { |
|
322 | + foreach ($container->config as $property => $class){ |
|
323 | + if (\property_exists($container, $property)){ |
|
324 | 324 | $container->$property = $constructor->get($property, $class); |
325 | 325 | } |
326 | 326 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | private function closeScope(): void |
335 | 335 | { |
336 | 336 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
337 | - if (!isset($this->scope)) { |
|
337 | + if (!isset($this->scope)){ |
|
338 | 338 | $this->destruct(); |
339 | 339 | return; |
340 | 340 | } |
@@ -343,10 +343,10 @@ discard block |
||
343 | 343 | |
344 | 344 | // Run finalizers |
345 | 345 | $errors = []; |
346 | - foreach ($this->state->finalizers as $finalizer) { |
|
347 | - try { |
|
346 | + foreach ($this->state->finalizers as $finalizer){ |
|
347 | + try{ |
|
348 | 348 | $this->invoker->invoke($finalizer); |
349 | - } catch (\Throwable $e) { |
|
349 | + }catch (\Throwable $e){ |
|
350 | 350 | $errors[] = $e; |
351 | 351 | } |
352 | 352 | } |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | $this->destruct(); |
356 | 356 | |
357 | 357 | // Throw collected errors |
358 | - if ($errors !== []) { |
|
358 | + if ($errors !== []){ |
|
359 | 359 | throw new FinalizersException($scopeName, $errors); |
360 | 360 | } |
361 | 361 | } |