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) :
| since |
1.0 |
|---|
Arguments
- parent
ContainerInterface|nullParent for hierarchical containers.
Response
mixed
alias
Create an alias for a given key for easy access.
alias( alias, key) :
| since |
1.0 |
|---|
Arguments
- alias
stringThe alias name- key
stringThe key to alias
Response
$this
buildObject
Build an object of the requested class
buildObject( resourceName, 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
stringThe class name to build.- shared
boolTrue to create a shared resource.
Response
object|falseInstance 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
exists
Method to check if specified dataStore key exists.
exists( key) :
| since |
1.0 |
|---|---|
| deprecated |
3.0 Use ContainerInterface::has() instead |
Arguments
- key
stringName of the dataStore key to check.
Response
boolTrue for success
extend
Extend a defined service Closure by wrapping the existing one with a new callable function.
extend( resourceName, Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 |Array callable) :
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
stringThe unique identifier for the Closure or property.- callable
callableA callable to wrap the original service Closure.
Response
void
get
Retrieve a resource
get( resourceName) :
| since |
1.0 |
|---|---|
| throws |
Arguments
- resourceName
stringName of the resource to get.
Response
mixedThe requested resource
getKeys
Retrieve the keys for services assigned to this container.
getKeys() : mixed||string|int
| since |
1.5.0 |
|---|
Response
array<string|int, mixed>
getMethodArgs
Build an array of method arguments.
getMethodArgs(\ReflectionMethod method) : mixed||string|int
| since |
1.0 |
|---|---|
| throws |
Arguments
- method
ReflectionMethodMethod for which to build the argument array.
Response
array<string|int, mixed>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( key) :
| since |
1.0 |
|---|
Arguments
- key
stringName of the resources key to get.
Response
mixedResults of running the callback for the specified key.
getResource
Get the raw data assigned to a key.
getResource( key, bail = false) : \Joomla\DI\ContainerResource|null
| since |
2.0.0 |
|---|---|
| throws |
Arguments
- key
stringThe key for which to get the stored item.- bail
boolThrow an exception, if the key is not found
Response
ContainerResource|nullThe resource if present, or null if instructed to not bail
getTagged
Fetch all services registered to the given tag.
getTagged( tag) : mixed||string|int
| since |
1.5.0 |
|---|
Arguments
- tag
stringThe tag name
Response
array<string|int, mixed>The resolved services for the given tag
has
Check if specified resource exists.
has( resourceName) :
| since |
1.5.0 |
|---|
Arguments
- resourceName
stringName of the resource to check.
Response
booltrue if key is defined, false otherwise
hasFlag
Check whether a flag (i.e., one of 'shared' or 'protected') is set
hasFlag( resourceName, method, default = true) :
| since |
2.0.0 |
|---|---|
| throws |
Arguments
- resourceName
stringName of the resource to check.- method
stringMethod to delegate to- default
boolDefault return value
Response
bool
isLocal
Check whether a resource is stored locally
isLocal( resourceName) :
| since |
3.0.0 |
|---|
Arguments
- resourceName
stringName of the resource to check.
Response
bool
isProtected
Check whether a resource is protected
isProtected( resourceName) :
| since |
2.0.0 |
|---|
Arguments
- resourceName
stringName of the resource to check.
Response
bool
lazy
Create a lazy proxy factory for given class.
lazy( class, Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 |Array factory) Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 841 : |Array
| since |
3.1.0 |
|---|
Arguments
- class
stringFull class name of the resource.- factory
callableCallback to create the class instance. The callback must return instance of the given class.
Response
callable
protect
Shortcut method for creating protected keys.
protect( key, value, shared = false) :
| since |
1.0 |
|---|
Arguments
- key
stringName of dataStore key to set.- value
mixedCallable function to run or string to retrieve when requesting the specified $key.- shared
boolTrue to create and store a shared instance.
Response
$this
registerServiceProvider
Register a service provider to the container.
registerServiceProvider(\Joomla\DI\ServiceProviderInterface provider) :
| since |
1.0 |
|---|
Arguments
- provider
ServiceProviderInterfaceThe service provider to register.
Response
$this
resolveAlias
Resolve a resource name.
resolveAlias( resourceName) :
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
stringThe key to search for.
Response
string
set
Set a resource to the container. If the value is null the resource is removed.
set( key, value, shared = false, protected = false) :
| since |
1.0 |
|---|---|
| throws |
|
Arguments
- key
stringName of resources key to set.- value
mixedCallable function to run or string to retrieve when requesting the specified $key.- shared
boolTrue to create and store a shared instance.- protected
boolTrue to protect this item from being overwritten. Useful for services.
Response
$this
tag
Assign a tag to services.
tag( tag, mixed||string|int keys) :
| since |
1.5.0 |
|---|
Arguments
- tag
stringThe tag name- keys
array<string|int, mixed>The service keys to tag
Response
$this
Properties
aliases
Holds the key aliases.
Format: 'alias' => 'key'
| since |
1.0 |
|---|
Type(s)
array<string|int, mixed>
resources
Holds the resources.
| since |
2.0.0 |
|---|
Type(s)
array<string|int, 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)
Container|ContainerInterface|null
tags
Holds the service tag mapping.
| since |
1.5.0 |
|---|
Type(s)
array<string|int, mixed>