Download the PHP package spriebsch/di without Composer
On this page you can find all versions of the php package spriebsch/di. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package di
Short Description A lightweight, smart and fast DI container with autowiring.
License BSD-3-Clause
Informations about the package di
DI Container
A lightweight, smart and fast Dependency Injection (DI) container with auto-wiring, supporting custom factories and virtual types. It follows an "as modular as possible" approach and requires no separate build or compilation step.
Installation
Basic Usage
To use the DI container, you need a configuration object (implementing Configuration) and one or more factory classes (extending AbstractFactory).
Autowiring
The container automatically resolves dependencies by inspecting the constructor of the requested class. Dependencies must be type-hinted with a class or interface name.
Scalar dependencies cannot be auto-wired. You must write a factory method to handle them.
Custom Factories
You can define custom factory methods in your factory class. The container looks for methods matching the class name (short name or long name).
Short Name Factory Method
If you request Project\Namespace\MyService, the container looks for a method named MyService in the factory.
Long Name Factory Method
If multiple classes have the same short name, you can use the fully qualified class name with backslashes replaced by underscores.
Virtual Types
Virtual types allow you to request a name that does not correspond to an existing class or interface. This is useful for named instances or configurations.
Passing Parameters
You can pass additional parameters to the get() method. These parameters are passed to the factory method.
Multiple Factories
You can provide multiple factory classes. The container will search for a handling factory in the order they are provided. If the first factory cannot create the type, it delegates to the next one.
This is particularly useful when using frameworks or libraries that have their own factories.
Using Configuration
Factories have access to the configuration object.
License
Copyright (c) 2025-2026, Stefan Priebsch [email protected]
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
All versions of di with dependencies
ext-sqlite3 Version *