mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-05 04:04:10 +02:00
- convert debug console processing to object
This commit is contained in:
@@ -21,28 +21,32 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $template_data = array();
|
||||
public $template_data = array();
|
||||
|
||||
/**
|
||||
* List of uid's which shall be ignored
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $ignore_uid = array();
|
||||
public $ignore_uid = array();
|
||||
|
||||
/**
|
||||
* Index of display() and fetch() calls
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $index = 0;
|
||||
public $index = 0;
|
||||
|
||||
/**
|
||||
* Counter for window offset
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $offset = 0;
|
||||
public $offset = 0;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging template
|
||||
@@ -50,15 +54,15 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
* @param \Smarty_Internal_Template $template template
|
||||
* @param null $mode true: display false: fetch null: subtemolate
|
||||
*/
|
||||
public static function start_template(Smarty_Internal_Template $template, $mode = null)
|
||||
public function start_template(Smarty_Internal_Template $template, $mode = null)
|
||||
{
|
||||
if (isset($mode)) {
|
||||
self::$index ++;
|
||||
self::$offset ++;
|
||||
self::$template_data[self::$index] = null;
|
||||
$this->index ++;
|
||||
$this->offset ++;
|
||||
$this->template_data[$this->index] = null;
|
||||
}
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[self::$index][$key]['start_template_time'] = microtime(true);
|
||||
$key = $this->get_key($template);
|
||||
$this->template_data[$this->index][$key]['start_template_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,11 +70,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template cached template
|
||||
*/
|
||||
public static function end_template(Smarty_Internal_Template $template)
|
||||
public function end_template(Smarty_Internal_Template $template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[self::$index][$key]['total_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_template_time'];
|
||||
//self::$template_data[self::$index][$key]['properties'] = $template->properties;
|
||||
$key = $this->get_key($template);
|
||||
$this->template_data[$this->index][$key]['total_time'] += microtime(true) - $this->template_data[$this->index][$key]['start_template_time'];
|
||||
//$this->template_data[$this->index][$key]['properties'] = $template->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,28 +82,28 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*/
|
||||
public static function start_compile(Smarty_Internal_Template $template)
|
||||
public function start_compile(Smarty_Internal_Template $template)
|
||||
{
|
||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||
if (!empty($template->compiler->trace_uid)) {
|
||||
$key = $template->compiler->trace_uid;
|
||||
if (!isset(self::$template_data[self::$index][$key])) {
|
||||
if (!isset($this->template_data[$this->index][$key])) {
|
||||
if (isset($_is_stringy[$template->source->type])) {
|
||||
self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
|
||||
$this->template_data[$this->index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
|
||||
} else {
|
||||
self::$template_data[self::$index][$key]['name'] = $template->source->filepath;
|
||||
$this->template_data[$this->index][$key]['name'] = $template->source->filepath;
|
||||
}
|
||||
self::$template_data[self::$index][$key]['compile_time'] = 0;
|
||||
self::$template_data[self::$index][$key]['render_time'] = 0;
|
||||
self::$template_data[self::$index][$key]['cache_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['compile_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['render_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['cache_time'] = 0;
|
||||
}
|
||||
} else {
|
||||
if (isset(self::$ignore_uid[$template->source->uid])) {
|
||||
if (isset($this->ignore_uid[$template->source->uid])) {
|
||||
return;
|
||||
}
|
||||
$key = self::get_key($template);
|
||||
$key = $this->get_key($template);
|
||||
}
|
||||
self::$template_data[self::$index][$key]['start_time'] = microtime(true);
|
||||
$this->template_data[$this->index][$key]['start_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,18 +111,18 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*/
|
||||
public static function end_compile(Smarty_Internal_Template $template)
|
||||
public function end_compile(Smarty_Internal_Template $template)
|
||||
{
|
||||
if (!empty($template->compiler->trace_uid)) {
|
||||
$key = $template->compiler->trace_uid;
|
||||
} else {
|
||||
if (isset(self::$ignore_uid[$template->source->uid])) {
|
||||
if (isset($this->ignore_uid[$template->source->uid])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$key = self::get_key($template);
|
||||
$key = $this->get_key($template);
|
||||
}
|
||||
self::$template_data[self::$index][$key]['compile_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time'];
|
||||
$this->template_data[$this->index][$key]['compile_time'] += microtime(true) - $this->template_data[$this->index][$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +130,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*/
|
||||
public static function start_render(Smarty_Internal_Template $template)
|
||||
public function start_render(Smarty_Internal_Template $template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[self::$index][$key]['start_time'] = microtime(true);
|
||||
$key = $this->get_key($template);
|
||||
$this->template_data[$this->index][$key]['start_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,10 +141,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*/
|
||||
public static function end_render(Smarty_Internal_Template $template)
|
||||
public function end_render(Smarty_Internal_Template $template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[self::$index][$key]['render_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time'];
|
||||
$key = $this->get_key($template);
|
||||
$this->template_data[$this->index][$key]['render_time'] += microtime(true) - $this->template_data[$this->index][$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,10 +152,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template cached template
|
||||
*/
|
||||
public static function start_cache(Smarty_Internal_Template $template)
|
||||
public function start_cache(Smarty_Internal_Template $template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[self::$index][$key]['start_time'] = microtime(true);
|
||||
$key = $this->get_key($template);
|
||||
$this->template_data[$this->index][$key]['start_time'] = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,10 +163,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template cached template
|
||||
*/
|
||||
public static function end_cache(Smarty_Internal_Template $template)
|
||||
public function end_cache(Smarty_Internal_Template $template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[self::$index][$key]['cache_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time'];
|
||||
$key = $this->get_key($template);
|
||||
$this->template_data[$this->index][$key]['cache_time'] += microtime(true) - $this->template_data[$this->index][$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +174,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template cached template
|
||||
*/
|
||||
public static function register_template(Smarty_Internal_Template $template)
|
||||
public function register_template(Smarty_Internal_Template $template)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -189,12 +193,12 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
* @param Smarty_Internal_Template|Smarty $obj object to debug
|
||||
* @param bool $full
|
||||
*/
|
||||
public static function display_debug($obj, $full = false)
|
||||
public function display_debug($obj, $full = false)
|
||||
{
|
||||
if (!$full) {
|
||||
self::$offset ++;
|
||||
$savedIndex = self::$index;
|
||||
self::$index = 9999;
|
||||
$this->offset ++;
|
||||
$savedIndex = $this->index;
|
||||
$this->index = 9999;
|
||||
}
|
||||
if ($obj instanceof Smarty) {
|
||||
$smarty = $obj;
|
||||
@@ -227,7 +231,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
$debObj->compile_id = null;
|
||||
$debObj->cache_id = null;
|
||||
// prepare information of assigned variables
|
||||
$ptr = self::get_debug_vars($obj);
|
||||
$ptr = $this->get_debug_vars($obj);
|
||||
$_assigned_vars = $ptr->tpl_vars;
|
||||
ksort($_assigned_vars);
|
||||
$_config_vars = $ptr->config_vars;
|
||||
@@ -239,7 +243,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
|
||||
}
|
||||
if ($obj instanceof Smarty || $full) {
|
||||
$_template->assign('template_data', self::$template_data[self::$index]);
|
||||
$_template->assign('template_data', $this->template_data[$this->index]);
|
||||
} else {
|
||||
$_template->assign('template_data', null);
|
||||
}
|
||||
@@ -247,13 +251,13 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
$_template->assign('config_vars', $_config_vars);
|
||||
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
|
||||
$_template->assign('display_mode', $debugging == 2 || !$full);
|
||||
$_template->assign('offset', self::$offset * 50);
|
||||
$_template->assign('offset', $this->offset * 50);
|
||||
echo $_template->fetch();
|
||||
if (isset($full)) {
|
||||
self::$index --;
|
||||
$this->index --;
|
||||
}
|
||||
if (!$full) {
|
||||
self::$index = $savedIndex;
|
||||
$this->index = $savedIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +268,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @return StdClass
|
||||
*/
|
||||
public static function get_debug_vars($obj)
|
||||
public function get_debug_vars($obj)
|
||||
{
|
||||
$config_vars = array();
|
||||
foreach ($obj->config_vars as $key => $var) {
|
||||
@@ -304,7 +308,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
}
|
||||
|
||||
if (isset($obj->parent)) {
|
||||
$parent = self::get_debug_vars($obj->parent);
|
||||
$parent = $this->get_debug_vars($obj->parent);
|
||||
foreach ($parent->tpl_vars as $name => $pvar) {
|
||||
if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) {
|
||||
$tpl_vars[$name]['scope'] = $pvar['scope'];
|
||||
@@ -351,7 +355,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @return string key into $template_data
|
||||
*/
|
||||
private static function get_key(Smarty_Internal_Template $template)
|
||||
private function get_key(Smarty_Internal_Template $template)
|
||||
{
|
||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||
// calculate Uid if not already done
|
||||
@@ -359,18 +363,18 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
$template->source->filepath;
|
||||
}
|
||||
$key = $template->source->uid;
|
||||
if (isset(self::$template_data[self::$index][$key])) {
|
||||
if (isset($this->template_data[$this->index][$key])) {
|
||||
return $key;
|
||||
} else {
|
||||
if (isset($_is_stringy[$template->source->type])) {
|
||||
self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
|
||||
$this->template_data[$this->index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
|
||||
} else {
|
||||
self::$template_data[self::$index][$key]['name'] = $template->source->filepath;
|
||||
$this->template_data[$this->index][$key]['name'] = $template->source->filepath;
|
||||
}
|
||||
self::$template_data[self::$index][$key]['compile_time'] = 0;
|
||||
self::$template_data[self::$index][$key]['render_time'] = 0;
|
||||
self::$template_data[self::$index][$key]['cache_time'] = 0;
|
||||
self::$template_data[self::$index][$key]['total_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['compile_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['render_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['cache_time'] = 0;
|
||||
$this->template_data[$this->index][$key]['total_time'] = 0;
|
||||
|
||||
return $key;
|
||||
}
|
||||
@@ -381,13 +385,13 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*/
|
||||
public static function ignore(Smarty_Internal_Template $template)
|
||||
public function ignore(Smarty_Internal_Template $template)
|
||||
{
|
||||
// calculate Uid if not already done
|
||||
if ($template->source->uid == '') {
|
||||
$template->source->filepath;
|
||||
}
|
||||
self::$ignore_uid[$template->source->uid] = true;
|
||||
$this->ignore_uid[$template->source->uid] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,7 +399,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*/
|
||||
public static function debugUrl(Smarty_Internal_Template $_template)
|
||||
public function debugUrl(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (isset($_SERVER['QUERY_STRING'])) {
|
||||
$_query_string = $_SERVER['QUERY_STRING'];
|
||||
|
||||
Reference in New Issue
Block a user