Menu

## Container
in package
implements ContainerInterface, FactoryInterface, InvokerInterface

Container.php : 39

Dependency Injection Container.

##### Tags

author

  Matthieu Napoli matthieu@mnapoli.fr

### Table of Contents

#### Interfaces

ContainerInterface
FactoryInterface
  Describes the basic interface of a factory.
InvokerInterface
  Invoke a callable.

#### 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.
$definitionResolver : DefinitionResolver
$definitionSource : MutableDefinitionSource
$fetchedDefinitions : array<string|int, Definition|null>
  Map of definitions that are already fetched (local cache).
$invoker : 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
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.
setDefinition() : void
createDefaultDefinitionSource() : SourceChain
getDefinition() : Definition|null
getEntryType() : string
  Get formatted entry type.
getInvoker() : InvokerInterface
resolveDefinition() : mixed
  Resolves a definition.

### Properties

#### $delegateContainer

Container.php : 67

Container that wraps this container. If none, points to $this.

`protected ContainerInterface $delegateContainer`

#### $entriesBeingResolved

Container.php : 60

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

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

#### $proxyFactory

Container.php : 69
`protected ProxyFactory $proxyFactory`

#### $resolvedEntries

Container.php : 44

Map of entries that are already resolved.

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

#### $definitionResolver

Container.php : 48
`private DefinitionResolver $definitionResolver`

#### $definitionSource

Container.php : 46
`private MutableDefinitionSource $definitionSource`

#### $fetchedDefinitions

Container.php : 55

Map of definitions that are already fetched (local cache).

`private array<string|int, Definition|null> $fetchedDefinitions = []`

#### $invoker

Container.php : 62
`private InvokerInterface|null $invoker = null`

### Methods

#### __construct()

Container.php : 90

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()

Container.php : 243

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()

Container.php : 71
`public static create(array<string|int, mixed> $definitions) : static`

##### Parameters

$definitions : array<string|int, mixed>

##### Return values

static

#### debugEntry()

Container.php : 296

Get entry debug information.

`public debugEntry(string $name) : string`

##### Parameters

$name : string

  Entry name

##### Tags

throws
  InvalidDefinition
throws
  NotFoundException

##### Return values

string

#### get()

Container.php : 124

Returns an entry of the container by its name.

`public get(string|T> $id) : mixed|T`

##### Parameters

$id : string|T>

  Entry name or a class name.

##### Tags

template

  T

throws
  DependencyException

  Error while resolving the entry.

throws
  NotFoundException

  No entry found for the given name.

##### Return values

mixed|T

#### getKnownEntryNames()

Container.php : 277

Get defined container entries.

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

##### Return values

array<string|int, string>

#### has()

Container.php : 187
`public has(string $id) : bool`

##### Parameters

$id : string

##### Return values

bool

#### injectOn()

Container.php : 210

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

  T

throws
  InvalidArgumentException
throws
  DependencyException

  Error while injecting dependencies

##### Return values

object|T —

$instance Returns the same instance

#### make()

Container.php : 172

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

  T

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()

Container.php : 254

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

#### setDefinition()

Container.php : 362
`protected setDefinition(string $name, Definition $definition) : void`

##### Parameters

$name : string
$definition : Definition

#### createDefaultDefinitionSource()

Container.php : 390
`private createDefaultDefinitionSource(array<string|int, mixed> $definitions) : SourceChain`

##### Parameters

$definitions : array<string|int, mixed>

##### Return values

SourceChain

#### getDefinition()

Container.php : 143
`private getDefinition(string $name) : Definition|null`

##### Parameters

$name : string

##### Return values

Definition|null

#### getEntryType()

Container.php : 313

Get formatted entry type.

`private getEntryType(mixed $entry) : string`

##### Parameters

$entry : mixed

##### Return values

string

#### getInvoker()

Container.php : 373
`private getInvoker() : InvokerInterface`

##### Return values

InvokerInterface

#### resolveDefinition()

Container.php : 341

Resolves a definition.

`private resolveDefinition(Definition $definition[, array<string|int, mixed> $parameters = [] ]) : mixed`

Checks for circular dependencies while resolving the definition.

##### Parameters

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

##### Tags

throws
  DependencyException

  Error while resolving the entry.

## Search results