Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions formwork/bootstrap.php
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion formwork/src/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 0 additions & 76 deletions formwork/views/error.php

This file was deleted.

5 changes: 5 additions & 0 deletions formwork/views/errors/error.php
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions formwork/views/errors/install.php
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions formwork/views/errors/partials/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
</div>
</body>
</html>
79 changes: 79 additions & 0 deletions formwork/views/errors/partials/header.php
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions formwork/views/errors/phpversion.php
Original file line number Diff line number Diff line change
@@ -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' ?>
6 changes: 1 addition & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();