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

package Default

 Methods

Constructor

__construct(null|\Zend\Di\DefinitionList $definitions = null, null|\Zend\Di\InstanceManager $instanceManager = null, null|\Zend\Di\Config $config = null

Parameters

$definitions

null\Zend\Di\DefinitionList

$instanceManager

null\Zend\Di\InstanceManager

$config

null\Zend\Di\Config

Provide a configuration object to configure this instance

configure(\Zend\Di\Config $config) : void

Parameters

$config

\Zend\Di\Config

definitions()

definitions() : \Zend\Di\DefinitionList

Returns

\Zend\Di\DefinitionList

Lazy-load a class

get(string $name, null|array $params = array()) : object | null

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

$name

string

Class name or service alias

$params

nullarray

Parameters to pass to the constructor

Returns

objectnull

Inject dependencies

injectDependencies(object $instance, array $params = array()) : void

Parameters

$instance

object

$params

array

instanceManager()

instanceManager() : \Zend\Di\InstanceManager

Returns

\Zend\Di\InstanceManager

Retrieve a new instance of a class

newInstance(mixed $name, array $params = array(), boolean $isShared = true) : object | null

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

inherited_from \Zend\Di\DependencyInjectionInterface::newInstance()

Parameters

$name

mixed

Class name or service alias

$params

array

Parameters to pass to the constructor

$isShared

boolean

Exceptions

\Zend\Di\Exception\ClassNotFoundException
\Zend\Di\Exception\RuntimeException

Returns

objectnull

setDefinitionList()

setDefinitionList(\Zend\Di\DefinitionList $definitions) : \Zend\Di\Di
fluent This method is part of a fluent interface and will return the same instance

Parameters

$definitions

\Zend\Di\DefinitionList

Returns

\Zend\Di\Di

Set the instance manager

setInstanceManager(\Zend\Di\InstanceManager $instanceManager) : \Zend\Di\Di

Parameters

$instanceManager

\Zend\Di\InstanceManager

Returns

\Zend\Di\Di

Get an object instance from the defined callback

createInstanceViaCallback(callable $callback, array $params, string $alias) : object

Parameters

$callback

callable

$params

array

$alias

string

Exceptions

\Zend\Di\Exception\InvalidCallbackException
\Zend\Di\Exception\RuntimeException

Returns

object

Retrieve a class instance based on class name

createInstanceViaConstructor(string $class, array $params, string|null $alias = null) : object

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

$class

string

$params

array

$alias

stringnull

Returns

object

getCallParameters()

getCallParameters($name, array $params, string $method = "__construct") : array

Parameters

$name

$params

array

$method

string

Returns

array

handleInjectDependencies()

handleInjectDependencies(object $instance, array $injectionMethods, array $params, string|null $instanceClass, $instanceAlias, string $requestedName) 

Parameters

$instance

object

$injectionMethods

array

$params

array

$instanceClass

stringnull

$instanceAlias

$requestedName

string

Exceptions

\Zend\Di\Exception\RuntimeException

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

isSubclassOf(string $className, $type) : boolean
Static
see
see
deprecated since zf 2.3 requires PHP >= 5.3.23

Parameters

$className

string

$type

Returns

boolean

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

resolveAndCallInjectionMethodForInstance(object $instance, string $method, array $params, string $alias, boolean $methodRequirementType, string|null $methodClass = null) : boolean

Parameters

$instance

object

$method

string

$params

array

$alias

string

$methodRequirementType

boolean

$methodClass

stringnull

Returns

boolean

Resolve parameters referencing other services

resolveMethodParameters(string $class, string $method, array $callTimeUserParams, string $alias, integer|boolean $methodRequirementType, boolean $isInstantiator = false) : array

Parameters

$class

string

$method

string

$callTimeUserParams

array

$alias

string

$methodRequirementType

integerboolean

$isInstantiator

boolean

Exceptions

\Zend\Di\Exception\MissingPropertyException
\Zend\Di\Exception\CircularDependencyException

Returns

array

 Properties

 

All the dependenent aliases

$currentAliasDependenencies : array

Default

array()
 

All the class dependencies [source][dependency]

$currentDependencies : array

Default

array()
 

$definitions

$definitions : \Zend\Di\DefinitionList

Default

null
 

$instanceContext

$instanceContext : string

Default

array()
 

$instanceManager

$instanceManager : \Zend\Di\InstanceManager

Default

null
 

All the class references [dependency][source]

$references : array

Default

array()

 Constants

 

resolve mode RESOLVE_EAGER

METHOD_IS_AWARE = 1 
 

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

METHOD_IS_CONSTRUCTOR = 3 
 

resolve mode RESOLVE_EAGER

METHOD_IS_EAGER = 1 
 

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

METHOD_IS_INSTANTIATOR = 3 
 

use only specified parameters

METHOD_IS_OPTIONAL = 0 
 

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

METHOD_IS_REQUIRED = 3 
 

Resolve method policy

RESOLVE_EAGER = 1 

EAGER: explore type preference or go through

 

Resolve method policy

RESOLVE_STRICT = 2 

STRICT: explore type preference or throw exception