Download the PHP package peroxide/container without Composer
On this page you can find all versions of the php package peroxide/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download peroxide/container
More information about peroxide/container
Files in peroxide/container
Package container
Short Description Peroxide Container, a simple factory-driven PSR-11 Dependency Injection Container with zero dependencies and low functionalities.
License MIT
Informations about the package container
pt-br
Peroxide/Container
A straightforward Dependency Injection container, designed for use with APIs, adhering to the PSR-11 standard. It boasts minimal functionality and operates independently, free from external dependencies.
Our filosophy
We are passionate about working with components that are as clean and simple as possible. Peroxide\Container is a fusion of inspiration drawn from libraries such as Laminas\ServiceManager, Pimple, and with a touch of PHP-DI.
The great advantage is that we have no external dependencies. All configuration is achieved through PHP code using array configuration files. All you need to do is ensure that your framework supports PSR-11, set up the configuration, and you're ready to begin your coding journey.
How to use it
Instaling
Starting your journey
Peroxide\Container is fully compliant with PSR-11, and it provides the following methods:
Create your configuration as array
Creating your Factory Class
It is also possible to set dependencies separately, after obtaining your container instance:
If the dependency doesn't exist, it will be created; otherwise, it will be replaced by the new factory.
More configurations
To handle dependency injection within the container, you can easily use to compose your dependencies.
You can also compose your configuration using the spread operator, as shown in the example:
How to deal with Singleton?
Just use the Singleton invocable class, here's an example:
The class serves as a wrapper to indicate to our container that we want this class to not create a new instance every time it is retrieved.
The first parameter of constructor, only accepts callable class or closures.
Why can't I config parameters on container?
We believe that storing configuration values in the dependency container is unnecessary. Instead, each service should be configured using external environment data. By doing so, you can centralize your project's configuration.