|
| 1 | +# PSR-11 Support |
| 2 | + |
| 3 | +[container-interop/container-interop 1.2.0](https://github.com/container-interop/container-interop/releases/tag/1.2.0) |
| 4 | +modifies its codebase to extend interfaces [psr/container](https://github.com/php-fig/container) |
| 5 | +(the official interfaces for [PSR-11](http://www.php-fig.org/psr/psr-11/)). If |
| 6 | +you are on a pre-3.3.0 version of zend-servicemanager, update your project, and |
| 7 | +receive container-interop 1.2, then zend-servicemanager can already act as a |
| 8 | +PSR-11 provider! |
| 9 | + |
| 10 | +zend-servicemanager 3.3.0 requires at least version 1.2 of container-interop, |
| 11 | +and _also_ requires psr/container 1.0 to explicitly signal that it is a PSR-11 |
| 12 | +provider, and to allow removal of the container-interop dependency later. |
| 13 | + |
| 14 | +Version 4.0 will require only psr/container, and will update the various factory |
| 15 | +interfaces and exception implementations to typehint against the PSR-11 |
| 16 | +interfaces, which will require changes to any implementations you have. In the |
| 17 | +meantime, you can [duck-type](https://en.wikipedia.org/wiki/Duck_typing) the |
| 18 | +following factory types: |
| 19 | + |
| 20 | +- `Zend\ServiceManager\Factory\FactoryInterface`: use a callable with the |
| 21 | + following signature: |
| 22 | + |
| 23 | + ```php |
| 24 | + function ( |
| 25 | + \Psr\Container\ContainerInterface $container, |
| 26 | + string $requestedName, |
| 27 | + array $options = null |
| 28 | + ) |
| 29 | + ``` |
| 30 | + |
| 31 | +- `Zend\ServiceManager\Factory\DelegatorFactoryInterface`: use a callable with |
| 32 | + the following signature: |
| 33 | + |
| 34 | + ```php |
| 35 | + function ( |
| 36 | + \Psr\Container\ContainerInterface $container, |
| 37 | + string $name, |
| 38 | + callable $callback, |
| 39 | + array $options = null |
| 40 | + ) |
| 41 | + ``` |
| 42 | + |
| 43 | +- `Zend\ServiceManager\Initializer\InitializerInterface`: use a callable with |
| 44 | + the following signature: |
| 45 | + |
| 46 | + ```php |
| 47 | + function ( |
| 48 | + \Psr\Container\ContainerInterface $container, |
| 49 | + $instance |
| 50 | + ) |
| 51 | + ``` |
| 52 | + |
| 53 | +Abstract factories _can not_ be duck typed, due to the additional `canCreate()` |
| 54 | +method. |
| 55 | + |
| 56 | +You can also leave your factories as-is for now, and update them once |
| 57 | +zend-servicemanager v4.0 is released, at which time we will be providing tooling |
| 58 | +to help migrate your factories to PSR-11. |
0 commit comments