https://github.com/phly/zend-servicemanager-interop
Inject zend-servicemanager with results from service-provider instances.
https://github.com/phly/zend-servicemanager-interop
Last synced: 6 months ago
JSON representation
Inject zend-servicemanager with results from service-provider instances.
- Host: GitHub
- URL: https://github.com/phly/zend-servicemanager-interop
- Owner: phly
- License: bsd-2-clause
- Created: 2016-04-19T17:46:21.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-19T17:56:22.000Z (about 10 years ago)
- Last Synced: 2025-01-19T13:49:59.616Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# servicemanager-interop
> :warning: **Archived 2025-08-17**
>
> Use at your own risk.
[](https://secure.travis-ci.org/phly/zend-servicemanager-interop)
[](https://coveralls.io/github/phly/zend-servicemanager-interop?branch=master)
Use [container-interop service providers](https://github.com/container-interop/service-provider/)
with [zend-servicemanager](https://zendframework.github.io/zend-servicemanager/).
## Installation
```console
$ composer require phly/zend-servicemanager-interop
```
## Usage
```php
use Zend\ServiceManager\Interop\ConfigInjector;
use Zend\ServiceManager\Interop\ProviderAggregate;
use Zend\ServiceManager\ServiceManager;
// Get a list of service provider classes and aggregate them:
$aggregate = new ProviderAggregate();
foreach (include 'providers.php' as $provider) {
$aggregate->enqueue($provider);
}
// Create and inject a service manager with the providers:
$container = (new ConfigInjector())->inject($aggregate, new ServiceManager());
```
## Internals
- `ProviderAggregate` allows passing either a class name of a provider, or an
instance. Internally, it creates instances from class names to ensure that
dequeued items are known-good types.
- `ConfigInjector` will create a closure around factories, to curry arguments
and ensure the factories have no conflicts with how zend-servicemanager
invokes them.
- `ConfigInjector` adds factories as delegators if the service is already
present in the zend-servicemanager instance. Again, the factory is wrapped in
a closure in order to curry arguments in the correct order.
## Differences from service-provider
This implementation experiments a bit and allows the following as factory
arguments:
- any valid PHP callable
- FQCN arguments that resolve to functors