From 307b1b1dacad36f36739df4c2fab4377b2347dfd Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Sun, 30 Oct 2022 15:04:05 +0100 Subject: [PATCH] Add informative errors on bootstrap --- formwork/bootstrap.php | 21 ++++++ formwork/src/Errors.php | 2 +- formwork/views/error.php | 76 ---------------------- formwork/views/errors/error.php | 5 ++ formwork/views/errors/install.php | 5 ++ formwork/views/errors/partials/footer.php | 3 + formwork/views/errors/partials/header.php | 79 +++++++++++++++++++++++ formwork/views/errors/phpversion.php | 5 ++ index.php | 6 +- 9 files changed, 120 insertions(+), 82 deletions(-) create mode 100644 formwork/bootstrap.php delete mode 100644 formwork/views/error.php create mode 100644 formwork/views/errors/error.php create mode 100644 formwork/views/errors/install.php create mode 100644 formwork/views/errors/partials/footer.php create mode 100644 formwork/views/errors/partials/header.php create mode 100644 formwork/views/errors/phpversion.php diff --git a/formwork/bootstrap.php b/formwork/bootstrap.php new file mode 100644 index 000000000..917a482f9 --- /dev/null +++ b/formwork/bootstrap.php @@ -0,0 +1,21 @@ +=')) { + require __DIR__ . DS . 'views' . DS . 'errors' . DS . 'phpversion.php'; + exit; +} + +// Check if Composer autoloader is available +if (file_exists($autoload = ROOT_PATH . 'vendor' . DS . 'autoload.php')) { + require $autoload; +} else { + require __DIR__ . DS . 'views' . DS . 'errors' . DS . 'install.php'; + exit; +} diff --git a/formwork/src/Errors.php b/formwork/src/Errors.php index b4374a90f..c9ecef949 100644 --- a/formwork/src/Errors.php +++ b/formwork/src/Errors.php @@ -29,7 +29,7 @@ public static function setHandlers(): void public static function displayErrorPage(int $status = 500): void { HTTPResponse::cleanOutputBuffers(); - $view = new View('error', ['status' => $status, 'message' => Header::HTTP_STATUS[$status]]); + $view = new View('errors.error', ['status' => $status, 'message' => Header::HTTP_STATUS[$status]]); $response = new Response($view->render(true), $status); $response->send(); // Don't exit, otherwise the error will not be logged diff --git a/formwork/views/error.php b/formwork/views/error.php deleted file mode 100644 index 588ce40c6..000000000 --- a/formwork/views/error.php +++ /dev/null @@ -1,76 +0,0 @@ - - -
-Formwork encountered an error while serving your request. Please check Formwork configuration or the server log for errors.
- -Formwork encountered an error while serving your request.
If you are the maintainer of this site, please check Formwork configuration or the server log for errors.
If you are the maintainer of this site, please run composer install. Composer autoloader was not found.