PageRenderTime 21ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty2/lib/plugins/modifier.debug_print_var.php

http://zoop.googlecode.com/
PHP | 57 lines | 33 code | 4 blank | 20 comment | 12 complexity | 08316533750e1d7b0e9c801f99fb5e1f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty debug_print_var modifier plugin
  9. *
  10. * Type: modifier<br>
  11. * Name: debug_print_var<br>
  12. * Purpose: formats variable contents for display in the console
  13. * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
  14. * debug_print_var (Smarty online manual)
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. * @param array|object
  17. * @param integer
  18. * @param integer
  19. * @return string
  20. */
  21. function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
  22. {
  23. $_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>');
  24. if (is_array($var)) {
  25. $results = "<b>Array (".count($var).")</b>";
  26. foreach ($var as $curr_key => $curr_val) {
  27. $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
  28. $results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> =&gt; $return";
  29. }
  30. } else if (is_object($var)) {
  31. $object_vars = get_object_vars($var);
  32. $results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
  33. foreach ($object_vars as $curr_key => $curr_val) {
  34. $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
  35. $results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
  36. }
  37. } else if (is_resource($var)) {
  38. $results = '<i>'.(string)$var.'</i>';
  39. } else if (empty($var) && $var != "0") {
  40. $results = '<i>empty</i>';
  41. } else {
  42. if (strlen($var) > $length ) {
  43. $results = substr($var, 0, $length-3).'...';
  44. } else {
  45. $results = $var;
  46. }
  47. $results = htmlspecialchars($results);
  48. $results = strtr($results, $_replace);
  49. }
  50. return $results;
  51. }
  52. /* vim: set expandtab: */
  53. ?>