TYPO3  7.6
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Swift_DependencyContainer Class Reference

Public Member Functions

 __construct ()
 
 listItems ()
 
 has ($itemName)
 
 lookup ($itemName)
 
 createDependenciesFor ($itemName)
 
 register ($itemName)
 
 asValue ($value)
 
 asAliasOf ($lookup)
 
 asNewInstanceOf ($className)
 
 asSharedInstanceOf ($className)
 
 withDependencies (array $lookups)
 
 addConstructorValue ($value)
 
 addConstructorLookup ($lookup)
 

Static Public Member Functions

static getInstance ()
 

Public Attributes

const TYPE_VALUE = 0x0001
 
const TYPE_INSTANCE = 0x0010
 
const TYPE_SHARED = 0x0100
 
const TYPE_ALIAS = 0x1000
 

Private Member Functions

 _getValue ($itemName)
 
 _createAlias ($itemName)
 
 _createNewInstance ($itemName)
 
 _createSharedInstance ($itemName)
 
_getEndPoint ()
 
 _resolveArgs (array $args)
 
 _lookupRecursive ($item)
 

Private Attributes

 $_store = array()
 
 $_endPoint
 

Static Private Attributes

static $_instance = null
 

Detailed Description

Dependency Injection container.

Author
Chris Corbyn

Definition at line 16 of file DependencyContainer.php.

Constructor & Destructor Documentation

__construct ( )

Constructor should not be used.

Use getInstance() instead.

Definition at line 44 of file DependencyContainer.php.

Member Function Documentation

_createAlias (   $itemName)
private

Resolve an alias to another item

Definition at line 301 of file DependencyContainer.php.

References lookup().

Referenced by lookup().

_createNewInstance (   $itemName)
private

Create a fresh instance of $itemName

Definition at line 307 of file DependencyContainer.php.

References createDependenciesFor().

Referenced by _createSharedInstance(), and lookup().

_createSharedInstance (   $itemName)
private

Create and register a shared instance of $itemName

Definition at line 320 of file DependencyContainer.php.

References _createNewInstance().

Referenced by lookup().

& _getEndPoint ( )
private

Get the current endpoint in the store

Definition at line 330 of file DependencyContainer.php.

References $_endPoint.

Referenced by addConstructorLookup(), addConstructorValue(), asAliasOf(), asNewInstanceOf(), asSharedInstanceOf(), asValue(), and withDependencies().

_getValue (   $itemName)
private

Get the literal value with $itemName

Definition at line 295 of file DependencyContainer.php.

Referenced by lookup().

_lookupRecursive (   $item)
private

Resolve a single dependency with an collections

Definition at line 360 of file DependencyContainer.php.

References lookup().

Referenced by _resolveArgs().

_resolveArgs ( array  $args)
private

Get an argument list with dependencies resolved

Definition at line 342 of file DependencyContainer.php.

References _lookupRecursive().

Referenced by createDependenciesFor().

addConstructorLookup (   $lookup)

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

See Also
withDependencies(), addConstructorValue()
Parameters
string$lookup
Returns
Swift_DependencyContainer

Definition at line 283 of file DependencyContainer.php.

References _getEndPoint().

Referenced by withDependencies().

addConstructorValue (   $value)

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

See Also
withDependencies(), addConstructorLookup()
Parameters
mixed$value
Returns
Swift_DependencyContainer

Definition at line 262 of file DependencyContainer.php.

References _getEndPoint().

asAliasOf (   $lookup)

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

Parameters
string$lookup
Returns
Swift_DependencyContainer

Definition at line 181 of file DependencyContainer.php.

References _getEndPoint().

asNewInstanceOf (   $className)

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

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

See Also
withDependencies(), addConstructorValue(), addConstructorLookup()
Parameters
string$className
Returns
Swift_DependencyContainer

Definition at line 203 of file DependencyContainer.php.

References _getEndPoint().

asSharedInstanceOf (   $className)

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

register() must be called before this will work.

Parameters
string$className
Returns
Swift_DependencyContainer

Definition at line 221 of file DependencyContainer.php.

References _getEndPoint().

asValue (   $value)

Specify the previously registered item as a literal value.

register() must be called before this will work.

Parameters
mixed$value
Returns
Swift_DependencyContainer

Definition at line 165 of file DependencyContainer.php.

References _getEndPoint().

createDependenciesFor (   $itemName)

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

Parameters
string$itemName
Returns
array

Definition at line 125 of file DependencyContainer.php.

References _resolveArgs().

Referenced by _createNewInstance().

static getInstance ( )
static
has (   $itemName)

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

See Also
register()
Parameters
string$itemName
Returns
bool

Definition at line 81 of file DependencyContainer.php.

Referenced by lookup().

listItems ( )

List the names of all items stored in the Container.

Returns
array

Definition at line 67 of file DependencyContainer.php.

lookup (   $itemName)

Lookup the item with the given $itemName.

See Also
register()
Parameters
string$itemName
Exceptions
Swift_DependencyExceptionIf the dependency is not found
Returns
mixed

Definition at line 98 of file DependencyContainer.php.

References _createAlias(), _createNewInstance(), _createSharedInstance(), _getValue(), and has().

Referenced by _createAlias(), and _lookupRecursive().

register (   $itemName)

Register a new dependency with $itemName.

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 Also
asNewInstanceOf(), asSharedInstanceOf(), asValue()
Parameters
string$itemName
Returns
Swift_DependencyContainer

Definition at line 148 of file DependencyContainer.php.

withDependencies ( array  $lookups)

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

This method takes an array of lookup names.

See Also
addConstructorValue(), addConstructorLookup()
Parameters
array$lookups
Returns
Swift_DependencyContainer

Definition at line 241 of file DependencyContainer.php.

References _getEndPoint(), and addConstructorLookup().

Member Data Documentation

$_endPoint
private

The current endpoint in the data container

Definition at line 37 of file DependencyContainer.php.

Referenced by _getEndPoint().

$_instance = null
staticprivate

Singleton instance

Definition at line 31 of file DependencyContainer.php.

$_store = array()
private

The data container

Definition at line 34 of file DependencyContainer.php.

const TYPE_ALIAS = 0x1000

Constant for aliases

Definition at line 28 of file DependencyContainer.php.

const TYPE_INSTANCE = 0x0010

Constant for new instance types

Definition at line 22 of file DependencyContainer.php.

const TYPE_SHARED = 0x0100

Constant for shared instance types

Definition at line 25 of file DependencyContainer.php.

const TYPE_VALUE = 0x0001

Constant for literal value types

Definition at line 19 of file DependencyContainer.php.