Final Class Yiisoft\Widget\NotInstantiableException
| Inheritance | Yiisoft\Widget\NotInstantiableException » Yiisoft\Definitions\Exception\NotInstantiableException |
|---|---|
| Implements | Yiisoft\FriendlyException\FriendlyExceptionInterface |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Widget\NotInstantiableException | |
| getName() | Yiisoft\Widget\NotInstantiableException | |
| getSolution() | Yiisoft\Widget\NotInstantiableException |
Method Details
| public mixed __construct ( string $widgetClassName, boolean $widgetFactoryInitialized, Throwable $previous ) | ||
| $widgetClassName | string | |
| $widgetFactoryInitialized | boolean | |
| $previous | Throwable | |
public function __construct(
private string $widgetClassName,
private bool $widgetFactoryInitialized,
private Throwable $previous,
) {
$message = 'Failed to create a widget "' . $this->widgetClassName . '". ' . $previous->getMessage();
if (!$this->widgetFactoryInitialized) {
$message .= ' Perhaps you need to initialize "' . WidgetFactory::class . '" with DI container to resolve dependencies.';
}
parent::__construct($message, previous: $previous);
}
| public string getName ( ) |
public function getName(): string
{
return 'Failed to create a widget "' . $this->widgetClassName . '". ' . $this->previous->getMessage();
}
| public string|null getSolution ( ) |
public function getSolution(): ?string
{
if ($this->widgetFactoryInitialized) {
return null;
}
$widgetFactoryClass = WidgetFactory::class;
return <<<SOLUTION
Perhaps you need to initialize "$widgetFactoryClass" with DI container to resolve dependencies.
To initialize the widget factory call `WidgetFactory::initialize()` before using the widget.
It is a good idea to do that for the whole application.
Example:
```php
/**
* @var Psr\Container\ContainerInterface \$container
*/
Yiisoft\Widget\WidgetFactory::initialize(
container: \$container,
definitions: [MyWidget::class => new MyWidget(/*...*/)],
themes: [
'custom' => [
MyWidget::class => [
'setValue()' => [42],
],
],
],
validate: true, // Whether definitions need to be validated.
);
```
See Yii example in the configuration file of this package `config/bootstrap.php`.
SOLUTION;
}
Signup or Login in order to comment.