Container
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
Initializes the root definition builder and exposes this container through the runtime contract.
Registers a transient definition that is rebuilt for each resolution.
Registers a root-owned definition whose resolved value retains identity for this container.
Registers a definition whose resolved value is retained only by an active scope.
Opens an isolated runtime scope for request, command, or job-local instances.
Registers a transient definition using the same behavior as {set()}.
Registers an existing object as the canonical root-owned service value.
Maps an alternate service ID to the target definition without creating another lifecycle cache.
Adds a wrapper that is applied whenever the explicitly defined target service resolves.
Updates the definition plan for future resolutions while preserving existing singleton identities.
Returns the current immutable definition snapshot without closing registration.
Finalizes definitions and returns the plan used by subsequent runtime resolution.
Reports whether definition mutations are permanently prohibited.
Registers one root-owned service and declares its membership in each supplied tagged collection.
Adds an explicit definition to a named collection capability.
Resolves the root-visible members of a named collection in declaration order.
Resolves a named collection against the supplied scope so scoped members retain scope-local identity.
Reports only whether an explicit definition exists after alias canonicalization.
Reports whether an ID has an explicit definition, alias, or already resolved root singleton.
Resolves an explicit definition or autowires an instantiable concrete class as a transient value.
Resolves a service using the supplied active scope for scoped dependencies and instances.
Rejects a singleton resolution chain that attempts to capture a scope-local value.
Details
__construct
__construct(ContainerBuilder|null $builder = null)
Initializes the root definition builder and exposes this container through the runtime contract.
set
void
set(string $id, callable|object|string $concrete)
Registers a transient definition that is rebuilt for each resolution.
singleton
void
singleton(string $id, callable|object|string $concrete)
Registers a root-owned definition whose resolved value retains identity for this container.
scoped
void
scoped(string $id, callable|object|string $concrete)
Registers a definition whose resolved value is retained only by an active scope.
beginScope
ScopedContainerInterface
beginScope(ScopeKind $kind)
Opens an isolated runtime scope for request, command, or job-local instances.
transient
void
transient(string $id, callable|object|string $concrete)
Registers a transient definition using the same behavior as {set()}.
instance
void
instance(string $id, object $instance)
Registers an existing object as the canonical root-owned service value.
alias
void
alias(string $alias, string $target)
Maps an alternate service ID to the target definition without creating another lifecycle cache.
decorate
void
decorate(string $serviceId, string|callable $decorator, int $priority = 0)
Adds a wrapper that is applied whenever the explicitly defined target service resolves.
when
ContextualBindingBuilder
when(string $consumer)
Updates the definition plan for future resolutions while preserving existing singleton identities.
compile
CompiledContainerPlan
compile()
Returns the current immutable definition snapshot without closing registration.
freeze
CompiledContainerPlan
freeze()
Finalizes definitions and returns the plan used by subsequent runtime resolution.
isFrozen
bool
isFrozen()
Reports whether definition mutations are permanently prohibited.
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.
tag
void
tag(string $serviceId, string $tag)
Adds an explicit definition to a named collection capability.
tagged
iterable
tagged(string $tag)
Resolves the root-visible members of a named collection in declaration order.
taggedInScope
iterable
taggedInScope(ScopedContainer $scope, string $tag)
Resolves a named collection against the supplied scope so scoped members retain scope-local identity.
has
bool
has(string $id)
Reports only whether an explicit definition exists after alias canonicalization.
isBound
bool
isBound(string $id)
Reports whether an ID has an explicit definition, alias, or already resolved root singleton.
get
mixed
get(string $id)
Resolves an explicit definition or autowires an instantiable concrete class as a transient value.
getInScope
mixed
getInScope(ScopedContainer $scope, string $id)
Resolves a service using the supplied active scope for scoped dependencies and instances.
assertScopeLocalServiceCanResolve
void
assertScopeLocalServiceCanResolve(string $id)
Rejects a singleton resolution chain that attempts to capture a scope-local value.