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
๐ Quick Start
โจ Features
- ๐งฉ PSR-11 compatible container configuration
- โก Autowiring support
- ๐ Service manager compatibility (Laminas/Mezzio)
- ๐ป CLI tool for autowire entry management
- ๐๏ธ Cache and proxy support
- ๐ Easy migration from other containers
๐ Introduction
zend-phpdi-config acts as a bridge to configure a PSR-11 compatible PHP-DI container using service manager configuration.
Requirements: PHP 8.2 or higher
It can be used with Laminas and Mezzio starting from v10.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:
Configuration Keys
The dependencies configuration array supports the following keys:
-
services: Maps a service name to a specific service instance, class name, or callable.- Values can be object instances, class names, or callables
- Used for registering pre-instantiated services or simple service definitions
- See ServicesTest.php for comprehensive examples
-
invokables: Maps service names to classes with no constructor dependencies.- Can be an associative array (alias => class name) or indexed array (class names)
- When alias differs from class name, the alias is created automatically
- Classes must have no required constructor parameters
- See InvokablesTest.php for comprehensive examples
-
autowires: Array of fully qualified class names to be autowired by PHP-DI.- PHP-DI automatically resolves constructor dependencies through type-hinting
- Works with or without constructor parameters
- Create aliases separately in the
aliasesconfiguration if needed
-
factories: Maps service names to factory classes or callables.- Factory classes must implement
__invoke(ContainerInterface $container) - Can reference other registered factories by name
- Factories must return the actual service instance (object, array, scalar, etc.), not service names
- Used when service instantiation requires custom or dynamic logic
- See FactoriesTest.php for comprehensive examples
- Factory classes must implement
-
aliases: Maps alias names to service names or other aliases.- Allows multiple names to resolve to the same service instance
- Can chain aliases (alias โ alias โ service)
- Only
invokablescreate aliases automatically
delegators: Maps service names to arrays of delegator factory classes.- Decorates or wraps services with additional functionality
- Delegators are applied in the order specified
- See Laminas delegators documentation for details
N.B.: All configuration except
dependenciesis merged into aconfigkey within the$container:
๐ป CLI Usage
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:
You can also add this as a Composer script:
๐งช Development & Testing
Running Tests
Git Hooks with GrumPHP
This project uses GrumPHP to automatically run tests before each commit.
After running composer install, GrumPHP will:
- Install git hooks automatically
- Run
composer testbefore every commit - Block commits if tests fail
Bypass the hook (not recommended):
Configure GrumPHP: Edit grumphp.yml to customize tasks and behavior.
๐ Troubleshooting / FAQ
Q: My service is not autowired.
A: Ensure it is listed in the autowires array and all dependencies are available.
Q: The CLI tool fails with a permissions error. A: Make sure the config file directory is writable.
Q: How do I debug container errors? A: Check that all dependencies are correctly defined and that your factories do not throw exceptions.
Using with Mezzio (formerly Expressive)
Replace contents of config/container.php with the following:
Example of a ConfigProvider class
Where UserManager depends on Mailer as follows:
Switching back to another container
To switch back to another container is straightforward:
- Create your factories with
__invokefunction - Replace
autowireskey in ConfigProvider byfactorieskey, 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.
๐ค Contributing
See CONTRIBUTING.md for guidelines on how to contribute, run tests, and submit pull requests.
๐ License
This project is licensed under the MIT License. See LICENSE for details.