Skip to content

Commit 540c27c

Browse files
authoredMar 20, 2017
Migrate to PSR-11 (#15)
1 parent eebb69d commit 540c27c

8 files changed

+20
-14
lines changed
 

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ Rather than have you re-implement support for dependency injection with differen
164164

165165
In this example it will `->get('twig')` from the container and inject it.
166166

167-
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.
167+
These resolvers can work with any dependency injection container compliant with [PSR-11](http://www.php-fig.org/psr/psr-11/).
168168

169169
Setting up those resolvers is simple:
170170

171171
```php
172-
// $container must be an instance of Interop\Container\ContainerInterface
172+
// $container must be an instance of Psr\Container\ContainerInterface
173173
$container = ...
174174

175175
$containerResolver = new TypeHintContainerResolver($container);
@@ -231,4 +231,4 @@ $invoker->call('WelcomeController::home');
231231

232232
That feature can be used as the base building block for a framework's dispatcher.
233233

234-
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.
234+
Again, any [PSR-11](http://www.php-fig.org/psr/psr-11/) compliant container can be provided.

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"require": {
19-
"container-interop/container-interop": "~1.1"
19+
"psr/container": "~1.0"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "~4.5",

‎src/CallableResolver.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Invoker;
44

5-
use Interop\Container\ContainerInterface;
6-
use Interop\Container\Exception\NotFoundException;
75
use Invoker\Exception\NotCallableException;
6+
use Psr\Container\ContainerInterface;
7+
use Psr\Container\NotFoundExceptionInterface;
88

99
/**
1010
* Resolves a callable from a container.
@@ -73,7 +73,10 @@ private function resolveFromContainer($callable)
7373
if (is_string($callable)) {
7474
try {
7575
return $this->container->get($callable);
76-
} catch (NotFoundException $e) {
76+
} catch (NotFoundExceptionInterface $e) {
77+
if ($this->container->has($callable)) {
78+
throw $e;
79+
}
7780
throw NotCallableException::fromInvalidCallable($callable, true);
7881
}
7982
}
@@ -85,7 +88,10 @@ private function resolveFromContainer($callable)
8588
// Replace the container entry name by the actual object
8689
$callable[0] = $this->container->get($callable[0]);
8790
return $callable;
88-
} catch (NotFoundException $e) {
91+
} catch (NotFoundExceptionInterface $e) {
92+
if ($this->container->has($callable[0])) {
93+
throw $e;
94+
}
8995
if ($isStaticCallToNonStaticMethod) {
9096
throw new NotCallableException(sprintf(
9197
'Cannot call %s::%s() because %s() is not a static method and "%s" is not a container entry',

‎src/Invoker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Invoker;
44

5-
use Interop\Container\ContainerInterface;
65
use Invoker\Exception\NotCallableException;
76
use Invoker\Exception\NotEnoughParametersException;
87
use Invoker\ParameterResolver\AssociativeArrayResolver;
@@ -11,6 +10,7 @@
1110
use Invoker\ParameterResolver\ParameterResolver;
1211
use Invoker\ParameterResolver\ResolverChain;
1312
use Invoker\Reflection\CallableReflection;
13+
use Psr\Container\ContainerInterface;
1414

1515
/**
1616
* Invoke a callable.

‎src/ParameterResolver/Container/ParameterNameContainerResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Invoker\ParameterResolver\Container;
44

5-
use Interop\Container\ContainerInterface;
65
use Invoker\ParameterResolver\ParameterResolver;
6+
use Psr\Container\ContainerInterface;
77
use ReflectionFunctionAbstract;
88

99
/**

‎src/ParameterResolver/Container/TypeHintContainerResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Invoker\ParameterResolver\Container;
44

5-
use Interop\Container\ContainerInterface;
65
use Invoker\ParameterResolver\ParameterResolver;
6+
use Psr\Container\ContainerInterface;
77
use ReflectionFunctionAbstract;
88

99
/**

‎tests/Mock/ArrayContainer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Invoker\Test\Mock;
44

5-
use Interop\Container\ContainerInterface;
5+
use Psr\Container\ContainerInterface;
66

77
/**
88
* Simple container.

‎tests/Mock/NotFound.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace Invoker\Test\Mock;
55

6-
use Interop\Container\Exception\NotFoundException;
6+
use Psr\Container\NotFoundExceptionInterface;
77

8-
class NotFound extends \Exception implements NotFoundException
8+
class NotFound extends \Exception implements NotFoundExceptionInterface
99
{
1010
}

0 commit comments

Comments
 (0)
Please sign in to comment.