final class Container implements ContainerInterface, ContainerBuilderInterface, ScopeFactoryInterface, TaggedServicesInterface (View source)

Resolves concrete object graphs through reflection while keeping explicit definitions and their lifecycle caches in one root-owned runtime container.

Methods

__construct(ContainerBuilder|null $builder = null)

Initializes the root definition builder and exposes this container through the runtime contract.

void
set(string $id, callable|object|string $concrete)

Registers a transient definition that is rebuilt for each resolution.

void
void
singleton(string $id, callable|object|string $concrete)

Registers a root-owned definition whose resolved value retains identity for this container.

void
void
scoped(string $id, callable|object|string $concrete)

Registers a definition whose resolved value is retained only by an active scope.

void
beginScope(ScopeKind $kind)

Opens an isolated runtime scope for request, command, or job-local instances.

void
transient(string $id, callable|object|string $concrete)

Registers a transient definition using the same behavior as {set()}.

void
void
instance(string $id, object $instance)

Registers an existing object as the canonical root-owned service value.

void
void
alias(string $alias, string $target)

Maps an alternate service ID to the target definition without creating another lifecycle cache.

void
void
decorate(string $serviceId, string|callable $decorator, int $priority = 0)

Adds a wrapper that is applied whenever the explicitly defined target service resolves.

void
when(string $consumer)

Updates the definition plan for future resolutions while preserving existing singleton identities.

Returns the current immutable definition snapshot without closing registration.

freeze()

Finalizes definitions and returns the plan used by subsequent runtime resolution.

bool

Reports whether definition mutations are permanently prohibited.

bool
void
singletonTagged(string $id, callable|object|string $concrete, string ...$tags)

Registers one root-owned service and declares its membership in each supplied tagged collection.

void
void
tag(string $serviceId, string $tag)

Adds an explicit definition to a named collection capability.

void
iterable
tagged(string $tag)

Resolves the root-visible members of a named collection in declaration order.

iterable
iterable
taggedInScope(ScopedContainer $scope, string $tag)

Resolves a named collection against the supplied scope so scoped members retain scope-local identity.

iterable
bool
has(string $id)

Reports only whether an explicit definition exists after alias canonicalization.

bool
bool
isBound(string $id)

Reports whether an ID has an explicit definition, alias, or already resolved root singleton.

bool
mixed
get(string $id)

Resolves an explicit definition or autowires an instantiable concrete class as a transient value.

mixed
mixed
getInScope(ScopedContainer $scope, string $id)

Resolves a service using the supplied active scope for scoped dependencies and instances.

mixed
void

Rejects a singleton resolution chain that attempts to capture a scope-local value.

void

Details

__construct

__construct(ContainerBuilder|null $builder = null)

Initializes the root definition builder and exposes this container through the runtime contract.

Parameters

ContainerBuilder|null $builder

set

void set(string $id, callable|object|string $concrete)

Registers a transient definition that is rebuilt for each resolution.

Parameters

string $id
callable|object|string $concrete

Return Value

void

singleton

void singleton(string $id, callable|object|string $concrete)

Registers a root-owned definition whose resolved value retains identity for this container.

Parameters

string $id
callable|object|string $concrete

Return Value

void

scoped

void scoped(string $id, callable|object|string $concrete)

Registers a definition whose resolved value is retained only by an active scope.

Parameters

string $id
callable|object|string $concrete

Return Value

void

beginScope

ScopedContainerInterface beginScope(ScopeKind $kind)

Opens an isolated runtime scope for request, command, or job-local instances.

Parameters

ScopeKind $kind

Return Value

ScopedContainerInterface

transient

void transient(string $id, callable|object|string $concrete)

Registers a transient definition using the same behavior as {set()}.

Parameters

string $id
callable|object|string $concrete

Return Value

void

instance

void instance(string $id, object $instance)

Registers an existing object as the canonical root-owned service value.

Parameters

string $id
object $instance

Return Value

void

alias

void alias(string $alias, string $target)

Maps an alternate service ID to the target definition without creating another lifecycle cache.

Parameters

string $alias
string $target

Return Value

void

decorate

void decorate(string $serviceId, string|callable $decorator, int $priority = 0)

Adds a wrapper that is applied whenever the explicitly defined target service resolves.

Parameters

string $serviceId
string|callable $decorator
int $priority

Return Value

void

when

ContextualBindingBuilder when(string $consumer)

Updates the definition plan for future resolutions while preserving existing singleton identities.

Parameters

string $consumer

Return Value

ContextualBindingBuilder

compile

Returns the current immutable definition snapshot without closing registration.

Return Value

CompiledContainerPlan

freeze

Finalizes definitions and returns the plan used by subsequent runtime resolution.

Return Value

CompiledContainerPlan

isFrozen

bool isFrozen()

Reports whether definition mutations are permanently prohibited.

Return Value

bool

singletonTagged

void singletonTagged(string $id, callable|object|string $concrete, string ...$tags)

Registers one root-owned service and declares its membership in each supplied tagged collection.

Parameters

string $id
callable|object|string $concrete
string ...$tags

Return Value

void

tag

void tag(string $serviceId, string $tag)

Adds an explicit definition to a named collection capability.

Parameters

string $serviceId
string $tag

Return Value

void

tagged

iterable tagged(string $tag)

Resolves the root-visible members of a named collection in declaration order.

Parameters

string $tag

Return Value

iterable

taggedInScope

iterable taggedInScope(ScopedContainer $scope, string $tag)

Resolves a named collection against the supplied scope so scoped members retain scope-local identity.

Parameters

ScopedContainer $scope
string $tag

Return Value

iterable

has

bool has(string $id)

Reports only whether an explicit definition exists after alias canonicalization.

Parameters

string $id

Return Value

bool

isBound

bool isBound(string $id)

Reports whether an ID has an explicit definition, alias, or already resolved root singleton.

Parameters

string $id

Return Value

bool

get

mixed get(string $id)

Resolves an explicit definition or autowires an instantiable concrete class as a transient value.

Parameters

string $id

Return Value

mixed

getInScope

mixed getInScope(ScopedContainer $scope, string $id)

Resolves a service using the supplied active scope for scoped dependencies and instances.

Parameters

ScopedContainer $scope
string $id

Return Value

mixed

assertScopeLocalServiceCanResolve

void assertScopeLocalServiceCanResolve(string $id)

Rejects a singleton resolution chain that attempts to capture a scope-local value.

Parameters

string $id

Return Value

void