Skip to content

Commit 5d41ab0

Browse files
committed
refactor: remove generator, pass providers directly
1 parent ce78cfc commit 5d41ab0

File tree

5 files changed

+17
-41
lines changed

5 files changed

+17
-41
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ composer.lock
2020
/phpunit.phar
2121
/phpunit.xml
2222
/.phpunit.cache
23+
.phpunit.result.cache
24+

config/params.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
return [
1111
'yiisoft/error-handler' => [
1212
'solutionProviders' => [
13-
Yiisoft\Definitions\Reference::to(Yiisoft\ErrorHandler\Solution\FriendlyExceptionSolution::class),
13+
\Yiisoft\Definitions\Reference::to(\Yiisoft\ErrorHandler\Solution\FriendlyExceptionSolution::class),
1414
],
1515
],
1616
];

src/Renderer/HtmlRenderer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Yiisoft\ErrorHandler\CompositeException;
1313
use Yiisoft\ErrorHandler\ErrorData;
1414
use Yiisoft\ErrorHandler\Exception\ErrorException;
15-
use Yiisoft\ErrorHandler\Solution\SolutionGenerator;
15+
use Yiisoft\ErrorHandler\Solution\SolutionProviderInterface;
1616
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
1717
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
1818
use Yiisoft\Http\Header;
@@ -108,7 +108,10 @@ final class HtmlRenderer implements ThrowableRendererInterface
108108
*/
109109
private ?array $vendorPaths = null;
110110

111-
private readonly SolutionGenerator $solutionGenerator;
111+
/**
112+
* @var SolutionProviderInterface[]
113+
*/
114+
private array $solutionProviders;
112115

113116
/**
114117
* @param array $settings (deprecated) Settings can have the following keys:
@@ -164,7 +167,7 @@ public function __construct(
164167
?? $settings['traceHeaderLine']
165168
?? null;
166169

167-
$this->solutionGenerator = new SolutionGenerator($solutionProviders);
170+
$this->solutionProviders = $solutionProviders;
168171
}
169172

170173
public function render(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
@@ -180,12 +183,11 @@ public function render(Throwable $t, ?ServerRequestInterface $request = null): E
180183

181184
public function renderVerbose(Throwable $t, ?ServerRequestInterface $request = null): ErrorData
182185
{
183-
$solutions = $this->solutionGenerator->generate($t);
184186
return new ErrorData(
185187
$this->renderTemplate($this->verboseTemplate, [
186188
'request' => $request,
187189
'throwable' => $t,
188-
'solutions' => $solutions,
190+
'solutions' => $this->solutionProviders,
189191
]),
190192
[Header::CONTENT_TYPE => self::CONTENT_TYPE],
191193
);

src/Solution/SolutionGenerator.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

templates/development.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
use Yiisoft\ErrorHandler\CompositeException;
55
use Yiisoft\ErrorHandler\Exception\ErrorException;
66
use Yiisoft\ErrorHandler\Renderer\HtmlRenderer;
7+
use Yiisoft\ErrorHandler\Solution\SolutionProviderInterface;
78
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
89

910
/**
1011
* @var $this HtmlRenderer
1112
* @var $request ServerRequestInterface|null
1213
* @var $throwable Throwable
13-
* @var $solutions string[]
14+
* @var $solutions SolutionProviderInterface[]
1415
*/
1516

1617
$theme = $_COOKIE['yii-exception-theme'] ?? '';
@@ -96,9 +97,11 @@
9697
if (!empty($solutions)) {
9798
echo '<div class="solutions">';
9899
foreach ($solutions as $i => $solution) {
99-
echo '<div class="solution solution-' . $i . '">';
100-
echo $this->parseMarkdown($solution);
101-
echo '</div>';
100+
if ($solution->supports($throwable)) {
101+
echo '<div class="solution solution-' . $i . '">';
102+
echo $this->parseMarkdown($solution->generate($throwable));
103+
echo '</div>';
104+
}
102105
}
103106
}
104107
?>

0 commit comments

Comments
 (0)