Avolutions\Di\Container
extends AbstractSingleton implements ContainerInterfaceDependency Injection Container
Properties
Property | Visibility | Type | Description |
---|---|---|---|
$instances | protected | array | An array of all instance of singleton classes |
$resolvedEntries | protected | array | Array to store resolved entries. |
Methods
Method | Visibility | Description |
---|---|---|
get() | public | Finds an entry of the container by its identifier and returns it. |
getInstance() | public | Returns an instance of the called class. If there is no instance so far, a new instance is created and returned. Otherwise, the existing one is returned (singleton). |
has() | public | Returns false otherwise. `has($id)` returning true does not mean that `get($id)` will not throw an exception. It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
make() | public | Works like get(), but resolve the entry every time (create new instance). Also, parameters can be passed to the constructor. |
set() | public | Set parameter values and alias definitions. |
setInstance() | public | Set the instance of the given class. |
Property Details
$instances
An array of all instance of singleton classes
protected static array<string|int, mixed> $instances = []
$resolvedEntries
Array to store resolved entries.
protected array<string|int, mixed> $resolvedEntries = []
Method Details
get()
Finds an entry of the container by its identifier and returns it.
public
get(string $id) : mixed
Parameters
string
$id
Identifier of the entry to look for.
Return values
mixed Finds an entry of the container by its identifier and returns it.getInstance()
Returns an instance of the called class. If there is no instance so far, a new instance is created and returned. Otherwise, the existing one is returned (singleton).
public
final static getInstance() : object
Return values
object Returns an instance of the called class. If there is no instance so far, a new instance is created and returned. Otherwise, the existing one is returned (singleton).has()
Returns false otherwise.
has($id)
returning true does not mean that get($id)
will not throw an exception.
It does however mean that get($id)
will not throw a NotFoundExceptionInterface
.
public
has(string $id) : bool
Parameters
string
$id
Identifier of the entry to look for.
Return values
bool Returns false otherwise. `has($id)` returning true does not mean that `get($id)` will not throw an exception. It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.make()
Works like get(), but resolve the entry every time (create new instance). Also, parameters can be passed to the constructor.
public
make(string $id[, array<string|int, mixed> $parameters = [] ]) : mixed
Parameters
string
$id
Identifier of the entry to look for.
array<string|int, mixed>
$parameters
(optional)
Array of parameters to pass to constructor, where key is name of parameter