LFT
  • Namespace
  • Class
  • Tree

Namespaces

  • Docoflow
    • Contracts
    • Entity
    • Facades
    • Models
    • Traits
  • Docolight
    • Agno
      • Traits
    • Container
    • Http
      • Contracts
    • Rest
      • Handler
      • Http
    • Support
      • Debug
      • Traits
  • Docotory
    • Traits
  • None

Classes

  • Container

Exceptions

  • BindingResolutionException

Class Container

Inversion of control container is a powerful tool for managing class dependencies. Dependency injection is a method of removing hard-coded class dependencies. Instead, the dependencies are injected at run-time, allowing for greater flexibility as dependency implementations may be swapped easily.

// Instantiate new container
$container = new Docolight\Container\Container;

// Bind a container
$container->bind('foo', function () { return new Foo; });

// Resolve type from container:
$container->make('foo'); // Foo implementation

Container also has ability to resolve the dependency by itself.

interface FooContract { public function foo(); }


class Foo implements FooContract { public function foo() {} }


class FooFactory
{
 protected $foo = null;
 public function __construct(FooContract $foo) { $this->foo = $foo; }
}


$container = new Docolight\Container\Container;

$container->bind('FooContract', 'Foo');

$fooFactory = $container->make('FooFactory'); // equals with: $fooFactory = new FooFactory(new Foo);
CApplicationComponent
Extended by Docolight\Container\Container implements ArrayAccess
Namespace: Docolight\Container
Category: Libraries
Author: Krisan Alfa Timur krisanalfa@docotel.co.id
Link: Interface to provide accessing objects as arrays.
Located at Docolight/Container/Container.php

Methods summary

protected boolean
# resolvable( string $abstract )

Determine if a given string is resolvable.

Determine if a given string is resolvable.

Parameters

$abstract

Returns

boolean
public boolean
# bound( string $abstract )

Determine if the given abstract type has been bound.

Determine if the given abstract type has been bound.

Parameters

$abstract

Returns

boolean
public boolean
# resolved( string $abstract )

Determine if the given abstract type has been resolved.

Determine if the given abstract type has been resolved.

Parameters

$abstract

Returns

boolean
public boolean
# isAlias( string $name )

Determine if a given string is an alias.

Determine if a given string is an alias.

Parameters

$name

Returns

boolean
public
# bind( string|array $abstract, Closure|string|null $concrete = null, boolean $shared = false )

Register a binding with the container.

Register a binding with the container.

Parameters

$abstract
$concrete
$shared
protected Closure
# getClosure( string $abstract, string $concrete )

Get the Closure to be used when building a type.

Get the Closure to be used when building a type.

Parameters

$abstract
$concrete

Returns

Closure
public
# bindIf( string $abstract, Closure|string|null $concrete = null, boolean $shared = false )

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

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

Parameters

$abstract
$concrete
$shared
public
# singleton( string $abstract, Closure|string|null $concrete = null )

Register a shared binding in the container.

Register a shared binding in the container.

Parameters

$abstract
$concrete
public Closure
# share( Closure $closure )

Wrap a Closure such that it is shared.

Wrap a Closure such that it is shared.

Parameters

$closure

Returns

Closure
public
# bindShared( string $abstract, Closure $closure )

Bind a shared Closure into the container.

Bind a shared Closure into the container.

Parameters

$abstract
$closure
public
# extend( string $abstract, Closure $closure )

"Extend" an abstract type in the container.

"Extend" an abstract type in the container.

Parameters

$abstract
$closure

Throws

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

Get an extender Closure for resolving a type.

Get an extender Closure for resolving a type.

Parameters

$abstract
$closure

Returns

Closure
public
# instance( string $abstract, mixed $instance )

Register an existing instance as shared in the container.

Register an existing instance as shared in the container.

Parameters

$abstract
$instance
public
# alias( string $abstract, string $alias )

Alias a type to a shorter name.

Alias a type to a shorter name.

Parameters

$abstract
$alias
protected array
# extractAlias( array $definition )

Extract the type and alias from a given definition.

Extract the type and alias from a given definition.

Parameters

$definition

Returns

array
public mixed
# rebinding( string $abstract, Closure $callback )

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

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

Parameters

$abstract
$callback

Returns

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

Refresh an instance on the given target and method.

Refresh an instance on the given target and method.

Parameters

$abstract
$target
$method

Returns

mixed
protected
# rebound( string $abstract )

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

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

Parameters

$abstract
protected array
# getReboundCallbacks( string $abstract )

Get the rebound callbacks for a given type.

Get the rebound callbacks for a given type.

Parameters

$abstract

Returns

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

Resolve the given type from the container.

Resolve the given type from the container.

Parameters

$abstract
$parameters

Returns

mixed
protected mixed
# getConcrete( string $abstract )

Get the concrete type for a given abstract.

Get the concrete type for a given abstract.

Parameters

$abstract

Returns

mixed
$concrete
protected boolean
# missingLeadingSlash( string $abstract )

Determine if the given abstract has a leading slash.

Determine if the given abstract has a leading slash.

Parameters

$abstract

Returns

boolean
public mixed
# build( string $concrete, array $parameters = array() )

Instantiate a concrete instance of the given type.

Instantiate a concrete instance of the given type.

Parameters

$concrete
$parameters

Returns

mixed

Throws

Docolight\Container\BindingResolutionException
protected array
# getDependencies( array $parameters, array $primitives = array() )

Resolve all of the dependencies from the ReflectionParameters.

Resolve all of the dependencies from the ReflectionParameters.

Parameters

$parameters
$primitives

Returns

array
protected mixed
# resolveNonClass( ReflectionParameter $parameter )

Resolve a non-class hinted dependency.

Resolve a non-class hinted dependency.

Parameters

$parameter

Returns

mixed

Throws

Docolight\Container\BindingResolutionException
protected mixed
# resolveClass( ReflectionParameter $parameter )

Resolve a class based dependency from the container.

Resolve a class based dependency from the container.

Parameters

$parameter

Returns

mixed

Throws

Docolight\Container\BindingResolutionException
protected array
# keyParametersByArgument( array $dependencies, array $parameters )

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

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

Parameters

$dependencies
$parameters

Returns

array
public
# resolving( string $abstract, Closure $callback )

Register a new resolving callback.

Register a new resolving callback.

Parameters

$abstract
$callback
public
# resolvingAny( Closure $callback )

Register a new resolving callback for all types.

Register a new resolving callback for all types.

Parameters

$callback
protected
# fireResolvingCallbacks( string $abstract, mixed $object )

Fire all of the resolving callbacks.

Fire all of the resolving callbacks.

Parameters

$abstract
$object
protected
# fireCallbackArray( mixed $object, array $callbacks )

Fire an array of callbacks with an object.

Fire an array of callbacks with an object.

Parameters

$object
$callbacks
public boolean
# isShared( string $abstract )

Determine if a given type is shared.

Determine if a given type is shared.

Parameters

$abstract

Returns

boolean
protected boolean
# isBuildable( mixed $concrete, string $abstract )

Determine if the given concrete is buildable.

Determine if the given concrete is buildable.

Parameters

$concrete
$abstract

Returns

boolean
protected string
# getAlias( string $abstract )

Get the alias for an abstract if available.

Get the alias for an abstract if available.

Parameters

$abstract

Returns

string
public array
# getBindings( )

Get the container's bindings.

Get the container's bindings.

Returns

array
protected
# dropStaleInstances( string $abstract )

Drop all of the stale instances and aliases.

Drop all of the stale instances and aliases.

Parameters

$abstract
public
# forgetInstance( string $abstract )

Remove a resolved instance from the instance cache.

Remove a resolved instance from the instance cache.

Parameters

$abstract
public
# forgetInstances( )

Clear all of the instances from the container.

Clear all of the instances from the container.

public boolean
# offsetExists( string $key )

Determine if a given offset exists.

Determine if a given offset exists.

Parameters

$key

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( string $key )

Get the value at a given offset.

Get the value at a given offset.

Parameters

$key

Returns

mixed

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( string $key, mixed $value )

Set the value at a given offset.

Set the value at a given offset.

Parameters

$key
$value

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( string $key )

Unset the value at a given offset.

Unset the value at a given offset.

Parameters

$key

Implementation of

ArrayAccess::offsetUnset()
public mixed
# __get( string $key )

Dynamically access container services.

Dynamically access container services.

Parameters

$key

Returns

mixed
public
# __set( string $key, mixed $value )

Dynamically set container services.

Dynamically set container services.

Parameters

$key
$value

Properties summary

protected array $resolved

An array of the types that have been resolved.

An array of the types that have been resolved.

# array()
protected array $bindings

The container's bindings.

The container's bindings.

# array()
protected array $instances

The container's shared instances.

The container's shared instances.

# array()
protected array $aliases

The registered type aliases.

The registered type aliases.

# array()
protected array $reboundCallbacks

All of the registered rebound callbacks.

All of the registered rebound callbacks.

# array()
protected array $resolvingCallbacks

All of the registered resolving callbacks.

All of the registered resolving callbacks.

# array()
protected array $globalResolvingCallbacks

All of the global resolving callbacks.

All of the global resolving callbacks.

# array()
LFT API documentation generated by ApiGen