Skip to content

Commit

Permalink
Use relative paths on debug error page
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Feb 9, 2021
1 parent 9a27e77 commit f2be3a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions classes/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function __construct()
/** @var Container $container */
$container = $this->getContainer();

$container['root_path'] = $this->getRootPath();

// Config.
$container['config'] = ConfigFactory::create($container);

Expand Down Expand Up @@ -110,4 +112,17 @@ public function __construct()
[$jsonController, 'json']
)->setName('json');
}

/**
* @return string|null
*/
private function getRootPath(): ?string
{
// realpath() can return false but we prefer using null.
if ($rootPath = realpath(__DIR__ . '/../')) {
return $rootPath;
}

return null;
}
}
2 changes: 1 addition & 1 deletion classes/Controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function error(Request $request, Response $response, Throwable $error): R
$response = $cspMiddleware->applyHeader($response);

if ($this->config->debug) {
$renderer = new HtmlErrorRenderer(true);
$renderer = new HtmlErrorRenderer(true, null, null, $this->container->get('root_path'));
$exception = $renderer->render($error);

$response->getBody()->write($exception->getAsString());
Expand Down
2 changes: 1 addition & 1 deletion classes/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function handle(Throwable $e)

if (class_exists(HtmlErrorRenderer::class)) {
// If dev dependencies are loaded, we can use symfony/error-handler.
$renderer = new HtmlErrorRenderer(true);
$renderer = new HtmlErrorRenderer(true, null, null, dirname(__DIR__));
$exception = $renderer->render($e);

http_response_code($exception->getStatusCode());
Expand Down

0 comments on commit f2be3a7

Please sign in to comment.