Skip to content

Commit cc8b2cc

Browse files
authored
Add separate parameters for HtmlRenderer settings (#137)
1 parent 16a53fd commit cc8b2cc

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
- Enh #125: Add error code & show function arguments (@xepozz)
66
- Enh #130: Pass exception message instead of rendered exception to logger in `ErrorHandler` (@olegbaturin)
7-
- Enh #133: Extract response generator from `ErrorCatcher` middleware into separate `ThrowableResponseFactory` class (@olegbaturin)
7+
- Enh #133: Extract response generator from `ErrorCatcher` middleware into separate `ThrowableResponseFactory`
8+
class (@olegbaturin)
9+
- Chg #137: Add separate parameters for each of `HtmlRenderer` settings in constructor. Mark `$settings` parameter as
10+
deprecated (@vjik)
811

912
## 3.3.0 July 11, 2024
1013

src/Renderer/HtmlRenderer.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ final class HtmlRenderer implements ThrowableRendererInterface
105105
private ?array $vendorPaths = null;
106106

107107
/**
108-
* @param array $settings Settings can have the following keys:
108+
* @param array $settings (deprecated) Settings can have the following keys:
109109
* - template: string, full path of the template file for rendering exceptions without call stack information.
110110
* - verboseTemplate: string, full path of the template file for rendering exceptions with call stack information.
111111
* - maxSourceLines: int, maximum number of source code lines to be displayed. Defaults to 19.
112112
* - maxTraceLines: int, maximum number of trace source code lines to be displayed. Defaults to 13.
113-
* - traceHeaderLine: string, trace header line with placeholders to be be substituted. Defaults to null.
113+
* - traceHeaderLine: string, trace header line with placeholders to be substituted. Defaults to null.
114+
* @param string|null $template The full path of the template file for rendering exceptions without call stack
115+
* information.
116+
* @param string|null $verboseTemplate The full path of the template file for rendering exceptions with call stack
117+
* information.
118+
* @param int|null $maxSourceLines The maximum number of source code lines to be displayed. Defaults to 19.
119+
* @param int|null $maxTraceLines The maximum number of trace source code lines to be displayed. Defaults to 13.
120+
* @param string|null $traceHeaderLine The trace header line with placeholders to be substituted. Defaults to null.
114121
*
115122
* @psalm-param array{
116123
* template?: string,
@@ -120,17 +127,33 @@ final class HtmlRenderer implements ThrowableRendererInterface
120127
* traceHeaderLine?: string,
121128
* } $settings
122129
*/
123-
public function __construct(array $settings = [])
124-
{
130+
public function __construct(
131+
array $settings = [],
132+
?string $template = null,
133+
?string $verboseTemplate = null,
134+
?int $maxSourceLines = null,
135+
?int $maxTraceLines = null,
136+
?string $traceHeaderLine = null,
137+
) {
125138
$this->markdownParser = new GithubMarkdown();
126139
$this->markdownParser->html5 = true;
127140

128141
$this->defaultTemplatePath = dirname(__DIR__, 2) . '/templates';
129-
$this->template = $settings['template'] ?? $this->defaultTemplatePath . '/production.php';
130-
$this->verboseTemplate = $settings['verboseTemplate'] ?? $this->defaultTemplatePath . '/development.php';
131-
$this->maxSourceLines = $settings['maxSourceLines'] ?? 19;
132-
$this->maxTraceLines = $settings['maxTraceLines'] ?? 13;
133-
$this->traceHeaderLine = $settings['traceHeaderLine'] ?? null;
142+
$this->template = $template
143+
?? $settings['template']
144+
?? $this->defaultTemplatePath . '/production.php';
145+
$this->verboseTemplate = $verboseTemplate
146+
?? $settings['verboseTemplate']
147+
?? $this->defaultTemplatePath . '/development.php';
148+
$this->maxSourceLines = $maxSourceLines
149+
?? $settings['maxSourceLines']
150+
?? 19;
151+
$this->maxTraceLines = $maxTraceLines
152+
?? $settings['maxTraceLines']
153+
?? 13;
154+
$this->traceHeaderLine = $traceHeaderLine
155+
?? $settings['traceHeaderLine']
156+
?? null;
134157
}
135158

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

0 commit comments

Comments
 (0)