enhance reporting precision of debug_print_var modifier

see: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=9281

thanks to cybot from the forums
This commit is contained in:
boots
2006-11-07 20:32:56 +00:00
parent 164bd76107
commit 35640e573f
2 changed files with 58 additions and 26 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- enhance reporting precision of debug_print_var modifier (cybot, boots)
- make html_select_date work consistently with 0000-00-00 00:00:00 and - make html_select_date work consistently with 0000-00-00 00:00:00 and
0000-00-00 inputs (cybot, boots) 0000-00-00 inputs (cybot, boots)
- fix wrong handling of insert's name attribute. (messju) - fix wrong handling of insert's name attribute. (messju)

View File

@@ -22,33 +22,64 @@
*/ */
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{ {
$_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>'); $_replace = array(
if (is_array($var)) { "\n" => '<i>\n</i>',
$results = "<b>Array (".count($var).")</b>"; "\r" => '<i>\r</i>',
foreach ($var as $curr_key => $curr_val) { "\t" => '<i>\t</i>'
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length); );
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> =&gt; $return";
} switch (gettype($var)) {
} else if (is_object($var)) { case 'array' :
$object_vars = get_object_vars($var); $results = '<b>Array (' . count($var) . ')</b>';
$results = "<b>".get_class($var)." Object (".count($object_vars).")</b>"; foreach ($var as $curr_key => $curr_val) {
foreach ($object_vars as $curr_key => $curr_val) { $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length); . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return"; . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
} }
} else if (is_resource($var)) { break;
$results = '<i>'.(string)$var.'</i>'; case 'object' :
} else if (empty($var) && $var != "0") { $object_vars = get_object_vars($var);
$results = '<i>empty</i>'; $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
} else { foreach ($object_vars as $curr_key => $curr_val) {
if (strlen($var) > $length ) { $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
$results = substr($var, 0, $length-3).'...'; . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
} else { . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
$results = $var; }
} break;
$results = htmlspecialchars($results); case 'boolean' :
$results = strtr($results, $_replace); 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 (strlen($var) > $length ) {
$results = substr($var, 0, $length - 3) . '...';
}
$results = htmlspecialchars('"' . $results . '"');
break;
case 'unknown type' :
default :
$results = strtr((string) $var, $_replace);
if (strlen($results) > $length ) {
$results = substr($results, 0, $length - 3) . '...';
}
$results = htmlspecialchars($results);
} }
return $results; return $results;
} }