Container
Implements ContainerInterfaceThe Container class.
since |
1.0 |
---|---|
package |
Joomla Framework |
Methods
__construct
Constructor for the DI Container
__construct(\Psr\Container\ContainerInterface|null parent = null) : mixed
since |
1.0 |
---|
Arguments
- parent
\Psr\Container\ContainerInterface|null
Parent for hierarchical containers.
Response
mixed
alias
Create an alias for a given key for easy access.
alias(string alias, string key) : $this
since |
1.0 |
---|
Arguments
- alias
string
The alias name- key
string
The key to alias
Response
$this
buildObject
Build an object of the requested class
buildObject(string resourceName, bool shared = false) : object|false
Creates an instance of the class specified by $resourceName with all dependencies injected. If the dependencies cannot be completely resolved, a DependencyResolutionException is thrown.
since |
1.0 |
---|---|
throws |
|
Arguments
- resourceName
string
The class name to build.- shared
bool
True to create a shared resource.
Response
object|false
Instance of class specified by $resourceName 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 has the ability to access the parent scope when resolving.
createChild() : \Joomla\DI\Container
since |
1.0 |
---|
Response
\Joomla\DI\Container
A new container with the current as a parent
exists
Method to check if specified dataStore key exists.
exists(string key) : bool
since |
1.0 |
---|---|
deprecated |
3.0 Use ContainerInterface::has() instead |
Arguments
- key
string
Name of the dataStore key to check.
Response
bool
True for success
extend
Extend a defined service Closure by wrapping the existing one with a new callable function.
extend(string resourceName, callable callable) : void
This works very similar to a decorator pattern. Note that this only works on service Closures that have been defined in the current container, not parent containers.
since |
1.0 |
---|---|
throws |
|
Arguments
- resourceName
string
The unique identifier for the Closure or property.- callable
callable
A callable to wrap the original service Closure.
get
Retrieve a resource
get(string resourceName) : mixed
since |
1.0 |
---|---|
throws |
|
Arguments
- resourceName
string
Name of the resource to get.
Response
mixed
The requested resource
getKeys
Retrieve the keys for services assigned to this container.
getKeys() : array
since |
1.5.0 |
---|
Response
array
getMethodArgs
Build an array of method arguments.
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 resources key to get.
Response
mixed
Results of running the callback for the specified key.
getResource
Get the raw data assigned to a key.
getResource(string key, bool bail = false) : \Joomla\DI\ContainerResource|null
since |
2.0.0 |
---|---|
throws |
|
Arguments
- key
string
The key for which to get the stored item.- bail
bool
Throw an exception, if the key is not found
Response
\Joomla\DI\ContainerResource|null
The resource if present, or null if instructed to not bail
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
Check if specified resource exists.
has(string resourceName) : bool
since |
1.5.0 |
---|
Arguments
- resourceName
string
Name of the resource to check.
Response
bool
true if key is defined, false otherwise
hasFlag
Check whether a flag (i.e., one of 'shared' or 'protected') is set
hasFlag(string resourceName, string method, bool default = true) : bool
since |
2.0.0 |
---|---|
throws |
|
Arguments
- resourceName
string
Name of the resource to check.- method
string
Method to delegate to- default
bool
Default return value
Response
bool
isProtected
Check whether a resource is protected
isProtected(string resourceName) : bool
since |
2.0.0 |
---|
Arguments
- resourceName
string
Name of the resource to check.
Response
bool
protect
Shortcut method for creating protected keys.
protect(string key, mixed value, bool shared = false) : $this
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
bool
True to create and store a shared instance.
Response
$this
registerServiceProvider
Register a service provider to the container.
registerServiceProvider(\Joomla\DI\ServiceProviderInterface provider) : $this
since |
1.0 |
---|
Arguments
- provider
\Joomla\DI\ServiceProviderInterface
The service provider to register.
Response
$this
resolveAlias
Resolve a resource name.
resolveAlias(string resourceName) : string
If the resource name is an alias, the corresponding key is returned. If the resource name is not an alias, the resource name is returned unchanged.
since |
1.0 |
---|
Arguments
- resourceName
string
The key to search for.
Response
string
set
Set a resource to the container. If the value is null the resource is removed.
set(string key, mixed value, bool shared = false, bool protected = false) : $this
since |
1.0 |
---|---|
throws |
|
Arguments
- key
string
Name of resources key to set.- value
mixed
Callable function to run or string to retrive when requesting the specified $key.- shared
bool
True to create and store a shared instance.- protected
bool
True to protect this item from being overwritten. Useful for services.
Response
$this
tag
Assign a tag to services.
tag(string tag, array keys) : $this
since |
1.5.0 |
---|
Arguments
- tag
string
The tag name- keys
array
The service keys to tag
Response
$this
Properties
aliases
Holds the key aliases.
Format: 'alias' => 'key'
since |
1.0 |
---|
Type(s)
array
resources
Holds the resources.
since |
2.0.0 |
---|
Type(s)
\Joomla\DI\ContainerResource[]
parent
Parent for hierarchical containers.
In fact, this can be any PSR-11 compatible container, which gets decorated by this
since |
1.0 |
---|
Type(s)
\Joomla\DI\Container|\Psr\Container\ContainerInterface|null
tags
Holds the service tag mapping.
since |
1.5.0 |
---|
Type(s)
array