mirror of
https://github.com/getgrav/grav.git
synced 2025-11-06 05:16:07 +01:00
Call onFatalException event also on internal PHP errors
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
1. [](#improved)
|
1. [](#improved)
|
||||||
* Added support for syslog and syslog facility logging (default: 'file')
|
* Added support for syslog and syslog facility logging (default: 'file')
|
||||||
* Improved usability of `System` configuration blueprint with side-tabs
|
* Improved usability of `System` configuration blueprint with side-tabs
|
||||||
|
* Call `onFatalException` event also on internal PHP errors
|
||||||
1. [](#bugfix)
|
1. [](#bugfix)
|
||||||
* Fixed asset manager to not add empty assets when they don't exist in the filesystem
|
* Fixed asset manager to not add empty assets when they don't exist in the filesystem
|
||||||
* Regression: Fixed asset manager methods with default legacy attributes
|
* Regression: Fixed asset manager methods with default legacy attributes
|
||||||
|
|||||||
35
index.php
35
index.php
@@ -9,35 +9,33 @@
|
|||||||
|
|
||||||
namespace Grav;
|
namespace Grav;
|
||||||
|
|
||||||
define('GRAV_PHP_MIN', '7.1.3');
|
\define('GRAV_PHP_MIN', '7.1.3');
|
||||||
|
|
||||||
// Ensure vendor libraries exist
|
|
||||||
$autoload = __DIR__ . '/vendor/autoload.php';
|
|
||||||
if (!is_file($autoload)) {
|
|
||||||
die("Please run: <i>bin/grav install</i>");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PHP_SAPI === 'cli-server') {
|
|
||||||
if (!isset($_SERVER['PHP_CLI_ROUTER'])) {
|
|
||||||
die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use Grav\Common\Grav;
|
|
||||||
use RocketTheme\Toolbox\Event\Event;
|
|
||||||
|
|
||||||
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
||||||
die(sprintf('You are running PHP %s, but Grav needs at least <strong>PHP %s</strong> to run.', $ver, $req));
|
die(sprintf('You are running PHP %s, but Grav needs at least <strong>PHP %s</strong> to run.', $ver, $req));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PHP_SAPI === 'cli-server' && !isset($_SERVER['PHP_CLI_ROUTER'])) {
|
||||||
|
die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure vendor libraries exist
|
||||||
|
$autoload = __DIR__ . '/vendor/autoload.php';
|
||||||
|
if (!is_file($autoload)) {
|
||||||
|
die('Please run: <i>bin/grav install</i>');
|
||||||
|
}
|
||||||
|
|
||||||
// Register the auto-loader.
|
// Register the auto-loader.
|
||||||
$loader = require $autoload;
|
$loader = require $autoload;
|
||||||
|
|
||||||
|
use Grav\Common\Grav;
|
||||||
|
use RocketTheme\Toolbox\Event\Event;
|
||||||
|
|
||||||
// Set timezone to default, falls back to system if php.ini not set
|
// Set timezone to default, falls back to system if php.ini not set
|
||||||
date_default_timezone_set(@date_default_timezone_get());
|
date_default_timezone_set(@date_default_timezone_get());
|
||||||
|
|
||||||
// Set internal encoding if mbstring loaded
|
// Set internal encoding if mbstring loaded
|
||||||
if (!extension_loaded('mbstring')) {
|
if (!\extension_loaded('mbstring')) {
|
||||||
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
|
die("'mbstring' extension is not loaded. This is required for Grav to run correctly");
|
||||||
}
|
}
|
||||||
mb_internal_encoding('UTF-8');
|
mb_internal_encoding('UTF-8');
|
||||||
@@ -52,6 +50,9 @@ $grav = Grav::instance(
|
|||||||
// Process the page
|
// Process the page
|
||||||
try {
|
try {
|
||||||
$grav->process();
|
$grav->process();
|
||||||
|
} catch (\Error $e) {
|
||||||
|
$grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
|
||||||
|
throw $e;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
|
$grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class Grav extends Container
|
|||||||
// Initialize Locale if set and configured.
|
// Initialize Locale if set and configured.
|
||||||
if ($this['language']->enabled() && $this['config']->get('system.languages.override_locale')) {
|
if ($this['language']->enabled() && $this['config']->get('system.languages.override_locale')) {
|
||||||
$language = $this['language']->getLanguage();
|
$language = $this['language']->getLanguage();
|
||||||
setlocale(LC_ALL, strlen($language) < 3 ? ($language . '_' . strtoupper($language)) : $language);
|
setlocale(LC_ALL, \strlen($language) < 3 ? ($language . '_' . strtoupper($language)) : $language);
|
||||||
} elseif ($this['config']->get('system.default_locale')) {
|
} elseif ($this['config']->get('system.default_locale')) {
|
||||||
setlocale(LC_ALL, $this['config']->get('system.default_locale'));
|
setlocale(LC_ALL, $this['config']->get('system.default_locale'));
|
||||||
}
|
}
|
||||||
@@ -295,7 +295,7 @@ class Grav extends Container
|
|||||||
public function shutdown()
|
public function shutdown()
|
||||||
{
|
{
|
||||||
// Prevent user abort allowing onShutdown event to run without interruptions.
|
// Prevent user abort allowing onShutdown event to run without interruptions.
|
||||||
if (function_exists('ignore_user_abort')) {
|
if (\function_exists('ignore_user_abort')) {
|
||||||
@ignore_user_abort(true);
|
@ignore_user_abort(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ class Grav extends Container
|
|||||||
// the connection to the client open. This will make page loads to feel much faster.
|
// the connection to the client open. This will make page loads to feel much faster.
|
||||||
|
|
||||||
// FastCGI allows us to flush all response data to the client and finish the request.
|
// FastCGI allows us to flush all response data to the client and finish the request.
|
||||||
$success = function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
|
$success = \function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
|
||||||
|
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
// Unfortunately without FastCGI there is no way to force close the connection.
|
// Unfortunately without FastCGI there is no way to force close the connection.
|
||||||
@@ -332,7 +332,7 @@ class Grav extends Container
|
|||||||
|
|
||||||
// Get length and close the connection.
|
// Get length and close the connection.
|
||||||
header('Content-Length: ' . ob_get_length());
|
header('Content-Length: ' . ob_get_length());
|
||||||
header("Connection: close");
|
header('Connection: close');
|
||||||
|
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
@ob_flush();
|
@ob_flush();
|
||||||
@@ -351,8 +351,8 @@ class Grav extends Container
|
|||||||
*/
|
*/
|
||||||
public function __call($method, $args)
|
public function __call($method, $args)
|
||||||
{
|
{
|
||||||
$closure = $this->$method;
|
$closure = $this->{$method};
|
||||||
call_user_func_array($closure, $args);
|
\call_user_func_array($closure, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -398,7 +398,7 @@ class Grav extends Container
|
|||||||
protected function registerServices()
|
protected function registerServices()
|
||||||
{
|
{
|
||||||
foreach (self::$diMap as $serviceKey => $serviceClass) {
|
foreach (self::$diMap as $serviceKey => $serviceClass) {
|
||||||
if (is_int($serviceKey)) {
|
if (\is_int($serviceKey)) {
|
||||||
$this->registerServiceProvider($serviceClass);
|
$this->registerServiceProvider($serviceClass);
|
||||||
} else {
|
} else {
|
||||||
$this->registerService($serviceKey, $serviceClass);
|
$this->registerService($serviceKey, $serviceClass);
|
||||||
@@ -475,8 +475,8 @@ class Grav extends Container
|
|||||||
/** @var Medium $medium */
|
/** @var Medium $medium */
|
||||||
$medium = $media[$media_file];
|
$medium = $media[$media_file];
|
||||||
foreach ($uri->query(null, true) as $action => $params) {
|
foreach ($uri->query(null, true) as $action => $params) {
|
||||||
if (in_array($action, ImageMedium::$magic_actions)) {
|
if (\in_array($action, ImageMedium::$magic_actions, true)) {
|
||||||
call_user_func_array([&$medium, $action], explode(',', $params));
|
\call_user_func_array([&$medium, $action], explode(',', $params));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils::download($medium->path(), false);
|
Utils::download($medium->path(), false);
|
||||||
@@ -495,7 +495,7 @@ class Grav extends Container
|
|||||||
|
|
||||||
if ($extension) {
|
if ($extension) {
|
||||||
$download = true;
|
$download = true;
|
||||||
if (in_array(ltrim($extension, '.'), $config->get('system.media.unsupported_inline_types', []))) {
|
if (\in_array(ltrim($extension, '.'), $config->get('system.media.unsupported_inline_types', []), true)) {
|
||||||
$download = false;
|
$download = false;
|
||||||
}
|
}
|
||||||
Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
|
Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
|
||||||
|
|||||||
Reference in New Issue
Block a user