mirror of
https://github.com/getgrav/grav.git
synced 2025-11-05 04:45:53 +01:00
Call onFatalException event also on internal PHP errors
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
1. [](#improved)
|
||||
* Added support for syslog and syslog facility logging (default: 'file')
|
||||
* Improved usability of `System` configuration blueprint with side-tabs
|
||||
* Call `onFatalException` event also on internal PHP errors
|
||||
1. [](#bugfix)
|
||||
* 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
|
||||
|
||||
35
index.php
35
index.php
@@ -9,35 +9,33 @@
|
||||
|
||||
namespace Grav;
|
||||
|
||||
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;
|
||||
\define('GRAV_PHP_MIN', '7.1.3');
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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.
|
||||
$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
|
||||
date_default_timezone_set(@date_default_timezone_get());
|
||||
|
||||
// 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");
|
||||
}
|
||||
mb_internal_encoding('UTF-8');
|
||||
@@ -52,6 +50,9 @@ $grav = Grav::instance(
|
||||
// Process the page
|
||||
try {
|
||||
$grav->process();
|
||||
} catch (\Error $e) {
|
||||
$grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
$grav->fireEvent('onFatalException', new Event(array('exception' => $e)));
|
||||
throw $e;
|
||||
|
||||
@@ -156,7 +156,7 @@ class Grav extends Container
|
||||
// Initialize Locale if set and configured.
|
||||
if ($this['language']->enabled() && $this['config']->get('system.languages.override_locale')) {
|
||||
$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')) {
|
||||
setlocale(LC_ALL, $this['config']->get('system.default_locale'));
|
||||
}
|
||||
@@ -295,7 +295,7 @@ class Grav extends Container
|
||||
public function shutdown()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ class Grav extends Container
|
||||
// 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.
|
||||
$success = function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
|
||||
$success = \function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
|
||||
|
||||
if (!$success) {
|
||||
// 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.
|
||||
header('Content-Length: ' . ob_get_length());
|
||||
header("Connection: close");
|
||||
header('Connection: close');
|
||||
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
@@ -351,8 +351,8 @@ class Grav extends Container
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$closure = $this->$method;
|
||||
call_user_func_array($closure, $args);
|
||||
$closure = $this->{$method};
|
||||
\call_user_func_array($closure, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,7 +398,7 @@ class Grav extends Container
|
||||
protected function registerServices()
|
||||
{
|
||||
foreach (self::$diMap as $serviceKey => $serviceClass) {
|
||||
if (is_int($serviceKey)) {
|
||||
if (\is_int($serviceKey)) {
|
||||
$this->registerServiceProvider($serviceClass);
|
||||
} else {
|
||||
$this->registerService($serviceKey, $serviceClass);
|
||||
@@ -475,8 +475,8 @@ class Grav extends Container
|
||||
/** @var Medium $medium */
|
||||
$medium = $media[$media_file];
|
||||
foreach ($uri->query(null, true) as $action => $params) {
|
||||
if (in_array($action, ImageMedium::$magic_actions)) {
|
||||
call_user_func_array([&$medium, $action], explode(',', $params));
|
||||
if (\in_array($action, ImageMedium::$magic_actions, true)) {
|
||||
\call_user_func_array([&$medium, $action], explode(',', $params));
|
||||
}
|
||||
}
|
||||
Utils::download($medium->path(), false);
|
||||
@@ -495,7 +495,7 @@ class Grav extends Container
|
||||
|
||||
if ($extension) {
|
||||
$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;
|
||||
}
|
||||
Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
|
||||
|
||||
Reference in New Issue
Block a user