0 follower

Final Class Yiisoft\Di\BuildingException

InheritanceYiisoft\Di\BuildingException » Exception
ImplementsPsr\Container\ContainerExceptionInterface, Yiisoft\FriendlyException\FriendlyExceptionInterface

It wraps all exceptions that don't implement ContainerExceptionInterface during the build process.

Also adds building context for more understanding.

Method Details

Hide inherited methods

__construct() public method

public __construct( string $id, Throwable $error, string[] $buildStack = [], Throwable|null $previous null ): mixed
$id string

ID of the definition or name of the class that wasn't found.

$error Throwable
$buildStack string[]

Stack of IDs of services requested definition or class that wasn't found.

$previous Throwable|null

                public function __construct(
    private readonly string $id,
    Throwable $error,
    array $buildStack = [],
    ?Throwable $previous = null,
) {
    $message = sprintf(
        'Caught unhandled error "%s" while building "%s".',
        $error->getMessage() === '' ? $error::class : $error->getMessage(),
        implode('" -> "', $buildStack === [] ? [$id] : $buildStack),
    );
    parent::__construct($message, 0, $previous);
}

            
getName() public method

public getName( ): string

                public function getName(): string
{
    return sprintf('Unable to build "%s" object.', $this->id);
}

            
getSolution() public method

public getSolution( ): string|null

                public function getSolution(): ?string
{
    $solution = <<<SOLUTION
        Ensure that either a service with ID "%1\$s" is defined or such class exists and is autoloadable.
        Ensure that configuration for service with ID "%1\$s" is correct.
        SOLUTION;
    return sprintf($solution, $this->id);
}