mirror of
https://github.com/getgrav/grav.git
synced 2026-02-26 00:21:31 +01:00
Add new event onFatalException and listen to it in problems plugin
This commit is contained in:
committed by
Djamil Legato
parent
ce68c36910
commit
b5982ea965
8
bin/grav
8
bin/grav
@@ -1,13 +1,13 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
require_once(__DIR__ . '/../system/defines.php');
|
||||
require_once(__DIR__ . '/../vendor/autoload.php');
|
||||
require_once(__DIR__ . '/../system/autoload.php');
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
if (!file_exists(ROOT_DIR . 'index.php')) {
|
||||
exit('FATAL: Must be run from ROOT directory of Grav!');
|
||||
|
||||
48
index.php
48
index.php
@@ -3,42 +3,40 @@ namespace Grav\Common;
|
||||
|
||||
use Tracy\Debugger;
|
||||
|
||||
require_once(__DIR__ . '/system/defines.php');
|
||||
// Register system libraries to the auto-loader.
|
||||
$loader = require_once __DIR__ . '/system/autoload.php';
|
||||
|
||||
if (!ini_get('date.timezone')) {
|
||||
date_default_timezone_set('GMT');
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
// Use output buffering to prevent headers from being sent too early.
|
||||
ob_start();
|
||||
|
||||
// Register all the classes to the auto-loader.
|
||||
require_once(VENDOR_DIR .'autoload.php');
|
||||
require_once(SYSTEM_DIR .'autoload.php');
|
||||
|
||||
// Create Required Folders if they don't exist
|
||||
if (!file_exists(LOG_DIR)) mkdir(LOG_DIR);
|
||||
if (!file_exists(CACHE_DIR)) mkdir(CACHE_DIR);
|
||||
if (!file_exists(IMAGES_DIR)) mkdir(IMAGES_DIR);
|
||||
if (!file_exists(DATA_DIR)) mkdir(DATA_DIR);
|
||||
|
||||
// Start the timer and enable debugger in production mode as we do not have system configuration yet.
|
||||
// Debugger catches all errors and logs them, for example if the script doesn't have write permissions.
|
||||
Debugger::timer();
|
||||
Debugger::enable(Debugger::PRODUCTION, LOG_DIR);
|
||||
Debugger::enable(Debugger::DEVELOPMENT, is_dir(LOG_DIR) ? LOG_DIR : null);
|
||||
|
||||
// Register all the Grav bits into registry.
|
||||
$registry = Registry::instance();
|
||||
$registry->store('Grav', new Grav);
|
||||
$registry->store('Uri', new Uri);
|
||||
$registry->store('Config', Config::instance(CACHE_DIR . 'config.php'));
|
||||
$registry->store('Cache', new Cache);
|
||||
$registry->store('Twig', new Twig);
|
||||
$registry->store('Pages', new Page\Pages);
|
||||
$registry->store('Taxonomy', new Taxonomy);
|
||||
$grav = new Grav;
|
||||
|
||||
/** @var Grav $grav */
|
||||
$grav = $registry->retrieve('Grav');
|
||||
$grav->process();
|
||||
try {
|
||||
// Register all the Grav bits into registry.
|
||||
$registry = Registry::instance();
|
||||
$registry->store('autoloader', $loader);
|
||||
$registry->store('Grav', $grav);
|
||||
$registry->store('Uri', new Uri);
|
||||
$registry->store('Config', Config::instance(CACHE_DIR . 'config.php'));
|
||||
$registry->store('Cache', new Cache);
|
||||
$registry->store('Twig', new Twig);
|
||||
$registry->store('Pages', new Page\Pages);
|
||||
$registry->store('Taxonomy', new Taxonomy);
|
||||
|
||||
$grav->process();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$grav->fireEvent('onFatalException', $e);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
ob_end_flush();
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
require_once(__DIR__ . '/../system/defines.php');
|
||||
|
||||
// Initiate Autoload of Grav classes
|
||||
spl_autoload_register(function ($class) {
|
||||
// Use composer auto-loader and just add our namespace into it.
|
||||
$loader = require_once(__DIR__ . '/../vendor/autoload.php');
|
||||
$loader->addPsr4('Grav\\', LIB_DIR . 'Grav');
|
||||
|
||||
if (strpos($class, 'Grav\\Common') === 0 || strpos($class, 'Grav\\Console') === 0) {
|
||||
$filename = str_replace('\\', '/', LIB_DIR.$class.'.php');
|
||||
include($filename);
|
||||
}
|
||||
});
|
||||
return $loader;
|
||||
|
||||
@@ -33,6 +33,7 @@ class Config extends Data
|
||||
* @var bool Flag to tell if configuration needs to be saved.
|
||||
*/
|
||||
public $updated = false;
|
||||
public $issues = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -92,7 +93,8 @@ class Config extends Data
|
||||
}
|
||||
$this->updated = false;
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Writing to cache folder failed (configuration).', 500, $e);
|
||||
$this->issues[] = 'Writing configuration into cache failed.';
|
||||
//throw new \RuntimeException('Writing configuration into cache failed.', 500, $e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -207,7 +207,7 @@ class Grav extends Getters
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config->get('system.debugger.log.timing') && !in_array($hook_id, $no_timing_hooks)) {
|
||||
if ($this->config && $this->config->get('system.debugger.log.timing') && !in_array($hook_id, $no_timing_hooks)) {
|
||||
static::log($hook_id.': %f ms');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,41 @@ class ProblemsPlugin extends Plugin
|
||||
Registry::get('Twig')->twig_paths[] = __DIR__ . '/templates';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function onFatalException($e)
|
||||
{
|
||||
// Run through potential issues
|
||||
if ($this->problemChecker()) {
|
||||
foreach ($this->results as $key => $result) {
|
||||
if ($key == 'files') {
|
||||
foreach ($result as $filename => $status) {
|
||||
if (key($status)) {
|
||||
continue;
|
||||
}
|
||||
$text = reset($status);
|
||||
echo "<div>{$filename} {$text}</div>";
|
||||
}
|
||||
} else {
|
||||
if (key($status)) {
|
||||
continue;
|
||||
}
|
||||
$text = reset($status);
|
||||
echo "<div>{$text}</div>";
|
||||
}
|
||||
}
|
||||
|
||||
// Create Required Folders if they don't exist
|
||||
if (!is_dir(LOG_DIR)) mkdir(LOG_DIR);
|
||||
if (!is_dir(CACHE_DIR)) mkdir(CACHE_DIR);
|
||||
if (!is_dir(IMAGES_DIR)) mkdir(IMAGES_DIR);
|
||||
if (!is_dir(DATA_DIR)) mkdir(DATA_DIR);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set needed variables to display the problems.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user