Zend Framework  3.0
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Di Class Reference

Dependency injector that can generate instances using class definitions and configured instance parameters. More...

Public Member Functions

 __construct (DefinitionList $definitions=null, InstanceManager $instanceManager=null, Config $config=null)
 Constructor.
 
 configure (Config $config)
 Provide a configuration object to configure this instance.
 
 setDefinitionList (DefinitionList $definitions)
 
 definitions ()
 
 setInstanceManager (InstanceManager $instanceManager)
 Set the instance manager.
 
 instanceManager ()
 
 has ($name)
 Is the DI container capable of returning the named instance?
 
 get ($name, array $params=[])
 Lazy-load a class.
 
 newInstance ($name, array $params=[], $isShared=true)
 Retrieve a new instance of a class.
 
 injectDependencies ($instance, array $params=[])
 Inject dependencies.
 
- Public Member Functions inherited from DependencyInjectionInterface
 newInstance ($name, array $params=[])
 Retrieve a new instance of a class.
 

Public Attributes

const RESOLVE_EAGER = 1
 Resolve method policy.
 
const RESOLVE_STRICT = 2
 Resolve method policy.
 
const METHOD_IS_OPTIONAL = 0
 use only specified parameters
 
const METHOD_IS_AWARE = 1
 resolve mode RESOLVE_EAGER
 
const METHOD_IS_CONSTRUCTOR = 3
 resolve mode RESOLVE_EAGER | RESOLVE_STRICT
 
const METHOD_IS_INSTANTIATOR = 3
 resolve mode RESOLVE_EAGER | RESOLVE_STRICT
 
const METHOD_IS_REQUIRED = 3
 resolve mode RESOLVE_EAGER | RESOLVE_STRICT
 
const METHOD_IS_EAGER = 1
 resolve mode RESOLVE_EAGER
 

Protected Member Functions

 getClass ($instance)
 Utility method used to retrieve the class of a particular instance.
 
 getCallParameters ($name, array $params, $method="__construct")
 
 handleInjectDependencies ($instance, $injectionMethods, $params, $instanceClass, $instanceAlias, $requestedName)
 
 createInstanceViaConstructor ($class, $params, $alias=null)
 Retrieve a class instance based on class name.
 
 createInstanceViaCallback ($callback, $params, $alias)
 Get an object instance from the defined callback.
 
 resolveAndCallInjectionMethodForInstance ($instance, $method, $params, $alias, $methodRequirementType, $methodClass=null)
 This parameter will handle any injection methods and resolution of dependencies for such methods.
 
 resolveMethodParameters ($class, $method, array $callTimeUserParams, $alias, $methodRequirementType, $isInstantiator=false)
 Resolve parameters referencing other services.
 

Static Protected Member Functions

static isSubclassOf ($className, $type)
 Checks if the object has this class as one of its parents.
 

Protected Attributes

 $definitions = null
 
 $instanceManager = null
 
 $instanceContext = []
 
 $currentDependencies = []
 
 $currentAliasDependenencies = []
 
 $references = []
 

Detailed Description

Dependency injector that can generate instances using class definitions and configured instance parameters.

Constructor & Destructor Documentation

__construct ( DefinitionList  $definitions = null,
InstanceManager  $instanceManager = null,
Config  $config = null 
)

Constructor.

Parameters
null | DefinitionList$definitions
null | InstanceManager$instanceManager
null | Config$config

Member Function Documentation

configure ( Config  $config)

Provide a configuration object to configure this instance.

Parameters
Config$config
Returns
void
createInstanceViaCallback (   $callback,
  $params,
  $alias 
)
protected

Get an object instance from the defined callback.

Parameters
callable$callback
array$params
string$alias
Returns
object
Exceptions
Exception\InvalidCallbackException
Exception\RuntimeException
createInstanceViaConstructor (   $class,
  $params,
  $alias = null 
)
protected

Retrieve a class instance based on class name.

Any parameters provided will be used as constructor arguments. If any given parameter is a DependencyReference object, it will be fetched from the container so that the instance may be injected.

Parameters
string$class
array$params
string | null$alias
Returns
object
definitions ( )
get (   $name,
array  $params = [] 
)

Lazy-load a class.

Attempts to load the class (or service alias) provided. If it has been loaded before, the previous instance will be returned (unless the service definition indicates shared instances should not be used).

Parameters
string$nameClass name or service alias
null | array$paramsParameters to pass to the constructor
Returns
object|null
getCallParameters (   $name,
array  $params,
  $method = "__construct" 
)
protected
Parameters
$name
array$params
string$method
Returns
array
getClass (   $instance)
protected

Utility method used to retrieve the class of a particular instance.

This is here to allow extending classes to override how class names are resolved

handleInjectDependencies (   $instance,
  $injectionMethods,
  $params,
  $instanceClass,
  $instanceAlias,
  $requestedName 
)
protected
Parameters
object$instance
array$injectionMethods
array$params
string | null$instanceClass
string|null$instanceAlias
string$requestedName
Exceptions
Exception\RuntimeException
has (   $name)

Is the DI container capable of returning the named instance?

Parameters
string$name
Returns
bool
injectDependencies (   $instance,
array  $params = [] 
)

Inject dependencies.

Parameters
object$instance
array$params
Returns
void
instanceManager ( )
static isSubclassOf (   $className,
  $type 
)
staticprotected

Checks if the object has this class as one of its parents.

See Also
https://bugs.php.net/bug.php?id=53727
https://github.com/zendframework/zf2/pull/1807
Deprecated:
since zf 2.3 requires PHP >= 5.3.23
Parameters
string$className
$type
Returns
bool
newInstance (   $name,
array  $params = [],
  $isShared = true 
)

Retrieve a new instance of a class.

Forces retrieval of a discrete instance of the given class, using the constructor parameters provided.

Parameters
mixed$nameClass name or service alias
array$paramsParameters to pass to the constructor
bool$isShared
Returns
object|null
Exceptions
Exception\ClassNotFoundException
Exception\RuntimeException
resolveAndCallInjectionMethodForInstance (   $instance,
  $method,
  $params,
  $alias,
  $methodRequirementType,
  $methodClass = null 
)
protected

This parameter will handle any injection methods and resolution of dependencies for such methods.

Parameters
object$instance
string$method
array$params
string$alias
bool$methodRequirementType
string | null$methodClass
Returns
bool
resolveMethodParameters (   $class,
  $method,
array  $callTimeUserParams,
  $alias,
  $methodRequirementType,
  $isInstantiator = false 
)
protected

Resolve parameters referencing other services.

Parameters
string$class
string$method
array$callTimeUserParams
string$alias
int | bool$methodRequirementType
bool$isInstantiator
Exceptions
Exception\MissingPropertyException
Exception\CircularDependencyException
Returns
array
setDefinitionList ( DefinitionList  $definitions)
Parameters
DefinitionList$definitions
Returns
self
setInstanceManager ( InstanceManager  $instanceManager)

Set the instance manager.

Parameters
InstanceManager$instanceManager
Returns
Di

Member Data Documentation

$currentAliasDependenencies = []
protected
$currentDependencies = []
protected
$definitions = null
protected
$instanceContext = []
protected
$instanceManager = null
protected
$references = []
protected
const METHOD_IS_AWARE = 1

resolve mode RESOLVE_EAGER

const METHOD_IS_CONSTRUCTOR = 3

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

const METHOD_IS_EAGER = 1

resolve mode RESOLVE_EAGER

const METHOD_IS_INSTANTIATOR = 3

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

const METHOD_IS_OPTIONAL = 0

use only specified parameters

const METHOD_IS_REQUIRED = 3

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

const RESOLVE_EAGER = 1

Resolve method policy.

EAGER: explore type preference or go through

const RESOLVE_STRICT = 2

Resolve method policy.

STRICT: explore type preference or throw exception