Recommend this page to a friend! |
Classes of Saiik on | Dependency Injection Container | README.md | Download |
|
DownloadContainerContainer gives you a small dependency injetion to use in your projects InstallationRun 'composer require saiik\container' and include your autoload.php UsageThe container class needs at least 1 parameter. The first parameter defines the "namespace" for your container. The 2nd one is a configuration array. Example:
Register a new instanceTo register a new instance you can do it in 2 ways. __When your class has dependencies on other classes, it will resolve them automatically.__ _In case you have dependencies on interfaces or an abstract class, you can set "mockup" in your configuration to true and it will mock up your interface / abstract class._ Using the register methodYou can use the register method. This method expects at least 2 parameters.
Example:
With args:
Using the container object as an arrayAlso you can handle the container object as an array and register objects without any functions. Example:
With args:
Get a stored instanceTo get one instance stored in the container just run this simple function:
And you get your instance. Full example
|