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

 Methods

Constructor

__construct(\Zend\Di\DefinitionList $definitions, \Zend\Di\InstanceManager $instanceManager, \Zend\Di\Config $config) 

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

Lazy-load a class

get(string $name, array $params) : 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) : void

Parameters

$instance

object

$params

array

instanceManager()

instanceManager() : \Zend\Di\InstanceManager

Retrieve a new instance of a class

newInstance(mixed $name, array $params, bool $isShared) : object | null

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

Parameters

$name

mixed

Class name or service alias

$params

array

Parameters to pass to the constructor

$isShared

bool

Exceptions

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

Returns

objectnull

setDefinitionList()

setDefinitionList(\Zend\Di\DefinitionList $definitions) : \Zend\Di\self

Parameters

Returns

\Zend\Di\self

Set the instance manager

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

Parameters

$instanceManager

\Zend\Di\InstanceManager

Returns

Get an object instance from the defined callback

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

Parameters

$callback

\Zend\Di\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) : 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) : 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

string|null$instanceAlias

$requestedName

string

Exceptions

\Zend\Di\Exception\RuntimeException

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

isSubclassOf(string $className, $type) : bool

see \Zend\Di\https://bugs.php.net/bug.php?id=53727
see \Zend\Di\https://github.com/zendframework/zf2/pull/1807

Parameters

$className

string

$type

Returns

bool

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

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

Parameters

$instance

object

$method

string

$params

array

$alias

string

$methodRequirementType

bool

$methodClass

stringnull

Returns

bool

Resolve parameters referencing other services

resolveMethodParameters(string $class, string $method, array $callTimeUserParams, string $alias, int | \Zend\Di\bolean $methodRequirementType, bool $isInstantiator) : array

Parameters

$class

string

$method

string

$callTimeUserParams

array

$alias

string

$methodRequirementType

int\Zend\Di\bolean

$isInstantiator

bool

Exceptions

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

Returns

array

 Properties

 

All the dependenent aliases

$currentAliasDependenencies : array

 

All the class dependencies [source][dependency]

$currentDependencies : array

 

$definitions

$definitions : \Zend\Di\DefinitionList

 

$instanceContext

$instanceContext : string

 

$instanceManager

$instanceManager : \Zend\Di\InstanceManager

 

All the class references [dependency][source]

$references : array

 Constants

 

resolve mode RESOLVE_EAGER

METHOD_IS_AWARE 

 

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

METHOD_IS_CONSTRUCTOR 

 

resolve mode RESOLVE_EAGER

METHOD_IS_EAGER 

 

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

METHOD_IS_INSTANTIATOR 

 

use only specified parameters

METHOD_IS_OPTIONAL 

 

resolve mode RESOLVE_EAGER | RESOLVE_STRICT

METHOD_IS_REQUIRED 

 

Resolve method policy

RESOLVE_EAGER 

EAGER: explore type preference or go through

 

Resolve method policy

RESOLVE_STRICT 

STRICT: explore type preference or throw exception