class Illuminate / Container / Container
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

Container

Implements

Properties

protected static

$instance static

The current globally available container (if any).

Default: null
protected

$resolved bool[]

An array of the types that have been resolved.

Default: []
protected

$bindings array[]

The container's bindings.

Default: []
protected

$methodBindings Closure[]

The container's method bindings.

Default: []
protected

$instances object[]

The container's shared instances.

Default: []
protected

$scopedInstances array

The container's scoped instances.

Default: []
protected

$aliases string[]

The registered type aliases.

Default: []
protected

$abstractAliases array[]

The registered aliases keyed by the abstract name.

Default: []
protected

$extenders array[]

The extension closures for services.

Default: []
protected

$tags array[]

All of the registered tags.

Default: []
protected

$buildStack array[]

The stack of concretions currently being built.

Default: []
protected

$with array[]

The parameter override stack.

Default: []
public

$contextual array[]

The contextual binding map.

Default: []
protected

$reboundCallbacks array[]

All of the registered rebound callbacks.

Default: []
protected

$globalBeforeResolvingCallbacks Closure[]

All of the global before resolving callbacks.

Default: []
protected

$globalResolvingCallbacks Closure[]

All of the global resolving callbacks.

Default: []
protected

$globalAfterResolvingCallbacks Closure[]

All of the global after resolving callbacks.

Default: []
protected

$beforeResolvingCallbacks array[]

All of the before resolving callbacks by class type.

Default: []
protected

$resolvingCallbacks array[]

All of the resolving callbacks by class type.

Default: []
protected

$afterResolvingCallbacks array[]

All of the after resolving callbacks by class type.

Default: []

Methods

public

when ( $concrete ) : ContextualBindingBuilder

Define a contextual binding.

Parameters

  • $concrete array|string
public

bound ( $abstract ) : bool

Determine if the given abstract type has been bound.

Parameters

  • $abstract string
public

has ( string $id ) : bool

{@inheritdoc}

public

resolved ( $abstract ) : bool

Determine if the given abstract type has been resolved.

Parameters

  • $abstract string
public

isShared ( $abstract ) : bool

Determine if a given type is shared.

Parameters

  • $abstract string
public

isAlias ( $name ) : bool

Determine if a given string is an alias.

Parameters

  • $name string
public

bind ( $abstract , $concrete , $shared ) : void

Register a binding with the container.

Parameters

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

getClosure ( $abstract , $concrete ) : Closure

Get the Closure to be used when building a type.

Parameters

  • $abstract string
  • $concrete string
public

hasMethodBinding ( $method ) : bool

Determine if the container has a method binding.

Parameters

  • $method string
public

bindMethod ( $method , $callback ) : void

Bind a callback to resolve with Container::call.

Parameters

  • $method array|string
  • $callback Closure
protected

parseBindMethod ( $method ) : string

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

Parameters

  • $method array|string
public

callMethodBinding ( $method , $instance ) : mixed

Get the method binding for the given method.

Parameters

  • $method string
  • $instance mixed
public

addContextualBinding ( $concrete , $abstract , $implementation ) : void

Add a contextual binding to the container.

Parameters

  • $concrete string
  • $abstract string
  • $implementation Closure |string
public

bindIf ( $abstract , $concrete , $shared ) : void

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

Parameters

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

singleton ( $abstract , $concrete ) : void

Register a shared binding in the container.

Parameters

  • $abstract string
  • $concrete Closure |string|null
public

singletonIf ( $abstract , $concrete ) : void

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

Parameters

  • $abstract string
  • $concrete Closure |string|null
public

scoped ( $abstract , $concrete ) : void

Register a scoped binding in the container.

Parameters

  • $abstract string
  • $concrete Closure |string|null
public

scopedIf ( $abstract , $concrete ) : void

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

Parameters

  • $abstract string
  • $concrete Closure |string|null
public

extend ( $abstract , Closure $closure ) : void

"Extend" an abstract type in the container.

Parameters

public

instance ( $abstract , $instance ) : mixed

Register an existing instance as shared in the container.

Parameters

  • $abstract string
  • $instance mixed
protected

removeAbstractAlias ( $searched ) : void

Remove an alias from the contextual binding alias cache.

Parameters

  • $searched string
public

tag ( $abstracts , $tags ) : void

Assign a set of tags to a given binding.

Parameters

  • $abstracts array|string
  • $tags array|mixed
public

tagged ( $tag ) : iterable

Resolve all of the bindings for a given tag.

Parameters

  • $tag string
public

alias ( $abstract , $alias ) : void

Alias a type to a different name.

Parameters

  • $abstract string
  • $alias string
public

rebinding ( $abstract , Closure $callback ) : mixed

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

Parameters

public

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

Refresh an instance on the given target and method.

Parameters

  • $abstract string
  • $target mixed
  • $method string
protected

rebound ( $abstract ) : void

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

Parameters

  • $abstract string
protected

getReboundCallbacks ( $abstract ) : array

Get the rebound callbacks for a given type.

Parameters

  • $abstract string
public

wrap ( Closure $callback , array $parameters ) : Closure

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

Parameters

public

call ( $callback , array $parameters , $defaultMethod ) : mixed

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

Parameters

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

getClassForCallable ( $callback ) : string|false

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

Parameters

  • $callback callable|string
public

factory ( $abstract ) : Closure

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

Parameters

  • $abstract string
public

makeWith ( $abstract , array $parameters ) : mixed

An alias function name for make().

Parameters

  • $abstract string|callable
  • $parameters array
public

make ( $abstract , array $parameters ) : mixed

Resolve the given type from the container.

Parameters

  • $abstract string|callable
  • $parameters array
public

get ( string $id ) : mixed

{@inheritdoc}

protected

resolve ( $abstract , $parameters , $raiseEvents ) : mixed

Resolve the given type from the container.

Parameters

  • $abstract string|callable
  • $parameters array
  • $raiseEvents bool
protected

getConcrete ( $abstract ) : mixed

Get the concrete type for a given abstract.

Parameters

  • $abstract string|callable
protected

getContextualConcrete ( $abstract ) : Closure |string|array|null

Get the contextual concrete binding for the given abstract.

Parameters

  • $abstract string|callable
protected

findInContextualBindings ( $abstract ) : Closure |string|null

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

Parameters

  • $abstract string|callable
protected

isBuildable ( $concrete , $abstract ) : bool

Determine if the given concrete is buildable.

Parameters

  • $concrete mixed
  • $abstract string
public

build ( $concrete ) : mixed

Instantiate a concrete instance of the given type.

Parameters

protected

resolveDependencies ( array $dependencies ) : array

Resolve all of the dependencies from the ReflectionParameters.

Parameters

  • $dependencies ReflectionParameter[]
protected

hasParameterOverride ( $dependency ) : bool

Determine if the given dependency has a parameter override.

Parameters

protected

getParameterOverride ( $dependency ) : mixed

Get a parameter override for a dependency.

Parameters

protected

getLastParameterOverride ( ) : array

Get the last parameter override.

protected

resolvePrimitive ( ReflectionParameter $parameter ) : mixed

Resolve a non-class hinted primitive dependency.

Parameters

protected

resolveClass ( ReflectionParameter $parameter ) : mixed

Resolve a class based dependency from the container.

Parameters

protected

resolveVariadicClass ( ReflectionParameter $parameter ) : mixed

Resolve a class based variadic dependency from the container.

Parameters

protected

notInstantiable ( $concrete ) : void

Throw an exception that the concrete is not instantiable.

Parameters

  • $concrete string
protected

unresolvablePrimitive ( ReflectionParameter $parameter ) : void

Throw an exception for an unresolvable primitive.

Parameters

public

beforeResolving ( $abstract , Closure $callback ) : void

Register a new before resolving callback for all types.

Parameters

public

resolving ( $abstract , Closure $callback ) : void

Register a new resolving callback.

Parameters

public

afterResolving ( $abstract , Closure $callback ) : void

Register a new after resolving callback for all types.

Parameters

protected

fireBeforeResolvingCallbacks ( $abstract , $parameters ) : void

Fire all of the before resolving callbacks.

Parameters

  • $abstract string
  • $parameters array
protected

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

Fire an array of callbacks with an object.

Parameters

  • $abstract string
  • $parameters array
  • $callbacks array
protected

fireResolvingCallbacks ( $abstract , $object ) : void

Fire all of the resolving callbacks.

Parameters

  • $abstract string
  • $object mixed
protected

fireAfterResolvingCallbacks ( $abstract , $object ) : void

Fire all of the after resolving callbacks.

Parameters

  • $abstract string
  • $object mixed
protected

getCallbacksForType ( $abstract , $object , array $callbacksPerType ) : array

Get all callbacks for a given type.

Parameters

  • $abstract string
  • $object object
  • $callbacksPerType array
protected

fireCallbackArray ( $object , array $callbacks ) : void

Fire an array of callbacks with an object.

Parameters

  • $object mixed
  • $callbacks array
public

getBindings ( ) : array

Get the container's bindings.

public

getAlias ( $abstract ) : string

Get the alias for an abstract if available.

Parameters

  • $abstract string
protected

getExtenders ( $abstract ) : array

Get the extender callbacks for a given type.

Parameters

  • $abstract string
public

forgetExtenders ( $abstract ) : void

Remove all of the extender callbacks for a given type.

Parameters

  • $abstract string
protected

dropStaleInstances ( $abstract ) : void

Drop all of the stale instances and aliases.

Parameters

  • $abstract string
public

forgetInstance ( $abstract ) : void

Remove a resolved instance from the instance cache.

Parameters

  • $abstract string
public

forgetInstances ( ) : void

Clear all of the instances from the container.

public

forgetScopedInstances ( ) : void

Clear all of the scoped instances from the container.

public

flush ( ) : void

Flush the container of all bindings and resolved instances.

public static

getInstance ( ) : static

Get the globally available instance of the container.

public static

setInstance ( Container $container ) : Container |static

Set the shared instance of the container.

Parameters

public

offsetExists ( $key ) : bool

Determine if a given offset exists.

Parameters

  • $key string
public

offsetGet ( $key ) : mixed

Get the value at a given offset.

Parameters

  • $key string
public

offsetSet ( $key , $value ) : void

Set the value at a given offset.

Parameters

  • $key string
  • $value mixed
public

offsetUnset ( $key ) : void

Unset the value at a given offset.

Parameters

  • $key string
public

__get ( $key ) : mixed

Dynamically access container services.

Parameters

  • $key string
public

__set ( $key , $value ) : void

Dynamically set container services.

Parameters

  • $key string
  • $value mixed