Final Class Yiisoft\Definitions\DefinitionStorage
| Inheritance | Yiisoft\Definitions\DefinitionStorage |
|---|
Stores service definitions and checks if a definition could be instantiated.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Definitions\DefinitionStorage | |
| get() | Get a definition with a given ID. | Yiisoft\Definitions\DefinitionStorage |
| getBuildStack() | Returns a stack with definition IDs in the order the latest dependency obtained would be built. | Yiisoft\Definitions\DefinitionStorage |
| has() | Checks if there is a definition with ID specified and that it can be created. | Yiisoft\Definitions\DefinitionStorage |
| set() | Set a definition. | Yiisoft\Definitions\DefinitionStorage |
| setDelegateContainer() | Yiisoft\Definitions\DefinitionStorage |
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\Definitions\Exception\CircularReferenceException | |
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\Definitions\Exception\CircularReferenceException | |
|---|---|---|
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 ( \Psr\Container\ContainerInterface $delegateContainer ) | ||
| $delegateContainer | \Psr\Container\ContainerInterface |
Container to fall back to when dependency is not found. |
public function setDelegateContainer(ContainerInterface $delegateContainer): void
{
$this->delegateContainer = $delegateContainer;
}
Signup or Login in order to comment.