forked from getgrav/grav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with PHP Debug Bar instead of Tracy
- Loading branch information
Showing
6 changed files
with
188 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,176 @@ | ||
<?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 | ||
* @package Grav\Common | ||
*/ | ||
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']; | ||
$config = $this->grav['config']; | ||
if ($config->get('system.debugger.enabled')) { | ||
$this->enabled = true; | ||
$this->debugbar->addCollector(new \DebugBar\DataCollector\ConfigCollector((array)$config->get('system'))); | ||
} | ||
if ($config->get('system.debugger.timing')) { | ||
$this->timing = true; | ||
} | ||
if ($config->get('system.debugger.twig')) { | ||
$this->twig = true; | ||
} | ||
return $this; | ||
} | ||
|
||
TracyDebugger::$logDirectory = $config->get('system.debugger.log.enabled') ? LOG_DIR : null; | ||
TracyDebugger::$maxDepth = $config->get('system.debugger.max_depth'); | ||
public function addAssets() | ||
{ | ||
if ($this->enabled) { | ||
|
||
// Switch debugger into development mode if configured | ||
if ($config->get('system.debugger.enabled')) { | ||
if ($config->get('system.debugger.strict')) { | ||
TracyDebugger::$strictMode = true; | ||
} | ||
$assets = $this->grav['assets']; | ||
|
||
$mode = $config->get('system.debugger.mode'); | ||
$this->renderer = $this->debugbar->getJavascriptRenderer(); | ||
$this->renderer->setIncludeVendors(false); | ||
|
||
if (function_exists('ini_set')) { | ||
ini_set('display_errors', !($mode === 'production')); | ||
// 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); | ||
} | ||
|
||
if ($mode === 'detect') { | ||
TracyDebugger::$productionMode = self::DETECT; | ||
} elseif ($mode === 'production') { | ||
TracyDebugger::$productionMode = self::PRODUCTION; | ||
} else { | ||
TracyDebugger::$productionMode = self::DEVELOPMENT; | ||
foreach ($js_files as $js) { | ||
$assets->addJs($js); | ||
} | ||
} | ||
return $this; | ||
} | ||
|
||
public function addCollector($collector) | ||
{ | ||
$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; | ||
} | ||
|
||
/** | ||
* Log a message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function log($message) | ||
public function startTimer($name, $desription = null) | ||
{ | ||
if (TracyDebugger::$logDirectory) { | ||
TracyDebugger::log(sprintf($message, TracyDebugger::timer() * 1000)); | ||
if ($this->enabled || $name == 'config' || $name == 'debugger') { | ||
$this->debugbar['time']->startMeasure($name, $desription); | ||
} | ||
return $this; | ||
} | ||
|
||
public static function dump($var) | ||
public function stopTimer($name) | ||
{ | ||
TracyDebugger::dump($var); | ||
if ($this->enabled || $name == 'config' || $name == 'debugger') { | ||
$this->debugbar['time']->stopMeasure($name); | ||
} | ||
return $this; | ||
} | ||
|
||
public static function barDump($var, $title = NULL, array $options = NULL) | ||
|
||
public function addMessage($message) | ||
{ | ||
TracyDebugger::barDump($var, $title, $options); | ||
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); | ||
// } | ||
} |
Oops, something went wrong.