Skip to content

Commit d88dfa2

Browse files
committed
fix(container): use ContainerExceptionInterface for non-NotFound errors
PSR-11 requires get() to throw ContainerExceptionInterface for general errors. Apply the same anonymous-class pattern already used for NotFoundExceptionInterface to factory, delegator, and circular-alias error paths.
1 parent 82f39d7 commit d88dfa2

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/Container/SimpleContainer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use function is_callable;
1010
use function is_int;
1111
use function is_string;
12+
use Psr\Container\ContainerExceptionInterface;
1213
use Psr\Container\ContainerInterface;
1314
use Psr\Container\NotFoundExceptionInterface;
1415
use RuntimeException;
@@ -50,7 +51,7 @@ public function get(string $id): mixed
5051
}
5152

5253
if (!is_callable($factory)) {
53-
throw new RuntimeException("Factory for '{$resolved}' is not callable.");
54+
throw new class("Factory for '{$resolved}' is not callable.") extends RuntimeException implements ContainerExceptionInterface {};
5455
}
5556

5657
$instance = $factory($this, $resolved);
@@ -64,7 +65,7 @@ public function get(string $id): mixed
6465
}
6566

6667
if (!is_callable($delegator)) {
67-
throw new RuntimeException("Delegator for '{$resolved}' is not callable.");
68+
throw new class("Delegator for '{$resolved}' is not callable.") extends RuntimeException implements ContainerExceptionInterface {};
6869
}
6970

7071
$instance = $delegator($this, $resolved, static fn (): mixed => $current);
@@ -148,7 +149,7 @@ private function resolveAlias(string $id): string
148149

149150
while (isset($this->aliases[$id])) {
150151
if (isset($seen[$id])) {
151-
throw new RuntimeException("Circular alias detected for '{$id}'.");
152+
throw new class("Circular alias detected for '{$id}'.") extends RuntimeException implements ContainerExceptionInterface {};
152153
}
153154

154155
$seen[$id] = true;

0 commit comments

Comments
 (0)