cvs: smarty / NEWS /libs/plugins modifier.debug_print_var.php

[email protected] ("boots") Tue, 07 Nov 2006 20:32:56 -0000
Newsgroups php.smarty.cvs
Message-ID <cvsboots1162931576@cvsserver>
boots		Tue Nov  7 20:32:56 2006 UTC

  Modified files:              
    /smarty	NEWS 
    /smarty/libs/plugins	modifier.debug_print_var.php 
  Log:
  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
  
http://cvs.php.net/viewvc.cgi/smarty/NEWS?r1=1.540&r2=1.541&diff_format=u
Index: smarty/NEWS
diff -u smarty/NEWS:1.540 smarty/NEWS:1.541
--- smarty/NEWS:1.540	Wed Nov  1 20:35:07 2006
+++ smarty/NEWS	Tue Nov  7 20:32:56 2006
@@ -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
   0000-00-00 inputs (cybot, boots)
 - fix wrong handling of insert's name attribute. (messju)
http://cvs.php.net/viewvc.cgi/smarty/libs/plugins/modifier.debug_print_var.php?r1=1.12&r2=1.13&diff_format=u
Index: smarty/libs/plugins/modifier.debug_print_var.php
diff -u smarty/libs/plugins/modifier.debug_print_var.php:1.12 smarty/libs/plugins/modifier.debug_print_var.php:1.13
--- smarty/libs/plugins/modifier.debug_print_var.php:1.12	Tue Oct 11 16:22:56 2005
+++ smarty/libs/plugins/modifier.debug_print_var.php	Tue Nov  7 20:32:56 2006
@@ -22,33 +22,64 @@
  */
 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>');
-    if (is_array($var)) {
-        $results = "<b>Array (".count($var).")</b>";
-        foreach ($var as $curr_key => $curr_val) {
-            $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";
-        }
-    } else if (is_object($var)) {
-        $object_vars = get_object_vars($var);
-        $results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
-        foreach ($object_vars as $curr_key => $curr_val) {
-            $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
-            $results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
-        }
-    } else if (is_resource($var)) {
-        $results = '<i>'.(string)$var.'</i>';
-    } else if (empty($var) && $var != "0") {
-        $results = '<i>empty</i>';
-    } else {
-        if (strlen($var) > $length ) {
-            $results = substr($var, 0, $length-3).'...';
-        } else {
-            $results = $var;
-        }
-        $results = htmlspecialchars($results);
-        $results = strtr($results, $_replace);
+    $_replace = array(
+        "\n" => '<i>\n</i>',
+        "\r" => '<i>\r</i>',
+        "\t" => '<i>\t</i>'
+    );
+
+    switch (gettype($var)) {
+        case 'array' :
+            $results = '<b>Array (' . count($var) . ')</b>';
+            foreach ($var as $curr_key => $curr_val) {
+                $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
+                    . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
+                    . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
+            }
+            break;
+        case 'object' :
+            $object_vars = get_object_vars($var);
+            $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
+            foreach ($object_vars as $curr_key => $curr_val) {
+                $results .= '<br>' . str_repeat('&nbsp;', $depth * 2)
+                    . '<b>' . strtr($curr_key, $_replace) . '</b> =&gt; '
+                    . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
+            }
+            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 (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;
 }