Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Replace container-interop with PSR-11 container interface #187

Merged
merged 8 commits into from
Feb 11, 2018
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
2 changes: 1 addition & 1 deletion benchmarks/BenchAsset/AbstractFactoryFoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ZendBench\ServiceManager\BenchAsset;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\AbstractFactoryInterface;

class AbstractFactoryFoo implements AbstractFactoryInterface
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/BenchAsset/FactoryFoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ZendBench\ServiceManager\BenchAsset;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

class FactoryFoo implements FactoryInterface
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"require": {
"php": "^7.1",
"container-interop/container-interop": "^1.2",
"psr/container": "^1.0",
"zendframework/zend-stdlib": "^3.1"
},
Expand All @@ -34,7 +33,6 @@
"zendframework/zend-coding-standard": "~1.0.0"
},
"provide": {
"container-interop/container-interop-implementation": "^1.2",
"psr/container-implementation": "^1.0"
},
"suggest": {
Expand All @@ -55,6 +53,9 @@
"config": {
"sort-packages": true
},
"conflict": {
"container-interop/container-interop": "<1.2.0"
},
"extra": {
"branch-alias": {
"dev-master": "3.3-dev",
Expand Down
64 changes: 32 additions & 32 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/book/configuring-the-service-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $serviceManager = new ServiceManager([
As said before, a factory can also be a callable, to create more complex objects:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\ServiceManager;
use stdClass;
Expand Down Expand Up @@ -267,7 +267,7 @@ For instance, if we'd want to automatically inject the dependency
`EventManagerAwareInterface`, we could create the following initializer:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use stdClass;
use Zend\ServiceManager\ServiceManager;

Expand Down Expand Up @@ -303,7 +303,7 @@ class MyInitializer implements InitializerInterface

// When creating the service manager:

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use stdClass;
use Zend\ServiceManager\ServiceManager;

Expand Down
4 changes: 2 additions & 2 deletions docs/book/delegators.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ intercept actions being performed on the delegate in an
A delegator factory has the following signature:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;

public function __invoke(
ContainerInterface $container,
Expand Down Expand Up @@ -106,7 +106,7 @@ A simple delegator factory for the `buzzer` service can be implemented as
following:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;

class BuzzerDelegatorFactory implements DelegatorFactoryInterface
Expand Down
43 changes: 43 additions & 0 deletions docs/book/migration-v4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Migration Guide

Migration guide for Zend Service version 4.0.0.

## PSR-11: Container Interface

[`container-interop/container-interop`](https://github.com/container-interop/container-interop)
was officially deprecated in favor of [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md)
on February 13, 2017. As such, all uses of the interop-container interfaces
have been replaced with PSR-11 containers interfaces as follows:
- `Interop\Container\ContainerInterface` to `Psr\Container\ContainerInterface`,
- `Interop\Container\Exception\ContainerException` to `Psr\Container\ContainerExceptionInterface`,
- `Interop\Container\Exception\NotFoundException` to `Psr\Container\NotFoundExceptionInterface`.

Further, installs of `container-interop/container-interop` below version `1.2.0`
is prohibited via Composer's `conflicts` configuration. Version `1.2.0` _does_
extend the PSR-11 interfaces, and is thus still usable.

If your project typehints any `Interop\ContainerInterop\*` interfaces where any
`Zend\ServiceManager\*` classes are expected, you _**must**_ update your code to
expect `Zend\ServiceManager\*` or `Psr\Container\*` classes or interfaces instead.
The latter is preferred, unless your code utilizes any additional functionality
provided by the `Zend\ServiceManager\*` classes that are not declared in the
PSR-11 interfaces.

To do this, use your favorite find-and-replace tool to update the following:
- `use Interop\Container\ContainerInterface;` -> `use Psr\Container\ContainerInterface;`
- `use Interop\Container\Exception\ContainerException;` -> `use Psr\Container\ContainerExceptionInterface;`
- `use Interop\Container\Exception\NotFoundException;` -> `use Psr\Container\NotFoundExceptionInterface;`
- **Note:** You will also need to replace `ContainerException` with `ContainerExceptionInterface`
and `NotFoundException` with `NotFoundExceptionInterface` where it is used
throughout your code. If you _don't_ want to do that, you can include
`as ContainerException`/`as NotFoundException` in the find-and-replace,
and any existing use of `ContainerException`/`NotFoundException` will
continue to work.

> ### Note
>
> If you use fully-qualified class names in your typehints, rather than taking
> advantage of `use` statements, you will need to run additional find-and-replace
> commands to update those class paths within your code. The exact finds and
> replaces to run for those scenarios are not covered in this migration guide, as
> they can vary greatly and are not a generally recommended practice.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration process is very basic, but I think it would be nice to have migration tool. I think it could be done later on, so I'd like to leave just a note for that. Unless you have another idea?

I think delivering migration tools will help to migrate quicker to newer version.

18 changes: 9 additions & 9 deletions docs/book/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ $container->mapLazyService('MyClass');
## ServiceLocatorInterface Changes

The `ServiceLocatorInterface` now extends the
[container-interop](https://github.com/container-interop/container-interop)
[Psr\Container\ContainerInterface](https://github.com/php-fig/container)
interface `ContainerInterface`, which defines the same `get()` and `has()`
methods as were previously defined.

Expand Down Expand Up @@ -436,7 +436,7 @@ To update this for version 3 compatibility, you will add the methods
them, and update the existing methods to proxy to the new methods:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand Down Expand Up @@ -474,7 +474,7 @@ the migration artifacts:
From our example above, we would update the class to read as follows:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\AbstractFactoryInterface; // <-- note the change!

class LenientAbstractFactory implements AbstractFactoryInterface
Expand Down Expand Up @@ -562,7 +562,7 @@ To prepare this for version 3, we'd implement the `__invoke()` signature from
version 3, and modify `createDelegatorWithName()` to proxy to it:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\DelegatorFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand Down Expand Up @@ -591,7 +591,7 @@ the migration artifacts:
From our example above, we would update the class to read as follows:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\DelegatorFactoryInterface; // <-- note the change!

class ObserverAttachmentDelegator implements DelegatorFactoryInterface
Expand Down Expand Up @@ -674,7 +674,7 @@ To prepare this for version 3, we'd implement the `__invoke()` signature from
version 3, and modify `createService()` to proxy to it:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand Down Expand Up @@ -706,7 +706,7 @@ the migration artifacts:
From our example above, we would update the class to read as follows:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface; // <-- note the change!

class FooFactory implements FactoryInterface
Expand Down Expand Up @@ -808,7 +808,7 @@ To prepare this for version 3, we'd implement the `__invoke()` signature from
version 3, and modify `initialize()` to proxy to it:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\InitializerInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand Down Expand Up @@ -839,7 +839,7 @@ the migration artifacts:
From our example above, we would update the class to read as follows:

```php
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Zend\ServiceManager\Initializer\InitializerInterface; // <-- note the change!

class FooInitializer implements InitializerInterface
Expand Down
58 changes: 0 additions & 58 deletions docs/book/psr-11.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/book/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The Service Manager is a modern, fast, and easy-to-use implementation of the
[Service Locator design pattern](https://en.wikipedia.org/wiki/Service_locator_pattern).
The implementation implements the
[Container Interop](https://github.com/container-interop/container-interop)
[Psr\Container\ContainerInterface](https://github.com/psr/container)
interfaces, providing interoperability with other implementations.

The following is a "quick start" tutorial intended to get you up and running
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pages:
- index.md
- 'Quick Start': quick-start.md
- Reference:
- 'PSR-11 Support': psr-11.md
- 'Configuring the service manager': configuring-the-service-manager.md
- Delegators: delegators.md
- 'Lazy services': lazy-services.md
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractFactory/ConfigAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ConfigAbstractFactory implements AbstractFactoryInterface
*
* {@inheritdoc}
*/
public function canCreate(\Interop\Container\ContainerInterface $container, $requestedName)
public function canCreate(\Psr\Container\ContainerInterface $container, $requestedName)
{
if (! $container->has('config') || ! array_key_exists(self::class, $container->get('config'))) {
return false;
Expand All @@ -38,7 +38,7 @@ public function canCreate(\Interop\Container\ContainerInterface $container, $req
/**
* {@inheritDoc}
*/
public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(\Psr\Container\ContainerInterface $container, $requestedName, array $options = null)
{
if (! $container->has('config')) {
throw new ServiceNotCreatedException('Cannot find a config array in the container');
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractFactory/ReflectionBasedAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Zend\ServiceManager\AbstractFactory;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use ReflectionClass;
use ReflectionParameter;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
Expand Down
Loading