@@ -23,21 +23,21 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function __construct( |
| 25 | 25 | private readonly ClassNode $node |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function leaveNode(Node $node): ?Node |
| 30 | 30 | { |
| 31 | - if (!$node instanceof Namespace_) { |
|
| 31 | + if (!$node instanceof Namespace_){ |
|
| 32 | 32 | return null; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $imported = []; |
| 36 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
| 37 | - foreach ($this->node->constructorParams as $param) { |
|
| 38 | - if (!empty($param->type) && $param->type->fullName) { |
|
| 36 | + if (!$this->node->hasConstructor && $this->node->constructorParams){ |
|
| 37 | + foreach ($this->node->constructorParams as $param){ |
|
| 38 | + if (!empty($param->type) && $param->type->fullName){ |
|
| 39 | 39 | $import = [$param->type->fullName, $param->type->alias]; |
| 40 | - if (\in_array($import, $imported, true)) { |
|
| 40 | + if (\in_array($import, $imported, true)){ |
|
| 41 | 41 | continue; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - foreach ($this->node->dependencies as $dependency) { |
|
| 50 | + foreach ($this->node->dependencies as $dependency){ |
|
| 51 | 51 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
| 52 | - if (\in_array($import, $imported, true)) { |
|
| 52 | + if (\in_array($import, $imported, true)){ |
|
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | private function definePlacementID(Namespace_ $node): int |
| 74 | 74 | { |
| 75 | - foreach ($node->stmts as $index => $child) { |
|
| 76 | - if ($child instanceof Class_) { |
|
| 75 | + foreach ($node->stmts as $index => $child){ |
|
| 76 | + if ($child instanceof Class_){ |
|
| 77 | 77 | return $index; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | $uses = $this->getExistingUseParts($stmts); |
| 92 | 92 | |
| 93 | - foreach ($nodes as $i => $node) { |
|
| 94 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 93 | + foreach ($nodes as $i => $node){ |
|
| 94 | + if (!$node instanceof Node\Stmt\Use_){ |
|
| 95 | 95 | continue; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - foreach ($node->uses as $use) { |
|
| 99 | - if (\in_array($use->name->parts, $uses, true)) { |
|
| 98 | + foreach ($node->uses as $use){ |
|
| 99 | + if (\in_array($use->name->parts, $uses, true)){ |
|
| 100 | 100 | unset($nodes[$i]); |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | private function getExistingUseParts(array $stmts): array |
| 116 | 116 | { |
| 117 | 117 | $uses = []; |
| 118 | - foreach ($stmts as $stmt) { |
|
| 119 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
| 118 | + foreach ($stmts as $stmt){ |
|
| 119 | + if (!$stmt instanceof Node\Stmt\Use_){ |
|
| 120 | 120 | continue; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ($stmt->uses as $use) { |
|
| 123 | + foreach ($stmt->uses as $use){ |
|
| 124 | 124 | $uses[] = $use->name->parts; |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
| 132 | 132 | { |
| 133 | 133 | $b = new Use_(new Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
| 134 | - if (!empty($alias)) { |
|
| 134 | + if (!empty($alias)){ |
|
| 135 | 135 | $b->as($alias); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -28,16 +28,21 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function leaveNode(Node $node): ?Node |
| 30 | 30 | { |
| 31 | - if (!$node instanceof Namespace_) { |
|
| 31 | + if (!$node instanceof Namespace_) |
|
| 32 | + { |
|
| 32 | 33 | return null; |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | 36 | $imported = []; |
| 36 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
| 37 | - foreach ($this->node->constructorParams as $param) { |
|
| 38 | - if (!empty($param->type) && $param->type->fullName) { |
|
| 37 | + if (!$this->node->hasConstructor && $this->node->constructorParams) |
|
| 38 | + { |
|
| 39 | + foreach ($this->node->constructorParams as $param) |
|
| 40 | + { |
|
| 41 | + if (!empty($param->type) && $param->type->fullName) |
|
| 42 | + { |
|
| 39 | 43 | $import = [$param->type->fullName, $param->type->alias]; |
| 40 | - if (\in_array($import, $imported, true)) { |
|
| 44 | + if (\in_array($import, $imported, true)) |
|
| 45 | + { |
|
| 41 | 46 | continue; |
| 42 | 47 | } |
| 43 | 48 | |
@@ -47,9 +52,11 @@ discard block |
||
| 47 | 52 | } |
| 48 | 53 | } |
| 49 | 54 | |
| 50 | - foreach ($this->node->dependencies as $dependency) { |
|
| 55 | + foreach ($this->node->dependencies as $dependency) |
|
| 56 | + { |
|
| 51 | 57 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
| 52 | - if (\in_array($import, $imported, true)) { |
|
| 58 | + if (\in_array($import, $imported, true)) |
|
| 59 | + { |
|
| 53 | 60 | continue; |
| 54 | 61 | } |
| 55 | 62 | |
@@ -72,8 +79,10 @@ discard block |
||
| 72 | 79 | |
| 73 | 80 | private function definePlacementID(Namespace_ $node): int |
| 74 | 81 | { |
| 75 | - foreach ($node->stmts as $index => $child) { |
|
| 76 | - if ($child instanceof Class_) { |
|
| 82 | + foreach ($node->stmts as $index => $child) |
|
| 83 | + { |
|
| 84 | + if ($child instanceof Class_) |
|
| 85 | + { |
|
| 77 | 86 | return $index; |
| 78 | 87 | } |
| 79 | 88 | } |
@@ -90,13 +99,17 @@ discard block |
||
| 90 | 99 | { |
| 91 | 100 | $uses = $this->getExistingUseParts($stmts); |
| 92 | 101 | |
| 93 | - foreach ($nodes as $i => $node) { |
|
| 94 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 102 | + foreach ($nodes as $i => $node) |
|
| 103 | + { |
|
| 104 | + if (!$node instanceof Node\Stmt\Use_) |
|
| 105 | + { |
|
| 95 | 106 | continue; |
| 96 | 107 | } |
| 97 | 108 | |
| 98 | - foreach ($node->uses as $use) { |
|
| 99 | - if (\in_array($use->name->parts, $uses, true)) { |
|
| 109 | + foreach ($node->uses as $use) |
|
| 110 | + { |
|
| 111 | + if (\in_array($use->name->parts, $uses, true)) |
|
| 112 | + { |
|
| 100 | 113 | unset($nodes[$i]); |
| 101 | 114 | } |
| 102 | 115 | } |
@@ -115,12 +128,15 @@ discard block |
||
| 115 | 128 | private function getExistingUseParts(array $stmts): array |
| 116 | 129 | { |
| 117 | 130 | $uses = []; |
| 118 | - foreach ($stmts as $stmt) { |
|
| 119 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
| 131 | + foreach ($stmts as $stmt) |
|
| 132 | + { |
|
| 133 | + if (!$stmt instanceof Node\Stmt\Use_) |
|
| 134 | + { |
|
| 120 | 135 | continue; |
| 121 | 136 | } |
| 122 | 137 | |
| 123 | - foreach ($stmt->uses as $use) { |
|
| 138 | + foreach ($stmt->uses as $use) |
|
| 139 | + { |
|
| 124 | 140 | $uses[] = $use->name->parts; |
| 125 | 141 | } |
| 126 | 142 | } |
@@ -131,7 +147,8 @@ discard block |
||
| 131 | 147 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
| 132 | 148 | { |
| 133 | 149 | $b = new Use_(new Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
| 134 | - if (!empty($alias)) { |
|
| 150 | + if (!empty($alias)) |
|
| 151 | + { |
|
| 135 | 152 | $b->as($alias); |
| 136 | 153 | } |
| 137 | 154 | |
@@ -17,28 +17,28 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | final class RemoveTrait extends NodeVisitorAbstract |
| 19 | 19 | { |
| 20 | - public function leaveNode(Node $node): int|Node|null |
|
| 20 | + public function leaveNode(Node $node): int | Node | null |
|
| 21 | 21 | { |
| 22 | - if (!$node instanceof TraitUse) { |
|
| 22 | + if (!$node instanceof TraitUse){ |
|
| 23 | 23 | return null; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - foreach ($node->traits as $index => $use) { |
|
| 27 | - if ($use instanceof Name) { |
|
| 26 | + foreach ($node->traits as $index => $use){ |
|
| 27 | + if ($use instanceof Name){ |
|
| 28 | 28 | $name = $this->trimSlashes(\implode('\\', $use->parts)); |
| 29 | 29 | if ( |
| 30 | 30 | \in_array($name, [ |
| 31 | 31 | $this->trimSlashes(PrototypeTrait::class), |
| 32 | 32 | Utils::shortName(PrototypeTrait::class), |
| 33 | 33 | ], true) |
| 34 | - ) { |
|
| 34 | + ){ |
|
| 35 | 35 | unset($node->traits[$index]); |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $node->traits = \array_values($node->traits); |
| 41 | - if (empty($node->traits)) { |
|
| 41 | + if (empty($node->traits)){ |
|
| 42 | 42 | return NodeTraverser::REMOVE_NODE; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -19,12 +19,15 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | public function leaveNode(Node $node): int|Node|null |
| 21 | 21 | { |
| 22 | - if (!$node instanceof TraitUse) { |
|
| 22 | + if (!$node instanceof TraitUse) |
|
| 23 | + { |
|
| 23 | 24 | return null; |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | - foreach ($node->traits as $index => $use) { |
|
| 27 | - if ($use instanceof Name) { |
|
| 27 | + foreach ($node->traits as $index => $use) |
|
| 28 | + { |
|
| 29 | + if ($use instanceof Name) |
|
| 30 | + { |
|
| 28 | 31 | $name = $this->trimSlashes(\implode('\\', $use->parts)); |
| 29 | 32 | if ( |
| 30 | 33 | \in_array($name, [ |
@@ -38,7 +41,8 @@ discard block |
||
| 38 | 41 | } |
| 39 | 42 | |
| 40 | 43 | $node->traits = \array_values($node->traits); |
| 41 | - if (empty($node->traits)) { |
|
| 44 | + if (empty($node->traits)) |
|
| 45 | + { |
|
| 42 | 46 | return NodeTraverser::REMOVE_NODE; |
| 43 | 47 | } |
| 44 | 48 | |
@@ -21,17 +21,17 @@ discard block |
||
| 21 | 21 | $this->assertContains(TestTrait::class, $reflection->getTraits()); |
| 22 | 22 | $this->assertContains(TestInterface::class, $reflection->getInterfaces()); |
| 23 | 23 | |
| 24 | - $this->assertSame([__NAMESPACE__ . '\hello'], $reflection->getFunctions()); |
|
| 24 | + $this->assertSame([__NAMESPACE__.'\hello'], $reflection->getFunctions()); |
|
| 25 | 25 | |
| 26 | 26 | $functionA = null; |
| 27 | 27 | $functionB = null; |
| 28 | 28 | |
| 29 | - foreach ($reflection->getInvocations() as $invocation) { |
|
| 30 | - if ($invocation->getName() == 'test_function_a') { |
|
| 29 | + foreach ($reflection->getInvocations() as $invocation){ |
|
| 30 | + if ($invocation->getName() == 'test_function_a'){ |
|
| 31 | 31 | $functionA = $invocation; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ($invocation->getName() == 'test_function_b') { |
|
| 34 | + if ($invocation->getName() == 'test_function_b'){ |
|
| 35 | 35 | $functionB = $invocation; |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function testReflectionFileWithNamedParameters(): void |
| 60 | 60 | { |
| 61 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassWithNamedParameter.php'); |
|
| 61 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassWithNamedParameter.php'); |
|
| 62 | 62 | |
| 63 | 63 | $this->assertSame([ |
| 64 | 64 | ClassWithNamedParameter::class, |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | public function testReflectionFileAnonymousClass(): void |
| 69 | 69 | { |
| 70 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassWithAnonymousClass.php'); |
|
| 70 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassWithAnonymousClass.php'); |
|
| 71 | 71 | |
| 72 | 72 | $this->assertSame([ |
| 73 | 73 | ClassWithAnonymousClass::class, |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | public function testReflectionFileWithHeredoc(): void |
| 78 | 78 | { |
| 79 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassWithHeredoc.php'); |
|
| 79 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassWithHeredoc.php'); |
|
| 80 | 80 | |
| 81 | 81 | $this->assertSame([ |
| 82 | 82 | 'Spiral\Tests\Tokenizer\Classes\ClassWithHeredoc', |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | public function testReflectionEnum(): void |
| 87 | 87 | { |
| 88 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassD.php'); |
|
| 88 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassD.php'); |
|
| 89 | 89 | |
| 90 | 90 | $this->assertSame([ |
| 91 | 91 | ClassD::class, |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | public function testReflectionTypedEnum(): void |
| 96 | 96 | { |
| 97 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassE.php'); |
|
| 97 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassE.php'); |
|
| 98 | 98 | |
| 99 | 99 | $this->assertSame([ |
| 100 | 100 | ClassE::class, |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | public function testReflectionInterface(): void |
| 105 | 105 | { |
| 106 | - $reflection = new ReflectionFile(__DIR__ . '/Interfaces/InterfaceA.php'); |
|
| 106 | + $reflection = new ReflectionFile(__DIR__.'/Interfaces/InterfaceA.php'); |
|
| 107 | 107 | |
| 108 | 108 | $this->assertSame([ |
| 109 | 109 | InterfaceA::class, |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | private readonly bool $secure = false, |
| 63 | 63 | private readonly bool $httpOnly = true, |
| 64 | 64 | ?string $sameSite = null |
| 65 | - ) { |
|
| 65 | + ){ |
|
| 66 | 66 | $this->sameSite = new SameSite($sameSite, $secure); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function createHeader(): string |
| 160 | 160 | { |
| 161 | - $header = [\rawurlencode($this->name) . '=' . \rawurlencode((string)$this->value)]; |
|
| 161 | + $header = [\rawurlencode($this->name).'='.\rawurlencode((string)$this->value)]; |
|
| 162 | 162 | |
| 163 | - if ($this->lifetime !== null) { |
|
| 164 | - $header[] = 'Expires=' . \gmdate(\DateTime::COOKIE, $this->getExpires()); |
|
| 163 | + if ($this->lifetime !== null){ |
|
| 164 | + $header[] = 'Expires='.\gmdate(\DateTime::COOKIE, $this->getExpires()); |
|
| 165 | 165 | $header[] = \sprintf('Max-Age=%d', $this->lifetime); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if (!empty($this->path)) { |
|
| 168 | + if (!empty($this->path)){ |
|
| 169 | 169 | $header[] = \sprintf('Path=%s', $this->path); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if (!empty($this->domain)) { |
|
| 172 | + if (!empty($this->domain)){ |
|
| 173 | 173 | $header[] = \sprintf('Domain=%s', $this->domain); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ($this->secure) { |
|
| 176 | + if ($this->secure){ |
|
| 177 | 177 | $header[] = 'Secure'; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ($this->httpOnly) { |
|
| 180 | + if ($this->httpOnly){ |
|
| 181 | 181 | $header[] = 'HttpOnly'; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if ($this->sameSite->get() !== null) { |
|
| 184 | + if ($this->sameSite->get() !== null){ |
|
| 185 | 185 | $header[] = \sprintf('SameSite=%s', $this->sameSite->get()); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public function getExpires(): ?int |
| 197 | 197 | { |
| 198 | - if ($this->lifetime === null) { |
|
| 198 | + if ($this->lifetime === null){ |
|
| 199 | 199 | return null; |
| 200 | 200 | } |
| 201 | 201 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function testInvalidInjector(): void |
| 42 | 42 | { |
| 43 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
| 43 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
| 44 | 44 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
| 45 | 45 | $this->expectException(InjectionException::class); |
| 46 | 46 | $this->expectExceptionMessage($excepted); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | public function testInvalidRuntimeInjector(): void |
| 68 | 68 | { |
| 69 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
| 69 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
| 70 | 70 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
| 71 | 71 | $this->expectException(InjectionException::class); |
| 72 | 72 | $this->expectExceptionMessage($excepted); |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | public function testExtendedInjectorAnonClassObjectParam(): void |
| 205 | 205 | { |
| 206 | 206 | $container = new Container(); |
| 207 | - $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface { |
|
| 208 | - public function createInjection(\ReflectionClass $class, object|string|null $context = null): object |
|
| 207 | + $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface{ |
|
| 208 | + public function createInjection(\ReflectionClass $class, object | string | null $context = null): object |
|
| 209 | 209 | { |
| 210 | 210 | return (object)['context' => $context]; |
| 211 | 211 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | public function testExtendedInjectorAnonClassMixedParam(): void |
| 221 | 221 | { |
| 222 | 222 | $container = new Container(); |
| 223 | - $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface { |
|
| 223 | + $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface{ |
|
| 224 | 224 | public function createInjection(\ReflectionClass $class, mixed $context = null): object |
| 225 | 225 | { |
| 226 | 226 | return (object)['context' => $context]; |
@@ -204,7 +204,8 @@ discard block |
||
| 204 | 204 | public function testExtendedInjectorAnonClassObjectParam(): void |
| 205 | 205 | { |
| 206 | 206 | $container = new Container(); |
| 207 | - $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface { |
|
| 207 | + $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface |
|
| 208 | + { |
|
| 208 | 209 | public function createInjection(\ReflectionClass $class, object|string|null $context = null): object |
| 209 | 210 | { |
| 210 | 211 | return (object)['context' => $context]; |
@@ -220,7 +221,8 @@ discard block |
||
| 220 | 221 | public function testExtendedInjectorAnonClassMixedParam(): void |
| 221 | 222 | { |
| 222 | 223 | $container = new Container(); |
| 223 | - $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface { |
|
| 224 | + $container->bind(stdClass::class, new Injectable(new class implements InjectorInterface |
|
| 225 | + { |
|
| 224 | 226 | public function createInjection(\ReflectionClass $class, mixed $context = null): object |
| 225 | 227 | { |
| 226 | 228 | return (object)['context' => $context]; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | // from the current `foo` scope |
| 49 | 49 | self::assertInstanceOf(KVLogger::class, $logger); |
| 50 | 50 | |
| 51 | - for ($i = 0; $i < 10; $i++) { |
|
| 51 | + for ($i = 0; $i < 10; $i++){ |
|
| 52 | 52 | // because of proxy |
| 53 | 53 | self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger()); |
| 54 | 54 | self::assertSame('kv', $carrier->logger->getName()); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | // from the current `foo` scope |
| 69 | 69 | self::assertInstanceOf(FileLogger::class, $logger); |
| 70 | 70 | |
| 71 | - for ($i = 0; $i < 10; $i++) { |
|
| 71 | + for ($i = 0; $i < 10; $i++){ |
|
| 72 | 72 | // because of proxy |
| 73 | 73 | self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger()); |
| 74 | 74 | self::assertSame('file', $carrier->logger->getName()); |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | $root = new Container(); |
| 86 | 86 | $root->getBinder('http')->bindSingleton(LoggerInterface::class, KVLogger::class); |
| 87 | 87 | |
| 88 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
| 88 | + $root->runScope(new Scope(), static function (Container $c1){ |
|
| 89 | 89 | $c1->runScope( |
| 90 | 90 | new Scope(name: 'http'), |
| 91 | 91 | static function ( |
| 92 | 92 | ScopedProxyLoggerCarrier $carrier, |
| 93 | 93 | ScopedProxyLoggerCarrier $carrier2, |
| 94 | 94 | LoggerInterface $logger, |
| 95 | - ) { |
|
| 95 | + ){ |
|
| 96 | 96 | // from the current `foo` scope |
| 97 | 97 | self::assertInstanceOf(KVLogger::class, $logger); |
| 98 | 98 | |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | $root = new Container(); |
| 113 | 113 | $root->getBinder('foo')->bind(LoggerInterface::class, KVLogger::class); |
| 114 | 114 | |
| 115 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
| 115 | + $root->runScope(new Scope(), static function (Container $c1){ |
|
| 116 | 116 | $c1->runScope( |
| 117 | 117 | new Scope(name: 'foo'), |
| 118 | - static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) { |
|
| 118 | + static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger){ |
|
| 119 | 119 | // from the current `foo` scope |
| 120 | 120 | self::assertInstanceOf(KVLogger::class, $logger); |
| 121 | 121 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | ->bind( |
| 137 | 137 | ContextInterface::class, |
| 138 | 138 | new Injectable( |
| 139 | - new class implements InjectorInterface { |
|
| 139 | + new class implements InjectorInterface{ |
|
| 140 | 140 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
| 141 | 141 | { |
| 142 | 142 | return new Context($context); |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | ), |
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
| 149 | - $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param) { |
|
| 148 | + $root->runScope(new Scope(), static function (Container $c1){ |
|
| 149 | + $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param){ |
|
| 150 | 150 | self::assertInstanceOf(ReflectionParameter::class, $param->value); |
| 151 | 151 | self::assertSame('param', $param->value->getName()); |
| 152 | 152 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | ->bind( |
| 178 | 178 | ContextInterface::class, |
| 179 | 179 | new Injectable( |
| 180 | - new class implements InjectorInterface { |
|
| 180 | + new class implements InjectorInterface{ |
|
| 181 | 181 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
| 182 | 182 | { |
| 183 | 183 | return new Context($context); |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | 189 | FiberHelper::runFiberSequence( |
| 190 | - static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx) { |
|
| 191 | - for ($i = 0; $i < 10; $i++) { |
|
| 190 | + static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx){ |
|
| 191 | + for ($i = 0; $i < 10; $i++){ |
|
| 192 | 192 | self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected'); |
| 193 | 193 | self::assertSame('ctx', $ctx->getValue()->getName()); |
| 194 | 194 | \Fiber::suspend(); |
| 195 | 195 | } |
| 196 | 196 | }), |
| 197 | - static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context) { |
|
| 198 | - for ($i = 0; $i < 10; $i++) { |
|
| 197 | + static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context){ |
|
| 198 | + for ($i = 0; $i < 10; $i++){ |
|
| 199 | 199 | self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected'); |
| 200 | 200 | self::assertSame('context', $context->getValue()->getName()); |
| 201 | 201 | \Fiber::suspend(); |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | { |
| 257 | 257 | $root = new Container(); |
| 258 | 258 | $context = (object)['destroyed' => false]; |
| 259 | - $class = new class($context) implements DestroyableInterface { |
|
| 259 | + $class = new class($context) implements DestroyableInterface{ |
|
| 260 | 260 | public function __construct( |
| 261 | 261 | private readonly \stdClass $context, |
| 262 | - ) { |
|
| 262 | + ){ |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | public function __destruct() |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | new Scope('http'), |
| 288 | 288 | static function () use ($root, $proxy) { |
| 289 | 289 | self::assertSame('Foo', $proxy->getName()); |
| 290 | - $proxy->setName(new class implements \Stringable { |
|
| 290 | + $proxy->setName(new class implements \Stringable{ |
|
| 291 | 291 | public function __toString(): string |
| 292 | 292 | { |
| 293 | 293 | return 'Bar'; |
@@ -44,11 +44,13 @@ discard block |
||
| 44 | 44 | LoggerInterface::class => KVLogger::class, |
| 45 | 45 | ], |
| 46 | 46 | ), |
| 47 | - static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) { |
|
| 47 | + static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) |
|
| 48 | + { |
|
| 48 | 49 | // from the current `foo` scope |
| 49 | 50 | self::assertInstanceOf(KVLogger::class, $logger); |
| 50 | 51 | |
| 51 | - for ($i = 0; $i < 10; $i++) { |
|
| 52 | + for ($i = 0; $i < 10; $i++) |
|
| 53 | + { |
|
| 52 | 54 | // because of proxy |
| 53 | 55 | self::assertNotInstanceOf(KVLogger::class, $carrier->getLogger()); |
| 54 | 56 | self::assertSame('kv', $carrier->logger->getName()); |
@@ -64,11 +66,13 @@ discard block |
||
| 64 | 66 | LoggerInterface::class => FileLogger::class, |
| 65 | 67 | ], |
| 66 | 68 | ), |
| 67 | - static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) { |
|
| 69 | + static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) use ($lc) |
|
| 70 | + { |
|
| 68 | 71 | // from the current `foo` scope |
| 69 | 72 | self::assertInstanceOf(FileLogger::class, $logger); |
| 70 | 73 | |
| 71 | - for ($i = 0; $i < 10; $i++) { |
|
| 74 | + for ($i = 0; $i < 10; $i++) |
|
| 75 | + { |
|
| 72 | 76 | // because of proxy |
| 73 | 77 | self::assertNotInstanceOf(FileLogger::class, $carrier->getLogger()); |
| 74 | 78 | self::assertSame('file', $carrier->logger->getName()); |
@@ -85,7 +89,8 @@ discard block |
||
| 85 | 89 | $root = new Container(); |
| 86 | 90 | $root->getBinder('http')->bindSingleton(LoggerInterface::class, KVLogger::class); |
| 87 | 91 | |
| 88 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
| 92 | + $root->runScope(new Scope(), static function (Container $c1) |
|
| 93 | + { |
|
| 89 | 94 | $c1->runScope( |
| 90 | 95 | new Scope(name: 'http'), |
| 91 | 96 | static function ( |
@@ -112,10 +117,12 @@ discard block |
||
| 112 | 117 | $root = new Container(); |
| 113 | 118 | $root->getBinder('foo')->bind(LoggerInterface::class, KVLogger::class); |
| 114 | 119 | |
| 115 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
| 120 | + $root->runScope(new Scope(), static function (Container $c1) |
|
| 121 | + { |
|
| 116 | 122 | $c1->runScope( |
| 117 | 123 | new Scope(name: 'foo'), |
| 118 | - static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) { |
|
| 124 | + static function (ScopedProxyLoggerCarrier $carrier, LoggerInterface $logger) |
|
| 125 | + { |
|
| 119 | 126 | // from the current `foo` scope |
| 120 | 127 | self::assertInstanceOf(KVLogger::class, $logger); |
| 121 | 128 | |
@@ -136,7 +143,8 @@ discard block |
||
| 136 | 143 | ->bind( |
| 137 | 144 | ContextInterface::class, |
| 138 | 145 | new Injectable( |
| 139 | - new class implements InjectorInterface { |
|
| 146 | + new class implements InjectorInterface |
|
| 147 | + { |
|
| 140 | 148 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
| 141 | 149 | { |
| 142 | 150 | return new Context($context); |
@@ -145,8 +153,10 @@ discard block |
||
| 145 | 153 | ), |
| 146 | 154 | ); |
| 147 | 155 | |
| 148 | - $root->runScope(new Scope(), static function (Container $c1) { |
|
| 149 | - $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param) { |
|
| 156 | + $root->runScope(new Scope(), static function (Container $c1) |
|
| 157 | + { |
|
| 158 | + $c1->runScope(new Scope(name: 'foo'), static function (Container $c, ContextInterface $param) |
|
| 159 | + { |
|
| 150 | 160 | self::assertInstanceOf(ReflectionParameter::class, $param->value); |
| 151 | 161 | self::assertSame('param', $param->value->getName()); |
| 152 | 162 | |
@@ -177,7 +187,8 @@ discard block |
||
| 177 | 187 | ->bind( |
| 178 | 188 | ContextInterface::class, |
| 179 | 189 | new Injectable( |
| 180 | - new class implements InjectorInterface { |
|
| 190 | + new class implements InjectorInterface |
|
| 191 | + { |
|
| 181 | 192 | public function createInjection(\ReflectionClass $class, mixed $context = null): Context |
| 182 | 193 | { |
| 183 | 194 | return new Context($context); |
@@ -187,15 +198,19 @@ discard block |
||
| 187 | 198 | ); |
| 188 | 199 | |
| 189 | 200 | FiberHelper::runFiberSequence( |
| 190 | - static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx) { |
|
| 191 | - for ($i = 0; $i < 10; $i++) { |
|
| 201 | + static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $ctx) |
|
| 202 | + { |
|
| 203 | + for ($i = 0; $i < 10; $i++) |
|
| 204 | + { |
|
| 192 | 205 | self::assertInstanceOf(ReflectionParameter::class, $ctx->getValue(), 'Context injected'); |
| 193 | 206 | self::assertSame('ctx', $ctx->getValue()->getName()); |
| 194 | 207 | \Fiber::suspend(); |
| 195 | 208 | } |
| 196 | 209 | }), |
| 197 | - static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context) { |
|
| 198 | - for ($i = 0; $i < 10; $i++) { |
|
| 210 | + static fn() => $root->runScope(new Scope(name: 'foo'), static function (ContextInterface $context) |
|
| 211 | + { |
|
| 212 | + for ($i = 0; $i < 10; $i++) |
|
| 213 | + { |
|
| 199 | 214 | self::assertInstanceOf(ReflectionParameter::class, $context->getValue(), 'Context injected'); |
| 200 | 215 | self::assertSame('context', $context->getValue()->getName()); |
| 201 | 216 | \Fiber::suspend(); |
@@ -211,8 +226,10 @@ discard block |
||
| 211 | 226 | |
| 212 | 227 | $root->runScope( |
| 213 | 228 | new Scope(), |
| 214 | - static function (#[Proxy] ContainerInterface $cp) use ($root) { |
|
| 215 | - $root->runScope(new Scope(name: 'http'), static function (ContainerInterface $c) use ($cp) { |
|
| 229 | + static function (#[Proxy] ContainerInterface $cp) use ($root) |
|
| 230 | + { |
|
| 231 | + $root->runScope(new Scope(name: 'http'), static function (ContainerInterface $c) use ($cp) |
|
| 232 | + { |
|
| 216 | 233 | self::assertNotSame($c, $cp); |
| 217 | 234 | self::assertSame($c, $cp->get(ContainerInterface::class)); |
| 218 | 235 | self::assertInstanceOf(KVLogger::class, $cp->get(LoggerInterface::class)); |
@@ -256,7 +273,8 @@ discard block |
||
| 256 | 273 | { |
| 257 | 274 | $root = new Container(); |
| 258 | 275 | $context = (object)['destroyed' => false]; |
| 259 | - $class = new class($context) implements DestroyableInterface { |
|
| 276 | + $class = new class($context) implements DestroyableInterface |
|
| 277 | + { |
|
| 260 | 278 | public function __construct( |
| 261 | 279 | private readonly \stdClass $context, |
| 262 | 280 | ) { |
@@ -285,7 +303,8 @@ discard block |
||
| 285 | 303 | |
| 286 | 304 | $root->runScope( |
| 287 | 305 | new Scope('http'), |
| 288 | - static function () use ($root, $proxy) { |
|
| 306 | + static function () use ($root, $proxy) |
|
| 307 | + { |
|
| 289 | 308 | self::assertSame('Foo', $proxy->getName()); |
| 290 | 309 | $proxy->setName(new class implements \Stringable { |
| 291 | 310 | public function __toString(): string |
@@ -36,7 +36,8 @@ discard block |
||
| 36 | 36 | $root = new Container(); |
| 37 | 37 | $root->bind('foo', SampleClass::class); |
| 38 | 38 | |
| 39 | - $root->runScoped(function (ContainerInterface $c1) { |
|
| 39 | + $root->runScoped(function (ContainerInterface $c1) |
|
| 40 | + { |
|
| 40 | 41 | $c1->get('foo'); |
| 41 | 42 | }, bindings: ['foo' => SampleClass::class]); |
| 42 | 43 | |
@@ -69,7 +70,8 @@ discard block |
||
| 69 | 70 | { |
| 70 | 71 | $root = new Container(); |
| 71 | 72 | |
| 72 | - $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) { |
|
| 73 | + $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) |
|
| 74 | + { |
|
| 73 | 75 | $obj1 = $c1->get($alias); |
| 74 | 76 | $obj2 = $c1->get($alias); |
| 75 | 77 | |
@@ -94,14 +96,16 @@ discard block |
||
| 94 | 96 | { |
| 95 | 97 | $root = new Container(); |
| 96 | 98 | |
| 97 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
| 99 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
| 100 | + { |
|
| 98 | 101 | $obj1 = $c1->get('foo'); |
| 99 | 102 | $this->weakMap->offsetSet($obj1, true); |
| 100 | 103 | |
| 101 | 104 | self::assertNotSame($root, $c1); |
| 102 | 105 | self::assertInstanceOf(stdClass::class, $obj1); |
| 103 | 106 | |
| 104 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) { |
|
| 107 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) |
|
| 108 | + { |
|
| 105 | 109 | $obj2 = $c2->get('foo'); |
| 106 | 110 | $this->weakMap->offsetSet($obj2, true); |
| 107 | 111 | |
@@ -130,14 +134,16 @@ discard block |
||
| 130 | 134 | $root->bindSingleton('bar', [Factory::class, 'makeStdClass']); |
| 131 | 135 | $root->bind(stdClass::class, new stdClass()); |
| 132 | 136 | |
| 133 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
| 137 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
| 138 | + { |
|
| 134 | 139 | $obj1 = $c1->get('foo'); |
| 135 | 140 | $this->weakMap->offsetSet($obj1, true); |
| 136 | 141 | |
| 137 | 142 | self::assertInstanceOf(stdClass::class, $obj1); |
| 138 | 143 | // Singleton must be the same |
| 139 | 144 | self::assertSame($c1->get('bar'), $root->get('bar')); |
| 140 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) { |
|
| 145 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) |
|
| 146 | + { |
|
| 141 | 147 | $obj2 = $c2->get('foo'); |
| 142 | 148 | |
| 143 | 149 | self::assertInstanceOf(stdClass::class, $obj2); |
@@ -270,7 +276,8 @@ discard block |
||
| 270 | 276 | { |
| 271 | 277 | $root = new Container(); |
| 272 | 278 | |
| 273 | - $root->invoke(static function () use ($root) { |
|
| 279 | + $root->invoke(static function () use ($root) |
|
| 280 | + { |
|
| 274 | 281 | self::assertNotNull(ContainerScope::getContainer()); |
| 275 | 282 | self::assertSame($root, ContainerScope::getContainer()); |
| 276 | 283 | }); |
@@ -279,7 +286,8 @@ discard block |
||
| 279 | 286 | public function testRegisterContainerOnGet(): void |
| 280 | 287 | { |
| 281 | 288 | $root = new Container(); |
| 282 | - $root->bind('foo', function () use ($root) { |
|
| 289 | + $root->bind('foo', function () use ($root) |
|
| 290 | + { |
|
| 283 | 291 | self::assertNotNull(ContainerScope::getContainer()); |
| 284 | 292 | self::assertSame($root, ContainerScope::getContainer()); |
| 285 | 293 | }); |
@@ -290,7 +298,8 @@ discard block |
||
| 290 | 298 | public function testRegisterContainerOnMake(): void |
| 291 | 299 | { |
| 292 | 300 | $root = new Container(); |
| 293 | - $root->bind('foo', function () use ($root) { |
|
| 301 | + $root->bind('foo', function () use ($root) |
|
| 302 | + { |
|
| 294 | 303 | self::assertNotNull(ContainerScope::getContainer()); |
| 295 | 304 | self::assertSame($root, ContainerScope::getContainer()); |
| 296 | 305 | }); |
@@ -308,7 +317,8 @@ discard block |
||
| 308 | 317 | $root->bind('isFoo', new Scalar(false)); |
| 309 | 318 | $root->getBinder('foo')->bind('isFoo', new Scalar(true)); |
| 310 | 319 | |
| 311 | - $root->bind('foo', function (#[Proxy] ContainerInterface $c, ContainerInterface $r) use ($root) { |
|
| 320 | + $root->bind('foo', function (#[Proxy] ContainerInterface $c, ContainerInterface $r) use ($root) |
|
| 321 | + { |
|
| 312 | 322 | // Direct |
| 313 | 323 | self::assertNotNull(ContainerScope::getContainer()); |
| 314 | 324 | self::assertNotSame($root, ContainerScope::getContainer()); |
@@ -323,7 +333,8 @@ discard block |
||
| 323 | 333 | |
| 324 | 334 | $root->runScope( |
| 325 | 335 | new Scope('foo'), |
| 326 | - function (ContainerInterface $c) { |
|
| 336 | + function (ContainerInterface $c) |
|
| 337 | + { |
|
| 327 | 338 | self::assertTrue($c->get('isFoo')); |
| 328 | 339 | $c->get('foo'); |
| 329 | 340 | } |
@@ -336,7 +347,8 @@ discard block |
||
| 336 | 347 | $root = new Container(); |
| 337 | 348 | $root->getBinder($scope)->bindSingleton('foo', SampleClass::class); |
| 338 | 349 | |
| 339 | - $root->runScope(new Scope($scope), function (Container $container) { |
|
| 350 | + $root->runScope(new Scope($scope), function (Container $container) |
|
| 351 | + { |
|
| 340 | 352 | $this->assertTrue($container->has('foo')); |
| 341 | 353 | $this->assertInstanceOf(SampleClass::class, $container->get('foo')); |
| 342 | 354 | }); |
@@ -348,20 +360,25 @@ discard block |
||
| 348 | 360 | $root = new Container(); |
| 349 | 361 | $root->bindSingleton('sampleClass', SampleClass::class); |
| 350 | 362 | |
| 351 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 363 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 364 | + { |
|
| 352 | 365 | $this->assertTrue($container->has('sampleClass')); |
| 353 | 366 | }); |
| 354 | 367 | |
| 355 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 356 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 368 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 369 | + { |
|
| 370 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 371 | + { |
|
| 357 | 372 | $this->assertTrue($container->has('sampleClass')); |
| 358 | 373 | }); |
| 359 | 374 | }); |
| 360 | 375 | |
| 361 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 376 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 377 | + { |
|
| 362 | 378 | $container->bindSingleton('otherClass', SampleClass::class); |
| 363 | 379 | |
| 364 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 380 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 381 | + { |
|
| 365 | 382 | $this->assertTrue($container->has('sampleClass')); |
| 366 | 383 | $this->assertTrue($container->has('otherClass')); |
| 367 | 384 | }); |
@@ -373,33 +390,41 @@ discard block |
||
| 373 | 390 | $root = new Container(); |
| 374 | 391 | $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class); |
| 375 | 392 | |
| 376 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 393 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 394 | + { |
|
| 377 | 395 | $this->assertTrue($container->has('sampleClass')); |
| 378 | 396 | }); |
| 379 | 397 | |
| 380 | - $root->runScope(new Scope('bar'), function (Container $container) { |
|
| 398 | + $root->runScope(new Scope('bar'), function (Container $container) |
|
| 399 | + { |
|
| 381 | 400 | $this->assertFalse($container->has('sampleClass')); |
| 382 | 401 | }); |
| 383 | 402 | |
| 384 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 385 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 403 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 404 | + { |
|
| 405 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 406 | + { |
|
| 386 | 407 | $this->assertTrue($container->has('sampleClass')); |
| 387 | 408 | }); |
| 388 | 409 | }); |
| 389 | 410 | |
| 390 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
| 411 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
| 412 | + { |
|
| 391 | 413 | $container->bindSingleton('otherClass', AttrScopeFoo::class); |
| 392 | 414 | |
| 393 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 415 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 416 | + { |
|
| 394 | 417 | $this->assertTrue($container->has('sampleClass')); |
| 395 | 418 | $this->assertTrue($container->has('otherClass')); |
| 396 | 419 | }); |
| 397 | 420 | }); |
| 398 | 421 | |
| 399 | - $root->runScope(new Scope('baz'), function (Container $container) { |
|
| 422 | + $root->runScope(new Scope('baz'), function (Container $container) |
|
| 423 | + { |
|
| 400 | 424 | $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class); |
| 401 | 425 | |
| 402 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
| 426 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
| 427 | + { |
|
| 403 | 428 | $this->assertFalse($container->has('sampleClass')); |
| 404 | 429 | $this->assertFalse($container->has('otherClass')); |
| 405 | 430 | }); |
@@ -75,19 +75,19 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @throws \Throwable |
| 77 | 77 | */ |
| 78 | - public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
|
| 78 | + public function make(string $alias, array $parameters = [], Stringable | string | null $context = null): mixed |
|
| 79 | 79 | { |
| 80 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 80 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
| 81 | 81 | return $this->state->singletons[$alias]; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $binding = $this->state->bindings[$alias] ?? null; |
| 85 | 85 | |
| 86 | - if ($binding === null) { |
|
| 86 | + if ($binding === null){ |
|
| 87 | 87 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - try { |
|
| 90 | + try{ |
|
| 91 | 91 | $this->tracer->push( |
| 92 | 92 | false, |
| 93 | 93 | action: 'resolve from binding', |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 118 | 118 | default => $binding, |
| 119 | 119 | }; |
| 120 | - } finally { |
|
| 120 | + }finally{ |
|
| 121 | 121 | $this->state->bindings[$alias] ??= $binding; |
| 122 | 122 | $this->tracer->pop(true); |
| 123 | 123 | $this->tracer->pop(false); |
@@ -131,18 +131,18 @@ discard block |
||
| 131 | 131 | private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments) |
| 132 | 132 | { |
| 133 | 133 | $context = $ctx->context; |
| 134 | - try { |
|
| 134 | + try{ |
|
| 135 | 135 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 136 | - } catch (\ReflectionException $e) { |
|
| 136 | + }catch (\ReflectionException $e){ |
|
| 137 | 137 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $injector = $binding->injector; |
| 141 | 141 | |
| 142 | - try { |
|
| 142 | + try{ |
|
| 143 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 144 | 144 | |
| 145 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 145 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 146 | 146 | throw new InjectionException( |
| 147 | 147 | \sprintf( |
| 148 | 148 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | default => (string)$context, |
| 170 | 170 | }); |
| 171 | 171 | |
| 172 | - if (!$reflection->isInstance($instance)) { |
|
| 172 | + if (!$reflection->isInstance($instance)){ |
|
| 173 | 173 | throw new InjectionException( |
| 174 | 174 | \sprintf( |
| 175 | 175 | "Invalid injection response for '%s'.", |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | return $instance; |
| 182 | - } finally { |
|
| 182 | + }finally{ |
|
| 183 | 183 | $this->state->bindings[$ctx->class] ??= $binding; |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -187,29 +187,29 @@ discard block |
||
| 187 | 187 | private function resolveAlias( |
| 188 | 188 | Alias $binding, |
| 189 | 189 | string $alias, |
| 190 | - Stringable|string|null $context, |
|
| 190 | + Stringable | string | null $context, |
|
| 191 | 191 | array $arguments, |
| 192 | 192 | ): mixed { |
| 193 | 193 | $result = $binding->alias === $alias |
| 194 | 194 | ? $this->autowire( |
| 195 | - new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton), |
|
| 195 | + new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton), |
|
| 196 | 196 | $arguments, |
| 197 | 197 | ) |
| 198 | 198 | //Binding is pointing to something else |
| 199 | 199 | : $this->make($binding->alias, $arguments, $context); |
| 200 | 200 | |
| 201 | - if ($binding->singleton && $arguments === []) { |
|
| 201 | + if ($binding->singleton && $arguments === []){ |
|
| 202 | 202 | $this->state->singletons[$alias] = $result; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | return $result; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - private function resolveProxy(Config\Proxy $binding, string $alias, Stringable|string|null $context): mixed |
|
| 208 | + private function resolveProxy(Config\Proxy $binding, string $alias, Stringable | string | null $context): mixed |
|
| 209 | 209 | { |
| 210 | 210 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 211 | 211 | |
| 212 | - if ($binding->singleton) { |
|
| 212 | + if ($binding->singleton){ |
|
| 213 | 213 | $this->state->singletons[$alias] = $result; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -219,13 +219,13 @@ discard block |
||
| 219 | 219 | private function resolveShared( |
| 220 | 220 | Shared $binding, |
| 221 | 221 | string $alias, |
| 222 | - Stringable|string|null $context, |
|
| 222 | + Stringable | string | null $context, |
|
| 223 | 223 | array $arguments, |
| 224 | 224 | ): object { |
| 225 | 225 | $avoidCache = $arguments !== []; |
| 226 | 226 | return $avoidCache |
| 227 | 227 | ? $this->createInstance( |
| 228 | - new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
|
| 228 | + new Ctx(alias : $alias, class : $binding->value::class, context : $context), |
|
| 229 | 229 | $arguments, |
| 230 | 230 | ) |
| 231 | 231 | : $binding->value; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | private function resolveAutowire( |
| 235 | 235 | Autowire $binding, |
| 236 | 236 | string $alias, |
| 237 | - Stringable|string|null $context, |
|
| 237 | + Stringable | string | null $context, |
|
| 238 | 238 | array $arguments, |
| 239 | 239 | ): mixed { |
| 240 | 240 | $instance = $binding->autowire->resolve($this, $arguments); |
@@ -244,17 +244,17 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | private function resolveFactory( |
| 247 | - Config\Factory|DeferredFactory $binding, |
|
| 247 | + Config\Factory | DeferredFactory $binding, |
|
| 248 | 248 | string $alias, |
| 249 | - Stringable|string|null $context, |
|
| 249 | + Stringable | string | null $context, |
|
| 250 | 250 | array $arguments, |
| 251 | 251 | ): mixed { |
| 252 | 252 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 253 | - try { |
|
| 253 | + try{ |
|
| 254 | 254 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 255 | 255 | ? ($binding->factory)() |
| 256 | 256 | : $this->invoker->invoke($binding->factory, $arguments); |
| 257 | - } catch (NotCallableException $e) { |
|
| 257 | + }catch (NotCallableException $e){ |
|
| 258 | 258 | throw new ContainerException( |
| 259 | 259 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 260 | 260 | $e->getCode(), |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | private function resolveWeakReference( |
| 269 | 269 | Config\WeakReference $binding, |
| 270 | 270 | string $alias, |
| 271 | - Stringable|string|null $context, |
|
| 271 | + Stringable | string | null $context, |
|
| 272 | 272 | array $arguments, |
| 273 | 273 | ): ?object { |
| 274 | 274 | $avoidCache = $arguments !== []; |
| 275 | 275 | |
| 276 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 277 | - try { |
|
| 276 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
| 277 | + try{ |
|
| 278 | 278 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 279 | 279 | |
| 280 | 280 | $object = $this->createInstance( |
| 281 | 281 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 282 | 282 | $arguments, |
| 283 | 283 | ); |
| 284 | - if ($avoidCache) { |
|
| 284 | + if ($avoidCache){ |
|
| 285 | 285 | return $object; |
| 286 | 286 | } |
| 287 | 287 | $binding->reference = WeakReference::create($object); |
| 288 | - } catch (\Throwable) { |
|
| 288 | + }catch (\Throwable){ |
|
| 289 | 289 | throw new ContainerException( |
| 290 | 290 | $this->tracer->combineTraceMessage( |
| 291 | 291 | \sprintf( |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | ) |
| 296 | 296 | ) |
| 297 | 297 | ); |
| 298 | - } finally { |
|
| 298 | + }finally{ |
|
| 299 | 299 | $this->tracer->pop(); |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -306,23 +306,23 @@ discard block |
||
| 306 | 306 | private function resolveWithoutBinding( |
| 307 | 307 | string $alias, |
| 308 | 308 | array $parameters = [], |
| 309 | - Stringable|string|null $context = null |
|
| 309 | + Stringable | string | null $context = null |
|
| 310 | 310 | ): mixed { |
| 311 | 311 | $parent = $this->scope->getParentFactory(); |
| 312 | 312 | |
| 313 | - if ($parent !== null) { |
|
| 314 | - try { |
|
| 313 | + if ($parent !== null){ |
|
| 314 | + try{ |
|
| 315 | 315 | $this->tracer->push(false, ...[ |
| 316 | 316 | 'current scope' => $this->scope->getScopeName(), |
| 317 | 317 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 318 | 318 | ]); |
| 319 | 319 | /** @psalm-suppress TooManyArguments */ |
| 320 | 320 | return $parent->make($alias, $parameters, $context); |
| 321 | - } catch (BadScopeException $e) { |
|
| 322 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 321 | + }catch (BadScopeException $e){ |
|
| 322 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
| 323 | 323 | throw $e; |
| 324 | 324 | } |
| 325 | - } catch (ContainerExceptionInterface $e) { |
|
| 325 | + }catch (ContainerExceptionInterface $e){ |
|
| 326 | 326 | $className = match (true) { |
| 327 | 327 | $e instanceof NotFoundException => NotFoundException::class, |
| 328 | 328 | default => ContainerException::class, |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | 'Can\'t resolve `%s`.', |
| 332 | 332 | $alias, |
| 333 | 333 | )), previous: $e); |
| 334 | - } finally { |
|
| 334 | + }finally{ |
|
| 335 | 335 | $this->tracer->pop(false); |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 340 | - try { |
|
| 340 | + try{ |
|
| 341 | 341 | //No direct instructions how to construct class, make is automatically |
| 342 | 342 | return $this->autowire( |
| 343 | 343 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 344 | 344 | $parameters, |
| 345 | 345 | ); |
| 346 | - } finally { |
|
| 346 | + }finally{ |
|
| 347 | 347 | $this->tracer->pop(false); |
| 348 | 348 | } |
| 349 | 349 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | && |
| 365 | 365 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
| 366 | 366 | )) |
| 367 | - ) { |
|
| 367 | + ){ |
|
| 368 | 368 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
| 369 | 369 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
| 370 | 370 | $this->tracer->getRootAlias(), |
@@ -390,13 +390,13 @@ discard block |
||
| 390 | 390 | Ctx $ctx, |
| 391 | 391 | array $arguments, |
| 392 | 392 | ): object { |
| 393 | - if ($this->options->checkScope) { |
|
| 393 | + if ($this->options->checkScope){ |
|
| 394 | 394 | // Check scope name |
| 395 | 395 | $ctx->reflection = new \ReflectionClass($instance); |
| 396 | 396 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 397 | - if ($scopeName !== null) { |
|
| 397 | + if ($scopeName !== null){ |
|
| 398 | 398 | $scope = $this->scope; |
| 399 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 399 | + while ($scope->getScopeName() !== $scopeName){ |
|
| 400 | 400 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -425,26 +425,26 @@ discard block |
||
| 425 | 425 | array $arguments, |
| 426 | 426 | ): object { |
| 427 | 427 | $class = $ctx->class; |
| 428 | - try { |
|
| 428 | + try{ |
|
| 429 | 429 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 430 | - } catch (\ReflectionException $e) { |
|
| 430 | + }catch (\ReflectionException $e){ |
|
| 431 | 431 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // Check scope name |
| 435 | - if ($this->options->checkScope) { |
|
| 435 | + if ($this->options->checkScope){ |
|
| 436 | 436 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 437 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 437 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
| 438 | 438 | throw new BadScopeException($scope, $class); |
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // We have to construct class using external injector when we know the exact context |
| 443 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 443 | + if ($arguments === [] && $this->binder->hasInjector($class)){ |
|
| 444 | 444 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if (!$reflection->isInstantiable()) { |
|
| 447 | + if (!$reflection->isInstantiable()){ |
|
| 448 | 448 | $itIs = match (true) { |
| 449 | 449 | $reflection->isEnum() => 'Enum', |
| 450 | 450 | $reflection->isAbstract() => 'Abstract class', |
@@ -457,12 +457,12 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | $constructor = $reflection->getConstructor(); |
| 459 | 459 | |
| 460 | - if ($constructor !== null) { |
|
| 461 | - try { |
|
| 460 | + if ($constructor !== null){ |
|
| 461 | + try{ |
|
| 462 | 462 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 463 | 463 | $this->tracer->push(true); |
| 464 | 464 | $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments); |
| 465 | - } catch (ValidationException $e) { |
|
| 465 | + }catch (ValidationException $e){ |
|
| 466 | 466 | throw new ContainerException( |
| 467 | 467 | $this->tracer->combineTraceMessage( |
| 468 | 468 | \sprintf( |
@@ -472,22 +472,22 @@ discard block |
||
| 472 | 472 | ) |
| 473 | 473 | ), |
| 474 | 474 | ); |
| 475 | - } finally { |
|
| 475 | + }finally{ |
|
| 476 | 476 | $this->tracer->pop(true); |
| 477 | 477 | $this->tracer->pop(false); |
| 478 | 478 | } |
| 479 | - try { |
|
| 479 | + try{ |
|
| 480 | 480 | // Using constructor with resolved arguments |
| 481 | 481 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 482 | 482 | $this->tracer->push(true); |
| 483 | 483 | $instance = new $class(...$args); |
| 484 | - } catch (\TypeError $e) { |
|
| 484 | + }catch (\TypeError $e){ |
|
| 485 | 485 | throw new WrongTypeException($constructor, $e); |
| 486 | - } finally { |
|
| 486 | + }finally{ |
|
| 487 | 487 | $this->tracer->pop(true); |
| 488 | 488 | $this->tracer->pop(false); |
| 489 | 489 | } |
| 490 | - } else { |
|
| 490 | + }else{ |
|
| 491 | 491 | // No constructor specified |
| 492 | 492 | $instance = $reflection->newInstance(); |
| 493 | 493 | } |
@@ -505,13 +505,13 @@ discard block |
||
| 505 | 505 | $instance = $this->runInflector($instance); |
| 506 | 506 | |
| 507 | 507 | //Declarative singletons |
| 508 | - if ($this->isSingleton($ctx)) { |
|
| 508 | + if ($this->isSingleton($ctx)){ |
|
| 509 | 509 | $this->state->singletons[$ctx->alias] = $instance; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | // Register finalizer |
| 513 | 513 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 514 | - if ($finalizer !== null) { |
|
| 514 | + if ($finalizer !== null){ |
|
| 515 | 515 | $this->state->finalizers[] = $finalizer; |
| 516 | 516 | } |
| 517 | 517 | |
@@ -523,12 +523,12 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | private function isSingleton(Ctx $ctx): bool |
| 525 | 525 | { |
| 526 | - if ($ctx->singleton === true) { |
|
| 526 | + if ($ctx->singleton === true){ |
|
| 527 | 527 | return true; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 531 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 531 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
| 532 | 532 | return true; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @var Attribute\Finalize|null $attribute |
| 543 | 543 | */ |
| 544 | 544 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
| 545 | - if ($attribute === null) { |
|
| 545 | + if ($attribute === null){ |
|
| 546 | 546 | return null; |
| 547 | 547 | } |
| 548 | 548 | |
@@ -556,10 +556,10 @@ discard block |
||
| 556 | 556 | { |
| 557 | 557 | $scope = $this->scope; |
| 558 | 558 | |
| 559 | - while ($scope !== null) { |
|
| 560 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 561 | - if ($instance instanceof $class) { |
|
| 562 | - foreach ($inflectors as $inflector) { |
|
| 559 | + while ($scope !== null){ |
|
| 560 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
| 561 | + if ($instance instanceof $class){ |
|
| 562 | + foreach ($inflectors as $inflector){ |
|
| 563 | 563 | $instance = $inflector->getParametersCount() > 1 |
| 564 | 564 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 565 | 565 | : ($inflector->inflector)($instance); |
@@ -575,9 +575,9 @@ discard block |
||
| 575 | 575 | |
| 576 | 576 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 577 | 577 | { |
| 578 | - try { |
|
| 578 | + try{ |
|
| 579 | 579 | $this->resolver->validateArguments($reflection, $arguments); |
| 580 | - } catch (\Throwable) { |
|
| 580 | + }catch (\Throwable){ |
|
| 581 | 581 | return false; |
| 582 | 582 | } |
| 583 | 583 | |
@@ -77,17 +77,20 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
| 79 | 79 | { |
| 80 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 80 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
| 81 | + { |
|
| 81 | 82 | return $this->state->singletons[$alias]; |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | 85 | $binding = $this->state->bindings[$alias] ?? null; |
| 85 | 86 | |
| 86 | - if ($binding === null) { |
|
| 87 | + if ($binding === null) |
|
| 88 | + { |
|
| 87 | 89 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 88 | 90 | } |
| 89 | 91 | |
| 90 | - try { |
|
| 92 | + try |
|
| 93 | + { |
|
| 91 | 94 | $this->tracer->push( |
| 92 | 95 | false, |
| 93 | 96 | action: 'resolve from binding', |
@@ -117,7 +120,9 @@ discard block |
||
| 117 | 120 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 118 | 121 | default => $binding, |
| 119 | 122 | }; |
| 120 | - } finally { |
|
| 123 | + } |
|
| 124 | + finally |
|
| 125 | + { |
|
| 121 | 126 | $this->state->bindings[$alias] ??= $binding; |
| 122 | 127 | $this->tracer->pop(true); |
| 123 | 128 | $this->tracer->pop(false); |
@@ -131,18 +136,23 @@ discard block |
||
| 131 | 136 | private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments) |
| 132 | 137 | { |
| 133 | 138 | $context = $ctx->context; |
| 134 | - try { |
|
| 139 | + try |
|
| 140 | + { |
|
| 135 | 141 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 136 | - } catch (\ReflectionException $e) { |
|
| 142 | + } |
|
| 143 | + catch (\ReflectionException $e) |
|
| 144 | + { |
|
| 137 | 145 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 138 | 146 | } |
| 139 | 147 | |
| 140 | 148 | $injector = $binding->injector; |
| 141 | 149 | |
| 142 | - try { |
|
| 150 | + try |
|
| 151 | + { |
|
| 143 | 152 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 144 | 153 | |
| 145 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 154 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 155 | + { |
|
| 146 | 156 | throw new InjectionException( |
| 147 | 157 | \sprintf( |
| 148 | 158 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -169,7 +179,8 @@ discard block |
||
| 169 | 179 | default => (string)$context, |
| 170 | 180 | }); |
| 171 | 181 | |
| 172 | - if (!$reflection->isInstance($instance)) { |
|
| 182 | + if (!$reflection->isInstance($instance)) |
|
| 183 | + { |
|
| 173 | 184 | throw new InjectionException( |
| 174 | 185 | \sprintf( |
| 175 | 186 | "Invalid injection response for '%s'.", |
@@ -179,7 +190,9 @@ discard block |
||
| 179 | 190 | } |
| 180 | 191 | |
| 181 | 192 | return $instance; |
| 182 | - } finally { |
|
| 193 | + } |
|
| 194 | + finally |
|
| 195 | + { |
|
| 183 | 196 | $this->state->bindings[$ctx->class] ??= $binding; |
| 184 | 197 | } |
| 185 | 198 | } |
@@ -198,7 +211,8 @@ discard block |
||
| 198 | 211 | //Binding is pointing to something else |
| 199 | 212 | : $this->make($binding->alias, $arguments, $context); |
| 200 | 213 | |
| 201 | - if ($binding->singleton && $arguments === []) { |
|
| 214 | + if ($binding->singleton && $arguments === []) |
|
| 215 | + { |
|
| 202 | 216 | $this->state->singletons[$alias] = $result; |
| 203 | 217 | } |
| 204 | 218 | |
@@ -209,7 +223,8 @@ discard block |
||
| 209 | 223 | { |
| 210 | 224 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 211 | 225 | |
| 212 | - if ($binding->singleton) { |
|
| 226 | + if ($binding->singleton) |
|
| 227 | + { |
|
| 213 | 228 | $this->state->singletons[$alias] = $result; |
| 214 | 229 | } |
| 215 | 230 | |
@@ -250,11 +265,14 @@ discard block |
||
| 250 | 265 | array $arguments, |
| 251 | 266 | ): mixed { |
| 252 | 267 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 253 | - try { |
|
| 268 | + try |
|
| 269 | + { |
|
| 254 | 270 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 255 | 271 | ? ($binding->factory)() |
| 256 | 272 | : $this->invoker->invoke($binding->factory, $arguments); |
| 257 | - } catch (NotCallableException $e) { |
|
| 273 | + } |
|
| 274 | + catch (NotCallableException $e) |
|
| 275 | + { |
|
| 258 | 276 | throw new ContainerException( |
| 259 | 277 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 260 | 278 | $e->getCode(), |
@@ -273,19 +291,24 @@ discard block |
||
| 273 | 291 | ): ?object { |
| 274 | 292 | $avoidCache = $arguments !== []; |
| 275 | 293 | |
| 276 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 277 | - try { |
|
| 294 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
| 295 | + { |
|
| 296 | + try |
|
| 297 | + { |
|
| 278 | 298 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 279 | 299 | |
| 280 | 300 | $object = $this->createInstance( |
| 281 | 301 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 282 | 302 | $arguments, |
| 283 | 303 | ); |
| 284 | - if ($avoidCache) { |
|
| 304 | + if ($avoidCache) |
|
| 305 | + { |
|
| 285 | 306 | return $object; |
| 286 | 307 | } |
| 287 | 308 | $binding->reference = WeakReference::create($object); |
| 288 | - } catch (\Throwable) { |
|
| 309 | + } |
|
| 310 | + catch (\Throwable) |
|
| 311 | + { |
|
| 289 | 312 | throw new ContainerException( |
| 290 | 313 | $this->tracer->combineTraceMessage( |
| 291 | 314 | \sprintf( |
@@ -295,7 +318,9 @@ discard block |
||
| 295 | 318 | ) |
| 296 | 319 | ) |
| 297 | 320 | ); |
| 298 | - } finally { |
|
| 321 | + } |
|
| 322 | + finally |
|
| 323 | + { |
|
| 299 | 324 | $this->tracer->pop(); |
| 300 | 325 | } |
| 301 | 326 | } |
@@ -310,19 +335,26 @@ discard block |
||
| 310 | 335 | ): mixed { |
| 311 | 336 | $parent = $this->scope->getParentFactory(); |
| 312 | 337 | |
| 313 | - if ($parent !== null) { |
|
| 314 | - try { |
|
| 338 | + if ($parent !== null) |
|
| 339 | + { |
|
| 340 | + try |
|
| 341 | + { |
|
| 315 | 342 | $this->tracer->push(false, ...[ |
| 316 | 343 | 'current scope' => $this->scope->getScopeName(), |
| 317 | 344 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 318 | 345 | ]); |
| 319 | 346 | /** @psalm-suppress TooManyArguments */ |
| 320 | 347 | return $parent->make($alias, $parameters, $context); |
| 321 | - } catch (BadScopeException $e) { |
|
| 322 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 348 | + } |
|
| 349 | + catch (BadScopeException $e) |
|
| 350 | + { |
|
| 351 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
| 352 | + { |
|
| 323 | 353 | throw $e; |
| 324 | 354 | } |
| 325 | - } catch (ContainerExceptionInterface $e) { |
|
| 355 | + } |
|
| 356 | + catch (ContainerExceptionInterface $e) |
|
| 357 | + { |
|
| 326 | 358 | $className = match (true) { |
| 327 | 359 | $e instanceof NotFoundException => NotFoundException::class, |
| 328 | 360 | default => ContainerException::class, |
@@ -331,19 +363,24 @@ discard block |
||
| 331 | 363 | 'Can\'t resolve `%s`.', |
| 332 | 364 | $alias, |
| 333 | 365 | )), previous: $e); |
| 334 | - } finally { |
|
| 366 | + } |
|
| 367 | + finally |
|
| 368 | + { |
|
| 335 | 369 | $this->tracer->pop(false); |
| 336 | 370 | } |
| 337 | 371 | } |
| 338 | 372 | |
| 339 | 373 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 340 | - try { |
|
| 374 | + try |
|
| 375 | + { |
|
| 341 | 376 | //No direct instructions how to construct class, make is automatically |
| 342 | 377 | return $this->autowire( |
| 343 | 378 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 344 | 379 | $parameters, |
| 345 | 380 | ); |
| 346 | - } finally { |
|
| 381 | + } |
|
| 382 | + finally |
|
| 383 | + { |
|
| 347 | 384 | $this->tracer->pop(false); |
| 348 | 385 | } |
| 349 | 386 | } |
@@ -390,13 +427,16 @@ discard block |
||
| 390 | 427 | Ctx $ctx, |
| 391 | 428 | array $arguments, |
| 392 | 429 | ): object { |
| 393 | - if ($this->options->checkScope) { |
|
| 430 | + if ($this->options->checkScope) |
|
| 431 | + { |
|
| 394 | 432 | // Check scope name |
| 395 | 433 | $ctx->reflection = new \ReflectionClass($instance); |
| 396 | 434 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 397 | - if ($scopeName !== null) { |
|
| 435 | + if ($scopeName !== null) |
|
| 436 | + { |
|
| 398 | 437 | $scope = $this->scope; |
| 399 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 438 | + while ($scope->getScopeName() !== $scopeName) |
|
| 439 | + { |
|
| 400 | 440 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 401 | 441 | } |
| 402 | 442 | } |
@@ -425,26 +465,33 @@ discard block |
||
| 425 | 465 | array $arguments, |
| 426 | 466 | ): object { |
| 427 | 467 | $class = $ctx->class; |
| 428 | - try { |
|
| 468 | + try |
|
| 469 | + { |
|
| 429 | 470 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 430 | - } catch (\ReflectionException $e) { |
|
| 471 | + } |
|
| 472 | + catch (\ReflectionException $e) |
|
| 473 | + { |
|
| 431 | 474 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 432 | 475 | } |
| 433 | 476 | |
| 434 | 477 | // Check scope name |
| 435 | - if ($this->options->checkScope) { |
|
| 478 | + if ($this->options->checkScope) |
|
| 479 | + { |
|
| 436 | 480 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 437 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 481 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
| 482 | + { |
|
| 438 | 483 | throw new BadScopeException($scope, $class); |
| 439 | 484 | } |
| 440 | 485 | } |
| 441 | 486 | |
| 442 | 487 | // We have to construct class using external injector when we know the exact context |
| 443 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 488 | + if ($arguments === [] && $this->binder->hasInjector($class)) |
|
| 489 | + { |
|
| 444 | 490 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 445 | 491 | } |
| 446 | 492 | |
| 447 | - if (!$reflection->isInstantiable()) { |
|
| 493 | + if (!$reflection->isInstantiable()) |
|
| 494 | + { |
|
| 448 | 495 | $itIs = match (true) { |
| 449 | 496 | $reflection->isEnum() => 'Enum', |
| 450 | 497 | $reflection->isAbstract() => 'Abstract class', |
@@ -457,12 +504,16 @@ discard block |
||
| 457 | 504 | |
| 458 | 505 | $constructor = $reflection->getConstructor(); |
| 459 | 506 | |
| 460 | - if ($constructor !== null) { |
|
| 461 | - try { |
|
| 507 | + if ($constructor !== null) |
|
| 508 | + { |
|
| 509 | + try |
|
| 510 | + { |
|
| 462 | 511 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 463 | 512 | $this->tracer->push(true); |
| 464 | 513 | $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments); |
| 465 | - } catch (ValidationException $e) { |
|
| 514 | + } |
|
| 515 | + catch (ValidationException $e) |
|
| 516 | + { |
|
| 466 | 517 | throw new ContainerException( |
| 467 | 518 | $this->tracer->combineTraceMessage( |
| 468 | 519 | \sprintf( |
@@ -472,22 +523,31 @@ discard block |
||
| 472 | 523 | ) |
| 473 | 524 | ), |
| 474 | 525 | ); |
| 475 | - } finally { |
|
| 526 | + } |
|
| 527 | + finally |
|
| 528 | + { |
|
| 476 | 529 | $this->tracer->pop(true); |
| 477 | 530 | $this->tracer->pop(false); |
| 478 | 531 | } |
| 479 | - try { |
|
| 532 | + try |
|
| 533 | + { |
|
| 480 | 534 | // Using constructor with resolved arguments |
| 481 | 535 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 482 | 536 | $this->tracer->push(true); |
| 483 | 537 | $instance = new $class(...$args); |
| 484 | - } catch (\TypeError $e) { |
|
| 538 | + } |
|
| 539 | + catch (\TypeError $e) |
|
| 540 | + { |
|
| 485 | 541 | throw new WrongTypeException($constructor, $e); |
| 486 | - } finally { |
|
| 542 | + } |
|
| 543 | + finally |
|
| 544 | + { |
|
| 487 | 545 | $this->tracer->pop(true); |
| 488 | 546 | $this->tracer->pop(false); |
| 489 | 547 | } |
| 490 | - } else { |
|
| 548 | + } |
|
| 549 | + else |
|
| 550 | + { |
|
| 491 | 551 | // No constructor specified |
| 492 | 552 | $instance = $reflection->newInstance(); |
| 493 | 553 | } |
@@ -505,13 +565,15 @@ discard block |
||
| 505 | 565 | $instance = $this->runInflector($instance); |
| 506 | 566 | |
| 507 | 567 | //Declarative singletons |
| 508 | - if ($this->isSingleton($ctx)) { |
|
| 568 | + if ($this->isSingleton($ctx)) |
|
| 569 | + { |
|
| 509 | 570 | $this->state->singletons[$ctx->alias] = $instance; |
| 510 | 571 | } |
| 511 | 572 | |
| 512 | 573 | // Register finalizer |
| 513 | 574 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 514 | - if ($finalizer !== null) { |
|
| 575 | + if ($finalizer !== null) |
|
| 576 | + { |
|
| 515 | 577 | $this->state->finalizers[] = $finalizer; |
| 516 | 578 | } |
| 517 | 579 | |
@@ -523,12 +585,14 @@ discard block |
||
| 523 | 585 | */ |
| 524 | 586 | private function isSingleton(Ctx $ctx): bool |
| 525 | 587 | { |
| 526 | - if ($ctx->singleton === true) { |
|
| 588 | + if ($ctx->singleton === true) |
|
| 589 | + { |
|
| 527 | 590 | return true; |
| 528 | 591 | } |
| 529 | 592 | |
| 530 | 593 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 531 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 594 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
| 595 | + { |
|
| 532 | 596 | return true; |
| 533 | 597 | } |
| 534 | 598 | |
@@ -542,7 +606,8 @@ discard block |
||
| 542 | 606 | * @var Attribute\Finalize|null $attribute |
| 543 | 607 | */ |
| 544 | 608 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
| 545 | - if ($attribute === null) { |
|
| 609 | + if ($attribute === null) |
|
| 610 | + { |
|
| 546 | 611 | return null; |
| 547 | 612 | } |
| 548 | 613 | |
@@ -556,10 +621,14 @@ discard block |
||
| 556 | 621 | { |
| 557 | 622 | $scope = $this->scope; |
| 558 | 623 | |
| 559 | - while ($scope !== null) { |
|
| 560 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 561 | - if ($instance instanceof $class) { |
|
| 562 | - foreach ($inflectors as $inflector) { |
|
| 624 | + while ($scope !== null) |
|
| 625 | + { |
|
| 626 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
| 627 | + { |
|
| 628 | + if ($instance instanceof $class) |
|
| 629 | + { |
|
| 630 | + foreach ($inflectors as $inflector) |
|
| 631 | + { |
|
| 563 | 632 | $instance = $inflector->getParametersCount() > 1 |
| 564 | 633 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 565 | 634 | : ($inflector->inflector)($instance); |
@@ -575,9 +644,12 @@ discard block |
||
| 575 | 644 | |
| 576 | 645 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 577 | 646 | { |
| 578 | - try { |
|
| 647 | + try |
|
| 648 | + { |
|
| 579 | 649 | $this->resolver->validateArguments($reflection, $arguments); |
| 580 | - } catch (\Throwable) { |
|
| 650 | + } |
|
| 651 | + catch (\Throwable) |
|
| 652 | + { |
|
| 581 | 653 | return false; |
| 582 | 654 | } |
| 583 | 655 | |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
| 54 | 54 | |
| 55 | 55 | private State $state; |
| 56 | - private ResolverInterface|Resolver $resolver; |
|
| 57 | - private FactoryInterface|Factory $factory; |
|
| 58 | - private ContainerInterface|Internal\Container $container; |
|
| 59 | - private BinderInterface|Binder $binder; |
|
| 60 | - private InvokerInterface|Invoker $invoker; |
|
| 56 | + private ResolverInterface | Resolver $resolver; |
|
| 57 | + private FactoryInterface | Factory $factory; |
|
| 58 | + private ContainerInterface | Internal\Container $container; |
|
| 59 | + private BinderInterface | Binder $binder; |
|
| 60 | + private InvokerInterface | Invoker $invoker; |
|
| 61 | 61 | private Internal\Scope $scope; |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function __construct( |
| 67 | 67 | private Config $config = new Config(), |
| 68 | - string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
| 68 | + string | \BackedEnum | null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
| 69 | 69 | private Options $options = new Options(), |
| 70 | - ) { |
|
| 71 | - if (\is_object($scopeName)) { |
|
| 72 | - $scopeName = (string) $scopeName->value; |
|
| 70 | + ){ |
|
| 71 | + if (\is_object($scopeName)){ |
|
| 72 | + $scopeName = (string)$scopeName->value; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $this->initServices($this, $scopeName); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @throws \Throwable |
| 124 | 124 | * @psalm-suppress TooManyArguments |
| 125 | 125 | */ |
| 126 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
| 126 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
| 127 | 127 | { |
| 128 | 128 | return ContainerScope::getContainer() === $this |
| 129 | 129 | ? $this->factory->make($alias, $parameters, $context) |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @throws \Throwable |
| 150 | 150 | * @psalm-suppress TooManyArguments |
| 151 | 151 | */ |
| 152 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
| 152 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
| 153 | 153 | { |
| 154 | 154 | return ContainerScope::getContainer() === $this |
| 155 | 155 | ? $this->container->get($id, $context) |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * If {@see string}, the default binder for the given scope will be returned. Default bindings won't affect |
| 170 | 170 | * already created Container instances except the case with the root one. |
| 171 | 171 | */ |
| 172 | - public function getBinder(string|\BackedEnum|null $scope = null): BinderInterface |
|
| 172 | + public function getBinder(string | \BackedEnum | null $scope = null): BinderInterface |
|
| 173 | 173 | { |
| 174 | - $scope = \is_object($scope) ? (string) $scope->value : $scope; |
|
| 174 | + $scope = \is_object($scope) ? (string)$scope->value : $scope; |
|
| 175 | 175 | |
| 176 | 176 | return $scope === null |
| 177 | 177 | ? $this->binder |
@@ -181,25 +181,25 @@ discard block |
||
| 181 | 181 | /** |
| 182 | 182 | * @throws \Throwable |
| 183 | 183 | */ |
| 184 | - public function runScope(Scope|array $bindings, callable $scope): mixed |
|
| 184 | + public function runScope(Scope | array $bindings, callable $scope): mixed |
|
| 185 | 185 | { |
| 186 | - if (!\is_array($bindings)) { |
|
| 186 | + if (!\is_array($bindings)){ |
|
| 187 | 187 | return $this->runIsolatedScope($bindings, $scope); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $binds = &$this->state->bindings; |
| 191 | 191 | $singletons = &$this->state->singletons; |
| 192 | 192 | $cleanup = $previous = $prevSin = []; |
| 193 | - foreach ($bindings as $alias => $resolver) { |
|
| 193 | + foreach ($bindings as $alias => $resolver){ |
|
| 194 | 194 | // Store previous bindings |
| 195 | - if (isset($binds[$alias])) { |
|
| 195 | + if (isset($binds[$alias])){ |
|
| 196 | 196 | $previous[$alias] = $binds[$alias]; |
| 197 | - } else { |
|
| 197 | + }else{ |
|
| 198 | 198 | // Store bindings to be removed |
| 199 | 199 | $cleanup[] = $alias; |
| 200 | 200 | } |
| 201 | 201 | // Store previous singletons |
| 202 | - if (isset($singletons[$alias])) { |
|
| 202 | + if (isset($singletons[$alias])){ |
|
| 203 | 203 | $prevSin[$alias] = $singletons[$alias]; |
| 204 | 204 | unset($singletons[$alias]); |
| 205 | 205 | } |
@@ -207,21 +207,21 @@ discard block |
||
| 207 | 207 | $this->binder->bind($alias, $resolver); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - try { |
|
| 210 | + try{ |
|
| 211 | 211 | return ContainerScope::getContainer() !== $this |
| 212 | 212 | ? ContainerScope::runScope($this, $scope) |
| 213 | 213 | : $scope($this); |
| 214 | - } finally { |
|
| 214 | + }finally{ |
|
| 215 | 215 | // Remove new bindings |
| 216 | - foreach ($cleanup as $alias) { |
|
| 216 | + foreach ($cleanup as $alias){ |
|
| 217 | 217 | unset($binds[$alias], $singletons[$alias]); |
| 218 | 218 | } |
| 219 | 219 | // Restore previous bindings |
| 220 | - foreach ($previous as $alias => $resolver) { |
|
| 220 | + foreach ($previous as $alias => $resolver){ |
|
| 221 | 221 | $binds[$alias] = $resolver; |
| 222 | 222 | } |
| 223 | 223 | // Restore singletons |
| 224 | - foreach ($prevSin as $alias => $instance) { |
|
| 224 | + foreach ($prevSin as $alias => $instance){ |
|
| 225 | 225 | $singletons[$alias] = $instance; |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * @param bool $force If the value is false, an exception will be thrown when attempting |
| 268 | 268 | * to bind an already constructed singleton. |
| 269 | 269 | */ |
| 270 | - public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void |
|
| 270 | + public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void |
|
| 271 | 271 | { |
| 272 | - if ($force) { |
|
| 272 | + if ($force){ |
|
| 273 | 273 | $this->binder->removeBinding($alias); |
| 274 | 274 | } |
| 275 | 275 | |
@@ -340,8 +340,8 @@ discard block |
||
| 340 | 340 | ], $this->options); |
| 341 | 341 | |
| 342 | 342 | // Create container services |
| 343 | - foreach ($container->config as $property => $class) { |
|
| 344 | - if (\property_exists($container, $property)) { |
|
| 343 | + foreach ($container->config as $property => $class){ |
|
| 344 | + if (\property_exists($container, $property)){ |
|
| 345 | 345 | $container->$property = $constructor->get($property, $class); |
| 346 | 346 | } |
| 347 | 347 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | private function closeScope(): void |
| 356 | 356 | { |
| 357 | 357 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
| 358 | - if (!isset($this->scope)) { |
|
| 358 | + if (!isset($this->scope)){ |
|
| 359 | 359 | $this->destruct(); |
| 360 | 360 | return; |
| 361 | 361 | } |
@@ -364,10 +364,10 @@ discard block |
||
| 364 | 364 | |
| 365 | 365 | // Run finalizers |
| 366 | 366 | $errors = []; |
| 367 | - foreach ($this->state->finalizers as $finalizer) { |
|
| 368 | - try { |
|
| 367 | + foreach ($this->state->finalizers as $finalizer){ |
|
| 368 | + try{ |
|
| 369 | 369 | $this->invoker->invoke($finalizer); |
| 370 | - } catch (\Throwable $e) { |
|
| 370 | + }catch (\Throwable $e){ |
|
| 371 | 371 | $errors[] = $e; |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | $this->destruct(); |
| 377 | 377 | |
| 378 | 378 | // Throw collected errors |
| 379 | - if ($errors !== []) { |
|
| 379 | + if ($errors !== []){ |
|
| 380 | 380 | throw new FinalizersException($scopeName, $errors); |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -398,18 +398,18 @@ discard block |
||
| 398 | 398 | $container->scope->setParent($this, $this->scope, $this->factory); |
| 399 | 399 | |
| 400 | 400 | // Add specific bindings |
| 401 | - foreach ($config->bindings as $alias => $resolver) { |
|
| 401 | + foreach ($config->bindings as $alias => $resolver){ |
|
| 402 | 402 | $container->binder->bind($alias, $resolver); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | return ContainerScope::runScope( |
| 406 | 406 | $container, |
| 407 | 407 | static function (self $container) use ($config, $closure): mixed { |
| 408 | - try { |
|
| 408 | + try{ |
|
| 409 | 409 | return $config->autowire |
| 410 | 410 | ? $container->invoke($closure) |
| 411 | 411 | : $closure($container); |
| 412 | - } finally { |
|
| 412 | + }finally{ |
|
| 413 | 413 | $container->closeScope(); |
| 414 | 414 | } |
| 415 | 415 | } |