Class Container
Inversion of control container is a powerful tool for managing class dependencies. Dependency injection is a method of removing hard-coded class dependencies. Instead, the dependencies are injected at run-time, allowing for greater flexibility as dependency implementations may be swapped easily.
// Instantiate new container $container = new Docolight\Container\Container; // Bind a container $container->bind('foo', function () { return new Foo; }); // Resolve type from container: $container->make('foo'); // Foo implementation
Container also has ability to resolve the dependency by itself.
interface FooContract { public function foo(); } class Foo implements FooContract { public function foo() {} } class FooFactory { protected $foo = null; public function __construct(FooContract $foo) { $this->foo = $foo; } } $container = new Docolight\Container\Container; $container->bind('FooContract', 'Foo'); $fooFactory = $container->make('FooFactory'); // equals with: $fooFactory = new FooFactory(new Foo);
- CApplicationComponent
- Docolight\Container\Container implements ArrayAccess
Category: Libraries
Author: Krisan Alfa Timur krisanalfa@docotel.co.id
Link: Interface to provide accessing objects as arrays.
Located at Docolight/Container/Container.php
Methods summary
protected
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
|
|
protected
Closure
|
|
public
|
|
public
|
|
public
Closure
|
|
public
|
|
public
|
|
protected
Closure
|
|
public
|
|
public
|
|
protected
array
|
|
public
mixed
|
|
public
mixed
|
|
protected
|
|
protected
array
|
|
public
mixed
|
|
protected
mixed
|
|
protected
boolean
|
|
public
mixed
|
|
protected
array
|
#
getDependencies( array $parameters, array $primitives = array() )
Resolve all of the dependencies from the ReflectionParameters. |
protected
mixed
|
|
protected
mixed
|
#
resolveClass( ReflectionParameter $parameter )
Resolve a class based dependency from the container. |
protected
array
|
#
keyParametersByArgument( array $dependencies, array $parameters )
If extra parameters are passed by numeric ID, rekey them by argument name. |
public
|
|
public
|
|
protected
|
|
protected
|
|
public
boolean
|
|
protected
boolean
|
|
protected
string
|
|
public
array
|
|
protected
|
|
public
|
|
public
|
|
public
boolean
|
|
public
mixed
|
|
public
|
|
public
|
|
public
mixed
|
|
public
|
Properties summary
protected
array
|
$resolved
An array of the types that have been resolved. |
#
array()
|
protected
array
|
$bindings
The container's bindings. |
#
array()
|
protected
array
|
$instances
The container's shared instances. |
#
array()
|
protected
array
|
$aliases
The registered type aliases. |
#
array()
|
protected
array
|
$reboundCallbacks
All of the registered rebound callbacks. |
#
array()
|
protected
array
|
$resolvingCallbacks
All of the registered resolving callbacks. |
#
array()
|
protected
array
|
$globalResolvingCallbacks
All of the global resolving callbacks. |
#
array()
|