1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-07-28 04:00:43 +02:00

Merge pull request #55 from GuimDev/master

Add register_shutdown function is most accurate (and support Twig)
This commit is contained in:
Maxime Bouroumeau-Fuseau
2013-12-26 05:58:04 -08:00
2 changed files with 41 additions and 2 deletions

View File

@@ -416,12 +416,14 @@ class DebugBar implements ArrayAccess
/**
* Returns a JavascriptRenderer for this instance
*
* @param stri $baseUrl
* @param string $basePathng
* @return JavascriptRenderer
*/
public function getJavascriptRenderer()
public function getJavascriptRenderer($baseUrl = null, $basePath = null)
{
if ($this->jsRenderer === null) {
$this->jsRenderer = new JavascriptRenderer($this);
$this->jsRenderer = new JavascriptRenderer($this, $baseUrl, $basePath);
}
return $this->jsRenderer;
}

View File

@@ -23,6 +23,8 @@ class JavascriptRenderer
const INITIALIZE_CONTROLS = 4;
const REPLACEABLE_TAG = "{--DEBUGBAR_OB_START_REPLACE_ME--}";
protected $debugBar;
protected $baseUrl;
@@ -644,6 +646,41 @@ class JavascriptRenderer
return rtrim($root, '/') . "/$uri";
}
/**
* Register shutdown to display the debug bar
*
* @param boolean $here Set position of HTML. True if is to current position or false for end file
* @param boolean $initialize Whether to render the de bug bar initialization code
* @return string Return "{--DEBUGBAR_OB_START_REPLACE_ME--}" or return an empty string if $here == false
*/
public function renderOnShutdown($here = true, $initialize = true, $renderStackedData = true) {
register_shutdown_function(array($this, "replaceTagInBuffer"), $here, $initialize, $renderStackedData);
if (ob_get_level() === 0) {
ob_start();
}
return ($here) ? self::REPLACEABLE_TAG : "";
}
/**
* Is callback function for register_shutdown_function(...)
*
* @param boolean $here Set position of HTML. True if is to current position or false for end file
* @param boolean $initialize Whether to render the de bug bar initialization code
*/
public function replaceTagInBuffer($here = true, $initialize = true, $renderStackedData = true) {
$render = $this->render($initialize, $renderStackedData);
$current = ($here && ob_get_level() > 0) ? ob_get_clean() : self::REPLACEABLE_TAG;
echo str_replace(self::REPLACEABLE_TAG, $render, $current, $count);
if ($count === 0) {
echo $render;
}
}
/**
* Returns the code needed to display the debug bar
*