@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $this->assertNull(ContainerScope::getContainer()); |
| 22 | 22 | |
| 23 | - $this->assertTrue(ContainerScope::runScope($container, function () use ($container) { |
|
| 23 | + $this->assertTrue(ContainerScope::runScope($container, function () use ($container) |
|
| 24 | + { |
|
| 24 | 25 | return $container === ContainerScope::getContainer(); |
| 25 | 26 | })); |
| 26 | 27 | |
@@ -33,11 +34,14 @@ discard block |
||
| 33 | 34 | |
| 34 | 35 | $this->assertNull(ContainerScope::getContainer()); |
| 35 | 36 | |
| 36 | - try { |
|
| 37 | + try |
|
| 38 | + { |
|
| 37 | 39 | $this->assertTrue(ContainerScope::runScope($container, function () use ($container): void { |
| 38 | 40 | throw new RuntimeException('exception'); |
| 39 | 41 | })); |
| 40 | - } catch (\Throwable $e) { |
|
| 42 | + } |
|
| 43 | + catch (\Throwable $e) |
|
| 44 | + { |
|
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | $this->assertInstanceOf(RuntimeException::class, $e); |
@@ -55,7 +59,8 @@ discard block |
||
| 55 | 59 | $this->assertTrue($c->runScope([ |
| 56 | 60 | 'bucket' => new Bucket('b'), |
| 57 | 61 | 'other' => new SampleClass() |
| 58 | - ], function () use ($c) { |
|
| 62 | + ], function () use ($c) |
|
| 63 | + { |
|
| 59 | 64 | $this->assertSame('b', $c->get('bucket')->getName()); |
| 60 | 65 | $this->assertTrue($c->has('other')); |
| 61 | 66 | |
@@ -77,21 +82,25 @@ discard block |
||
| 77 | 82 | $this->assertTrue($c->runScope([ |
| 78 | 83 | 'bucket' => new Bucket('b'), |
| 79 | 84 | 'other' => new SampleClass() |
| 80 | - ], function () use ($c) { |
|
| 85 | + ], function () use ($c) |
|
| 86 | + { |
|
| 81 | 87 | $this->assertSame('b', $c->get('bucket')->getName()); |
| 82 | 88 | $this->assertTrue($c->has('other')); |
| 83 | 89 | |
| 84 | 90 | return $c->get('bucket')->getName() == 'b' && $c->has('other'); |
| 85 | 91 | })); |
| 86 | 92 | |
| 87 | - try { |
|
| 93 | + try |
|
| 94 | + { |
|
| 88 | 95 | $this->assertTrue($c->runScope([ |
| 89 | 96 | 'bucket' => new Bucket('b'), |
| 90 | 97 | 'other' => new SampleClass() |
| 91 | 98 | ], function () use ($c): void { |
| 92 | 99 | throw new RuntimeException('exception'); |
| 93 | 100 | })); |
| 94 | - } catch (\Throwable $e) { |
|
| 101 | + } |
|
| 102 | + catch (\Throwable $e) |
|
| 103 | + { |
|
| 95 | 104 | } |
| 96 | 105 | |
| 97 | 106 | $this->assertSame('a', $c->get('bucket')->getName()); |
@@ -107,7 +116,8 @@ discard block |
||
| 107 | 116 | ContainerScope::runScope($container, static fn (ContainerInterface $container) => $container) |
| 108 | 117 | ); |
| 109 | 118 | |
| 110 | - $result = ContainerScope::runScope($container, static function (Container $container) { |
|
| 119 | + $result = ContainerScope::runScope($container, static function (Container $container) |
|
| 120 | + { |
|
| 111 | 121 | return $container->runScope([], static fn (Container $container) => $container); |
| 112 | 122 | }); |
| 113 | 123 | |
@@ -58,7 +58,8 @@ discard block |
||
| 58 | 58 | $constructor = new Internal\Registry($config, [ |
| 59 | 59 | 'state' => new Internal\State(), |
| 60 | 60 | ]); |
| 61 | - foreach ($config as $property => $class) { |
|
| 61 | + foreach ($config as $property => $class) |
|
| 62 | + { |
|
| 62 | 63 | $this->$property = $constructor->get($property, $class); |
| 63 | 64 | } |
| 64 | 65 | |
@@ -143,26 +144,35 @@ discard block |
||
| 143 | 144 | { |
| 144 | 145 | $binds = &$this->state->bindings; |
| 145 | 146 | $cleanup = $previous = []; |
| 146 | - foreach ($bindings as $alias => $resolver) { |
|
| 147 | - if (isset($binds[$alias])) { |
|
| 147 | + foreach ($bindings as $alias => $resolver) |
|
| 148 | + { |
|
| 149 | + if (isset($binds[$alias])) |
|
| 150 | + { |
|
| 148 | 151 | $previous[$alias] = $binds[$alias]; |
| 149 | - } else { |
|
| 152 | + } |
|
| 153 | + else |
|
| 154 | + { |
|
| 150 | 155 | $cleanup[] = $alias; |
| 151 | 156 | } |
| 152 | 157 | |
| 153 | 158 | $this->binder->bind($alias, $resolver); |
| 154 | 159 | } |
| 155 | 160 | |
| 156 | - try { |
|
| 161 | + try |
|
| 162 | + { |
|
| 157 | 163 | return ContainerScope::getContainer() !== $this |
| 158 | 164 | ? ContainerScope::runScope($this, $scope) |
| 159 | 165 | : $scope($this); |
| 160 | - } finally { |
|
| 161 | - foreach ($previous as $alias => $resolver) { |
|
| 166 | + } |
|
| 167 | + finally |
|
| 168 | + { |
|
| 169 | + foreach ($previous as $alias => $resolver) |
|
| 170 | + { |
|
| 162 | 171 | $binds[$alias] = $resolver; |
| 163 | 172 | } |
| 164 | 173 | |
| 165 | - foreach ($cleanup as $alias) { |
|
| 174 | + foreach ($cleanup as $alias) |
|
| 175 | + { |
|
| 166 | 176 | unset($binds[$alias]); |
| 167 | 177 | } |
| 168 | 178 | } |
@@ -33,9 +33,12 @@ |
||
| 33 | 33 | { |
| 34 | 34 | [$previous, self::$container] = [self::$container, $container]; |
| 35 | 35 | |
| 36 | - try { |
|
| 36 | + try |
|
| 37 | + { |
|
| 37 | 38 | return $scope(self::$container); |
| 38 | - } finally { |
|
| 39 | + } |
|
| 40 | + finally |
|
| 41 | + { |
|
| 39 | 42 | self::$container = $previous; |
| 40 | 43 | } |
| 41 | 44 | } |