Download the PHP package redot/container without Composer
On this page you can find all versions of the php package redot/container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redot/container
More information about redot/container
Files in redot/container
Package container
Short Description Minimal, Lightweight, and Fast PHP Dependency Injection Container.
License MIT
Informations about the package container
Redot PHP Container
Minimal, Lightweight, and Fast PHP Dependency Injection Container
Installation
Testing
Usage
The methodologies of the container are based on the Dependency Injection paradigm, using the ReflectionClass
to get class dependencies.
To use the container, you must first create a new instance of the container.
Or just use the static method Container::getInstance()
, that will return the globally available container if it exists, or create a new one.
After you have created the container, you can bind your dependencies to the container.
Also, you can create a singleton, that will be returned every time you call the get
method.
Singletons are useful for classes that are expensive to instantiate, but only need to be created once.
To get a dependency from the container, you can call the make
method.
The main difference between make
and get
is that make
accepts a second parameter, which is an array of parameters to pass to the constructor of the class, while get
does not because of implementing PSR-11
By the way you can also create an alias for a class, so you can call it with a different name.
Auto-wiring
Don't worry about the auto-wiring, the container will do it for you.
It will automatically bind the dependencies of the class, and if the class has a constructor, it will pass the dependencies to it, also the container can inject specific method dependencies using the call
method.
And that's it! Enjoy ✌.