Download the PHP package mts7/php-dependency-injection without Composer
On this page you can find all versions of the php package mts7/php-dependency-injection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mts7/php-dependency-injection
More information about mts7/php-dependency-injection
Files in mts7/php-dependency-injection
Package php-dependency-injection
Short Description Simple dependency injection container for PHP
License MIT
Informations about the package php-dependency-injection
PHP Dependency Injection
PHP Dependency Injection Container
Installation
Usage
Set
Getting an instantiated object can only happen after the container knows about
the class. One way to tell the container about the definition is to use the
set
method. set
can take an alias or fully-qualified class name as the first
parameter and a fully-qualified class name, instantiated object, or null as the
second parameter.
Full Example
Load
To make things easier for projects, passing the abstract and concrete values to
Container can happen through the load
method. Provide an array indexed by the
abstract ID (key, class name, etc.) with a value of a concretion.
Load handles a variety of parameters, allowing for most implementations to work
out-of-the-box. When both the key and value are present, the list of definitions
available adds valid values and their keys. When the config array has no key,
load
uses the value to determine the key (which should be the fully-qualified
class name). Each value goes through validation to determine if the concretion
provided is a valid class or object. Check the
tests for examples.
Load is best used when combined with a factory that provides auto-loading of a preconfigured list of abstractions and their concretions.
Full Example
Get
When a class has its own dependencies, all dependencies can exist once they are set in the container. The container uses auto-wiring through Reflection to determine which parameters are classes and then instantiate each one.
Full Example