class Container implements ArrayAccess, Container

Traits

Constants

protected BUILD_STACK_CONTEXT_KEY

Context key for the coroutine-local build stack.

DEPTH_CONTEXT_KEY

Context key for the coroutine-local resolution depth counter.

protected RESOLVING_STACK_CONTEXT_KEY

Context key for the coroutine-local resolving stack.

Tracks abstracts currently being resolved, used exclusively for circular dependency detection. Separate from BUILD_STACK_CONTEXT_KEY (which is also used by call() for contextual binding lookup) to avoid false positives when call() pushes a class name that is then re-resolved inside the method body.

protected MAX_RESOLUTION_DEPTH

Maximum resolution depth before assuming a circular dependency.

Safety net for indirect cycles (e.g., through interfaces) where the abstract names differ from the concretes pushed by build(), making the direct in_array check insufficient.

protected PARAMETER_OVERRIDES_CONTEXT_KEY

Context key for the coroutine-local parameter override stack.

protected SCOPED_CONTEXT_PREFIX

Context key prefix for coroutine-local scoped instances.

Properties

static protected null|Container $instance

The current globally available container (if any).

protected bool[] $resolved

An array of the types that have been resolved.

protected array[] $bindings

The container's bindings.

protected Closure[] $methodBindings

The container's method bindings.

protected array<string, mixed> $instances

The container's shared instances.

protected object[] $autoSingletons

Auto-singletoned instances for unbound concrete classes.

protected SharedResolution> $sharedResolutions

Cacheable first resolutions currently owned by a coroutine.

protected array<int, int> $sharedResolutionWaits

Container waits keyed by the waiting coroutine ID.

protected array<string, true> $scopedInstances

The abstract names registered as scoped bindings.

protected string[] $aliases

The registered type aliases.

protected array[] $abstractAliases

The registered aliases keyed by the abstract name.

protected array[] $extenders

The extension closures for services.

protected array[] $tags

All of the registered tags.

array[] $contextual

The contextual binding map.

array[] $contextualAttributes

The contextual attribute handlers.

protected array<class-string, true> $checkedForAttributeBindings

Whether an abstract class has already had its attributes checked for bindings.

protected array<class-string, null|"scoped"|"singleton"> $checkedForSingletonOrScopedAttributes

Whether a class has already been checked for Singleton or Scoped attributes.

protected array[] $reboundCallbacks

All of the registered rebound callbacks.

protected Closure[] $globalBeforeResolvingCallbacks

All of the global before resolving callbacks.

protected Closure[] $globalResolvingCallbacks

All of the global resolving callbacks.

protected Closure[] $globalAfterResolvingCallbacks

All of the global after resolving callbacks.

protected array[] $beforeResolvingCallbacks

All of the before resolving callbacks by class type.

protected array[] $resolvingCallbacks

All of the resolving callbacks by class type.

protected array[] $afterResolvingCallbacks

All of the after resolving callbacks by class type.

protected Closure>> $afterResolvingAttributeCallbacks

All of the after resolving attribute callbacks by class type.

protected null|(callable(array<int, string>|string): bool|string) $environmentResolver

The callback used to determine the container's environment.

static protected BuildRecipe> $buildRecipes

Cache of computed build recipes.

Methods

string
firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

array
firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

array
closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

array
closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

when(string|array $concrete)

Define a contextual binding.

void
whenHasAttribute(string $attribute, Closure $handler)

Define a contextual binding based on an attribute.

bool
bound(string $abstract)

Determine if the given abstract type has been bound.

bool
has(string $id)

No description

bool
resolved(string $abstract)

Determine if the given abstract type has been resolved.

bool
isShared(string $abstract)

Determine if a given type is shared.

bool
isScoped(string $abstract)

Determine if a given abstract is a scoped binding.

string|null
getScopedType(ReflectionClass|string $reflection)

Determine if a ReflectionClass has scoping attributes applied.

bool
isAlias(string $name)

Determine if a given string is an alias.

void
bind(Closure|string $abstract, Closure|string|null $concrete = null, bool $shared = false)

Register a binding with the container.

void
registerBinding(string $abstract, Closure|string|null $concrete, bool $shared, bool $scoped)

Register one binding and its lifecycle.

getClosure(string $abstract, string $concrete)

Get the Closure to be used when building a type.

bool
hasMethodBinding(string $method)

Determine if the container has a method binding.

void
bindMethod(array|string $method, Closure $callback)

Bind a callback to resolve with Container::call.

string
parseBindMethod(array|string $method)

Get the method to be bound in class@method format.

mixed
callMethodBinding(string $method, mixed $instance)

Get the method binding for the given method.

void
addContextualBinding(string $concrete, string $abstract, mixed $implementation)

Add a contextual binding to the container.

void
bindIf(Closure|string $abstract, Closure|string|null $concrete = null, bool $shared = false)

Register a binding if it hasn't already been registered.

void
singleton(Closure|string $abstract, Closure|string|null $concrete = null)

Register a shared binding in the container.

void
singletonIf(Closure|string $abstract, Closure|string|null $concrete = null)

Register a shared binding if it hasn't already been registered.

void
scoped(Closure|string $abstract, Closure|string|null $concrete = null)

Register a scoped binding in the container.

void
scopedIf(Closure|string $abstract, Closure|string|null $concrete = null)

Register a scoped binding if it hasn't already been registered.

void
bindBasedOnClosureReturnTypes(Closure $abstract, Closure|string|null $concrete = null, bool $shared = false, bool $scoped = false, bool $onlyIfUnbound = false)

Register a binding with the container based on the given Closure's return types.

void
extend(string $abstract, Closure $closure)

"Extend" an abstract type in the container.

mixed
instance(string $abstract, mixed $instance)

Register an existing instance as shared in the container.

void
removeAbstractAlias(string $searched)

Remove an alias from the contextual binding alias cache.

void
tag(array|string $abstracts, array|string $tags)

Assign a set of tags to a given binding.

iterable
tagged(string $tag)

Resolve all of the bindings for a given tag.

void
alias(string $abstract, string $alias)

Alias a type to a different name.

mixed
rebinding(string $abstract, Closure $callback)

Bind a new callback to an abstract's rebind event.

mixed
refresh(string $abstract, mixed $target, string $method)

Refresh an instance on the given target and method.

void
rebound(string $abstract)

Fire the "rebound" callbacks for the given abstract type.

array
getReboundCallbacks(string $abstract)

Get the rebound callbacks for a given type.

wrap(Closure $callback, array $parameters = [])

Wrap the given closure such that its dependencies will be injected when executed.

mixed
call(callable|string $callback, array $parameters = [], string|null $defaultMethod = null)

Call the given Closure / class@method and inject its dependencies.

string|false
getClassForCallable(callable|string $callback)

Get the class name for the given callback, if one can be determined.

factory(string $abstract)

Get a closure to resolve the given type from the container.

mixed
makeWith(string $abstract, array $parameters = [])

An alias function name for make().

mixed
make(string $abstract, array $parameters = [])

Resolve the given type from the container.

mixed
get(string $id)

No description

mixed
resolve(string $abstract, array $parameters = [], bool $raiseEvents = true)

Resolve the given type from the container.

bool
shouldCoordinateSharedResolution(string $abstract, mixed $concrete, bool $needsContextualBuild, bool $raiseEvents)

Determine whether this miss can publish a worker-shared instance.

mixed
awaitSharedResolution(string $abstract, SharedResolution $resolution)

Wait for a shared resolution without introducing a coordinator cycle.

bool
sharedResolutionOwnerIsAncestor(int $ownerId, int $coroutineId)

Determine whether the resolution owner is an ancestor of a coroutine.

bool
sharedResolutionWaitWouldCycle(int $waiterId, int $ownerId)

Determine whether adding a container wait edge would close a cycle.

mixed
getConcrete(string $abstract)

Get the concrete type for a given abstract.

mixed
getConcreteBindingFromAttributes(string $abstract)

Get the concrete binding for an abstract from the Bind attribute.

mixed
getContextualConcrete(string $abstract)

Get the contextual concrete binding for the given abstract.

array
getBuildStack()

Get the current build stack from coroutine-local context.

void
setBuildStack(array $stack)

Set the build stack in coroutine-local context.

void
pushBuildStack(string $abstract)

Push an abstract onto the coroutine-local build stack.

void
popBuildStack()

Pop the last entry from the coroutine-local build stack.

array
getResolvingStack()

Get the resolving stack from coroutine-local context.

void
pushResolvingStack(string $abstract)

Push an abstract onto the coroutine-local resolving stack.

void
popResolvingStack()

Pop the last entry from the coroutine-local resolving stack.

array
getParameterOverrideStack()

Get the parameter override stack from coroutine-local context.

void
pushParameterOverrides(array $parameters)

Push parameter overrides onto the coroutine-local stack.

void
popParameterOverrides()

Pop the last parameter overrides from the coroutine-local stack.

array
getLastParameterOverride()

Get the last parameter override from the coroutine-local stack.

mixed
findInContextualBindings(string $abstract)

Find the concrete binding for the given abstract in the contextual binding array.

bool
isBuildable(mixed $concrete, string $abstract)

Determine if the given concrete is buildable.

getBuildRecipe(string $concrete)

Get the cached build recipe for the given concrete class.

computeBuildRecipe(string $concrete)

Compute the build recipe for the given concrete class.

mixed
buildWith(Closure|string $concrete, array $parameters = [])

Instantiate a concrete instance with the given parameter overrides.

mixed
build(Closure|string $concrete)

Instantiate a concrete instance of the given type.

mixed
buildSelfBuildingInstance(string $concrete, BuildRecipe $recipe)

Instantiate a concrete instance of the given self building type.

array
resolveRecipeParameters(BuildRecipe $recipe)

Resolve all constructor parameters using cached recipe metadata.

bool
hasParameterOverride(ParameterRecipe $param)

Determine if the given dependency has a parameter override.

mixed
getParameterOverride(ParameterRecipe $param)

Get a parameter override for a dependency.

mixed
resolvePrimitive(ParameterRecipe $param)

Resolve a non-class hinted primitive dependency.

mixed
resolveClass(ParameterRecipe $param)

Resolve a class based dependency from the container.

mixed
resolveVariadicClass(ParameterRecipe $param)

Resolve a class based variadic dependency from the container.

mixed
resolveFromAttribute(ReflectionAttribute $attribute, ReflectionParameter $parameter)

Resolve a dependency based on an attribute.

never
notInstantiable(string $concrete)

Throw an exception that the concrete is not instantiable.

never
unresolvablePrimitive(ParameterRecipe $param)

Throw an exception for an unresolvable primitive.

void
beforeResolving(Closure|string $abstract, Closure|null $callback = null)

Register a new before resolving callback for all types.

void
resolving(Closure|string $abstract, Closure|null $callback = null)

Register a new resolving callback.

void
afterResolving(Closure|string $abstract, Closure|null $callback = null)

Register a new after resolving callback for all types.

void
afterResolvingAttribute(string $attribute, Closure $callback)

Register a new after resolving attribute callback for all types.

void
fireBeforeResolvingCallbacks(string $abstract, array $parameters = [])

Fire all of the before resolving callbacks.

void
fireBeforeCallbackArray(string $abstract, array $parameters, array $callbacks)

Fire an array of callbacks with an object.

void
fireResolvingCallbacks(string $abstract, mixed $object)

Fire all of the resolving callbacks.

void
fireAfterResolvingCallbacks(string $abstract, mixed $object)

Fire all of the after resolving callbacks.

void
fireAfterResolvingAttributeCallbacks(array $attributes, mixed $object)

Fire all of the after resolving attribute callbacks.

void
fireCallbacksForType(string $abstract, mixed $object, array $callbacksPerType)

Fire all callbacks that match the given abstract or object type.

void
fireCallbackArray(mixed $object, array $callbacks)

Fire an array of callbacks with an object.

string|null
currentlyResolving()

Get the name of the binding the container is currently resolving.

array
getBindings()

Get the container's bindings.

string
getAlias(string $abstract)

Get the alias for an abstract if available.

array
getExtenders(string $abstract)

Get the extender callbacks for a given type.

void
forgetExtenders(string $abstract)

Remove all of the extender callbacks for a given type.

void
dropStaleInstances(string $abstract)

Drop all of the stale instances and aliases.

void
forgetCachedInstances(string $abstract)

Forget every cached instance for an abstract without changing its lifecycle.

void
forgetInstance(string $abstract)

Remove a resolved instance from the instance cache.

void
forgetInstances()

Clear all of the instances from the container.

void
forgetScopedInstances()

Clear all of the scoped instances from the container.

void
resolveEnvironmentUsing(callable|null $callback)

Set the callback which determines the current container environment.

bool
currentEnvironmentIs(array|string $environments)

Determine the environment for the container.

void
flush()

Flush the container of all bindings and resolved instances.

static Container
getInstance()

Get the globally available instance of the container.

static Container|null
setInstance(Container|null $container = null)

Set the shared instance of the container.

static void
flushState()

Flush all static state.

bool
offsetExists(string $key)

Determine if a given offset exists.

mixed
offsetGet(string $key)

Get the value at a given offset.

void
offsetSet(string $key, mixed $value)

Set the value at a given offset.

void
offsetUnset(string $key)

Unset the value at a given offset.

mixed
__get(string $key)

Dynamically access container services.

void
__set(string $key, mixed $value)

Dynamically set container services.

Details

in ReflectsClosures at line 25
protected string firstClosureParameterType(Closure $closure)

Get the class name of the first parameter of the given Closure.

Parameters

Closure $closure

Return Value

string

Exceptions

ReflectionException
RuntimeException

in ReflectsClosures at line 48
protected array firstClosureParameterTypes(Closure $closure)

Get the class names of the first parameter of the given Closure, including union types.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException
RuntimeException

in ReflectsClosures at line 74
protected array closureParameterTypes(Closure $closure)

Get the class names / types of the parameters of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

in ReflectsClosures at line 94
protected array closureReturnTypes(Closure $closure)

Get the class names / types of the return type of the given Closure.

Parameters

Closure $closure

Return Value

array

Exceptions

ReflectionException

at line 284
ContextualBindingBuilder when(string|array $concrete)

Define a contextual binding.

Parameters

string|array $concrete

Return Value

ContextualBindingBuilder

at line 298
void whenHasAttribute(string $attribute, Closure $handler)

Define a contextual binding based on an attribute.

Parameters

string $attribute
Closure $handler

Return Value

void

at line 306
bool bound(string $abstract)

Determine if the given abstract type has been bound.

Parameters

string $abstract

Return Value

bool

at line 314
bool has(string $id)

No description

Parameters

string $id

Return Value

bool

at line 322
bool resolved(string $abstract)

Determine if the given abstract type has been resolved.

Parameters

string $abstract

Return Value

bool

at line 336
bool isShared(string $abstract)

Determine if a given type is shared.

Parameters

string $abstract

Return Value

bool

at line 368
bool isScoped(string $abstract)

Determine if a given abstract is a scoped binding.

Parameters

string $abstract

Return Value

bool

at line 393
protected string|null getScopedType(ReflectionClass|string $reflection)

Determine if a ReflectionClass has scoping attributes applied.

Parameters

ReflectionClass|string $reflection

Return Value

string|null

at line 425
bool isAlias(string $name)

Determine if a given string is an alias.

Parameters

string $name

Return Value

bool

at line 440
void bind(Closure|string $abstract, Closure|string|null $concrete = null, bool $shared = false)

Register a binding with the container.

Boot-only. Bindings persist on the worker-lifetime container; runtime use races across coroutines and changes resolution for every subsequent request.

Parameters

Closure|string $abstract
Closure|string|null $concrete
bool $shared

Return Value

void

Exceptions

TypeError
ReflectionException

at line 458
protected void registerBinding(string $abstract, Closure|string|null $concrete, bool $shared, bool $scoped)

Register one binding and its lifecycle.

Parameters

string $abstract
Closure|string|null $concrete
bool $shared
bool $scoped

Return Value

void

at line 495
protected Closure getClosure(string $abstract, string $concrete)

Get the Closure to be used when building a type.

Parameters

string $abstract
string $concrete

Return Value

Closure

at line 513
bool hasMethodBinding(string $method)

Determine if the container has a method binding.

Parameters

string $method

Return Value

bool

at line 524
void bindMethod(array|string $method, Closure $callback)

Bind a callback to resolve with Container::call.

Boot-only. Method bindings persist on the worker-lifetime container and affect every subsequent Container::call() for the bound method.

Parameters

array|string $method
Closure $callback

Return Value

void

at line 532
protected string parseBindMethod(array|string $method)

Get the method to be bound in class@method format.

Parameters

array|string $method

Return Value

string

at line 544
mixed callMethodBinding(string $method, mixed $instance)

Get the method binding for the given method.

Parameters

string $method
mixed $instance

Return Value

mixed

at line 556
void addContextualBinding(string $concrete, string $abstract, mixed $implementation)

Add a contextual binding to the container.

Boot-only. Contextual bindings persist on the worker-lifetime container; runtime use races across coroutines and changes dependency resolution for every subsequent build of the concrete.

Parameters

string $concrete
string $abstract
mixed $implementation

Return Value

void

at line 567
void bindIf(Closure|string $abstract, Closure|string|null $concrete = null, bool $shared = false)

Register a binding if it hasn't already been registered.

Boot-only. Conditional bindings mutate the worker-lifetime container for every subsequent request.

Parameters

Closure|string $abstract
Closure|string|null $concrete
bool $shared

Return Value

void

at line 592
void singleton(Closure|string $abstract, Closure|string|null $concrete = null)

Register a shared binding in the container.

Boot-only. Singleton bindings persist on the worker-lifetime container; runtime use races across coroutines and changes shared resolution for every subsequent request.

Parameters

Closure|string $abstract
Closure|string|null $concrete

Return Value

void

at line 603
void singletonIf(Closure|string $abstract, Closure|string|null $concrete = null)

Register a shared binding if it hasn't already been registered.

Boot-only. Conditional singleton bindings mutate the worker-lifetime container for every subsequent request.

Parameters

Closure|string $abstract
Closure|string|null $concrete

Return Value

void

at line 614
void scoped(Closure|string $abstract, Closure|string|null $concrete = null)

Register a scoped binding in the container.

Boot-only. Scoped binding definitions persist on the worker-lifetime container; only their resolved instances are coroutine-scoped.

Parameters

Closure|string $abstract
Closure|string|null $concrete

Return Value

void

at line 631
void scopedIf(Closure|string $abstract, Closure|string|null $concrete = null)

Register a scoped binding if it hasn't already been registered.

Boot-only. Conditional scoped bindings mutate the worker-lifetime container for every subsequent request.

Parameters

Closure|string $abstract
Closure|string|null $concrete

Return Value

void

at line 653
protected void bindBasedOnClosureReturnTypes(Closure $abstract, Closure|string|null $concrete = null, bool $shared = false, bool $scoped = false, bool $onlyIfUnbound = false)

Register a binding with the container based on the given Closure's return types.

Parameters

Closure $abstract
Closure|string|null $concrete
bool $shared
bool $scoped
bool $onlyIfUnbound

Return Value

void

at line 681
void extend(string $abstract, Closure $closure)

"Extend" an abstract type in the container.

Boot-only. The extender persists in the container's $extenders array for the worker lifetime and runs on every subsequent resolution of $abstract.

Parameters

string $abstract
Closure $closure

Return Value

void

Exceptions

InvalidArgumentException

at line 725
mixed instance(string $abstract, mixed $instance)

Register an existing instance as shared in the container.

Tests only. Replaces a worker-lifetime shared instance; runtime use races across coroutines and changes the object returned to every subsequent resolver.

Parameters

string $abstract
mixed $instance

Return Value

mixed

at line 750
protected void removeAbstractAlias(string $searched)

Remove an alias from the contextual binding alias cache.

Parameters

string $searched

Return Value

void

at line 771
void tag(array|string $abstracts, array|string $tags)

Assign a set of tags to a given binding.

Boot-only. Tags persist on the worker-lifetime container and affect every subsequent tagged() resolution.

Parameters

array|string $abstracts
array|string $tags

Return Value

void

at line 789
iterable tagged(string $tag)

Resolve all of the bindings for a given tag.

Parameters

string $tag

Return Value

iterable

at line 811
void alias(string $abstract, string $alias)

Alias a type to a different name.

Boot-only. Aliases persist on the worker-lifetime container; runtime use races across coroutines and changes resolution for every subsequent request.

Parameters

string $abstract
string $alias

Return Value

void

Exceptions

LogicException

at line 846
mixed rebinding(string $abstract, Closure $callback)

Bind a new callback to an abstract's rebind event.

Boot-only. Rebinding callbacks persist on the worker-lifetime container and run whenever the abstract is rebound later in the worker.

Parameters

string $abstract
Closure $callback

Return Value

mixed

at line 863
mixed refresh(string $abstract, mixed $target, string $method)

Refresh an instance on the given target and method.

Boot-only. Registers a rebinding callback on the worker-lifetime container; runtime use leaks the callback across later rebindings.

Parameters

string $abstract
mixed $target
string $method

Return Value

mixed

at line 873
protected void rebound(string $abstract)

Fire the "rebound" callbacks for the given abstract type.

Parameters

string $abstract

Return Value

void

at line 889
protected array getReboundCallbacks(string $abstract)

Get the rebound callbacks for a given type.

Parameters

string $abstract

Return Value

array

at line 897
Closure wrap(Closure $callback, array $parameters = [])

Wrap the given closure such that its dependencies will be injected when executed.

Parameters

Closure $callback
array $parameters

Return Value

Closure

at line 909
mixed call(callable|string $callback, array $parameters = [], string|null $defaultMethod = null)

Call the given Closure / class@method and inject its dependencies.

Parameters

callable|string $callback
array $parameters
string|null $defaultMethod

Return Value

mixed

Exceptions

InvalidArgumentException

at line 974
protected string|false getClassForCallable(callable|string $callback)

Get the class name for the given callback, if one can be determined.

Closures are handled directly in call() before this method is reached, so this only needs to handle non-closure callable types.

Parameters

callable|string $callback

Return Value

string|false

at line 999
Closure factory(string $abstract)

Get a closure to resolve the given type from the container.

Parameters

string $abstract

Return Value

Closure

at line 1014
mixed makeWith(string $abstract, array $parameters = [])

An alias function name for make().

Parameters

string $abstract
array $parameters

Return Value

mixed

Exceptions

BindingResolutionException

at line 1029
mixed make(string $abstract, array $parameters = [])

Resolve the given type from the container.

Parameters

string $abstract
array $parameters

Return Value

mixed

Exceptions

BindingResolutionException

at line 1043
mixed get(string $id)

No description

Parameters

string $id

Return Value

mixed

Exceptions

CircularDependencyException
EntryNotFoundException

at line 1067
protected mixed resolve(string $abstract, array $parameters = [], bool $raiseEvents = true)

Resolve the given type from the container.

Parameters

string $abstract
array $parameters
bool $raiseEvents

Return Value

mixed

Exceptions

BindingResolutionException
CircularDependencyException

at line 1293
protected bool shouldCoordinateSharedResolution(string $abstract, mixed $concrete, bool $needsContextualBuild, bool $raiseEvents)

Determine whether this miss can publish a worker-shared instance.

Parameters

string $abstract
mixed $concrete
bool $needsContextualBuild
bool $raiseEvents

Return Value

bool

at line 1317
protected mixed awaitSharedResolution(string $abstract, SharedResolution $resolution)

Wait for a shared resolution without introducing a coordinator cycle.

Parameters

string $abstract
SharedResolution $resolution

Return Value

mixed

at line 1347
protected bool sharedResolutionOwnerIsAncestor(int $ownerId, int $coroutineId)

Determine whether the resolution owner is an ancestor of a coroutine.

Parameters

int $ownerId
int $coroutineId

Return Value

bool

at line 1367
protected bool sharedResolutionWaitWouldCycle(int $waiterId, int $ownerId)

Determine whether adding a container wait edge would close a cycle.

Parameters

int $waiterId
int $ownerId

Return Value

bool

at line 1383
protected mixed getConcrete(string $abstract)

Get the concrete type for a given abstract.

Parameters

string $abstract

Return Value

mixed

at line 1403
protected mixed getConcreteBindingFromAttributes(string $abstract)

Get the concrete binding for an abstract from the Bind attribute.

Parameters

string $abstract

Return Value

mixed

at line 1457
protected mixed getContextualConcrete(string $abstract)

Get the contextual concrete binding for the given abstract.

Parameters

string $abstract

Return Value

mixed

at line 1484
protected array getBuildStack()

Get the current build stack from coroutine-local context.

Return Value

array

at line 1494
protected void setBuildStack(array $stack)

Set the build stack in coroutine-local context.

Parameters

array $stack

Return Value

void

at line 1502
protected void pushBuildStack(string $abstract)

Push an abstract onto the coroutine-local build stack.

Parameters

string $abstract

Return Value

void

at line 1512
protected void popBuildStack()

Pop the last entry from the coroutine-local build stack.

Return Value

void

at line 1528
protected array getResolvingStack()

Get the resolving stack from coroutine-local context.

Used exclusively for circular dependency detection. Separate from the build stack so that call()'s contextual-binding pushes don't trigger false positives.

Return Value

array

at line 1536
protected void pushResolvingStack(string $abstract)

Push an abstract onto the coroutine-local resolving stack.

Parameters

string $abstract

Return Value

void

at line 1546
protected void popResolvingStack()

Pop the last entry from the coroutine-local resolving stack.

Return Value

void

at line 1558
protected array getParameterOverrideStack()

Get the parameter override stack from coroutine-local context.

Return Value

array

at line 1566
protected void pushParameterOverrides(array $parameters)

Push parameter overrides onto the coroutine-local stack.

Parameters

array $parameters

Return Value

void

at line 1576
protected void popParameterOverrides()

Pop the last parameter overrides from the coroutine-local stack.

Return Value

void

at line 1586
protected array getLastParameterOverride()

Get the last parameter override from the coroutine-local stack.

Return Value

array

at line 1595
protected mixed findInContextualBindings(string $abstract)

Find the concrete binding for the given abstract in the contextual binding array.

Parameters

string $abstract

Return Value

mixed

at line 1605
protected bool isBuildable(mixed $concrete, string $abstract)

Determine if the given concrete is buildable.

Parameters

mixed $concrete
string $abstract

Return Value

bool

at line 1613
protected BuildRecipe getBuildRecipe(string $concrete)

Get the cached build recipe for the given concrete class.

Parameters

string $concrete

Return Value

BuildRecipe

at line 1625
protected BuildRecipe computeBuildRecipe(string $concrete)

Compute the build recipe for the given concrete class.

Analyzes the class via reflection and caches the result as a BuildRecipe. This happens once per class per worker lifetime, avoiding repeated reflection on every build() call.

Parameters

string $concrete

Return Value

BuildRecipe

at line 1687
mixed buildWith(Closure|string $concrete, array $parameters = [])

Instantiate a concrete instance with the given parameter overrides.

Bypasses all binding lookups and the auto-singleton cache, so the returned instance is always freshly constructed. Class-typed dependencies are still resolved via the container.

Parameters

Closure|string $concrete
array $parameters

Return Value

mixed

Exceptions

BindingResolutionException
CircularDependencyException

at line 1709
mixed build(Closure|string $concrete)

Instantiate a concrete instance of the given type.

Parameters

Closure|string $concrete

Return Value

mixed

Exceptions

BindingResolutionException
CircularDependencyException

at line 1788
protected mixed buildSelfBuildingInstance(string $concrete, BuildRecipe $recipe)

Instantiate a concrete instance of the given self building type.

Parameters

string $concrete
BuildRecipe $recipe

Return Value

mixed

Exceptions

BindingResolutionException

at line 1817
protected array resolveRecipeParameters(BuildRecipe $recipe)

Resolve all constructor parameters using cached recipe metadata.

Parameters

BuildRecipe $recipe

Return Value

array

Exceptions

BindingResolutionException

at line 1866
protected bool hasParameterOverride(ParameterRecipe $param)

Determine if the given dependency has a parameter override.

Parameters

ParameterRecipe $param

Return Value

bool

at line 1877
protected mixed getParameterOverride(ParameterRecipe $param)

Get a parameter override for a dependency.

Parameters

ParameterRecipe $param

Return Value

mixed

at line 1887
protected mixed resolvePrimitive(ParameterRecipe $param)

Resolve a non-class hinted primitive dependency.

Parameters

ParameterRecipe $param

Return Value

mixed

Exceptions

BindingResolutionException

at line 1913
protected mixed resolveClass(ParameterRecipe $param)

Resolve a class based dependency from the container.

Parameters

ParameterRecipe $param

Return Value

mixed

Exceptions

BindingResolutionException

at line 1943
protected mixed resolveVariadicClass(ParameterRecipe $param)

Resolve a class based variadic dependency from the container.

Parameters

ParameterRecipe $param

Return Value

mixed

at line 1961
mixed resolveFromAttribute(ReflectionAttribute $attribute, ReflectionParameter $parameter)

Resolve a dependency based on an attribute.

Parameters

ReflectionAttribute $attribute
ReflectionParameter $parameter

Return Value

mixed

Exceptions

BindingResolutionException

at line 1983
protected never notInstantiable(string $concrete)

Throw an exception that the concrete is not instantiable.

Parameters

string $concrete

Return Value

never

Exceptions

BindingResolutionException

at line 2003
protected never unresolvablePrimitive(ParameterRecipe $param)

Throw an exception for an unresolvable primitive.

Parameters

ParameterRecipe $param

Return Value

never

Exceptions

BindingResolutionException

at line 2016
void beforeResolving(Closure|string $abstract, Closure|null $callback = null)

Register a new before resolving callback for all types.

Boot-only. The callback persists on the worker-lifetime container and runs before every matching future resolution.

Parameters

Closure|string $abstract
Closure|null $callback

Return Value

void

at line 2035
void resolving(Closure|string $abstract, Closure|null $callback = null)

Register a new resolving callback.

Boot-only. The callback persists on the worker-lifetime container and runs during every matching future resolution.

Parameters

Closure|string $abstract
Closure|null $callback

Return Value

void

at line 2054
void afterResolving(Closure|string $abstract, Closure|null $callback = null)

Register a new after resolving callback for all types.

Boot-only. The callback persists on the worker-lifetime container and runs after every matching future resolution.

Parameters

Closure|string $abstract
Closure|null $callback

Return Value

void

at line 2073
void afterResolvingAttribute(string $attribute, Closure $callback)

Register a new after resolving attribute callback for all types.

Boot-only. The callback persists on the worker-lifetime container and runs after every future resolution with the matching attribute.

Parameters

string $attribute
Closure $callback

Return Value

void

at line 2081
protected void fireBeforeResolvingCallbacks(string $abstract, array $parameters = [])

Fire all of the before resolving callbacks.

Parameters

string $abstract
array $parameters

Return Value

void

at line 2099
protected void fireBeforeCallbackArray(string $abstract, array $parameters, array $callbacks)

Fire an array of callbacks with an object.

Parameters

string $abstract
array $parameters
array $callbacks

Return Value

void

at line 2109
protected void fireResolvingCallbacks(string $abstract, mixed $object)

Fire all of the resolving callbacks.

Parameters

string $abstract
mixed $object

Return Value

void

at line 2128
protected void fireAfterResolvingCallbacks(string $abstract, mixed $object)

Fire all of the after resolving callbacks.

Parameters

string $abstract
mixed $object

Return Value

void

at line 2140
void fireAfterResolvingAttributeCallbacks(array $attributes, mixed $object)

Fire all of the after resolving attribute callbacks.

Parameters

array $attributes
mixed $object

Return Value

void

at line 2172
protected void fireCallbacksForType(string $abstract, mixed $object, array $callbacksPerType)

Fire all callbacks that match the given abstract or object type.

Parameters

string $abstract
mixed $object
array $callbacksPerType

Return Value

void

at line 2186
protected void fireCallbackArray(mixed $object, array $callbacks)

Fire an array of callbacks with an object.

Parameters

mixed $object
array $callbacks

Return Value

void

at line 2198
string|null currentlyResolving()

Get the name of the binding the container is currently resolving.

Return Value

string|null

at line 2208
array getBindings()

Get the container's bindings.

Return Value

array

at line 2216
string getAlias(string $abstract)

Get the alias for an abstract if available.

Parameters

string $abstract

Return Value

string

at line 2226
protected array getExtenders(string $abstract)

Get the extender callbacks for a given type.

Parameters

string $abstract

Return Value

array

at line 2238
void forgetExtenders(string $abstract)

Remove all of the extender callbacks for a given type.

Boot or tests only. Clears worker-lifetime extender callbacks; concurrent resolutions may diverge depending on whether they resolved before or after the removal.

Parameters

string $abstract

Return Value

void

at line 2246
protected void dropStaleInstances(string $abstract)

Drop all of the stale instances and aliases.

Parameters

string $abstract

Return Value

void

at line 2257
protected void forgetCachedInstances(string $abstract)

Forget every cached instance for an abstract without changing its lifecycle.

Parameters

string $abstract

Return Value

void

at line 2271
void forgetInstance(string $abstract)

Remove a resolved instance from the instance cache.

Boot or tests only. Clears a worker-lifetime shared instance and current coroutine scoped instance; concurrent coroutines may still hold references that next resolution will not share.

Parameters

string $abstract

Return Value

void

at line 2283
void forgetInstances()

Clear all of the instances from the container.

Boot or tests only. Clears worker-lifetime shared instances and all scoped context entries known to this container; concurrent coroutines may still hold references that next resolution will not share.

Return Value

void

at line 2297
void forgetScopedInstances()

Clear all of the scoped instances from the container.

Boot or tests only. Clears scoped context entries known to this container; runtime use can invalidate scoped services while a coroutine is still handling a request.

Return Value

void

at line 2312
void resolveEnvironmentUsing(callable|null $callback)

Set the callback which determines the current container environment.

Boot-only. The resolver persists on the worker-lifetime container and is used by every currentEnvironmentIs() call.

Parameters

callable|null $callback

Return Value

void

at line 2322
bool currentEnvironmentIs(array|string $environments)

Determine the environment for the container.

Parameters

array|string $environments

Return Value

bool

at line 2335
void flush()

Flush the container of all bindings and resolved instances.

Tests only. Clears the worker-lifetime container registry; runtime use breaks every concurrent resolution in the worker.

Return Value

void

at line 2360
static Container getInstance()

Get the globally available instance of the container.

Return Value

Container

at line 2371
static Container|null setInstance(Container|null $container = null)

Set the shared instance of the container.

Tests only. Replaces the process-wide container singleton; runtime use races across coroutines and breaks every facade/global container lookup.

Parameters

Container|null $container

Return Value

Container|null

at line 2379
static void flushState()

Flush all static state.

Return Value

void

at line 2389
bool offsetExists(string $key)

Determine if a given offset exists.

Parameters

string $key

Return Value

bool

at line 2399
mixed offsetGet(string $key)

Get the value at a given offset.

Parameters

string $key

Return Value

mixed

at line 2410
void offsetSet(string $key, mixed $value)

Set the value at a given offset.

Parameters

string $key
mixed $value

Return Value

void

at line 2420
void offsetUnset(string $key)

Unset the value at a given offset.

Parameters

string $key

Return Value

void

at line 2430
mixed __get(string $key)

Dynamically access container services.

Parameters

string $key

Return Value

mixed

at line 2438
void __set(string $key, mixed $value)

Dynamically set container services.

Parameters

string $key
mixed $value

Return Value

void