class Container implements ArrayAccess (View source)

Properties

protected array $resolved

An array of the types that have been resolved.

protected array $bindings

The container's bindings.

protected array $instances

The container's shared instances.

protected array $aliases

The registered type aliases.

protected array $reboundCallbacks

All of the registered rebound callbacks.

protected array $resolvingCallbacks

All of the registered resolving callbacks.

protected array $globalResolvingCallbacks

All of the global resolving callbacks.

Methods

bool
resolvable(string $abstract)

Determine if a given string is resolvable.

bool
bound(string $abstract)

Determine if the given abstract type has been bound.

bool
resolved(string $abstract)

Determine if the given abstract type has been resolved.

bool
isAlias(string $name)

Determine if a given string is an alias.

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

Register a binding with the container.

getClosure(string $abstract, string $concrete)

Get the Closure to be used when building a type.

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

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

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

Register a shared binding in the container.

share(Closure $closure)

Wrap a Closure such that it is shared.

void
bindShared(string $abstract, Closure $closure)

Bind a shared Closure into the container.

void
extend(string $abstract, Closure $closure)

"Extend" an abstract type in the container.

getExtender(string $abstract, Closure $closure)

Get an extender Closure for resolving a type.

void
instance(string $abstract, mixed $instance)

Register an existing instance as shared in the container.

void
alias(string $abstract, string $alias)

Alias a type to a shorter name.

array
extractAlias(array $definition)

Extract the type and alias from a given definition.

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.

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

Resolve the given type from the container.

mixed
getConcrete(string $abstract)

Get the concrete type for a given abstract.

bool
missingLeadingSlash(string $abstract)

Determine if the given abstract has a leading slash.

mixed
build(string $concrete, array $parameters = array())

Instantiate a concrete instance of the given type.

array
getDependencies(array $parameters, array $primitives = array())

Resolve all of the dependencies from the ReflectionParameters.

mixed
resolveNonClass(ReflectionParameter $parameter)

Resolve a non-class hinted dependency.

mixed
resolveClass(ReflectionParameter $parameter)

Resolve a class based dependency from the container.

array
keyParametersByArgument(array $dependencies, array $parameters)

If extra parameters are passed by numeric ID, rekey them by argument name.

void
resolving(string $abstract, Closure $callback)

Register a new resolving callback.

void
resolvingAny(Closure $callback)

Register a new resolving callback for all types.

void
fireResolvingCallbacks(string $abstract, mixed $object)

Fire all of the resolving callbacks.

fireCallbackArray(mixed $object, array $callbacks)

Fire an array of callbacks with an object.

bool
isShared(string $abstract)

Determine if a given type is shared.

bool
isBuildable(mixed $concrete, string $abstract)

Determine if the given concrete is buildable.

string
getAlias(string $abstract)

Get the alias for an abstract if available.

array
getBindings()

Get the container's bindings.

void
dropStaleInstances(string $abstract)

Drop all of the stale instances and aliases.

void
forgetInstance(string $abstract)

Remove a resolved instance from the instance cache.

void
forgetInstances()

Clear all of the instances from the container.

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

protected bool resolvable(string $abstract)

Determine if a given string is resolvable.

Parameters

string $abstract

Return Value

bool

bool bound(string $abstract)

Determine if the given abstract type has been bound.

Parameters

string $abstract

Return Value

bool

bool resolved(string $abstract)

Determine if the given abstract type has been resolved.

Parameters

string $abstract

Return Value

bool

bool isAlias(string $name)

Determine if a given string is an alias.

Parameters

string $name

Return Value

bool

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

Register a binding with the container.

Parameters

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

Return Value

void

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

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

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

Parameters

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

Return Value

void

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

Register a shared binding in the container.

Parameters

string $abstract
Closure|string|null $concrete

Return Value

void

Closure share(Closure $closure)

Wrap a Closure such that it is shared.

Parameters

Closure $closure

Return Value

Closure

void bindShared(string $abstract, Closure $closure)

Bind a shared Closure into the container.

Parameters

string $abstract
Closure $closure

Return Value

void

void extend(string $abstract, Closure $closure)

"Extend" an abstract type in the container.

Parameters

string $abstract
Closure $closure

Return Value

void

Exceptions

InvalidArgumentException

protected Closure getExtender(string $abstract, Closure $closure)

Get an extender Closure for resolving a type.

Parameters

string $abstract
Closure $closure

Return Value

Closure

void instance(string $abstract, mixed $instance)

Register an existing instance as shared in the container.

Parameters

string $abstract
mixed $instance

Return Value

void

void alias(string $abstract, string $alias)

Alias a type to a shorter name.

Parameters

string $abstract
string $alias

Return Value

void

protected array extractAlias(array $definition)

Extract the type and alias from a given definition.

Parameters

array $definition

Return Value

array

mixed rebinding(string $abstract, Closure $callback)

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

Parameters

string $abstract
Closure $callback

Return Value

mixed

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

Refresh an instance on the given target and method.

Parameters

string $abstract
mixed $target
string $method

Return Value

mixed

protected void rebound(string $abstract)

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

Parameters

string $abstract

Return Value

void

protected array getReboundCallbacks(string $abstract)

Get the rebound callbacks for a given type.

Parameters

string $abstract

Return Value

array

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

Resolve the given type from the container.

Parameters

string $abstract
array $parameters

Return Value

mixed

protected mixed getConcrete(string $abstract)

Get the concrete type for a given abstract.

Parameters

string $abstract

Return Value

mixed $concrete

protected bool missingLeadingSlash(string $abstract)

Determine if the given abstract has a leading slash.

Parameters

string $abstract

Return Value

bool

mixed build(string $concrete, array $parameters = array())

Instantiate a concrete instance of the given type.

Parameters

string $concrete
array $parameters

Return Value

mixed

Exceptions

BindingResolutionException

protected array getDependencies(array $parameters, array $primitives = array())

Resolve all of the dependencies from the ReflectionParameters.

Parameters

array $parameters
array $primitives

Return Value

array

protected mixed resolveNonClass(ReflectionParameter $parameter)

Resolve a non-class hinted dependency.

Parameters

ReflectionParameter $parameter

Return Value

mixed

Exceptions

BindingResolutionException

protected mixed resolveClass(ReflectionParameter $parameter)

Resolve a class based dependency from the container.

Parameters

ReflectionParameter $parameter

Return Value

mixed

Exceptions

BindingResolutionException

protected array keyParametersByArgument(array $dependencies, array $parameters)

If extra parameters are passed by numeric ID, rekey them by argument name.

Parameters

array $dependencies
array $parameters

Return Value

array

void resolving(string $abstract, Closure $callback)

Register a new resolving callback.

Parameters

string $abstract
Closure $callback

Return Value

void

void resolvingAny(Closure $callback)

Register a new resolving callback for all types.

Parameters

Closure $callback

Return Value

void

protected void fireResolvingCallbacks(string $abstract, mixed $object)

Fire all of the resolving callbacks.

Parameters

string $abstract
mixed $object

Return Value

void

protected fireCallbackArray(mixed $object, array $callbacks)

Fire an array of callbacks with an object.

Parameters

mixed $object
array $callbacks

bool isShared(string $abstract)

Determine if a given type is shared.

Parameters

string $abstract

Return Value

bool

protected bool isBuildable(mixed $concrete, string $abstract)

Determine if the given concrete is buildable.

Parameters

mixed $concrete
string $abstract

Return Value

bool

protected string getAlias(string $abstract)

Get the alias for an abstract if available.

Parameters

string $abstract

Return Value

string

array getBindings()

Get the container's bindings.

Return Value

array

protected void dropStaleInstances(string $abstract)

Drop all of the stale instances and aliases.

Parameters

string $abstract

Return Value

void

void forgetInstance(string $abstract)

Remove a resolved instance from the instance cache.

Parameters

string $abstract

Return Value

void

void forgetInstances()

Clear all of the instances from the container.

Return Value

void

bool offsetExists(string $key)

Determine if a given offset exists.

Parameters

string $key

Return Value

bool

mixed offsetGet(string $key)

Get the value at a given offset.

Parameters

string $key

Return Value

mixed

void offsetSet(string $key, mixed $value)

Set the value at a given offset.

Parameters

string $key
mixed $value

Return Value

void

void offsetUnset(string $key)

Unset the value at a given offset.

Parameters

string $key

Return Value

void

mixed __get(string $key)

Dynamically access container services.

Parameters

string $key

Return Value

mixed

void __set(string $key, mixed $value)

Dynamically set container services.

Parameters

string $key
mixed $value

Return Value

void