mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Initial commit with PHP Debug Bar instead of Tracy
This commit is contained in:
parent
6c912d126a
commit
2bfcd88bfd
|
|
@ -31,7 +31,7 @@ RewriteRule ^bin/(.*)$ error [R=301,L]
|
|||
RewriteRule ^system/(.*)$ error [R=301,L]
|
||||
|
||||
# Block vendor/
|
||||
RewriteRule ^vendor/(.*)$ error [R=301,L]
|
||||
# RewriteRule ^vendor/(.*)$ error [R=301,L]
|
||||
|
||||
</IfModule>
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
"symfony/event-dispatcher": "~2.5",
|
||||
"doctrine/cache": "~1.3",
|
||||
"tracy/tracy": "2.3.*@dev",
|
||||
"maximebf/debugbar": ">=1.0.0",
|
||||
"gregwar/image": "~2.0",
|
||||
"ircmaxell/password-compat": "1.0.*",
|
||||
"mrclay/minify": "dev-master",
|
||||
|
|
|
|||
|
|
@ -22,13 +22,12 @@ if (!ini_get('date.timezone')) {
|
|||
|
||||
$grav = Grav::instance(
|
||||
array(
|
||||
'loader' => $loader,
|
||||
'debugger' => new Debugger(Debugger::PRODUCTION)
|
||||
'loader' => $loader
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$grav['debugger']->init();
|
||||
$grav['debugger'];
|
||||
$grav->process();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ class Assets
|
|||
}
|
||||
|
||||
if( !array_key_exists($asset, $this->css)) {
|
||||
$this->css[$asset] = ['asset'=>$asset, 'priority'=>$priority, 'pipeline'=>$pipeline];
|
||||
$this->css[$asset] = ['asset'=>$asset, 'priority'=>$priority, 'order' => count($this->css), 'pipeline'=>$pipeline];
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
@ -300,7 +300,8 @@ class Assets
|
|||
}
|
||||
|
||||
if( !array_key_exists($asset, $this->js)) {
|
||||
$this->js[$asset] = ['asset' => $asset, 'priority' => $priority, 'pipeline' => $pipeline];
|
||||
|
||||
$this->js[$asset] = ['asset' => $asset, 'priority' => $priority, 'order' => count($this->js), 'pipeline' => $pipeline];
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
@ -317,8 +318,15 @@ class Assets
|
|||
if( ! $this->css)
|
||||
return null;
|
||||
|
||||
if (self::$grav)
|
||||
|
||||
// Sort array by priorities (larger priority first)
|
||||
usort($this->css, function ($a, $b) {return $a['priority'] - $b['priority'];});
|
||||
usort($this->css, function ($a, $b) {
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $b['order'] - $a['order'];
|
||||
}
|
||||
return $a['priority'] - $b['priority'];
|
||||
});
|
||||
$this->css = array_reverse($this->css);
|
||||
|
||||
$attributes = $this->attributes(array_merge([ 'type' => 'text/css', 'rel' => 'stylesheet' ], $attributes));
|
||||
|
|
@ -363,7 +371,12 @@ class Assets
|
|||
return null;
|
||||
|
||||
// Sort array by priorities (larger priority first)
|
||||
usort($this->js, function ($a, $b) {return $a['priority'] - $b['priority'];});
|
||||
usort($this->js, function ($a, $b) {
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return $b['order'] - $a['order'];
|
||||
}
|
||||
return $a['priority'] - $b['priority'];
|
||||
});
|
||||
$this->js = array_reverse($this->js);
|
||||
|
||||
$attributes = $this->attributes(array_merge([ 'type' => 'text/javascript' ], $attributes));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
<?php
|
||||
namespace Grav\Common;
|
||||
|
||||
use \Tracy\Debugger as TracyDebugger;
|
||||
use DebugBar\Bridge\Twig\TraceableTwigEnvironment;
|
||||
use DebugBar\JavascriptRenderer;
|
||||
use DebugBar\StandardDebugBar;
|
||||
//use \Tracy\Debugger as TracyDebugger;
|
||||
|
||||
/**
|
||||
* Class Debugger
|
||||
|
|
@ -9,70 +12,165 @@ use \Tracy\Debugger as TracyDebugger;
|
|||
*/
|
||||
class Debugger
|
||||
{
|
||||
const PRODUCTION = TracyDebugger::PRODUCTION;
|
||||
const DEVELOPMENT = TracyDebugger::DEVELOPMENT;
|
||||
const DETECT = TracyDebugger::DETECT;
|
||||
protected $grav;
|
||||
protected $enabled = false;
|
||||
protected $timing = false;
|
||||
protected $twig = false;
|
||||
protected $debugbar;
|
||||
protected $renderer;
|
||||
|
||||
public function __construct($mode = self::PRODUCTION)
|
||||
{
|
||||
// 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.
|
||||
TracyDebugger::timer();
|
||||
TracyDebugger::enable($mode, is_dir(LOG_DIR) ? LOG_DIR : null);
|
||||
public function __construct() {
|
||||
$this->grav = Grav::instance();
|
||||
$this->debugbar = new StandardDebugBar();
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $grav['config'];
|
||||
|
||||
TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null;
|
||||
TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth');
|
||||
|
||||
// Switch debugger into development mode if configured
|
||||
$config = $this->grav['config'];
|
||||
if ($config->get('system.debugger.enabled')) {
|
||||
if ($config->get('system.debugger.strict')) {
|
||||
TracyDebugger::$strictMode = true;
|
||||
}
|
||||
|
||||
$mode = $config->get('system.debugger.mode');
|
||||
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('display_errors', !($mode === 'production'));
|
||||
}
|
||||
|
||||
if ($mode === 'detect') {
|
||||
TracyDebugger::$productionMode = self::DETECT;
|
||||
} elseif ($mode === 'production') {
|
||||
TracyDebugger::$productionMode = self::PRODUCTION;
|
||||
} else {
|
||||
TracyDebugger::$productionMode = self::DEVELOPMENT;
|
||||
}
|
||||
|
||||
$this->enabled = true;
|
||||
$this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$config->get('system')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function log($message)
|
||||
{
|
||||
if (TracyDebugger::$logDirectory) {
|
||||
TracyDebugger::log(sprintf($message, TracyDebugger::timer() * 1000));
|
||||
if ($config->get('system.debugger.timing')) {
|
||||
$this->timing = true;
|
||||
}
|
||||
if ($config->get('system.debugger.twig')) {
|
||||
$this->twig = true;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function dump($var)
|
||||
public function addAssets()
|
||||
{
|
||||
TracyDebugger::dump($var);
|
||||
if ($this->enabled) {
|
||||
|
||||
$assets = $this->grav['assets'];
|
||||
|
||||
$this->renderer = $this->debugbar->getJavascriptRenderer();
|
||||
$this->renderer->setIncludeVendors(false);
|
||||
|
||||
// Get the required CSS files
|
||||
list($css_files, $js_files) = $this->renderer->getAssets(null, JavascriptRenderer::RELATIVE_URL);
|
||||
foreach ($css_files as $css) {
|
||||
$assets->addCss($css);
|
||||
}
|
||||
|
||||
foreach ($js_files as $js) {
|
||||
$assets->addJs($js);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function barDump($var, $title = NULL, array $options = NULL)
|
||||
public function addCollector($collector)
|
||||
{
|
||||
TracyDebugger::barDump($var, $title, $options);
|
||||
$this->debugbar->addCollector($collector);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCollector($collector)
|
||||
{
|
||||
return $this->debugbar->getCollector($collector);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if ($this->enabled) {
|
||||
echo $this->renderer->render();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function startTimer($name, $desription = null)
|
||||
{
|
||||
if ($this->enabled || $name == 'config' || $name == 'debugger') {
|
||||
$this->debugbar['time']->startMeasure($name, $desription);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stopTimer($name)
|
||||
{
|
||||
if ($this->enabled || $name == 'config' || $name == 'debugger') {
|
||||
$this->debugbar['time']->stopMeasure($name);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function addMessage($message)
|
||||
{
|
||||
if ($this->enabled) {
|
||||
$this->debugbar['messages']->addMessage($message);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
// const PRODUCTION = TracyDebugger::PRODUCTION;
|
||||
// const DEVELOPMENT = TracyDebugger::DEVELOPMENT;
|
||||
// const DETECT = TracyDebugger::DETECT;
|
||||
|
||||
// public function __construct($mode = self::PRODUCTION)
|
||||
// {
|
||||
// // 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.
|
||||
//// TracyDebugger::timer();
|
||||
//// TracyDebugger::enable($mode, is_dir(LOG_DIR) ? LOG_DIR : null);
|
||||
// }
|
||||
//
|
||||
// public function init()
|
||||
// {
|
||||
//
|
||||
//
|
||||
// /** @var Config $config */
|
||||
// $config = $grav['config'];
|
||||
//
|
||||
// TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null;
|
||||
// TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth');
|
||||
//
|
||||
// // Switch debugger into development mode if configured
|
||||
// if ($config->get('system.debugger.enabled')) {
|
||||
// if ($config->get('system.debugger.strict')) {
|
||||
// TracyDebugger::$strictMode = true;
|
||||
// }
|
||||
//
|
||||
// $mode = $config->get('system.debugger.mode');
|
||||
//
|
||||
// if (function_exists('ini_set')) {
|
||||
// ini_set('display_errors', !($mode === 'production'));
|
||||
// }
|
||||
//
|
||||
// if ($mode === 'detect') {
|
||||
// TracyDebugger::$productionMode = self::DETECT;
|
||||
// } elseif ($mode === 'production') {
|
||||
// TracyDebugger::$productionMode = self::PRODUCTION;
|
||||
// } else {
|
||||
// TracyDebugger::$productionMode = self::DEVELOPMENT;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Log a message.
|
||||
// *
|
||||
// * @param string $message
|
||||
// */
|
||||
// public function log($message)
|
||||
// {
|
||||
// if (TracyDebugger::$logDirectory) {
|
||||
// TracyDebugger::log(sprintf($message, TracyDebugger::timer() * 1000));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static function dump($var)
|
||||
// {
|
||||
// TracyDebugger::dump($var);
|
||||
// }
|
||||
//
|
||||
// public static function barDump($var, $title = NULL, array $options = NULL)
|
||||
// {
|
||||
// TracyDebugger::barDump($var, $title, $options);
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ use Grav\Common\Page\Medium;
|
|||
* @author Andy Miller
|
||||
* @link http://www.rockettheme.com
|
||||
* @license http://opensource.org/licenses/MIT
|
||||
* @version 0.8.0
|
||||
*
|
||||
* Originally based on Pico by Gilbert Pellegrom - http://pico.dev7studios.com
|
||||
* Influenced by Pico, Stacey, Kirby, PieCrust and other great platforms...
|
||||
*/
|
||||
class Grav extends Container
|
||||
|
|
@ -55,6 +53,10 @@ class Grav extends Container
|
|||
|
||||
$container['grav'] = $container;
|
||||
|
||||
$container['debugger'] = function ($c) {
|
||||
return new Debugger($c);
|
||||
};
|
||||
|
||||
$container['uri'] = function ($c) {
|
||||
return new Uri($c);
|
||||
};
|
||||
|
|
@ -147,15 +149,23 @@ class Grav extends Container
|
|||
ob_start();
|
||||
|
||||
// Initialize configuration.
|
||||
$this['debugger']->startTimer('config', 'Configuration');
|
||||
$this['config']->init();
|
||||
$this['debugger']->stopTimer('config');
|
||||
|
||||
$this['debugger']->startTimer('debugger', 'Debugger');
|
||||
$this['debugger']->init();
|
||||
$this['debugger']->stopTimer('debugger');
|
||||
|
||||
$this['debugger']->startTimer('plugins', 'Plugins');
|
||||
$this['plugins']->init();
|
||||
|
||||
$this->fireEvent('onPluginsInitialized');
|
||||
$this['debugger']->stopTimer('plugins');
|
||||
|
||||
$this['debugger']->startTimer('themes', 'Themes');
|
||||
$this['themes']->init();
|
||||
|
||||
$this->fireEvent('onThemeInitialized');
|
||||
$this['debugger']->stopTimer('themes');
|
||||
|
||||
$task = $this['task'];
|
||||
if ($task) {
|
||||
|
|
@ -163,28 +173,36 @@ class Grav extends Container
|
|||
}
|
||||
|
||||
$this['assets']->init();
|
||||
|
||||
$this['debugger']->addAssets();
|
||||
$this->fireEvent('onAssetsInitialized');
|
||||
|
||||
$this['debugger']->startTimer('twig', 'Twig');
|
||||
$this['twig']->init();
|
||||
$this['pages']->init();
|
||||
$this['debugger']->stopTimer('twig');
|
||||
|
||||
$this['debugger']->startTimer('pages', 'Pages');
|
||||
$this['pages']->init();
|
||||
$this->fireEvent('onPagesInitialized');
|
||||
$this['debugger']->stopTimer('pages');
|
||||
|
||||
$this->fireEvent('onPageInitialized');
|
||||
|
||||
// Process whole page as required
|
||||
$this->output = $this['output'];
|
||||
|
||||
|
||||
// Process whole page as required
|
||||
$this['debugger']->startTimer('render', 'Render');
|
||||
$this->output = $this['output'];
|
||||
$this->fireEvent('onOutputGenerated');
|
||||
$this['debugger']->stopTimer('render');
|
||||
|
||||
// Set the header type
|
||||
$this->header();
|
||||
|
||||
echo $this->output;
|
||||
$this['debugger']->render();
|
||||
|
||||
$this->fireEvent('onOutputRendered');
|
||||
|
||||
|
||||
register_shutdown_function([$this, 'shutdown']);
|
||||
}
|
||||
|
||||
|
|
@ -235,9 +253,7 @@ class Grav extends Container
|
|||
*/
|
||||
public function header()
|
||||
{
|
||||
/** @var Uri $uri */
|
||||
$uri = $this['uri'];
|
||||
header('Content-type: ' . $this->mime($uri->extension()));
|
||||
header('Content-type: ' . $this->mime($this['uri']->extension()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user