Documentation

CompiledContainer extends Container
in package

AbstractYes

Compiled version of the dependency injection container.

Tags
author

Matthieu Napoli matthieu@mnapoli.fr

Table of Contents

Constants

METHOD_MAPPING  = []
This const is overridden in child classes (compiled containers).

Properties

$delegateContainer  : ContainerInterface
Container that wraps this container. If none, points to $this.
$entriesBeingResolved  : array<string|int, mixed>
Array of entries being resolved. Used to avoid circular dependencies and infinite loops.
$proxyFactory  : ProxyFactory
$resolvedEntries  : array<string|int, mixed>
Map of entries that are already resolved.
$factoryInvoker  : InvokerInterface|null

Methods

__construct()  : mixed
Use `$container = new Container()` if you want a container with the default configuration.
call()  : mixed
Call the given function using the given parameters.
create()  : static
debugEntry()  : string
Get entry debug information.
get()  : mixed|T
Returns an entry of the container by its name.
getKnownEntryNames()  : array<string|int, string>
Get defined container entries.
has()  : bool
Returns true if the container can return an entry for the given identifier.
injectOn()  : object|T
Inject all dependencies on an existing instance.
make()  : mixed|T
Build an entry of the container by its name.
set()  : void
Define an object or a value in the container.
resolveFactory()  : mixed
Invoke the given callable.
setDefinition()  : void

Constants

METHOD_MAPPING

This const is overridden in child classes (compiled containers).

protected array<string|int, mixed> METHOD_MAPPING = []

Properties

$entriesBeingResolved

Array of entries being resolved. Used to avoid circular dependencies and infinite loops.

protected array<string|int, mixed> $entriesBeingResolved = []

$resolvedEntries

Map of entries that are already resolved.

protected array<string|int, mixed> $resolvedEntries = []

Methods

__construct()

Use `$container = new Container()` if you want a container with the default configuration.

public __construct([array<string|int, mixed>|MutableDefinitionSource $definitions = [] ][, ProxyFactory|null $proxyFactory = null ][, ContainerInterface $wrapperContainer = null ]) : mixed

If you want to customize the container's behavior, you are discouraged to create and pass the dependencies yourself, the ContainerBuilder class is here to help you instead.

Parameters
$definitions : array<string|int, mixed>|MutableDefinitionSource = []
$proxyFactory : ProxyFactory|null = null
$wrapperContainer : ContainerInterface = null

If the container is wrapped by another container.

Tags
see
ContainerBuilder

call()

Call the given function using the given parameters.

public call(callable|array<string|int, mixed>|string $callable[, array<string|int, mixed> $parameters = [] ]) : mixed

Missing parameters will be resolved from the container.

Parameters
$callable : callable|array<string|int, mixed>|string

Function to call.

$parameters : array<string|int, mixed> = []

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 values
mixed

Result of the function.

create()

public static create(array<string|int, mixed> $definitions) : static
Parameters
$definitions : array<string|int, mixed>
Return values
static

get()

Returns an entry of the container by its name.

public get(string $id) : mixed|T
Parameters
$id : string

Entry name or a class name.

Return values
mixed|T

getKnownEntryNames()

Get defined container entries.

public getKnownEntryNames() : array<string|int, string>
Return values
array<string|int, string>

has()

Returns true if the container can return an entry for the given identifier.

public has(string $id) : bool

Returns false otherwise.

has($id) returning true does not mean that get($id) will not throw an exception. It does however mean that get($id) will not throw a NotFoundExceptionInterface.

Parameters
$id : string

Identifier of the entry to look for.

Return values
bool

injectOn()

Inject all dependencies on an existing instance.

public injectOn(object|T $instance) : object|T
Parameters
$instance : object|T

Object to perform injection upon

Tags
template
throws
InvalidArgumentException
throws
DependencyException

Error while injecting dependencies

Return values
object|T

$instance Returns the same instance

make()

Build an entry of the container by its name.

public make(string|T> $name[, array<string|int, mixed> $parameters = [] ]) : mixed|T

This method behave like get() except resolves the entry again every 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.

Parameters
$name : string|T>

Entry name or a class name.

$parameters : array<string|int, mixed> = []

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.

Tags
template
throws
InvalidArgumentException

The name parameter must be of type string.

throws
DependencyException

Error while resolving the entry.

throws
NotFoundException

No entry found for the given name.

Return values
mixed|T

set()

Define an object or a value in the container.

public set(string $name, mixed|DefinitionHelper $value) : void
Parameters
$name : string

Entry name

$value : mixed|DefinitionHelper

Value, use definition helpers to define objects

resolveFactory()

Invoke the given callable.

protected resolveFactory(mixed $callable, mixed $entryName[, array<string|int, mixed> $extraParameters = [] ]) : mixed
Parameters
$callable : mixed
$entryName : mixed
$extraParameters : array<string|int, mixed> = []

setDefinition()

protected setDefinition(string $name, Definition $definition) : void
Parameters
$name : string
$definition : Definition

        
On this page

Search results