JOOMLA中国
  • Joomla中国首页
  • 社区
  • 教程
  • 应用市场
  • B计划
Joomla! Framework TM
  • Namespace
  • Class
  • Tree
  • Deprecated

Namespaces

  • Composer
    • Autoload
  • Joomla
    • Application
      • Cli
        • Output
          • Processor
      • Web
    • Data
    • DI
      • Exception
    • Event
    • Filter
    • Input
    • Ldap
    • Registry
      • Format
    • Session
      • Storage
    • String
    • Uri
    • Utilities
  • None
  • PasswordCompat
    • binary
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Yaml
        • Exception
    • Polyfill
      • Util

Classes

  • Container

Interfaces

  • ContainerAwareInterface
  • ServiceProviderInterface

Traits

  • ContainerAwareTrait

Class Container

The Container class.

Namespace: Joomla\DI
Since: 1.0
Located at vendor/joomla/di/src/Container.php

Methods summary

public
# __construct( Joomla\DI\Container $parent = null )

Constructor for the DI Container

Constructor for the DI Container

Parameters

$parent
Joomla\DI\Container - $parent Parent for hierarchical containers.

Since

1.0
public Joomla\DI\Container
# alias( string $alias, string $key )

Create an alias for a given key for easy access.

Create an alias for a given key for easy access.

Parameters

$alias
string - $alias The alias name
$key
string - $key The key to alias

Returns

Joomla\DI\Container - This object for chaining.

Since

1.0
protected string
# resolveAlias( string $key )

Search the aliases property for a matching alias key.

Search the aliases property for a matching alias key.

Parameters

$key
string - $key The key to search for.

Returns

string

Since

1.0
public mixed
# buildObject( string $key, boolean $shared = false )

Build an object of class $key;

Build an object of class $key;

Parameters

$key
string - $key The class name to build.
$shared
boolean - $shared True to create a shared resource.

Returns

mixed - Instance of class specified by $key with all dependencies injected. Returns an object if the class exists and false otherwise

Since

1.0
public object
# buildSharedObject( string $key )

Convenience method for building a shared object.

Convenience method for building a shared object.

Parameters

$key
string - $key The class name to build.

Returns

object - Instance of class specified by $key with all dependencies injected.

Since

1.0
public Joomla\DI\Container
# createChild( )

Create a child Container with a new property scope that that has the ability to access the parent scope when resolving.

Create a child Container with a new property scope that that has the ability to access the parent scope when resolving.

Returns

Joomla\DI\Container - This object for chaining.

Since

1.0
public
# extend( string $key, Closure $callable )

Extend a defined service Closure by wrapping the existing one with a new Closure. This works very similar to a decorator pattern. Note that this only works on service Closures that have been defined in the current Provider, not parent providers.

Extend a defined service Closure by wrapping the existing one with a new Closure. This works very similar to a decorator pattern. Note that this only works on service Closures that have been defined in the current Provider, not parent providers.

Parameters

$key
string - $key The unique identifier for the Closure or property.
$callable
Closure - $callable A Closure to wrap the original service Closure.

Throws

InvalidArgumentException

Since

1.0
protected array
# getMethodArgs( ReflectionMethod $method )

Build an array of constructor parameters.

Build an array of constructor parameters.

Parameters

$method
ReflectionMethod - $method Method for which to build the argument array.

Returns

array - Array of arguments to pass to the method.

Throws

Joomla\DI\Exception\DependencyResolutionException

Since

1.0
public Joomla\DI\Container
# set( string $key, mixed $value, boolean $shared = false, boolean $protected = false )

Method to set the key and callback to the dataStore array.

Method to set the key and callback to the dataStore array.

Parameters

$key
string - $key Name of dataStore key to set.
$value
mixed - $value Callable function to run or string to retrive when requesting the specified $key.
$shared
boolean - $shared True to create and store a shared instance.
$protected
boolean - $protected True to protect this item from being overwritten. Useful for services.

Returns

Joomla\DI\Container - This object for chaining.

Throws

OutOfBoundsException - Thrown if the provided key is already set and is protected.

Since

1.0
public Joomla\DI\Container
# protect( string $key, callable $callback, boolean $shared = false )

Convenience method for creating protected keys.

Convenience method for creating protected keys.

Parameters

$key
string - $key Name of dataStore key to set.
$callback
callable - $callback Callable function to run when requesting the specified $key.
$shared
boolean - $shared True to create and store a shared instance.

Returns

Joomla\DI\Container - This object for chaining.

Since

1.0
public Joomla\DI\Container
# share( string $key, callable $callback, boolean $protected = false )

Convenience method for creating shared keys.

Convenience method for creating shared keys.

Parameters

$key
string - $key Name of dataStore key to set.
$callback
callable - $callback Callable function to run when requesting the specified $key.
$protected
boolean - $protected True to create and store a shared instance.

Returns

Joomla\DI\Container - This object for chaining.

Since

1.0
public mixed
# get( string $key, boolean $forceNew = false )

Method to retrieve the results of running the $callback for the specified $key;

Method to retrieve the results of running the $callback for the specified $key;

Parameters

$key
string - $key Name of the dataStore key to get.
$forceNew
boolean - $forceNew True to force creation and return of a new instance.

Returns

mixed - Results of running the $callback for the specified $key.

Throws

InvalidArgumentException

Since

1.0
public boolean
# exists( string $key )

Method to check if specified dataStore key exists.

Method to check if specified dataStore key exists.

Parameters

$key
string - $key Name of the dataStore key to check.

Returns

boolean - True for success

Since

1.0
protected mixed
# getRaw( string $key )

Get the raw data assigned to a key.

Get the raw data assigned to a key.

Parameters

$key
string - $key The key for which to get the stored item.

Returns

mixed

Since

1.0
public mixed
# getNewInstance( string $key )

Method to force the container to return a new instance of the results of the callback for requested $key.

Method to force the container to return a new instance of the results of the callback for requested $key.

Parameters

$key
string - $key Name of the dataStore key to get.

Returns

mixed - Results of running the $callback for the specified $key.

Since

1.0
public Joomla\DI\Container
# registerServiceProvider( Joomla\DI\ServiceProviderInterface $provider )

Register a service provider to the container.

Register a service provider to the container.

Parameters

$provider
Joomla\DI\ServiceProviderInterface - $provider The service provider to register.

Returns

Joomla\DI\Container - This object for chaining.

Since

1.0

Magic methods summary

Properties summary

protected array $aliases
#

Holds the key aliases.

Holds the key aliases.

Since

1.0
protected array $instances
#

Holds the shared instances.

Holds the shared instances.

Since

1.0
protected array $dataStore
#

Holds the keys, their callbacks, and whether or not the item is meant to be a shared resource.

Holds the keys, their callbacks, and whether or not the item is meant to be a shared resource.

Since

1.0
protected Joomla\DI\Container $parent
#

Parent for hierarchical containers.

Parent for hierarchical containers.

Since

1.0
Joomla! Framework TM API documentation generated by ApiGen 2.8.0
Joomla!® and Joomla! Framework™ are trademarks of Open Source Matters, Inc. in the United States and other countries.