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 @@ - - - - <?= $message ?> | Formwork - - - - - -
-

- - -

-

Oops, something went wrong!

-

Formwork encountered an error while serving your request. Please check Formwork configuration or the server log for errors.

-

Report an issue to GitHub

-
- - diff --git a/formwork/views/errors/error.php b/formwork/views/errors/error.php new file mode 100644 index 000000000..38afad08c --- /dev/null +++ b/formwork/views/errors/error.php @@ -0,0 +1,5 @@ +insert('errors.partials.header') ?> +

Oops, something went wrong!

+

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.

+

Report an issue to GitHub

+insert('errors.partials.footer') ?> diff --git a/formwork/views/errors/install.php b/formwork/views/errors/install.php new file mode 100644 index 000000000..3556fe253 --- /dev/null +++ b/formwork/views/errors/install.php @@ -0,0 +1,5 @@ + + +

The site is currently offline
due to technical problems

+

If you are the maintainer of this site, please run composer install. Composer autoloader was not found.

+ diff --git a/formwork/views/errors/partials/footer.php b/formwork/views/errors/partials/footer.php new file mode 100644 index 000000000..d5f6fbcfd --- /dev/null +++ b/formwork/views/errors/partials/footer.php @@ -0,0 +1,3 @@ + + + diff --git a/formwork/views/errors/partials/header.php b/formwork/views/errors/partials/header.php new file mode 100644 index 000000000..7c8236b4e --- /dev/null +++ b/formwork/views/errors/partials/header.php @@ -0,0 +1,79 @@ + + + + <?= $message ?? 'Internal Server Error' ?> | Formwork + + + + + +
+

+ + +

diff --git a/formwork/views/errors/phpversion.php b/formwork/views/errors/phpversion.php new file mode 100644 index 000000000..9523a8abd --- /dev/null +++ b/formwork/views/errors/phpversion.php @@ -0,0 +1,5 @@ + + +

The site is currently offline
due to technical problems

+

If you are the maintainer of this site, please switch to a PHP version supported by the installed release of Formwork.

+ diff --git a/index.php b/index.php index 52b122fad..c5c33d2a0 100644 --- a/index.php +++ b/index.php @@ -4,12 +4,8 @@ const DS = DIRECTORY_SEPARATOR; const ROOT_PATH = __DIR__ . DS; -const FORMWORK_PATH = ROOT_PATH . 'formwork' . DS; -const SITE_PATH = ROOT_PATH . 'site' . DS; -const CONFIG_PATH = SITE_PATH . 'config' . DS; -const ADMIN_PATH = ROOT_PATH . 'admin' . DS; -require ROOT_PATH . 'vendor' . DS . 'autoload.php'; +require ROOT_PATH . 'formwork' . DS . 'bootstrap.php'; $formwork = new Formwork(); $formwork->run();