Dependency Injection container.

package Swift
author Chris Corbyn

 Methods

Constructor should not be used.

__construct() 

Use getInstance() instead.

Specify a dependency lookup for the constructor of the previously registered item.

addConstructorLookup(string $lookup) : \Swift_DependencyContainer
see addConstructorValue()

Parameters

$lookup

string

Returns

Specify a literal (non looked up) value for the constructor of the previously registered item.

addConstructorValue(mixed $value) : \Swift_DependencyContainer
see addConstructorLookup()

Parameters

$value

mixed

Returns

Specify the previously registered item as an alias of another item.

asAliasOf(string $lookup) : \Swift_DependencyContainer

Parameters

$lookup

string

Returns

Specify the previously registered item as a new instance of $className.

asNewInstanceOf(string $className) : \Swift_DependencyContainer

register() must be called before this will work. Any arguments can be set with withDependencies(), addConstructorValue() or addConstructorLookup().

see addConstructorValue(), addConstructorLookup()

Parameters

$className

string

Returns

Specify the previously registered item as a shared instance of $className.

asSharedInstanceOf(string $className) : \Swift_DependencyContainer

register() must be called before this will work.

Parameters

$className

string

Returns

Specify the previously registered item as a literal value.

asValue(mixed $value) : \Swift_DependencyContainer

register() must be called before this will work.

Parameters

$value

mixed

Returns

Create an array of arguments passed to the constructor of $itemName.

createDependenciesFor(string $itemName) : array

Parameters

$itemName

string

Returns

array

Returns a singleton of the DependencyContainer.

getInstance() : \Swift_DependencyContainer
Static

Test if an item is registered in this container with the given name.

has(string $itemName) : boolean
see \register()

Parameters

$itemName

string

Returns

boolean

List the names of all items stored in the Container.

listItems() : array

Returns

array

Lookup the item with the given $itemName.

lookup(string $itemName) : mixed
see \register()

Parameters

$itemName

string

Exceptions

\Swift_DependencyException If the dependency is not found

Returns

mixed

Register a new dependency with $itemName.

register(string $itemName) : \Swift_DependencyContainer

This method returns the current DependencyContainer instance because it requires the use of the fluid interface to set the specific details for the dependency.

see asSharedInstanceOf(), asValue()

Parameters

$itemName

string

Returns

Specify a list of injected dependencies for the previously registered item.

withDependencies(array $lookups) : \Swift_DependencyContainer

This method takes an array of lookup names.

see addConstructorLookup()

Parameters

$lookups

array

Returns

Resolve an alias to another item

_createAlias($itemName) 

Parameters

$itemName

Create a fresh instance of $itemName

_createNewInstance($itemName) 

Parameters

$itemName

Create and register a shared instance of $itemName

_createSharedInstance($itemName) 

Parameters

$itemName

Get the current endpoint in the store

_getEndPoint() 

Get the literal value with $itemName

_getValue($itemName) 

Parameters

$itemName

Resolve a single dependency with an collections

_lookupRecursive($item) 

Parameters

$item

Get an argument list with dependencies resolved

_resolveArgs(array $args) 

Parameters

$args

 Properties

 

$_endPoint 
 

$_instance 
 

$_store 

 Constants

 

Constant for aliases

TYPE_ALIAS 
 

Constant for new instance types

TYPE_INSTANCE 
 

Constant for shared instance types

TYPE_SHARED 
 

Constant for literal value types

TYPE_VALUE