PHP Class DI\Container

Author: Matthieu Napoli ([email protected])
Inheritance: implements Interop\Container\ContainerInterface, implements di\FactoryInterface, implements DI\InvokerInterface
Datei anzeigen Open project: mnapoli/php-di Class Usage Examples

Public Methods

Method Description
__construct ( DI\Definition\Source\DefinitionSource $definitionSource, ProxyFactory $proxyFactory, Interop\Container\ContainerInterface $wrapperContainer = null ) Use the ContainerBuilder to ease constructing the Container.
call ( callable $callable, array $parameters = [] ) : mixed Call the given function using the given parameters.
get ( string $name ) : mixed Returns an entry of the container by its name.
has ( string $name ) : boolean Test if the container can provide something for the given name.
injectOn ( object $instance ) : object Inject all dependencies on an existing instance.
make ( string $name, array $parameters = [] ) : mixed Build an entry of the container by its name.
set ( string $name, mixed | DI\Definition\Helper\DefinitionHelper $value ) Define an object or a value in the container.

Private Methods

Method Description
getInvoker ( ) : Invoker\InvokerInterface
resolveDefinition ( DI\Definition\Definition $definition, array $parameters = [] ) : mixed Resolves a definition.
setDefinition ( $name, DI\Definition\Definition $definition )

Method Details

__construct() public method

Use the ContainerBuilder to ease constructing the Container.
See also: ContainerBuilder
public __construct ( DI\Definition\Source\DefinitionSource $definitionSource, ProxyFactory $proxyFactory, Interop\Container\ContainerInterface $wrapperContainer = null )
$definitionSource DI\Definition\Source\DefinitionSource
$proxyFactory DI\Proxy\ProxyFactory
$wrapperContainer Interop\Container\ContainerInterface If the container is wrapped by another container.

call() public method

Missing parameters will be resolved from the container.
public call ( callable $callable, array $parameters = [] ) : mixed
$callable callable Function to call.
$parameters array Parameters to use. Can be indexed by the parameter names or not indexed (same order as the parameters). The array can also contain DI definitions, e.g. DI\get().
return mixed Result of the function.

get() public method

Returns an entry of the container by its name.
public get ( string $name ) : mixed
$name string Entry name or a class name.
return mixed

has() public method

Test if the container can provide something for the given name.
public has ( string $name ) : boolean
$name string Entry name or a class name.
return boolean

injectOn() public method

Inject all dependencies on an existing instance.
public injectOn ( object $instance ) : object
$instance object Object to perform injection upon
return object $instance Returns the same instance

make() public method

This method behave like get() except it forces the scope to "prototype", which means the definition of the entry will be re-evaluated each time. For example, if the entry is a class, then a new instance will be created each time. This method makes the container behave like a factory.
public make ( string $name, array $parameters = [] ) : mixed
$name string Entry name or a class name.
$parameters array Optional parameters to use to build the entry. Use this to force specific parameters to specific values. Parameters not defined in this array will be resolved using the container.
return mixed

set() public method

Define an object or a value in the container.
public set ( string $name, mixed | DI\Definition\Helper\DefinitionHelper $value )
$name string Entry name
$value mixed | DI\Definition\Helper\DefinitionHelper Value, use definition helpers to define objects