PHP Класс DI\Container

Автор: Matthieu Napoli ([email protected])
Наследование: implements Interop\Container\ContainerInterface, implements di\FactoryInterface, implements DI\InvokerInterface
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
getInvoker ( ) : Invoker\InvokerInterface
resolveDefinition ( DI\Definition\Definition $definition, array $parameters = [] ) : mixed Resolves a definition.
setDefinition ( $name, DI\Definition\Definition $definition )

Описание методов

__construct() публичный Метод

Use the ContainerBuilder to ease constructing the Container.
См. также: 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() публичный Метод

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().
Результат mixed Result of the function.

get() публичный Метод

Returns an entry of the container by its name.
public get ( string $name ) : mixed
$name string Entry name or a class name.
Результат mixed

has() публичный Метод

Test if the container can provide something for the given name.
public has ( string $name ) : boolean
$name string Entry name or a class name.
Результат boolean

injectOn() публичный Метод

Inject all dependencies on an existing instance.
public injectOn ( object $instance ) : object
$instance object Object to perform injection upon
Результат object $instance Returns the same instance

make() публичный Метод

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.
Результат mixed

set() публичный Метод

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