PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/Debug.php

https://bitbucket.org/ksekar/campus
PHP | 108 lines | 41 code | 11 blank | 56 comment | 6 complexity | 791382b936557f4be3a8cdcea715cb92 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Debug
  17. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Debug.php 24594 2012-01-05 21:27:01Z matthew $
  20. */
  21. /**
  22. * Concrete class for generating debug dumps related to the output source.
  23. *
  24. * @category Zend
  25. * @package Zend_Debug
  26. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Debug
  30. {
  31. /**
  32. * @var string
  33. */
  34. protected static $_sapi = null;
  35. /**
  36. * Get the current value of the debug output environment.
  37. * This defaults to the value of PHP_SAPI.
  38. *
  39. * @return string;
  40. */
  41. public static function getSapi()
  42. {
  43. if (self::$_sapi === null) {
  44. self::$_sapi = PHP_SAPI;
  45. }
  46. return self::$_sapi;
  47. }
  48. /**
  49. * Set the debug ouput environment.
  50. * Setting a value of null causes Zend_Debug to use PHP_SAPI.
  51. *
  52. * @param string $sapi
  53. * @return void;
  54. */
  55. public static function setSapi($sapi)
  56. {
  57. self::$_sapi = $sapi;
  58. }
  59. /**
  60. * Debug helper function. This is a wrapper for var_dump() that adds
  61. * the <pre /> tags, cleans up newlines and indents, and runs
  62. * htmlentities() before output.
  63. *
  64. * @param mixed $var The variable to dump.
  65. * @param string $label OPTIONAL Label to prepend to output.
  66. * @param bool $echo OPTIONAL Echo output if true.
  67. * @return string
  68. */
  69. public static function dump($var, $label=null, $echo=true)
  70. {
  71. // format the label
  72. $label = ($label===null) ? '' : rtrim($label) . ' ';
  73. // var_dump the variable into a buffer and keep the output
  74. ob_start();
  75. var_dump($var);
  76. $output = ob_get_clean();
  77. // neaten the newlines and indents
  78. $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
  79. if (self::getSapi() == 'cli') {
  80. $output = PHP_EOL . $label
  81. . PHP_EOL . $output
  82. . PHP_EOL;
  83. } else {
  84. if(!extension_loaded('xdebug')) {
  85. $output = htmlspecialchars($output, ENT_QUOTES);
  86. }
  87. $output = '<pre>'
  88. . $label
  89. . $output
  90. . '</pre>';
  91. }
  92. if ($echo) {
  93. echo($output);
  94. }
  95. return $output;
  96. }
  97. }