@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | $root = new Container(); |
| 35 | 35 | $root->bind('foo', SampleClass::class); |
| 36 | 36 | |
| 37 | - $root->runScoped(function (ContainerInterface $c1) { |
|
| 37 | + $root->runScoped(function (ContainerInterface $c1) |
|
| 38 | + { |
|
| 38 | 39 | $c1->get('foo'); |
| 39 | 40 | }, bindings: ['foo' => SampleClass::class]); |
| 40 | 41 | |
@@ -67,7 +68,8 @@ discard block |
||
| 67 | 68 | { |
| 68 | 69 | $root = new Container(); |
| 69 | 70 | |
| 70 | - $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) { |
|
| 71 | + $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) |
|
| 72 | + { |
|
| 71 | 73 | $obj1 = $c1->get($alias); |
| 72 | 74 | $obj2 = $c1->get($alias); |
| 73 | 75 | |
@@ -92,14 +94,16 @@ discard block |
||
| 92 | 94 | { |
| 93 | 95 | $root = new Container(); |
| 94 | 96 | |
| 95 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
| 97 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
| 98 | + { |
|
| 96 | 99 | $obj1 = $c1->get('foo'); |
| 97 | 100 | $this->weakMap->offsetSet($obj1, true); |
| 98 | 101 | |
| 99 | 102 | self::assertNotSame($root, $c1); |
| 100 | 103 | self::assertInstanceOf(stdClass::class, $obj1); |
| 101 | 104 | |
| 102 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) { |
|
| 105 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) |
|
| 106 | + { |
|
| 103 | 107 | $obj2 = $c2->get('foo'); |
| 104 | 108 | $this->weakMap->offsetSet($obj2, true); |
| 105 | 109 | |
@@ -128,14 +132,16 @@ discard block |
||
| 128 | 132 | $root->bindSingleton('bar', (new Factory())->makeStdClass(...)); |
| 129 | 133 | $root->bind(stdClass::class, new stdClass()); |
| 130 | 134 | |
| 131 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
| 135 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
| 136 | + { |
|
| 132 | 137 | $obj1 = $c1->get('foo'); |
| 133 | 138 | $this->weakMap->offsetSet($obj1, true); |
| 134 | 139 | |
| 135 | 140 | self::assertInstanceOf(stdClass::class, $obj1); |
| 136 | 141 | // Singleton must be the same |
| 137 | 142 | self::assertSame($c1->get('bar'), $root->get('bar')); |
| 138 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) { |
|
| 143 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) |
|
| 144 | + { |
|
| 139 | 145 | $obj2 = $c2->get('foo'); |
| 140 | 146 | |
| 141 | 147 | self::assertInstanceOf(stdClass::class, $obj2); |
@@ -268,7 +274,8 @@ discard block |
||
| 268 | 274 | { |
| 269 | 275 | $root = new Container(); |
| 270 | 276 | |
| 271 | - $root->invoke(static function () use ($root) { |
|
| 277 | + $root->invoke(static function () use ($root) |
|
| 278 | + { |
|
| 272 | 279 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
| 273 | 280 | self::assertSame($root, \Spiral\Core\ContainerScope::getContainer()); |
| 274 | 281 | }); |
@@ -277,7 +284,8 @@ discard block |
||
| 277 | 284 | public function testRegisterContainerOnGet(): void |
| 278 | 285 | { |
| 279 | 286 | $root = new Container(); |
| 280 | - $root->bind('foo', function () use ($root) { |
|
| 287 | + $root->bind('foo', function () use ($root) |
|
| 288 | + { |
|
| 281 | 289 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
| 282 | 290 | self::assertSame($root, \Spiral\Core\ContainerScope::getContainer()); |
| 283 | 291 | }); |
@@ -288,7 +296,8 @@ discard block |
||
| 288 | 296 | public function testRegisterContainerOnMake(): void |
| 289 | 297 | { |
| 290 | 298 | $root = new Container(); |
| 291 | - $root->bind('foo', function () use ($root) { |
|
| 299 | + $root->bind('foo', function () use ($root) |
|
| 300 | + { |
|
| 292 | 301 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
| 293 | 302 | self::assertSame($root, \Spiral\Core\ContainerScope::getContainer()); |
| 294 | 303 | }); |
@@ -306,7 +315,8 @@ discard block |
||
| 306 | 315 | $root->bind('isFoo', new Scalar(false)); |
| 307 | 316 | $root->getBinder('foo')->bind('isFoo', new Scalar(true)); |
| 308 | 317 | |
| 309 | - $root->bind('foo', function (#[Proxy] ContainerInterface $c, ContainerInterface $r) use ($root) { |
|
| 318 | + $root->bind('foo', function (#[Proxy] ContainerInterface $c, ContainerInterface $r) use ($root) |
|
| 319 | + { |
|
| 310 | 320 | // Direct |
| 311 | 321 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
| 312 | 322 | self::assertNotSame($root, \Spiral\Core\ContainerScope::getContainer()); |
@@ -321,7 +331,8 @@ discard block |
||
| 321 | 331 | |
| 322 | 332 | $root->runScope( |
| 323 | 333 | new Scope('foo'), |
| 324 | - function (ContainerInterface $c) { |
|
| 334 | + function (ContainerInterface $c) |
|
| 335 | + { |
|
| 325 | 336 | self::assertTrue($c->get('isFoo')); |
| 326 | 337 | $c->get('foo'); |
| 327 | 338 | } |
@@ -334,7 +345,8 @@ discard block |
||
| 334 | 345 | $root = new Container(); |
| 335 | 346 | $root->getBinder($scope)->bindSingleton('foo', SampleClass::class); |
| 336 | 347 | |
| 337 | - $root->runScope(new Scope($scope), function (Container $container) { |
|
| 348 | + $root->runScope(new Scope($scope), function (Container $container) |
|
| 349 | + { |
|
| 338 | 350 | $this->assertTrue($container->has('foo')); |
| 339 | 351 | $this->assertInstanceOf(SampleClass::class, $container->get('foo')); |
| 340 | 352 | }); |
@@ -346,20 +358,25 @@ discard block |
||
| 346 | 358 | $root = new Container(); |
| 347 | 359 | $root->bindSingleton('sampleClass', SampleClass::class); |
| 348 | 360 | |
| 349 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 361 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 362 | + { |
|
| 350 | 363 | $this->assertTrue($container->has('sampleClass')); |
| 351 | 364 | }); |
| 352 | 365 | |
| 353 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 354 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 366 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 367 | + { |
|
| 368 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 369 | + { |
|
| 355 | 370 | $this->assertTrue($container->has('sampleClass')); |
| 356 | 371 | }); |
| 357 | 372 | }); |
| 358 | 373 | |
| 359 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 374 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 375 | + { |
|
| 360 | 376 | $container->bindSingleton('otherClass', SampleClass::class); |
| 361 | 377 | |
| 362 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 378 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 379 | + { |
|
| 363 | 380 | $this->assertTrue($container->has('sampleClass')); |
| 364 | 381 | $this->assertTrue($container->has('otherClass')); |
| 365 | 382 | }); |
@@ -371,33 +388,41 @@ discard block |
||
| 371 | 388 | $root = new Container(); |
| 372 | 389 | $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class); |
| 373 | 390 | |
| 374 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 391 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 392 | + { |
|
| 375 | 393 | $this->assertTrue($container->has('sampleClass')); |
| 376 | 394 | }); |
| 377 | 395 | |
| 378 | - $root->runScope(new Scope('bar'), function (Container $container) { |
|
| 396 | + $root->runScope(new Scope('bar'), function (Container $container) |
|
| 397 | + { |
|
| 379 | 398 | $this->assertFalse($container->has('sampleClass')); |
| 380 | 399 | }); |
| 381 | 400 | |
| 382 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 383 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 401 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 402 | + { |
|
| 403 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 404 | + { |
|
| 384 | 405 | $this->assertTrue($container->has('sampleClass')); |
| 385 | 406 | }); |
| 386 | 407 | }); |
| 387 | 408 | |
| 388 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 409 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 410 | + { |
|
| 389 | 411 | $container->bindSingleton('otherClass', AttrScopeFoo::class); |
| 390 | 412 | |
| 391 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 413 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 414 | + { |
|
| 392 | 415 | $this->assertTrue($container->has('sampleClass')); |
| 393 | 416 | $this->assertTrue($container->has('otherClass')); |
| 394 | 417 | }); |
| 395 | 418 | }); |
| 396 | 419 | |
| 397 | - $root->runScope(new Scope('baz'), function (Container $container) { |
|
| 420 | + $root->runScope(new Scope('baz'), function (Container $container) |
|
| 421 | + { |
|
| 398 | 422 | $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class); |
| 399 | 423 | |
| 400 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 424 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 425 | + { |
|
| 401 | 426 | $this->assertFalse($container->has('sampleClass')); |
| 402 | 427 | $this->assertFalse($container->has('otherClass')); |
| 403 | 428 | }); |