Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to PSR-11 #15

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"require": {
"container-interop/container-interop": "~1.1"
"psr/container": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
Expand Down
14 changes: 10 additions & 4 deletions src/CallableResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/Invoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Invoker;

use Interop\Container\ContainerInterface;
use Invoker\Exception\NotCallableException;
use Invoker\Exception\NotEnoughParametersException;
use Invoker\ParameterResolver\AssociativeArrayResolver;
Expand All @@ -11,6 +10,7 @@
use Invoker\ParameterResolver\ParameterResolver;
use Invoker\ParameterResolver\ResolverChain;
use Invoker\Reflection\CallableReflection;
use Psr\Container\ContainerInterface;

/**
* Invoke a callable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Invoker\ParameterResolver\Container;

use Interop\Container\ContainerInterface;
use Invoker\ParameterResolver\ParameterResolver;
use Psr\Container\ContainerInterface;
use ReflectionFunctionAbstract;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Invoker\ParameterResolver\Container;

use Interop\Container\ContainerInterface;
use Invoker\ParameterResolver\ParameterResolver;
use Psr\Container\ContainerInterface;
use ReflectionFunctionAbstract;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Mock/ArrayContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Invoker\Test\Mock;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;

/**
* Simple container.
Expand Down
4 changes: 2 additions & 2 deletions tests/Mock/NotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}