diff --git a/README.md b/README.md index 19adfe5..6454835 100644 --- a/README.md +++ b/README.md @@ -164,12 +164,12 @@ Rather than have you re-implement support for dependency injection with differen In this example it will `->get('twig')` from the container and inject it. -These resolvers can work with any dependency injection container compliant with [container-interop](https://github.com/container-interop/container-interop). If you container is not compliant you can use the [Acclimate](https://github.com/jeremeamia/acclimate-container) package. +These resolvers can work with any dependency injection container compliant with [PSR-11](http://www.php-fig.org/psr/psr-11/). Setting up those resolvers is simple: ```php -// $container must be an instance of Interop\Container\ContainerInterface +// $container must be an instance of Psr\Container\ContainerInterface $container = ... $containerResolver = new TypeHintContainerResolver($container); @@ -231,4 +231,4 @@ $invoker->call('WelcomeController::home'); That feature can be used as the base building block for a framework's dispatcher. -Again, any [container-interop](https://github.com/container-interop/container-interop) compliant container can be provided, and [Acclimate](https://github.com/jeremeamia/acclimate-container) can be used for incompatible containers. +Again, any [PSR-11](http://www.php-fig.org/psr/psr-11/) compliant container can be provided. diff --git a/composer.json b/composer.json index 3f0c041..36b9f0b 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } }, "require": { - "container-interop/container-interop": "~1.1" + "psr/container": "~1.0" }, "require-dev": { "phpunit/phpunit": "~4.5", diff --git a/src/CallableResolver.php b/src/CallableResolver.php index 463b49f..61dc28f 100644 --- a/src/CallableResolver.php +++ b/src/CallableResolver.php @@ -2,9 +2,9 @@ namespace Invoker; -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\NotFoundException; use Invoker\Exception\NotCallableException; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Resolves a callable from a container. @@ -73,7 +73,10 @@ private function resolveFromContainer($callable) if (is_string($callable)) { try { return $this->container->get($callable); - } catch (NotFoundException $e) { + } catch (NotFoundExceptionInterface $e) { + if ($this->container->has($callable)) { + throw $e; + } throw NotCallableException::fromInvalidCallable($callable, true); } } @@ -85,7 +88,10 @@ private function resolveFromContainer($callable) // Replace the container entry name by the actual object $callable[0] = $this->container->get($callable[0]); return $callable; - } catch (NotFoundException $e) { + } catch (NotFoundExceptionInterface $e) { + if ($this->container->has($callable[0])) { + throw $e; + } if ($isStaticCallToNonStaticMethod) { throw new NotCallableException(sprintf( 'Cannot call %s::%s() because %s() is not a static method and "%s" is not a container entry', diff --git a/src/Invoker.php b/src/Invoker.php index ffdcd0b..6238157 100644 --- a/src/Invoker.php +++ b/src/Invoker.php @@ -2,7 +2,6 @@ namespace Invoker; -use Interop\Container\ContainerInterface; use Invoker\Exception\NotCallableException; use Invoker\Exception\NotEnoughParametersException; use Invoker\ParameterResolver\AssociativeArrayResolver; @@ -11,6 +10,7 @@ use Invoker\ParameterResolver\ParameterResolver; use Invoker\ParameterResolver\ResolverChain; use Invoker\Reflection\CallableReflection; +use Psr\Container\ContainerInterface; /** * Invoke a callable. diff --git a/src/ParameterResolver/Container/ParameterNameContainerResolver.php b/src/ParameterResolver/Container/ParameterNameContainerResolver.php index 983dea4..1259327 100644 --- a/src/ParameterResolver/Container/ParameterNameContainerResolver.php +++ b/src/ParameterResolver/Container/ParameterNameContainerResolver.php @@ -2,8 +2,8 @@ namespace Invoker\ParameterResolver\Container; -use Interop\Container\ContainerInterface; use Invoker\ParameterResolver\ParameterResolver; +use Psr\Container\ContainerInterface; use ReflectionFunctionAbstract; /** diff --git a/src/ParameterResolver/Container/TypeHintContainerResolver.php b/src/ParameterResolver/Container/TypeHintContainerResolver.php index 65a4079..3a6b0d8 100644 --- a/src/ParameterResolver/Container/TypeHintContainerResolver.php +++ b/src/ParameterResolver/Container/TypeHintContainerResolver.php @@ -2,8 +2,8 @@ namespace Invoker\ParameterResolver\Container; -use Interop\Container\ContainerInterface; use Invoker\ParameterResolver\ParameterResolver; +use Psr\Container\ContainerInterface; use ReflectionFunctionAbstract; /** diff --git a/tests/Mock/ArrayContainer.php b/tests/Mock/ArrayContainer.php index 8524183..cda7a69 100644 --- a/tests/Mock/ArrayContainer.php +++ b/tests/Mock/ArrayContainer.php @@ -2,7 +2,7 @@ namespace Invoker\Test\Mock; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; /** * Simple container. diff --git a/tests/Mock/NotFound.php b/tests/Mock/NotFound.php index a7acab4..142cee1 100644 --- a/tests/Mock/NotFound.php +++ b/tests/Mock/NotFound.php @@ -3,8 +3,8 @@ namespace Invoker\Test\Mock; -use Interop\Container\Exception\NotFoundException; +use Psr\Container\NotFoundExceptionInterface; -class NotFound extends \Exception implements NotFoundException +class NotFound extends \Exception implements NotFoundExceptionInterface { }