[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Debug.php
blobe079f31b805215e3d0409848a2c9f1656d43551b
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Debug
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id$
22 /**
23 * Concrete class for generating debug dumps related to the output source.
25 * @category Zend
26 * @package Zend_Debug
27 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
28 * @license http://framework.zend.com/license/new-bsd New BSD License
31 class Zend_Debug
34 /**
35 * @var string
37 protected static $_sapi = null;
39 /**
40 * Get the current value of the debug output environment.
41 * This defaults to the value of PHP_SAPI.
43 * @return string;
45 public static function getSapi()
47 if (self::$_sapi === null) {
48 self::$_sapi = PHP_SAPI;
50 return self::$_sapi;
53 /**
54 * Set the debug ouput environment.
55 * Setting a value of null causes Zend_Debug to use PHP_SAPI.
57 * @param string $sapi
58 * @return void;
60 public static function setSapi($sapi)
62 self::$_sapi = $sapi;
65 /**
66 * Debug helper function. This is a wrapper for var_dump() that adds
67 * the <pre /> tags, cleans up newlines and indents, and runs
68 * htmlentities() before output.
70 * @param mixed $var The variable to dump.
71 * @param string $label OPTIONAL Label to prepend to output.
72 * @param bool $echo OPTIONAL Echo output if true.
73 * @return string
75 public static function dump($var, $label=null, $echo=true)
77 // format the label
78 $label = ($label===null) ? '' : rtrim($label) . ' ';
80 // var_dump the variable into a buffer and keep the output
81 ob_start();
82 var_dump($var);
83 $output = ob_get_clean();
85 // neaten the newlines and indents
86 $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
87 if (self::getSapi() == 'cli') {
88 $output = PHP_EOL . $label
89 . PHP_EOL . $output
90 . PHP_EOL;
91 } else {
92 if(!extension_loaded('xdebug')) {
93 $output = htmlspecialchars($output, ENT_QUOTES);
96 $output = '<pre>'
97 . $label
98 . $output
99 . '</pre>';
102 if ($echo) {
103 echo($output);
105 return $output;