Download the PHP package gspataro/dependencyinjection without Composer
On this page you can find all versions of the php package gspataro/dependencyinjection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gspataro/dependencyinjection
More information about gspataro/dependencyinjection
Files in gspataro/dependencyinjection
Package dependencyinjection
Short Description A dependency injection container component to handle the booting process of your application
License MIT
Informations about the package dependencyinjection
GSpataro/DependencyInjection
A dependency injection container component made to handle the booting process of your application easier.
Installation
Requires [PHP 8.0+](PHP: Releases)
To install this package you have to require it with Composer:
Quick start
The fastest way to use the container is to initialize it and provide the services that you need:
Container
The Container class is the heart of this component.
Service dependencies
When defining a service, the Container class and params array are passed to the factory to have access to the class dependencies.
Variables
Sometimes some configurations or other variables will be needed globally across services. In this case, you can define variables accessible by the container.
Direct instance
If you need to instanciate a new class but you don't need to register it as a service, you can directly instanciate it. This is not recomended, but you'll still need it in some cases:
Components
The components are another feature of the container. The issue is: if you define your services one by one, the risk of booting a service before its dependency is higher and you have to remember what you booted first.
To simplify this process, the components are "archives" of services that will be booted in the order you specify.
Defining a component
Boot components
To boot your components you need to register them into the container and then call the boot method.
Let's assume you have two components: ComponentA and ComponentB. If ComponentA depends on some services provided by ComponentB, you can change the order of them in the loadComponents method: