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

package Default
inherited_from \Zend\Di\Di

 Methods

Constructor

__construct(\Zend\Di\Di $di, \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, null|\Zend\ServiceManager\Di\DiInstanceManagerProxy $diImProxy = null
inherited_from \Zend\Di\Di::__construct()

Parameters

$di

\Zend\Di\Di

$serviceLocator

\Zend\ServiceManager\ServiceLocatorInterface

$diImProxy

null\Zend\ServiceManager\Di\DiInstanceManagerProxy

Constructor

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

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
Inherited

Parameters

$config

\Zend\Di\Config

definitions()

definitions() : \Zend\Di\DefinitionList
Inherited

Returns

\Zend\Di\DefinitionList

Lazy-load a class

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

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

Initialize

initialize($instance, \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) 
inherited_from \Zend\ServiceManager\InitializerInterface::initialize()

Parameters

$instance

$serviceLocator

\Zend\ServiceManager\ServiceLocatorInterface

Exceptions

\Exception

Inject dependencies

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

Parameters

$instance

object

$params

array

instanceManager()

instanceManager() : \Zend\Di\InstanceManager
Inherited

Returns

\Zend\Di\InstanceManager

Retrieve a new instance of a class

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

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\ServiceManager\Di\DiServiceInitializer
Inherited
fluent This method is part of a fluent interface and will return the same instance

Parameters

$definitions

\Zend\Di\DefinitionList

Returns

\Zend\ServiceManager\Di\DiServiceInitializer

Set the instance manager

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

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
Inherited

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
Inherited

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
Inherited

Parameters

$name

$params

array

$method

string

Returns

array

handleInjectDependencies()

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

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
InheritedStatic
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
Inherited

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
Inherited

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
 

$di

$di : \Zend\Di\Di

Default

null
 

$diInstanceManagerProxy

$diInstanceManagerProxy : \Zend\ServiceManager\Di\DiInstanceManagerProxy

Default

null
 

$instanceContext

$instanceContext : string

Default

array()
 

$instanceManager

$instanceManager : \Zend\Di\InstanceManager

Default

null
 

All the class references [dependency][source]

$references : array

Default

array()
 

$serviceLocator

$serviceLocator : \Zend\ServiceManager\ServiceLocatorInterface

Default

null

 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