See https://doc.nette.org/en/dependency-injection/nette-container#toc-psr-11-container
Last active
August 27, 2026 01:31
-
-
Save dg/7f02403bd36d9d1c73802a6268a4361f to your computer and use it in GitHub Desktop.
PSR-11 adapter for Nette DI Container
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey David, just wanted to let you know that this PSR-11 adapter is not correct.
First: in your
get($id)implementation, you're throwing aPsr\Container\NotFoundException. There's noPsr\Container\NotFoundExceptionin PSR-11, there's only aPsr\Container\NotFoundExceptionInterfaceinterface which — being an interface — cannot be instantiated and thrown. You have to create an exception that implements it — and throw that.Second:
get($id)has to throw an exception implementingPsr\Container\ContainerExceptionInterfaceinterface if resolving$idfails (for whatever reason) — this adapter is not doing that at all. You have to wrapreturn $this->netteContainer->getService($id);in atry...catchblock to catch any thrown exception and if that happens — throw an exception implementingPsr\Container\ContainerExceptionInterfaceinterface.It should look something like this: