Download the PHP package robert430404/rc-container without Composer
On this page you can find all versions of the php package robert430404/rc-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robert430404/rc-container
More information about robert430404/rc-container
Files in robert430404/rc-container
Package rc-container
Short Description This is a simple Dependency Injection Container for PHP.
License MIT
Informations about the package rc-container
What Is This?
This is RC Container. This is a simple dependency injection container that allows you to register services, parameters, and factories for your application and then retrieve/de-register them.
Why Write This?
I did it to flex my brain, and get a full understanding of how DI-Containers work in the PHP space. Rather than just reading about it and assuming I knew what did what, I wrote this to solidify my knowledge.
Installing The Package
To install and use this package, install it with composer:
composer require robert430404/rc-container
How Does It Work?
The container relies on composer for the autoloading of the classes. You then create a new instance of the Container() object and start assigning your services/parameters/factories to the instance.
You can also assign multiple services, parameters, or factories in a single call using this method:
Or you can use a more conceise syntax like this:
Once you have your services/parameters/factories defined, you then call the retrieval methods on the container to get access to your registered services/parameters/factories.
What Are Some Of The Features?
The container allows you to bind service, factories, and parameters to it. This allows you to have a central place to access your dependencies and inject what ever is needed as needed. You can also inject interlocking dependencies via the container by passing the container into the closure.
The same method works to pass around services:
This gives you a robust and easy to use container that should suit most DI needs.