Skip to content

Commit

Permalink
Move providers to config
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Jul 18, 2024
1 parent f09026b commit 85ec4f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"source-directory": "config"
},
"config-plugin": {
"di-web": "di-web.php"
"di-web": "di-web.php",
"params": "params.php"
}
},
"config": {
Expand Down
5 changes: 5 additions & 0 deletions config/di-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@

return [
ThrowableRendererInterface::class => HtmlRenderer::class,
HtmlRenderer::class => [
'__construct()' => [
'solutionProviders' => $params['yiisoft/error-handler']['solutionProviders'],
],
],
];
18 changes: 18 additions & 0 deletions config/params.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Yiisoft\ErrorHandler\Renderer\HtmlRenderer;
use Yiisoft\ErrorHandler\ThrowableRendererInterface;

/**
* @var array $params
*/

return [
'yiisoft/error-handler' => [
'solutionProviders' => [
\Yiisoft\Definitions\Reference::to(\Yiisoft\ErrorHandler\Solution\FriendlyExceptionSolution::class),
]
]
];
6 changes: 3 additions & 3 deletions src/Renderer/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Yiisoft\ErrorHandler\ErrorData;
use Yiisoft\ErrorHandler\Exception\ErrorException;
use Yiisoft\ErrorHandler\Solution\SolutionGenerator;
use Yiisoft\ErrorHandler\Solution\FriendlyExceptionSolution;
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
use Yiisoft\FriendlyException\FriendlyExceptionInterface;

Expand Down Expand Up @@ -123,8 +122,9 @@ final class HtmlRenderer implements ThrowableRendererInterface
* maxTraceLines?: int,
* traceHeaderLine?: string,
* } $settings
* @param \Yiisoft\ErrorHandler\Solution\SolutionProviderInterface[] $solutionProviders
*/
public function __construct(array $settings = [])
public function __construct(array $settings = [], array $solutionProviders = [])
{
$this->markdownParser = new GithubMarkdown();
$this->markdownParser->html5 = true;
Expand All @@ -135,7 +135,7 @@ public function __construct(array $settings = [])
$this->maxSourceLines = $settings['maxSourceLines'] ?? 19;
$this->maxTraceLines = $settings['maxTraceLines'] ?? 13;
$this->traceHeaderLine = $settings['traceHeaderLine'] ?? null;
$this->solutionGenerator = new SolutionGenerator([new FriendlyExceptionSolution()]);
$this->solutionGenerator = new SolutionGenerator($solutionProviders);

Check failure on line 138 in src/Renderer/HtmlRenderer.php

View workflow job for this annotation

GitHub Actions / psalm80 / PHP 8.0-ubuntu-latest

InvalidArgument

src/Renderer/HtmlRenderer.php:138:58: InvalidArgument: Argument 1 of Yiisoft\ErrorHandler\Solution\SolutionGenerator::__construct expects array<array-key, Yiisoft\ErrorHandler\Solution\SolutionGeneratorInterface>, but array<array-key, Yiisoft\ErrorHandler\Solution\SolutionProviderInterface> provided (see https://psalm.dev/004)

Check failure on line 138 in src/Renderer/HtmlRenderer.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

InvalidArgument

src/Renderer/HtmlRenderer.php:138:58: InvalidArgument: Argument 1 of Yiisoft\ErrorHandler\Solution\SolutionGenerator::__construct expects array<array-key, Yiisoft\ErrorHandler\Solution\SolutionGeneratorInterface>, but array<array-key, Yiisoft\ErrorHandler\Solution\SolutionProviderInterface> provided (see https://psalm.dev/004)

Check failure on line 138 in src/Renderer/HtmlRenderer.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

InvalidArgument

src/Renderer/HtmlRenderer.php:138:58: InvalidArgument: Argument 1 of Yiisoft\ErrorHandler\Solution\SolutionGenerator::__construct expects array<array-key, Yiisoft\ErrorHandler\Solution\SolutionGeneratorInterface>, but array<array-key, Yiisoft\ErrorHandler\Solution\SolutionProviderInterface> provided (see https://psalm.dev/004)
}

public function render(Throwable $t, ServerRequestInterface $request = null): ErrorData
Expand Down

0 comments on commit 85ec4f0

Please sign in to comment.