Container
Implements \Psr\Container\ContainerInterfaceThe Container class.
since |
1.0 |
---|
Methods
__construct
Constructor for the DI Container
__construct(\Psr\Container\ContainerInterface $parent = null)
since |
1.0 |
---|
Arguments
- $parent
\Psr\Container\ContainerInterface
Parent for hierarchical containers.
alias
Create an alias for a given key for easy access.
alias(string $alias, string $key) : \Joomla\DI\Container
since |
1.0 |
---|
Arguments
- $alias
string
The alias name- $key
string
The key to alias
Response
\Joomla\DI\Container
This object for chaining.
buildObject
Build an object of class $key;
buildObject(string $key, boolean $shared = false) : object|false
since |
1.0 |
---|
Arguments
- $key
string
The class name to build.- $shared
boolean
True to create a shared resource.
Response
object|false
Instance of class specified by $key with all dependencies injected.
Returns an object if the class exists and false otherwise
createChild
Create a child Container with a new property scope that that has the ability to access the parent scope when resolving.
createChild() : \Joomla\DI\Container
exists
Method to check if specified dataStore key exists.
exists(string $key) : boolean
since |
1.0 |
---|---|
deprecated |
3.0 Use ContainerInterface::has() instead |
Arguments
- $key
string
Name of the dataStore key to check.
Response
boolean
True for success
extend
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(string $key, \Closure $callable) : void
since |
1.0 |
---|---|
throws |
|
Arguments
- $key
string
The unique identifier for the Closure or property.- $callable
\Closure
A Closure to wrap the original service Closure.
get
Method to retrieve the results of running the $callback for the specified $key;
get(string $key, boolean $forceNew = false) : mixed
since |
1.0 |
---|---|
throws |
|
Arguments
- $key
string
Name of the dataStore key to get.- $forceNew
boolean
True to force creation and return of a new instance.
Response
mixed
Results of running the $callback for the specified $key.
getKeys
Retrieve the keys for services assigned to this container.
getKeys() : array
since |
1.5.0 |
---|
Response
array
getMethodArgs
Build an array of constructor parameters.
getMethodArgs(\ReflectionMethod $method) : array
since |
1.0 |
---|---|
throws |
|
Arguments
- $method
\ReflectionMethod
Method for which to build the argument array.
Response
array
Array of arguments to pass to the method.
getNewInstance
Method to force the container to return a new instance of the results of the callback for requested $key.
getNewInstance(string $key) : mixed
since |
1.0 |
---|
Arguments
- $key
string
Name of the dataStore key to get.
Response
mixed
Results of running the $callback for the specified $key.
getRaw
Get the raw data assigned to a key.
getRaw(string $key) : mixed
since |
1.0 |
---|
Arguments
- $key
string
The key for which to get the stored item.
Response
mixed
getTagged
Fetch all services registered to the given tag.
getTagged(string $tag) : array
since |
1.5.0 |
---|
Arguments
- $tag
string
The tag name
Response
array
The resolved services for the given tag
has
Method to check if specified dataStore key exists.
has(string $key) : boolean
since |
1.5.0 |
---|
Arguments
- $key
string
Name of the dataStore key to check.
Response
boolean
True for success
protect
Convenience method for creating protected keys.
protect(string $key, mixed $value, boolean $shared = false) : \Joomla\DI\Container
since |
1.0 |
---|
Arguments
- $key
string
Name of dataStore key to set.- $value
mixed
Callable function to run or string to retrive when requesting the specified $key.- $shared
boolean
True to create and store a shared instance.
Response
\Joomla\DI\Container
This object for chaining.
registerServiceProvider
Register a service provider to the container.
registerServiceProvider(\Joomla\DI\ServiceProviderInterface $provider) : \Joomla\DI\Container
since |
1.0 |
---|
Arguments
- $provider
\Joomla\DI\ServiceProviderInterface
The service provider to register.
Response
\Joomla\DI\Container
This object for chaining.
resolveAlias
Search the aliases property for a matching alias key.
resolveAlias(string $key) : string
since |
1.0 |
---|
Arguments
- $key
string
The key to search for.
Response
string
set
Method to set the key and callback to the dataStore array.
set(string $key, mixed $value, boolean $shared = false, boolean $protected = false) : \Joomla\DI\Container
since |
1.0 |
---|---|
throws |
|
Arguments
- $key
string
Name of dataStore key to set.- $value
mixed
Callable function to run or string to retrive when requesting the specified $key.- $shared
boolean
True to create and store a shared instance.- $protected
boolean
True to protect this item from being overwritten. Useful for services.
Response
\Joomla\DI\Container
This object for chaining.
tag
Assign a tag to services.
tag(string $tag, array $keys) : \Joomla\DI\Container
since |
1.5.0 |
---|
Arguments
- $tag
string
The tag name- $keys
array
The service keys to tag
Response
\Joomla\DI\Container
This object for chaining.
Properties
aliases
Holds the key aliases.
since |
1.0 |
---|
Type(s)
array
instances
Holds the shared instances.
since |
1.0 |
---|
Type(s)
array
dataStore
Holds the keys, their callbacks, and whether or not the item is meant to be a shared resource.
since |
1.0 |
---|
Type(s)
array
parent
Parent for hierarchical containers.
tags
Holds the service tag mapping.
since |
1.5.0 |
---|
Type(s)
array