Download the PHP package mdarc/di without Composer
On this page you can find all versions of the php package mdarc/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package di
Short Description A simple yet powerful PSR-11 autowiring dependency injection container
License MIT
Homepage https://github.com/mdarc/DI
Informations about the package di
mdarc/DI
A simple yet powerful PSR-11 autowiring dependency injection container.
mdarc/DI was conceived to be simple to configure and use. It was built for performance. (check benchmarks)
mdarc/DI has an very small but robust code base. It is production ready and can be used for small micro-services or large monolithic projects.
Features:
- Autowiring: Automatically instantiate and inject dependencies
- Manual configuration: When classes cannot be autowired, you can create them by yourself
- Circular reference detection: It throws a
CircularReferenceException
with enough details to fix the problem
What mdarc/DI is not good for:
- Autowiring via setter methods is not supported (and it will never be)
- Autowiring using phpDoc annotations is not supported (and it will never be)
- Automatically injecting dependencies on constructor parameters without type hints is not supported. You must manually configure those cases
Installation
Composer
Before anything else, use this to add it to your composer.json
Usage
Creating a container ready to use with autowiring enabled is a matter of creating a Container
instance:
If your classes contain constructor parameters that are other objects, then simply:
As any other DI container, $myClass
will always get the same instance on the requested class.
If you want to create a new object every time (instead of getting the same object instance) then use the factory helper:
For those classes that cannot be created using autowiring, then you can add their definitions:
Defining aliases for binding interfaces to implementations is simple:
Specifying arguments for classes with constructor parameters that are scalar, array or undefined type:
License
mdarc/DI is licensed under the MIT License.