library zend-servicemanager-interop
Providing service-provider compilation for zend-servicemanager
phly/zend-servicemanager-interop
Providing service-provider compilation for zend-servicemanager
- Tuesday, April 19, 2016
- by weierophinney
- Repository
- 4 Watchers
- 0 Stars
- 3 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
servicemanager-interop
, (*1)
Use container-interop service providers
with zend-servicemanager., (*2)
Installation
$ composer require phly/zend-servicemanager-interop
Usage
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:, (*3)
- any valid PHP callable
- FQCN arguments that resolve to functors