Container
class Container implements ArrayAccess, Container (View source)
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 | $instances | The container's shared instances. | |
protected array | $aliases | The registered type aliases. | |
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. | |
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
ContextualBindingBuilder | when(string $concrete) Define a contextual binding. | |
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. | |
Closure | getClosure(string $abstract, string $concrete) Get the Closure to be used when building a type. | |
void | addContextualBinding(string $concrete, string $abstract, Closure|string $implementation) Add a contextual binding to the container. | |
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|array $abstract, Closure|string|null $concrete = null) Register a shared binding in the container. | |
Closure | share(Closure $closure) Wrap a Closure such that it is shared. | |
void | extend(string $abstract, Closure $closure) "Extend" an abstract type in the container. | |
void | instance(string $abstract, mixed $instance) Register an existing instance as shared in the container. | |
void | tag(array|string $abstracts, array|mixed $tags) Assign a set of tags to a given binding. | |
array | tagged(array $tag) Resolve all of the bindings for a given tag. | |
void | alias(string $abstract, string $alias) Alias a type to a different 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. | |
Closure | 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. | |
bool | isCallableWithAtSign(mixed $callback) Determine if the given string is in Class@method syntax. | |
array | getMethodDependencies(callable|string $callback, array $parameters = []) Get all dependencies for a given method. | |
ReflectionFunctionAbstract | getCallReflector(callable|string $callback) Get the proper reflection instance for the given callback. | |
mixed | addDependencyForCallParameter(ReflectionParameter $parameter, array $parameters, array $dependencies) Get the dependency for the given call parameter. | |
mixed | callClass(string $target, array $parameters = [], string|null $defaultMethod = null) Call a string reference to a class using Class@method syntax. | |
Closure | factory(string $abstract, array $defaults = []) Get a closure to resolve the given type from the container. | |
mixed | make(string $abstract, array $parameters = []) Resolve the given type from the container. | |
mixed | getConcrete(string $abstract) Get the concrete type for a given abstract. | |
string|null | getContextualConcrete(string $abstract) Get the contextual concrete binding for the given abstract. | |
mixed | normalize(mixed $service) Normalize the given class name by removing leading slashes. | |
array | getExtenders(string $abstract) Get the extender callbacks for a given type. | |
mixed | build(string $concrete, array $parameters = []) Instantiate a concrete instance of the given type. | |
array | getDependencies(array $parameters, array $primitives = []) 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 = null) Register a new resolving callback. | |
void | afterResolving(string $abstract, Closure $callback = null) Register a new after resolving callback for all types. | |
void | resolvingCallback(Closure $callback) Register a new resolving callback by type of its first argument. | |
void | afterResolvingCallback(Closure $callback) Register a new after resolving callback by type of its first argument. | |
mixed | getFunctionHint(Closure $callback) Get the type hint for this closure's first argument. | |
void | fireResolvingCallbacks(string $abstract, mixed $object) Fire all of the resolving callbacks. | |
array | getCallbacksForType(string $abstract, object $object, array $callbacksPerType) Get all callbacks for a given type. | |
void | 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. | |
void | flush() Flush the container of all bindings and resolved instances. | |
static Container | getInstance() Set the globally available instance of the container. | |
static Container | setInstance(Container $container = null) Set the shared instance of 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
ContextualBindingBuilder when(string $concrete)
Define a contextual binding.
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.
protected Closure getClosure(string $abstract, string $concrete)
Get the Closure to be used when building a type.
void addContextualBinding(string $concrete, string $abstract, Closure|string $implementation)
Add a contextual binding to the container.
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|array $abstract, Closure|string|null $concrete = null)
Register a shared binding in the container.
void extend(string $abstract, Closure $closure)
"Extend" an abstract type in the container.
void instance(string $abstract, mixed $instance)
Register an existing instance as shared in the container.
void tag(array|string $abstracts, array|mixed $tags)
Assign a set of tags to a given binding.
array tagged(array $tag)
Resolve all of the bindings for a given tag.
void alias(string $abstract, string $alias)
Alias a type to a different name.
protected 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.
protected void rebound(string $abstract)
Fire the "rebound" callbacks for the given abstract type.
protected array getReboundCallbacks(string $abstract)
Get the rebound callbacks for a given type.
Closure 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.
protected bool isCallableWithAtSign(mixed $callback)
Determine if the given string is in Class@method syntax.
protected array getMethodDependencies(callable|string $callback, array $parameters = [])
Get all dependencies for a given method.
protected ReflectionFunctionAbstract getCallReflector(callable|string $callback)
Get the proper reflection instance for the given callback.
protected mixed addDependencyForCallParameter(ReflectionParameter $parameter, array $parameters, array $dependencies)
Get the dependency for the given call parameter.
protected mixed callClass(string $target, array $parameters = [], string|null $defaultMethod = null)
Call a string reference to a class using Class@method syntax.
Closure factory(string $abstract, array $defaults = [])
Get a closure to resolve the given type from the container.
mixed make(string $abstract, array $parameters = [])
Resolve the given type from the container.
protected mixed getConcrete(string $abstract)
Get the concrete type for a given abstract.
protected string|null getContextualConcrete(string $abstract)
Get the contextual concrete binding for the given abstract.
protected mixed normalize(mixed $service)
Normalize the given class name by removing leading slashes.
protected array getExtenders(string $abstract)
Get the extender callbacks for a given type.
mixed build(string $concrete, array $parameters = [])
Instantiate a concrete instance of the given type.
protected array getDependencies(array $parameters, array $primitives = [])
Resolve all of the dependencies from the ReflectionParameters.
protected mixed resolveNonClass(ReflectionParameter $parameter)
Resolve a non-class hinted dependency.
protected mixed resolveClass(ReflectionParameter $parameter)
Resolve a class based dependency from the container.
protected 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 = null)
Register a new resolving callback.
void afterResolving(string $abstract, Closure $callback = null)
Register a new after resolving callback for all types.
protected void resolvingCallback(Closure $callback)
Register a new resolving callback by type of its first argument.
protected void afterResolvingCallback(Closure $callback)
Register a new after resolving callback by type of its first argument.
protected mixed getFunctionHint(Closure $callback)
Get the type hint for this closure's first argument.
protected void fireResolvingCallbacks(string $abstract, mixed $object)
Fire all of the resolving callbacks.
protected array getCallbacksForType(string $abstract, object $object, array $callbacksPerType)
Get all callbacks for a given type.
protected void fireCallbackArray(mixed $object, array $callbacks)
Fire an array of callbacks with an object.
bool isShared(string $abstract)
Determine if a given type is shared.
protected 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.
protected 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.
void flush()
Flush the container of all bindings and resolved instances.
static Container getInstance()
Set the globally available instance of 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.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Container/Container.html