0 follower

Final Class Yiisoft\Aliases\AliasReference

InheritanceYiisoft\Aliases\AliasReference
ImplementsYiisoft\Definitions\Contract\ReferenceInterface

Reference to an alias that will be resolved at runtime.

Public Methods

Hide inherited methods

Method Description Defined By
resolve() Retrieves {@see Aliases} from the container and uses it to resolve the alias to its actual path. Yiisoft\Aliases\AliasReference
to() Creates a new alias reference. Yiisoft\Aliases\AliasReference

Method Details

Hide inherited methods

resolve() public method

Retrieves {@see Aliases} from the container and uses it to resolve the alias to its actual path.

public string resolve ( \Psr\Container\ContainerInterface $container )
$container \Psr\Container\ContainerInterface

The DI container.

return string

The resolved path for the alias.

                public function resolve(ContainerInterface $container): string
{
    /** @var Aliases $aliases */
    $aliases = $container->get(Aliases::class);
    return $aliases->get($this->alias);
}

            
to() public static method

Creates a new alias reference.

public static self to ( string $id )
$id string

The alias to be resolved.

return self

An instance of reference.

                public static function to(mixed $id): self
{
    if (!is_string($id)) {
        throw new InvalidArgumentException('Alias must be a string.');
    }
    return new self($id);
}