mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-17 13:38:22 +01:00
Add informative errors on bootstrap
This commit is contained in:
parent
2b02349211
commit
307b1b1dac
21
formwork/bootstrap.php
Normal file
21
formwork/bootstrap.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
// Define constants
|
||||
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;
|
||||
|
||||
// Check PHP version requirements
|
||||
if (!version_compare(PHP_VERSION, '8.0.2', '>=')) {
|
||||
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;
|
||||
}
|
@ -29,7 +29,7 @@ class Errors
|
||||
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
|
||||
|
@ -1,76 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title><?= $message ?> | Formwork</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
@media (min-width: 768px) {
|
||||
html {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f8f8f8;
|
||||
color: #666;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 2rem auto;
|
||||
padding: 1rem;
|
||||
max-width: 32rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 3rem;
|
||||
font-size: 1.75rem;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 1rem;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
a {
|
||||
outline: none;
|
||||
color: #3498da;
|
||||
text-decoration: none;
|
||||
transition: color 150ms;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #1a608e;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
display: block;
|
||||
color: #999;
|
||||
font-weight: 400;
|
||||
font-size: 8rem;
|
||||
}
|
||||
|
||||
.error-status {
|
||||
display: block;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>
|
||||
<span class="error-code"><?= $status ?></span>
|
||||
<span class="error-status"><?= $message ?></span>
|
||||
</h1>
|
||||
<h2>Oops, something went wrong!</h2>
|
||||
<p>Formwork encountered an error while serving your request. Please check Formwork configuration or the server log for errors.</p>
|
||||
<p><a href="https://github.com/getformwork/formwork/issues" target="_blank">Report an issue to GitHub</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
5
formwork/views/errors/error.php
Normal file
5
formwork/views/errors/error.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php $this->insert('errors.partials.header') ?>
|
||||
<h2>Oops, something went wrong!</h2>
|
||||
<p>Formwork encountered an error while serving your request.<br>If you are the maintainer of this site, please check Formwork configuration or the server log for errors.</p>
|
||||
<p><a href="https://github.com/getformwork/formwork/issues" target="_blank">Report an issue to GitHub</a></p>
|
||||
<?php $this->insert('errors.partials.footer') ?>
|
5
formwork/views/errors/install.php
Normal file
5
formwork/views/errors/install.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0') . ' 500 Internal Server Error'); ?>
|
||||
<?php include __DIR__ . DS . 'partials' . DS . 'header.php' ?>
|
||||
<h2>The site is currently offline<br>due to technical problems</h2>
|
||||
<p>If you are the maintainer of this site, please run <code>composer install</code>. Composer autoloader was not found.</p>
|
||||
<?php include __DIR__ . DS . 'partials' . DS . 'footer.php' ?>
|
3
formwork/views/errors/partials/footer.php
Normal file
3
formwork/views/errors/partials/footer.php
Normal file
@ -0,0 +1,3 @@
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
79
formwork/views/errors/partials/header.php
Normal file
79
formwork/views/errors/partials/header.php
Normal file
@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title><?= $message ?? 'Internal Server Error' ?> | Formwork</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
background-color: #f7f7f7;
|
||||
color: #262626;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 32rem;
|
||||
padding: 1rem;
|
||||
margin: 4rem auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
margin-top: 0;
|
||||
letter-spacing: -0.027rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 3rem;
|
||||
font-size: 1.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 1rem;
|
||||
font-size: 2rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #3498da;
|
||||
outline: none;
|
||||
text-decoration: none;
|
||||
transition: color 150ms;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #1a608e;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
code {
|
||||
color: #7d7d7d;
|
||||
font-family: SFMono-Regular, 'SF Mono', 'Cascadia Mono', 'Liberation Mono', Menlo, Consolas, monospace;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
display: block;
|
||||
color: #969696;
|
||||
font-size: 8rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.error-status {
|
||||
display: block;
|
||||
color: #969696;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>
|
||||
<span class="error-code"><?= $status ?? 500 ?></span>
|
||||
<span class="error-status"><?= $message ?? 'Internal Server Error' ?></span>
|
||||
</h1>
|
5
formwork/views/errors/phpversion.php
Normal file
5
formwork/views/errors/phpversion.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0') . ' 500 Internal Server Error'); ?>
|
||||
<?php include __DIR__ . DS . 'partials' . DS . 'header.php' ?>
|
||||
<h2>The site is currently offline<br>due to technical problems</h2>
|
||||
<p>If you are the maintainer of this site, please switch to a PHP version supported by the installed release of Formwork.</p>
|
||||
<?php include __DIR__ . DS . 'partials' . DS . 'footer.php' ?>
|
@ -4,12 +4,8 @@ use Formwork\Formwork;
|
||||
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user