Final Class Yiisoft\Definitions\DefinitionStorage
| Inheritance | Yiisoft\ |
|---|
Stores service definitions and checks if a definition could be instantiated.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| get() | Get a definition with a given ID. | Yiisoft\ |
| getBuildStack() | Returns a stack with definition IDs in the order the latest dependency obtained would be built. | Yiisoft\ |
| has() | Checks if there is a definition with ID specified and that it can be created. | Yiisoft\ |
| set() | Set a definition. | Yiisoft\ |
| setDelegateContainer() | Yiisoft\ |
Method Details
| public mixed __construct ( array $definitions = [], boolean $useStrictMode = false ) | ||
| $definitions | array |
Definitions to store. |
| $useStrictMode | boolean |
If every dependency should be defined explicitly including classes. |
public function __construct(
private array $definitions = [],
private readonly bool $useStrictMode = false,
) {}
Get a definition with a given ID.
| public mixed|object get ( string $id ) | ||
| $id | string | |
| return | mixed|object |
Definition with a given ID. |
|---|---|---|
| throws | Yiisoft\ |
|
public function get(string $id): mixed
{
if (!$this->has($id)) {
throw new RuntimeException("Service $id doesn't exist in DefinitionStorage.");
}
return $this->definitions[$id];
}
Returns a stack with definition IDs in the order the latest dependency obtained would be built.
| public string[] getBuildStack ( ) | ||
| return | string[] |
Build stack. |
|---|---|---|
public function getBuildStack(): array
{
return array_keys($this->buildStack);
}
Checks if there is a definition with ID specified and that it can be created.
| public boolean has ( string $id ) | ||
| $id | string |
Class name, interface name or alias name |
| throws | Yiisoft\ |
|
|---|---|---|
public function has(string $id): bool
{
$this->buildStack = [];
return $this->isResolvable($id, []);
}
Set a definition.
| public void set ( string $id, mixed $definition ) | ||
| $id | string |
ID to set definition for. |
| $definition | mixed |
Definition to set. |
public function set(string $id, mixed $definition): void
{
$this->definitions[$id] = $definition;
}
| public void setDelegateContainer ( \ | ||
| $delegateContainer | \ |
Container to fall back to when dependency is not found. |
public function setDelegateContainer(ContainerInterface $delegateContainer): void
{
$this->delegateContainer = $delegateContainer;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.