Download the PHP package elie29/zend-phpdi-config without Composer
On this page you can find all versions of the php package elie29/zend-phpdi-config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elie29/zend-phpdi-config
More information about elie29/zend-phpdi-config
Files in elie29/zend-phpdi-config
Package zend-phpdi-config
Short Description PSR-11 PHP-DI autowire container configurator for Laminas, Mezzio, ZF2, ZF3 and Zend Expressive applications
License MIT
Informations about the package zend-phpdi-config
zend-phpdi-config
Introduction
zend-phpdi-config acts as a bridge to configure a PSR-11 compatible PHP-DI container using service manager configuration. It can be used with Laminas and Mezzio starting from v6.0.0
This library uses autowiring technique, cache compilation and cache definitions as defined in PHP-DI.
Configuration
To get a configured PSR-11 PHP-DI container, do the following:
The dependencies
sub associative array can contain the following keys:
services
: an associative array that maps a key to a specific service instance or service name.invokables
: an associative array that map a key to a constructor-less service; i.e., for services that do not require arguments to the constructor. The key and service name usually are the same; if they are not, the key is treated as an alias. It could also be an array of services.autowires
: an array of service with or without a constructor; PHP-DI offers an autowire technique that will scan the code and see what are the parameters needed in the constructors. Any aliases needed should be created in the aliases configuration.factories
: an associative array that maps a service name to a factory class name, or any callable. Factory classes must be instantiable without arguments, and callable once instantiated (i.e., implement the__invoke()
method).aliases
: an associative array that maps an alias to a service name (or another alias).delegators
: an associative array that maps service names to lists of delegator factory keys, see the Expressive delegators documentation for more details.
N.B.: The whole configuration -- unless
dependencies
-- is merged in aconfig
key within the$container
:
CLI command to add a new autowire entry
The cli command add-autowires-entry
creates the configuration file if it doesn't exist otherwise it adds the entry
to the autowires key.
Example of adding ConsoleHelper to a config.php:
Using with Expressive
Replace contents of config/container.php
with the following:
Example of a ConfigProvider class
Where UserManager depends on Mailer as follow:
Switching back to another container
To switch back to another container is very easy:
- Create your factories with
__invoke
function - Replace
autowires
key in ConfigProvider byfactories
key, then for each class name attach its correspondent factory.
PSR 11 and Interop\Container\ContainerInterface
V4.x supports as well Interop\Container\ContainerInterface
Migration guides
- Migration from 3.x to 4.0
- Migration from 4.x to 5.0: container-interop/container-interop was dropped in favor of PSR-11.