Container
class Container implements ArrayAccess, Container
Properties
static protected Container | $instance | The current globally available container (if any). |
|
protected array | $resolved | An array of the types that have been resolved. |
|
protected array | $bindings | The container's bindings. |
|
protected array | $methodBindings | The container's method bindings. |
|
protected array | $instances | The container's shared instances. |
|
protected array | $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. |
|
protected array | $buildStack | The stack of concretions currently being built. |
|
protected array | $with | The parameter override stack. |
|
array | $contextual | The contextual binding map. |
|
protected array | $reboundCallbacks | All of the registered rebound callbacks. |
|
protected array | $globalResolvingCallbacks | All of the global resolving callbacks. |
|
protected array | $globalAfterResolvingCallbacks | All of the global after resolving callbacks. |
|
protected array | $resolvingCallbacks | All of the resolving callbacks by class type. |
|
protected array | $afterResolvingCallbacks | All of the after resolving callbacks by class type. |
Methods
Define a contextual binding.
Determine if the given abstract type has been bound.
Determine if the given abstract type has been resolved.
Determine if a given type is shared.
Determine if a given string is an alias.
Get the Closure to be used when building a type.
Determine if the container has a method binding.
Get the method binding for the given method.
Add a contextual binding to the container.
Register an existing instance as shared in the container.
Remove an alias from the contextual binding alias cache.
Assign a set of tags to a given binding.
Resolve all of the bindings for a given tag.
Alias a type to a different name.
Refresh an instance on the given target and method.
Fire the "rebound" callbacks for the given abstract type.
Get the rebound callbacks for a given type.
Call the given Closure / class@method and inject its dependencies.
Resolve the given type with the given parameter overrides.
Resolve the given type from the container.
Resolve the given type from the container.
Get the concrete type for a given abstract.
Get the contextual concrete binding for the given abstract.
Find the concrete binding for the given abstract in the contextual binding array.
Determine if the given concrete is buildable.
Instantiate a concrete instance of the given type.
Resolve all of the dependencies from the ReflectionParameters.
Determine if the given dependency has a parameter override from makeWith.
Get the last parameter override.
Throw an exception that the concrete is not instantiable.
Throw an exception for an unresolvable primitive.
Register a new after resolving callback for all types.
Fire all of the resolving callbacks.
Fire all of the after resolving callbacks.
Get all callbacks for a given type.
Fire an array of callbacks with an object.
Get the container's bindings.
Get the alias for an abstract if available.
Get the extender callbacks for a given type.
Remove all of the extender callbacks for a given type.
Drop all of the stale instances and aliases.
Remove a resolved instance from the instance cache.
Clear all of the instances from the container.
Flush the container of all bindings and resolved instances.
Set the globally available instance of the container.
Determine if a given offset exists.
Get the value at a given offset.
Set the value at a given offset.
Unset the value at a given offset.
Dynamically access container services.
Dynamically set container services.
Details
at line 140
ContextualBindingBuilder
when(string $concrete)
Define a contextual binding.
at line 151
bool
bound(string $abstract)
Determine if the given abstract type has been bound.
at line 164
bool
resolved(string $abstract)
Determine if the given abstract type has been resolved.
at line 180
bool
isShared(string $abstract)
Determine if a given type is shared.
at line 193
bool
isAlias(string $name)
Determine if a given string is an alias.
at line 206
void
bind(string|array $abstract, Closure|string|null $concrete = null, bool $shared = false)
Register a binding with the container.
at line 241
protected Closure
getClosure(string $abstract, string $concrete)
Get the Closure to be used when building a type.
at line 258
bool
hasMethodBinding(string $method)
Determine if the container has a method binding.
at line 270
void
bindMethod(string $method, Closure $callback)
Bind a callback to resolve with Container::call.
at line 282
mixed
callMethodBinding(string $method, mixed $instance)
Get the method binding for the given method.
at line 295
void
addContextualBinding(string $concrete, string $abstract, Closure|string $implementation)
Add a contextual binding to the container.
at line 308
void
bindIf(string $abstract, Closure|string|null $concrete = null, bool $shared = false)
Register a binding if it hasn't already been registered.
at line 322
void
singleton(string|array $abstract, Closure|string|null $concrete = null)
Register a shared binding in the container.
at line 336
void
extend(string $abstract, Closure $closure)
"Extend" an abstract type in the container.
at line 360
void
instance(string $abstract, mixed $instance)
Register an existing instance as shared in the container.
at line 384
protected void
removeAbstractAlias(string $searched)
Remove an alias from the contextual binding alias cache.
at line 406
void
tag(array|string $abstracts, array|mixed $tags)
Assign a set of tags to a given binding.
at line 427
array
tagged(array $tag)
Resolve all of the bindings for a given tag.
at line 447
void
alias(string $abstract, string $alias)
Alias a type to a different name.
at line 461
mixed
rebinding(string $abstract, Closure $callback)
Bind a new callback to an abstract's rebind event.
at line 478
mixed
refresh(string $abstract, mixed $target, string $method)
Refresh an instance on the given target and method.
at line 491
protected void
rebound(string $abstract)
Fire the "rebound" callbacks for the given abstract type.
at line 506
protected array
getReboundCallbacks(string $abstract)
Get the rebound callbacks for a given type.
at line 522
Closure
wrap(Closure $callback, array $parameters = [])
Wrap the given closure such that its dependencies will be injected when executed.
at line 537
mixed
call(callable|string $callback, array $parameters = [], string|null $defaultMethod = null)
Call the given Closure / class@method and inject its dependencies.
at line 548
Closure
factory(string $abstract)
Get a closure to resolve the given type from the container.
at line 562
mixed
makeWith(string $abstract, array $parameters)
Resolve the given type with the given parameter overrides.
at line 573
mixed
make(string $abstract)
Resolve the given type from the container.
at line 585
protected mixed
resolve(string $abstract, array $parameters = [])
Resolve the given type from the container.
at line 645
protected mixed
getConcrete(string $abstract)
Get the concrete type for a given abstract.
at line 667
protected string|null
getContextualConcrete(string $abstract)
Get the contextual concrete binding for the given abstract.
at line 693
protected string|null
findInContextualBindings(string $abstract)
Find the concrete binding for the given abstract in the contextual binding array.
at line 707
protected bool
isBuildable(mixed $concrete, string $abstract)
Determine if the given concrete is buildable.
at line 720
mixed
build(string $concrete)
Instantiate a concrete instance of the given type.
at line 771
protected array
resolveDependencies(array $dependencies)
Resolve all of the dependencies from the ReflectionParameters.
at line 802
protected bool
hasParameterOverride(ReflectionParameter $dependency)
Determine if the given dependency has a parameter override from makeWith.
at line 815
protected mixed
getParameterOverride(ReflectionParameter $dependency)
Get a parameter override for a dependency.
at line 825
protected array
getLastParameterOverride()
Get the last parameter override.
at line 838
protected mixed
resolvePrimitive(ReflectionParameter $parameter)
Resolve a non-class hinted primitive dependency.
at line 859
protected mixed
resolveClass(ReflectionParameter $parameter)
Resolve a class based dependency from the container.
at line 885
protected void
notInstantiable(string $concrete)
Throw an exception that the concrete is not instantiable.
at line 906
protected void
unresolvablePrimitive(ReflectionParameter $parameter)
Throw an exception for an unresolvable primitive.
at line 920
void
resolving(string $abstract, Closure $callback = null)
Register a new resolving callback.
at line 940
void
afterResolving(string $abstract, Closure $callback = null)
Register a new after resolving callback for all types.
at line 960
protected void
fireResolvingCallbacks(string $abstract, mixed $object)
Fire all of the resolving callbacks.
at line 978
protected void
fireAfterResolvingCallbacks(string $abstract, mixed $object)
Fire all of the after resolving callbacks.
at line 996
protected array
getCallbacksForType(string $abstract, object $object, array $callbacksPerType)
Get all callbacks for a given type.
at line 1016
protected void
fireCallbackArray(mixed $object, array $callbacks)
Fire an array of callbacks with an object.
at line 1028
array
getBindings()
Get the container's bindings.
at line 1041
string
getAlias(string $abstract)
Get the alias for an abstract if available.
at line 1060
protected array
getExtenders(string $abstract)
Get the extender callbacks for a given type.
at line 1077
void
forgetExtenders(string $abstract)
Remove all of the extender callbacks for a given type.
at line 1088
protected void
dropStaleInstances(string $abstract)
Drop all of the stale instances and aliases.
at line 1099
void
forgetInstance(string $abstract)
Remove a resolved instance from the instance cache.
at line 1109
void
forgetInstances()
Clear all of the instances from the container.
at line 1119
void
flush()
Flush the container of all bindings and resolved instances.
at line 1133
static Container
getInstance()
Set the globally available instance of the container.
at line 1148
static Container
setInstance(Container $container = null)
Set the shared instance of the container.
at line 1159
bool
offsetExists(string $key)
Determine if a given offset exists.
at line 1170
mixed
offsetGet(string $key)
Get the value at a given offset.
at line 1182
void
offsetSet(string $key, mixed $value)
Set the value at a given offset.
at line 1195
void
offsetUnset(string $key)
Unset the value at a given offset.
at line 1206
mixed
__get(string $key)
Dynamically access container services.
at line 1218
void
__set(string $key, mixed $value)
Dynamically set container services.