Qse_XDebug--FirefoxのPHPデバッグコンソール


と書く
/**
*FirefoxのPHPデバッグコンソール、firephp要求FF 3.5+PHP 5のみ使用可能
*面倒ですが、ここでは自分で似たような機能を実現しています
*firebugログ情報:http://getfirebug.com/logging
*/
 
class Qse_XDebug {
	
	private $met_out = array(
		'log' => 'log' ,
		'debug' => 'debug' ,
		'info' => 'info' ,
		'warn' => 'warn' ,
		'error' => 'error' ,
		'time' => 'time' ,
		'timeEnd' => 'timeEnd' ,
		'profile' => 'profile' ,
		'profileEnd' => 'profileEnd' ,
		'trace' => 'trace' ,
		'group' => 'group' ,
		'groupEnd' => 'groupEnd' ,
		'dir' => 'dir' ,
		'dirxml' => 'dirxml' ,
	); 
	
	protected $info_store = array();

	public function __construct(){
		$this->group(get_class($this) . "      ");
	}
	
	private function js_text($js_code=null){
		return "{$js_code}
" ; } function __call($funcname,$args){ if (!empty($funcname) && isset($this->met_out[$funcname])) { $object = array( $funcname => $args ); $this->insert_data($object); } } private function insert_data($object=null){ array_push($this->info_store,$object); } function execute($returnvalue=false){ $output = "<script>%s</script>" ; $content = '' ; foreach ($this->info_store as $info){ if (!is_array($info)) continue ; foreach ($info as $met=>$args){ $str_args = $this->parse_values($args) ; $content .= $this->js_text("console.{$met}({$str_args});"); } } if ($return_value) return sprintf($output,$content) ; echo sprintf($output,$content) ; } private function parse_values($args){ if (!is_array($args)) return '' ; $values = $val = '' ; foreach ($args as $arg){ if (is_string($arg)) $val = "'{$arg}'"; else if(is_numeric($arg)) $val = $arg ; else if(is_array($arg) || is_object($arg)){ if (function_exists('json_encode')) $val = json_encode($arg); } $values .= $val . ',' ; } return preg_replace('/,$/','',$values) ; } }

 demo:
<?php 
	$xdebug->log("hellow world!");
 $xdebug->group("   ");
 $xdebug->error("   %s ;   : %d","    ",time());
 $xdebug->warn("hellow world!",'chouzhutou',array(1,2,4,QContext::instance()));
?>

  Qse_XDebug -- Firefox 的PHP调试控制台_第1张图片