2015-08-23 22:38:18 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty plugin
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Debug
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smarty debug_print_var modifier plugin
|
|
|
|
* Type: modifier<br>
|
|
|
|
* Name: debug_print_var<br>
|
|
|
|
* Purpose: formats variable contents for display in the console
|
|
|
|
*
|
|
|
|
* @author Monte Ohrt <monte at ohrt dot com>
|
|
|
|
*
|
2016-01-12 02:47:38 +01:00
|
|
|
* @param array|object $var variable to be formatted
|
|
|
|
* @param int $max maximum recursion depth if $var is an array or object
|
|
|
|
* @param int $length maximum string length if $var is a string
|
|
|
|
* @param int $depth actual recursion depth
|
|
|
|
* @param array $objects processed objects in actual depth to prevent recursive object processing
|
2015-08-23 22:38:18 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-01-12 02:47:38 +01:00
|
|
|
function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array())
|
2015-08-23 22:38:18 +02:00
|
|
|
{
|
2016-01-12 02:47:38 +01:00
|
|
|
$_replace = array("\n" => '\n',
|
|
|
|
"\r" => '\r',
|
|
|
|
"\t" => '\t'
|
2015-08-23 22:38:18 +02:00
|
|
|
);
|
|
|
|
switch (gettype($var)) {
|
|
|
|
case 'array' :
|
|
|
|
$results = '<b>Array (' . count($var) . ')</b>';
|
2016-01-12 02:47:38 +01:00
|
|
|
if ($depth == $max) {
|
|
|
|
break;
|
|
|
|
}
|
2015-08-23 22:38:18 +02:00
|
|
|
foreach ($var as $curr_key => $curr_val) {
|
|
|
|
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
|
|
|
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
2016-01-12 02:47:38 +01:00
|
|
|
. smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
|
2015-08-23 22:38:18 +02:00
|
|
|
$depth --;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'object' :
|
|
|
|
$object_vars = get_object_vars($var);
|
|
|
|
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
|
2016-01-12 02:47:38 +01:00
|
|
|
if (in_array($var, $objects)) {
|
|
|
|
$results .= ' called recursive';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($depth == $max) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$objects[] = $var;
|
2015-08-23 22:38:18 +02:00
|
|
|
foreach ($object_vars as $curr_key => $curr_val) {
|
|
|
|
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
|
|
|
. '<b> ->' . strtr($curr_key, $_replace) . '</b> = '
|
2016-01-12 02:47:38 +01:00
|
|
|
. smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
|
2015-08-23 22:38:18 +02:00
|
|
|
$depth --;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'boolean' :
|
|
|
|
case 'NULL' :
|
|
|
|
case 'resource' :
|
|
|
|
if (true === $var) {
|
|
|
|
$results = 'true';
|
|
|
|
} elseif (false === $var) {
|
|
|
|
$results = 'false';
|
|
|
|
} elseif (null === $var) {
|
|
|
|
$results = 'null';
|
|
|
|
} else {
|
|
|
|
$results = htmlspecialchars((string) $var);
|
|
|
|
}
|
|
|
|
$results = '<i>' . $results . '</i>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'integer' :
|
|
|
|
case 'float' :
|
|
|
|
$results = htmlspecialchars((string) $var);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'string' :
|
|
|
|
$results = strtr($var, $_replace);
|
|
|
|
if (Smarty::$_MBSTRING) {
|
|
|
|
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
|
|
|
|
$results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($var[$length])) {
|
|
|
|
$results = substr($var, 0, $length - 3) . '...';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = htmlspecialchars('"' . $results . '"');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unknown type' :
|
|
|
|
default :
|
|
|
|
$results = strtr((string) $var, $_replace);
|
|
|
|
if (Smarty::$_MBSTRING) {
|
|
|
|
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
|
|
|
|
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strlen($results) > $length) {
|
|
|
|
$results = substr($results, 0, $length - 3) . '...';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = htmlspecialchars($results);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|