firephp.class.php

来自「QeePHP v2.1.2116 bulid 090120」· PHP 代码 · 共 1,376 行 · 第 1/3 页

PHP
1,376 行
字号
<?php/** * *** BEGIN LICENSE BLOCK ***** *   * This file is part of FirePHP (http://www.firephp.org/). *  * Software License Agreement (New BSD License) *  * Copyright (c) 2006-2008, Christoph Dorn * All rights reserved. *  * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: *  *     * Redistributions of source code must retain the above copyright notice, *       this list of conditions and the following disclaimer. *  *     * Redistributions in binary form must reproduce the above copyright notice, *       this list of conditions and the following disclaimer in the documentation *       and/or other materials provided with the distribution. *  *     * Neither the name of Christoph Dorn nor the names of its *       contributors may be used to endorse or promote products derived from this *       software without specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * ***** END LICENSE BLOCK ***** *  * @copyright   Copyright (C) 2007-2008 Christoph Dorn * @author      Christoph Dorn <christoph@christophdorn.com> * @license     http://www.opensource.org/licenses/bsd-license.php * @package     FirePHP */  /** * Sends the given data to the FirePHP Firefox Extension. * The data can be displayed in the Firebug Console or in the * "Server" request tab. *  * For more information see: http://www.firephp.org/ *  * @copyright   Copyright (C) 2007-2008 Christoph Dorn * @author      Christoph Dorn <christoph@christophdorn.com> * @license     http://www.opensource.org/licenses/bsd-license.php * @package     FirePHP */class FirePHP {    /**   * FirePHP version   *   * @var string   */  const VERSION = '0.2.1';    /**   * Firebug LOG level   *   * Logs a message to firebug console.   *    * @var string   */  const LOG = 'LOG';    /**   * Firebug INFO level   *   * Logs a message to firebug console and displays an info icon before the message.   *    * @var string   */  const INFO = 'INFO';    /**   * Firebug WARN level   *   * Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise.   *    * @var string   */  const WARN = 'WARN';    /**   * Firebug ERROR level   *   * Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count.   *    * @var string   */  const ERROR = 'ERROR';    /**   * Dumps a variable to firebug's server panel   *   * @var string   */  const DUMP = 'DUMP';    /**   * Displays a stack trace in firebug console   *   * @var string   */  const TRACE = 'TRACE';    /**   * Displays an exception in firebug console   *    * Increments the firebug error count.   *   * @var string   */  const EXCEPTION = 'EXCEPTION';    /**   * Displays an table in firebug console   *   * @var string   */  const TABLE = 'TABLE';    /**   * Starts a group in firebug console   *    * @var string   */  const GROUP_START = 'GROUP_START';    /**   * Ends a group in firebug console   *    * @var string   */  const GROUP_END = 'GROUP_END';    /**   * Singleton instance of FirePHP   *   * @var FirePHP   */  protected static $instance = null;    /**   * Wildfire protocol message index   *   * @var int   */  protected $messageIndex = 1;      /**   * Options for the library   *    * @var array   */  protected $options = array();    /**   * Filters used to exclude object members when encoding   *    * @var array   */  protected $objectFilters = array();    /**   * A stack of objects used to detect recursion during object encoding   *    * @var object   */  protected $objectStack = array();    /**   * Flag to enable/disable logging   *    * @var boolean   */  protected $enabled = true;    /**   * The object constructor   */  function __construct() {    $this->options['maxObjectDepth'] = 10;    $this->options['maxArrayDepth'] = 20;    $this->options['useNativeJsonEncode'] = true;    $this->options['includeLineNumbers'] = true;  }      /**   * When the object gets serialized only include specific object members.   *    * @return array   */    public function __sleep() {    return array('options','objectFilters','enabled');  }      /**   * Gets singleton instance of FirePHP   *   * @param boolean $AutoCreate   * @return FirePHP   */  public static function getInstance($AutoCreate=false) {    if($AutoCreate===true && !self::$instance) {      self::init();    }    return self::$instance;  }     /**   * Creates FirePHP object and stores it for singleton access   *   * @return FirePHP   */  public static function init() {    return self::$instance = new self();  }    /**   * Enable and disable logging to Firebug   *    * @param boolean $Enabled TRUE to enable, FALSE to disable   * @return void   */  public function setEnabled($Enabled) {    $this->enabled = $Enabled;  }    /**   * Check if logging is enabled   *    * @return boolean TRUE if enabled   */  public function getEnabled() {    return $this->enabled;  }    /**   * Specify a filter to be used when encoding an object   *    * Filters are used to exclude object members.   *    * @param string $Class The class name of the object   * @param array $Filter An array or members to exclude   * @return void   */  public function setObjectFilter($Class, $Filter) {    $this->objectFilters[$Class] = $Filter;  }    /**   * Set some options for the library   *    * Options:   *  - maxObjectDepth: The maximum depth to traverse objects (default: 10)   *  - maxArrayDepth: The maximum depth to traverse arrays (default: 20)   *  - useNativeJsonEncode: If true will use json_encode() (default: true)   *  - includeLineNumbers: If true will include line numbers and filenames (default: true)   *    * @param array $Options The options to be set   * @return void   */  public function setOptions($Options) {    $this->options = array_merge($this->options,$Options);  }    /**   * Register FirePHP as your error handler   *    * Will throw exceptions for each php error.   */  public function registerErrorHandler()  {    //NOTE: The following errors will not be caught by this error handler:    //      E_ERROR, E_PARSE, E_CORE_ERROR,    //      E_CORE_WARNING, E_COMPILE_ERROR,    //      E_COMPILE_WARNING, E_STRICT        set_error_handler(array($this,'errorHandler'));       }  /**   * FirePHP's error handler   *    * Throws exception for each php error that will occur.   *   * @param int $errno   * @param string $errstr   * @param string $errfile   * @param int $errline   * @param array $errcontext   */  public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)  {    // Don't throw exception if error reporting is switched off    if (error_reporting() == 0) {      return;    }    // Only throw exceptions for errors we are asking for    if (error_reporting() & $errno) {      throw new ErrorException($errstr, 0, $errno, $errfile, $errline);    }  }    /**   * Register FirePHP as your exception handler   */  public function registerExceptionHandler()  {    set_exception_handler(array($this,'exceptionHandler'));       }    /**   * FirePHP's exception handler   *    * Logs all exceptions to your firebug console and then stops the script.   *   * @param Exception $Exception   * @throws Exception   */  function exceptionHandler($Exception) {    $this->fb($Exception);  }    /**   * Set custom processor url for FirePHP   *   * @param string $URL   */      public function setProcessorUrl($URL)  {    $this->setHeader('X-FirePHP-ProcessorURL', $URL);  }  /**   * Set custom renderer url for FirePHP   *   * @param string $URL   */  public function setRendererUrl($URL)  {    $this->setHeader('X-FirePHP-RendererURL', $URL);  }    /**   * Start a group for following messages   *   * @param string $Name   * @return true   * @throws Exception   */  public function group($Name) {    return $this->fb(null, $Name, FirePHP::GROUP_START);  }    /**   * Ends a group you have started before   *   * @return true   * @throws Exception   */  public function groupEnd() {    return $this->fb(null, null, FirePHP::GROUP_END);  }  /**   * Log object with label to firebug console   *   * @see FirePHP::LOG   * @param mixes $Object   * @param string $Label   * @return true   * @throws Exception   */  public function log($Object, $Label=null) {    return $this->fb($Object, $Label, FirePHP::LOG);  }   /**   * Log object with label to firebug console   *   * @see FirePHP::INFO   * @param mixes $Object   * @param string $Label   * @return true   * @throws Exception   */  public function info($Object, $Label=null) {    return $this->fb($Object, $Label, FirePHP::INFO);  }   /**   * Log object with label to firebug console   *   * @see FirePHP::WARN   * @param mixes $Object   * @param string $Label   * @return true   * @throws Exception   */  public function warn($Object, $Label=null) {    return $this->fb($Object, $Label, FirePHP::WARN);  }   /**   * Log object with label to firebug console   *   * @see FirePHP::ERROR   * @param mixes $Object   * @param string $Label   * @return true   * @throws Exception   */  public function error($Object, $Label=null) {    return $this->fb($Object, $Label, FirePHP::ERROR);  }   /**   * Dumps key and variable to firebug server panel   *   * @see FirePHP::DUMP   * @param string $Key   * @param mixed $Variable   * @return true   * @throws Exception   */  public function dump($Key, $Variable) {    return $this->fb($Variable, $Key, FirePHP::DUMP);  }    /**   * Log a trace in the firebug console   *   * @see FirePHP::TRACE   * @param string $Label   * @return true   * @throws Exception   */  public function trace($Label) {    return $this->fb($Label, FirePHP::TRACE);  }   /**   * Log a table in the firebug console   *   * @see FirePHP::TABLE   * @param string $Label   * @param string $Table

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?