0 follower

Final Class Yiisoft\Definitions\DefinitionStorage

InheritanceYiisoft\Definitions\DefinitionStorage

Stores service definitions and checks if a definition could be instantiated.

Public Methods

Hide inherited 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

Hide inherited methods

__construct() public method

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() public method

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];
}

            
getBuildStack() public method

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);
}

            
has() public method

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() public method

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;
}

            
setDelegateContainer() public method

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;
}