PageRenderTime 1625ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 1ms

/application/libraries/Firephp.php

https://bitbucket.org/matyhaty/senses-designertravelv3
PHP | 1808 lines | 1051 code | 187 blank | 570 comment | 208 complexity | 3d9f3411df32778316a238955a5fd14b MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * *** BEGIN LICENSE BLOCK *****
  4. *
  5. * This file is part of FirePHP (http://www.firephp.org/).
  6. *
  7. * Software License Agreement (New BSD License)
  8. *
  9. * Copyright (c) 2006-2010, Christoph Dorn
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. *
  15. * * Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * * Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * * Neither the name of Christoph Dorn nor the names of its
  23. * contributors may be used to endorse or promote products derived from this
  24. * software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  27. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  28. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  33. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * ***** END LICENSE BLOCK *****
  38. *
  39. * @copyright Copyright (C) 2007-2009 Christoph Dorn
  40. * @author Christoph Dorn <christoph@christophdorn.com>
  41. * @license http://www.opensource.org/licenses/bsd-license.php
  42. * @package FirePHPCore
  43. */
  44. /**
  45. * @see http://code.google.com/p/firephp/issues/detail?id=112
  46. */
  47. if (!defined('E_STRICT')) {
  48. define('E_STRICT', 2048);
  49. }
  50. if (!defined('E_RECOVERABLE_ERROR')) {
  51. define('E_RECOVERABLE_ERROR', 4096);
  52. }
  53. if (!defined('E_DEPRECATED')) {
  54. define('E_DEPRECATED', 8192);
  55. }
  56. if (!defined('E_USER_DEPRECATED')) {
  57. define('E_USER_DEPRECATED', 16384);
  58. }
  59. /**
  60. * Sends the given data to the FirePHP Firefox Extension.
  61. * The data can be displayed in the Firebug Console or in the
  62. * "Server" request tab.
  63. *
  64. * For more information see: http://www.firephp.org/
  65. *
  66. * @copyright Copyright (C) 2007-2009 Christoph Dorn
  67. * @author Christoph Dorn <christoph@christophdorn.com>
  68. * @license http://www.opensource.org/licenses/bsd-license.php
  69. * @package FirePHPCore
  70. */
  71. class FirePHP {
  72. /**
  73. * FirePHP version
  74. *
  75. * @var string
  76. */
  77. const VERSION = '0.3'; // @pinf replace '0.3' with '%%package.version%%'
  78. /**
  79. * Firebug LOG level
  80. *
  81. * Logs a message to firebug console.
  82. *
  83. * @var string
  84. */
  85. const LOG = 'LOG';
  86. /**
  87. * Firebug INFO level
  88. *
  89. * Logs a message to firebug console and displays an info icon before the message.
  90. *
  91. * @var string
  92. */
  93. const INFO = 'INFO';
  94. /**
  95. * Firebug WARN level
  96. *
  97. * Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise.
  98. *
  99. * @var string
  100. */
  101. const WARN = 'WARN';
  102. /**
  103. * Firebug ERROR level
  104. *
  105. * Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count.
  106. *
  107. * @var string
  108. */
  109. const ERROR = 'ERROR';
  110. /**
  111. * Dumps a variable to firebug's server panel
  112. *
  113. * @var string
  114. */
  115. const DUMP = 'DUMP';
  116. /**
  117. * Displays a stack trace in firebug console
  118. *
  119. * @var string
  120. */
  121. const TRACE = 'TRACE';
  122. /**
  123. * Displays an exception in firebug console
  124. *
  125. * Increments the firebug error count.
  126. *
  127. * @var string
  128. */
  129. const EXCEPTION = 'EXCEPTION';
  130. /**
  131. * Displays an table in firebug console
  132. *
  133. * @var string
  134. */
  135. const TABLE = 'TABLE';
  136. /**
  137. * Starts a group in firebug console
  138. *
  139. * @var string
  140. */
  141. const GROUP_START = 'GROUP_START';
  142. /**
  143. * Ends a group in firebug console
  144. *
  145. * @var string
  146. */
  147. const GROUP_END = 'GROUP_END';
  148. /**
  149. * Singleton instance of FirePHP
  150. *
  151. * @var FirePHP
  152. */
  153. protected static $instance = null;
  154. /**
  155. * Flag whether we are logging from within the exception handler
  156. *
  157. * @var boolean
  158. */
  159. protected $inExceptionHandler = false;
  160. /**
  161. * Flag whether to throw PHP errors that have been converted to ErrorExceptions
  162. *
  163. * @var boolean
  164. */
  165. protected $throwErrorExceptions = true;
  166. /**
  167. * Flag whether to convert PHP assertion errors to Exceptions
  168. *
  169. * @var boolean
  170. */
  171. protected $convertAssertionErrorsToExceptions = true;
  172. /**
  173. * Flag whether to throw PHP assertion errors that have been converted to Exceptions
  174. *
  175. * @var boolean
  176. */
  177. protected $throwAssertionExceptions = false;
  178. /**
  179. * Wildfire protocol message index
  180. *
  181. * @var int
  182. */
  183. protected $messageIndex = 1;
  184. /**
  185. * Options for the library
  186. *
  187. * @var array
  188. */
  189. protected $options = array('maxDepth' => 10,
  190. 'maxObjectDepth' => 5,
  191. 'maxArrayDepth' => 5,
  192. 'useNativeJsonEncode' => true,
  193. 'includeLineNumbers' => true);
  194. /**
  195. * Filters used to exclude object members when encoding
  196. *
  197. * @var array
  198. */
  199. protected $objectFilters = array(
  200. 'firephp' => array('objectStack', 'instance', 'json_objectStack'),
  201. 'firephp_test_class' => array('objectStack', 'instance', 'json_objectStack')
  202. );
  203. /**
  204. * A stack of objects used to detect recursion during object encoding
  205. *
  206. * @var object
  207. */
  208. protected $objectStack = array();
  209. /**
  210. * Flag to enable/disable logging
  211. *
  212. * @var boolean
  213. */
  214. protected $enabled = true;
  215. /**
  216. * The insight console to log to if applicable
  217. *
  218. * @var object
  219. */
  220. protected $logToInsightConsole = null;
  221. /**
  222. * When the object gets serialized only include specific object members.
  223. *
  224. * @return array
  225. */
  226. public function __sleep()
  227. {
  228. return array('options','objectFilters','enabled');
  229. }
  230. /**
  231. * Gets singleton instance of FirePHP
  232. *
  233. * @param boolean $AutoCreate
  234. * @return FirePHP
  235. */
  236. public static function getInstance($AutoCreate = false)
  237. {
  238. if ($AutoCreate===true && !self::$instance) {
  239. self::init();
  240. }
  241. return self::$instance;
  242. }
  243. /**
  244. * Creates FirePHP object and stores it for singleton access
  245. *
  246. * @return FirePHP
  247. */
  248. public static function init()
  249. {
  250. return self::setInstance(new self());
  251. }
  252. /**
  253. * Set the instance of the FirePHP singleton
  254. *
  255. * @param FirePHP $instance The FirePHP object instance
  256. * @return FirePHP
  257. */
  258. public static function setInstance($instance)
  259. {
  260. return self::$instance = $instance;
  261. }
  262. /**
  263. * Set an Insight console to direct all logging calls to
  264. *
  265. * @param object $console The console object to log to
  266. * @return void
  267. */
  268. public function setLogToInsightConsole($console)
  269. {
  270. if(is_string($console)) {
  271. if(get_class($this)!='FirePHP_Insight' && !is_subclass_of($this, 'FirePHP_Insight')) {
  272. throw new Exception('FirePHP instance not an instance or subclass of FirePHP_Insight!');
  273. }
  274. $this->logToInsightConsole = $this->to('request')->console($console);
  275. } else {
  276. $this->logToInsightConsole = $console;
  277. }
  278. }
  279. /**
  280. * Enable and disable logging to Firebug
  281. *
  282. * @param boolean $Enabled TRUE to enable, FALSE to disable
  283. * @return void
  284. */
  285. public function setEnabled($Enabled)
  286. {
  287. $this->enabled = $Enabled;
  288. }
  289. /**
  290. * Check if logging is enabled
  291. *
  292. * @return boolean TRUE if enabled
  293. */
  294. public function getEnabled()
  295. {
  296. return $this->enabled;
  297. }
  298. /**
  299. * Specify a filter to be used when encoding an object
  300. *
  301. * Filters are used to exclude object members.
  302. *
  303. * @param string $Class The class name of the object
  304. * @param array $Filter An array of members to exclude
  305. * @return void
  306. */
  307. public function setObjectFilter($Class, $Filter)
  308. {
  309. $this->objectFilters[strtolower($Class)] = $Filter;
  310. }
  311. /**
  312. * Set some options for the library
  313. *
  314. * Options:
  315. * - maxDepth: The maximum depth to traverse (default: 10)
  316. * - maxObjectDepth: The maximum depth to traverse objects (default: 5)
  317. * - maxArrayDepth: The maximum depth to traverse arrays (default: 5)
  318. * - useNativeJsonEncode: If true will use json_encode() (default: true)
  319. * - includeLineNumbers: If true will include line numbers and filenames (default: true)
  320. *
  321. * @param array $Options The options to be set
  322. * @return void
  323. */
  324. public function setOptions($Options)
  325. {
  326. $this->options = array_merge($this->options,$Options);
  327. }
  328. /**
  329. * Get options from the library
  330. *
  331. * @return array The currently set options
  332. */
  333. public function getOptions()
  334. {
  335. return $this->options;
  336. }
  337. /**
  338. * Set an option for the library
  339. *
  340. * @param string $Name
  341. * @param mixed $Value
  342. * @throws Exception
  343. * @return void
  344. */
  345. public function setOption($Name, $Value)
  346. {
  347. if (!isset($this->options[$Name])) {
  348. throw $this->newException('Unknown option: ' . $Name);
  349. }
  350. $this->options[$Name] = $Value;
  351. }
  352. /**
  353. * Get an option from the library
  354. *
  355. * @param string $Name
  356. * @throws Exception
  357. * @return mixed
  358. */
  359. public function getOption($Name)
  360. {
  361. if (!isset($this->options[$Name])) {
  362. throw $this->newException('Unknown option: ' . $Name);
  363. }
  364. return $this->options[$Name];
  365. }
  366. /**
  367. * Register FirePHP as your error handler
  368. *
  369. * Will throw exceptions for each php error.
  370. *
  371. * @return mixed Returns a string containing the previously defined error handler (if any)
  372. */
  373. public function registerErrorHandler($throwErrorExceptions = false)
  374. {
  375. //NOTE: The following errors will not be caught by this error handler:
  376. // E_ERROR, E_PARSE, E_CORE_ERROR,
  377. // E_CORE_WARNING, E_COMPILE_ERROR,
  378. // E_COMPILE_WARNING, E_STRICT
  379. $this->throwErrorExceptions = $throwErrorExceptions;
  380. return set_error_handler(array($this,'errorHandler'));
  381. }
  382. /**
  383. * FirePHP's error handler
  384. *
  385. * Throws exception for each php error that will occur.
  386. *
  387. * @param int $errno
  388. * @param string $errstr
  389. * @param string $errfile
  390. * @param int $errline
  391. * @param array $errcontext
  392. */
  393. public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
  394. {
  395. // Don't throw exception if error reporting is switched off
  396. if (error_reporting() == 0) {
  397. return;
  398. }
  399. // Only throw exceptions for errors we are asking for
  400. if (error_reporting() & $errno) {
  401. $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline);
  402. if ($this->throwErrorExceptions) {
  403. throw $exception;
  404. } else {
  405. $this->fb($exception);
  406. }
  407. }
  408. }
  409. /**
  410. * Register FirePHP as your exception handler
  411. *
  412. * @return mixed Returns the name of the previously defined exception handler,
  413. * or NULL on error.
  414. * If no previous handler was defined, NULL is also returned.
  415. */
  416. public function registerExceptionHandler()
  417. {
  418. return set_exception_handler(array($this,'exceptionHandler'));
  419. }
  420. /**
  421. * FirePHP's exception handler
  422. *
  423. * Logs all exceptions to your firebug console and then stops the script.
  424. *
  425. * @param Exception $Exception
  426. * @throws Exception
  427. */
  428. function exceptionHandler($Exception)
  429. {
  430. $this->inExceptionHandler = true;
  431. header('HTTP/1.1 500 Internal Server Error');
  432. try {
  433. $this->fb($Exception);
  434. } catch (Exception $e) {
  435. echo 'We had an exception: ' . $e;
  436. }
  437. $this->inExceptionHandler = false;
  438. }
  439. /**
  440. * Register FirePHP driver as your assert callback
  441. *
  442. * @param boolean $convertAssertionErrorsToExceptions
  443. * @param boolean $throwAssertionExceptions
  444. * @return mixed Returns the original setting or FALSE on errors
  445. */
  446. public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false)
  447. {
  448. $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions;
  449. $this->throwAssertionExceptions = $throwAssertionExceptions;
  450. if ($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) {
  451. throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!');
  452. }
  453. return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler'));
  454. }
  455. /**
  456. * FirePHP's assertion handler
  457. *
  458. * Logs all assertions to your firebug console and then stops the script.
  459. *
  460. * @param string $file File source of assertion
  461. * @param int $line Line source of assertion
  462. * @param mixed $code Assertion code
  463. */
  464. public function assertionHandler($file, $line, $code)
  465. {
  466. if ($this->convertAssertionErrorsToExceptions) {
  467. $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line);
  468. if ($this->throwAssertionExceptions) {
  469. throw $exception;
  470. } else {
  471. $this->fb($exception);
  472. }
  473. } else {
  474. $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line));
  475. }
  476. }
  477. /**
  478. * Start a group for following messages.
  479. *
  480. * Options:
  481. * Collapsed: [true|false]
  482. * Color: [#RRGGBB|ColorName]
  483. *
  484. * @param string $Name
  485. * @param array $Options OPTIONAL Instructions on how to log the group
  486. * @return true
  487. * @throws Exception
  488. */
  489. public function group($Name, $Options = null)
  490. {
  491. if (!$Name) {
  492. throw $this->newException('You must specify a label for the group!');
  493. }
  494. if ($Options) {
  495. if (!is_array($Options)) {
  496. throw $this->newException('Options must be defined as an array!');
  497. }
  498. if (array_key_exists('Collapsed', $Options)) {
  499. $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false';
  500. }
  501. }
  502. return $this->fb(null, $Name, FirePHP::GROUP_START, $Options);
  503. }
  504. /**
  505. * Ends a group you have started before
  506. *
  507. * @return true
  508. * @throws Exception
  509. */
  510. public function groupEnd()
  511. {
  512. return $this->fb(null, null, FirePHP::GROUP_END);
  513. }
  514. /**
  515. * Log object with label to firebug console
  516. *
  517. * @see FirePHP::LOG
  518. * @param mixes $Object
  519. * @param string $Label
  520. * @return true
  521. * @throws Exception
  522. */
  523. public function log($Object, $Label = null, $Options = array())
  524. {
  525. return $this->fb($Object, $Label, FirePHP::LOG, $Options);
  526. }
  527. /**
  528. * Log object with label to firebug console
  529. *
  530. * @see FirePHP::INFO
  531. * @param mixes $Object
  532. * @param string $Label
  533. * @return true
  534. * @throws Exception
  535. */
  536. public function info($Object, $Label = null, $Options = array())
  537. {
  538. if(ENVIRONMENT == 'development')
  539. {
  540. log_message('info' , 'FB Log: '.$Object);
  541. }
  542. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest")
  543. {
  544. // ajax dont do
  545. }
  546. else {
  547. return $this->fb($Object, $Label, FirePHP::INFO, $Options);
  548. }
  549. }
  550. /**
  551. * Log object with label to firebug console
  552. *
  553. * @see FirePHP::WARN
  554. * @param mixes $Object
  555. * @param string $Label
  556. * @return true
  557. * @throws Exception
  558. */
  559. public function warn($Object, $Label = null, $Options = array())
  560. {
  561. if(ENVIRONMENT == 'development')
  562. {
  563. log_message('error' , 'FB Log: '.$Object);
  564. }
  565. return $this->fb($Object, $Label, FirePHP::WARN, $Options);
  566. }
  567. /**
  568. * Log object with label to firebug console
  569. *
  570. * @see FirePHP::ERROR
  571. * @param mixes $Object
  572. * @param string $Label
  573. * @return true
  574. * @throws Exception
  575. */
  576. public function error($Object, $Label = null, $Options = array())
  577. {
  578. if(ENVIRONMENT == 'development')
  579. {
  580. log_message('error' , 'FB Log: '.$Object);
  581. }
  582. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest")
  583. {
  584. // ajax dont do
  585. }
  586. else {
  587. return $this->fb($Object, $Label, FirePHP::ERROR, $Options);
  588. }
  589. }
  590. /**
  591. * Dumps key and variable to firebug server panel
  592. *
  593. * @see FirePHP::DUMP
  594. * @param string $Key
  595. * @param mixed $Variable
  596. * @return true
  597. * @throws Exception
  598. */
  599. public function dump($Key, $Variable, $Options = array())
  600. {
  601. if (!is_string($Key)) {
  602. throw $this->newException('Key passed to dump() is not a string');
  603. }
  604. if (strlen($Key)>100) {
  605. throw $this->newException('Key passed to dump() is longer than 100 characters');
  606. }
  607. if (!preg_match_all('/^[a-zA-Z0-9-_\.:]*$/', $Key, $m)) {
  608. throw $this->newException('Key passed to dump() contains invalid characters [a-zA-Z0-9-_\.:]');
  609. }
  610. return $this->fb($Variable, $Key, FirePHP::DUMP, $Options);
  611. }
  612. /**
  613. * Log a trace in the firebug console
  614. *
  615. * @see FirePHP::TRACE
  616. * @param string $Label
  617. * @return true
  618. * @throws Exception
  619. */
  620. public function trace($Label)
  621. {
  622. return $this->fb($Label, FirePHP::TRACE);
  623. }
  624. /**
  625. * Log a table in the firebug console
  626. *
  627. * @see FirePHP::TABLE
  628. * @param string $Label
  629. * @param string $Table
  630. * @return true
  631. * @throws Exception
  632. */
  633. public function table($Label, $Table, $Options = array())
  634. {
  635. return $this->fb($Table, $Label, FirePHP::TABLE, $Options);
  636. }
  637. /**
  638. * Insight API wrapper
  639. *
  640. * @see Insight_Helper::to()
  641. */
  642. public static function to()
  643. {
  644. $instance = self::getInstance();
  645. if (!method_exists($instance, "_to")) {
  646. throw new Exception("FirePHP::to() implementation not loaded");
  647. }
  648. $args = func_get_args();
  649. return call_user_func_array(array($instance, '_to'), $args);
  650. }
  651. /**
  652. * Insight API wrapper
  653. *
  654. * @see Insight_Helper::plugin()
  655. */
  656. public static function plugin()
  657. {
  658. $instance = self::getInstance();
  659. if (!method_exists($instance, "_plugin")) {
  660. throw new Exception("FirePHP::plugin() implementation not loaded");
  661. }
  662. $args = func_get_args();
  663. return call_user_func_array(array($instance, '_plugin'), $args);
  664. }
  665. /**
  666. * Check if FirePHP is installed on client
  667. *
  668. * @return boolean
  669. */
  670. public function detectClientExtension()
  671. {
  672. // Check if FirePHP is installed on client via User-Agent header
  673. if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) &&
  674. version_compare($m[1][0],'0.0.6','>=')) {
  675. return true;
  676. } else
  677. // Check if FirePHP is installed on client via X-FirePHP-Version header
  678. if (@preg_match_all('/^([\.\d]*)$/si',$this->getRequestHeader("X-FirePHP-Version"),$m) &&
  679. version_compare($m[1][0],'0.0.6','>=')) {
  680. return true;
  681. }
  682. return false;
  683. }
  684. /**
  685. * Log varible to Firebug
  686. *
  687. * @see http://www.firephp.org/Wiki/Reference/Fb
  688. * @param mixed $Object The variable to be logged
  689. * @return true Return TRUE if message was added to headers, FALSE otherwise
  690. * @throws Exception
  691. */
  692. public function fb($Object)
  693. {
  694. if($this instanceof FirePHP_Insight && method_exists($this, '_logUpgradeClientMessage')) {
  695. if(!FirePHP_Insight::$upgradeClientMessageLogged) { // avoid infinite recursion as _logUpgradeClientMessage() logs a message
  696. $this->_logUpgradeClientMessage();
  697. }
  698. }
  699. static $insightGroupStack = array();
  700. if (!$this->getEnabled()) {
  701. return false;
  702. }
  703. if ($this->headersSent($filename, $linenum)) {
  704. // If we are logging from within the exception handler we cannot throw another exception
  705. if ($this->inExceptionHandler) {
  706. // Simply echo the error out to the page
  707. echo '<div style="border: 2px solid red; font-family: Arial; font-size: 12px; background-color: lightgray; padding: 5px;"><span style="color: red; font-weight: bold;">FirePHP ERROR:</span> Headers already sent in <b>'.$filename.'</b> on line <b>'.$linenum.'</b>. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.</div>';
  708. } else {
  709. throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.');
  710. }
  711. }
  712. $Type = null;
  713. $Label = null;
  714. $Options = array();
  715. if (func_num_args()==1) {
  716. } else
  717. if (func_num_args()==2) {
  718. switch(func_get_arg(1)) {
  719. case self::LOG:
  720. case self::INFO:
  721. case self::WARN:
  722. case self::ERROR:
  723. case self::DUMP:
  724. case self::TRACE:
  725. case self::EXCEPTION:
  726. case self::TABLE:
  727. case self::GROUP_START:
  728. case self::GROUP_END:
  729. $Type = func_get_arg(1);
  730. break;
  731. default:
  732. $Label = func_get_arg(1);
  733. break;
  734. }
  735. } else
  736. if (func_num_args()==3) {
  737. $Type = func_get_arg(2);
  738. $Label = func_get_arg(1);
  739. } else
  740. if (func_num_args()==4) {
  741. $Type = func_get_arg(2);
  742. $Label = func_get_arg(1);
  743. $Options = func_get_arg(3);
  744. } else {
  745. throw $this->newException('Wrong number of arguments to fb() function!');
  746. }
  747. if($this->logToInsightConsole!==null && (get_class($this)=='FirePHP_Insight' || is_subclass_of($this, 'FirePHP_Insight'))) {
  748. $msg = $this->logToInsightConsole;
  749. if ($Object instanceof Exception) {
  750. $Type = self::EXCEPTION;
  751. }
  752. if($Label && $Type!=self::TABLE && $Type!=self::GROUP_START) {
  753. $msg = $msg->label($Label);
  754. }
  755. switch($Type) {
  756. case self::DUMP:
  757. case self::LOG:
  758. return $msg->log($Object);
  759. case self::INFO:
  760. return $msg->info($Object);
  761. case self::WARN:
  762. return $msg->warn($Object);
  763. case self::ERROR:
  764. return $msg->error($Object);
  765. case self::TRACE:
  766. return $msg->trace($Object);
  767. case self::EXCEPTION:
  768. return $this->plugin('engine')->handleException($Object, $msg);
  769. case self::TABLE:
  770. if (isset($Object[0]) && !is_string($Object[0]) && $Label) {
  771. $Object = array($Label, $Object);
  772. }
  773. return $msg->table($Object[0], array_slice($Object[1],1), $Object[1][0]);
  774. case self::GROUP_START:
  775. $insightGroupStack[] = $msg->group(md5($Label))->open();
  776. return $msg->log($Label);
  777. case self::GROUP_END:
  778. if(count($insightGroupStack)==0) {
  779. throw new Error('Too many groupEnd() as opposed to group() calls!');
  780. }
  781. $group = array_pop($insightGroupStack);
  782. return $group->close();
  783. default:
  784. return $msg->log($Object);
  785. }
  786. }
  787. if (!$this->detectClientExtension()) {
  788. return false;
  789. }
  790. $meta = array();
  791. $skipFinalObjectEncode = false;
  792. if ($Object instanceof Exception) {
  793. $meta['file'] = $this->_escapeTraceFile($Object->getFile());
  794. $meta['line'] = $Object->getLine();
  795. $trace = $Object->getTrace();
  796. if ($Object instanceof ErrorException
  797. && isset($trace[0]['function'])
  798. && $trace[0]['function']=='errorHandler'
  799. && isset($trace[0]['class'])
  800. && $trace[0]['class']=='FirePHP') {
  801. $severity = false;
  802. switch($Object->getSeverity()) {
  803. case E_WARNING: $severity = 'E_WARNING'; break;
  804. case E_NOTICE: $severity = 'E_NOTICE'; break;
  805. case E_USER_ERROR: $severity = 'E_USER_ERROR'; break;
  806. case E_USER_WARNING: $severity = 'E_USER_WARNING'; break;
  807. case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break;
  808. case E_STRICT: $severity = 'E_STRICT'; break;
  809. case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break;
  810. case E_DEPRECATED: $severity = 'E_DEPRECATED'; break;
  811. case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break;
  812. }
  813. $Object = array('Class'=>get_class($Object),
  814. 'Message'=>$severity.': '.$Object->getMessage(),
  815. 'File'=>$this->_escapeTraceFile($Object->getFile()),
  816. 'Line'=>$Object->getLine(),
  817. 'Type'=>'trigger',
  818. 'Trace'=>$this->_escapeTrace(array_splice($trace,2)));
  819. $skipFinalObjectEncode = true;
  820. } else {
  821. $Object = array('Class'=>get_class($Object),
  822. 'Message'=>$Object->getMessage(),
  823. 'File'=>$this->_escapeTraceFile($Object->getFile()),
  824. 'Line'=>$Object->getLine(),
  825. 'Type'=>'throw',
  826. 'Trace'=>$this->_escapeTrace($trace));
  827. $skipFinalObjectEncode = true;
  828. }
  829. $Type = self::EXCEPTION;
  830. } else
  831. if ($Type==self::TRACE) {
  832. $trace = debug_backtrace();
  833. if (!$trace) return false;
  834. for( $i=0 ; $i<sizeof($trace) ; $i++ ) {
  835. if (isset($trace[$i]['class'])
  836. && isset($trace[$i]['file'])
  837. && ($trace[$i]['class']=='FirePHP'
  838. || $trace[$i]['class']=='FB')
  839. && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
  840. || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
  841. /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
  842. } else
  843. if (isset($trace[$i]['class'])
  844. && isset($trace[$i+1]['file'])
  845. && $trace[$i]['class']=='FirePHP'
  846. && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
  847. /* Skip fb() */
  848. } else
  849. if ($trace[$i]['function']=='fb'
  850. || $trace[$i]['function']=='trace'
  851. || $trace[$i]['function']=='send') {
  852. $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'',
  853. 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'',
  854. 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'',
  855. 'Message'=>$trace[$i]['args'][0],
  856. 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'',
  857. 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'',
  858. 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'',
  859. 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1)));
  860. $skipFinalObjectEncode = true;
  861. $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'';
  862. $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
  863. break;
  864. }
  865. }
  866. } else
  867. if ($Type==self::TABLE) {
  868. if (isset($Object[0]) && is_string($Object[0])) {
  869. $Object[1] = $this->encodeTable($Object[1]);
  870. } else {
  871. $Object = $this->encodeTable($Object);
  872. }
  873. $skipFinalObjectEncode = true;
  874. } else
  875. if ($Type==self::GROUP_START) {
  876. if (!$Label) {
  877. throw $this->newException('You must specify a label for the group!');
  878. }
  879. } else {
  880. if ($Type===null) {
  881. $Type = self::LOG;
  882. }
  883. }
  884. if ($this->options['includeLineNumbers']) {
  885. if (!isset($meta['file']) || !isset($meta['line'])) {
  886. $trace = debug_backtrace();
  887. for( $i=0 ; $trace && $i<sizeof($trace) ; $i++ ) {
  888. if (isset($trace[$i]['class'])
  889. && isset($trace[$i]['file'])
  890. && ($trace[$i]['class']=='FirePHP'
  891. || $trace[$i]['class']=='FB')
  892. && (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
  893. || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
  894. /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
  895. } else
  896. if (isset($trace[$i]['class'])
  897. && isset($trace[$i+1]['file'])
  898. && $trace[$i]['class']=='FirePHP'
  899. && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
  900. /* Skip fb() */
  901. } else
  902. if (isset($trace[$i]['file'])
  903. && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') {
  904. /* Skip FB::fb() */
  905. } else {
  906. $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'';
  907. $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
  908. break;
  909. }
  910. }
  911. }
  912. } else {
  913. unset($meta['file']);
  914. unset($meta['line']);
  915. }
  916. $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
  917. $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION);
  918. $structure_index = 1;
  919. if ($Type==self::DUMP) {
  920. $structure_index = 2;
  921. $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');
  922. } else {
  923. $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
  924. }
  925. if ($Type==self::DUMP) {
  926. $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}';
  927. } else {
  928. $msg_meta = $Options;
  929. $msg_meta['Type'] = $Type;
  930. if ($Label!==null) {
  931. $msg_meta['Label'] = $Label;
  932. }
  933. if (isset($meta['file']) && !isset($msg_meta['File'])) {
  934. $msg_meta['File'] = $meta['file'];
  935. }
  936. if (isset($meta['line']) && !isset($msg_meta['Line'])) {
  937. $msg_meta['Line'] = $meta['line'];
  938. }
  939. $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']';
  940. }
  941. $parts = explode("\n",chunk_split($msg, 5000, "\n"));
  942. for( $i=0 ; $i<count($parts) ; $i++) {
  943. $part = $parts[$i];
  944. if ($part) {
  945. if (count($parts)>2) {
  946. // Message needs to be split into multiple parts
  947. $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex,
  948. (($i==0)?strlen($msg):'')
  949. . '|' . $part . '|'
  950. . (($i<count($parts)-2)?'\\':''));
  951. } else {
  952. $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex,
  953. strlen($part) . '|' . $part . '|');
  954. }
  955. $this->messageIndex++;
  956. if ($this->messageIndex > 99999) {
  957. throw $this->newException('Maximum number (99,999) of messages reached!');
  958. }
  959. }
  960. }
  961. $this->setHeader('X-Wf-1-Index',$this->messageIndex-1);
  962. return true;
  963. }
  964. /**
  965. * Standardizes path for windows systems.
  966. *
  967. * @param string $Path
  968. * @return string
  969. */
  970. protected function _standardizePath($Path)
  971. {
  972. return preg_replace('/\\\\+/','/',$Path);
  973. }
  974. /**
  975. * Escape trace path for windows systems
  976. *
  977. * @param array $Trace
  978. * @return array
  979. */
  980. protected function _escapeTrace($Trace)
  981. {
  982. if (!$Trace) return $Trace;
  983. for( $i=0 ; $i<sizeof($Trace) ; $i++ ) {
  984. if (isset($Trace[$i]['file'])) {
  985. $Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']);
  986. }
  987. if (isset($Trace[$i]['args'])) {
  988. $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']);
  989. }
  990. }
  991. return $Trace;
  992. }
  993. /**
  994. * Escape file information of trace for windows systems
  995. *
  996. * @param string $File
  997. * @return string
  998. */
  999. protected function _escapeTraceFile($File)
  1000. {
  1001. /* Check if we have a windows filepath */
  1002. if (strpos($File,'\\')) {
  1003. /* First strip down to single \ */
  1004. $file = preg_replace('/\\\\+/','\\',$File);
  1005. return $file;
  1006. }
  1007. return $File;
  1008. }
  1009. /**
  1010. * Check if headers have already been sent
  1011. *
  1012. * @param string $Filename
  1013. * @param integer $Linenum
  1014. */
  1015. protected function headersSent(&$Filename, &$Linenum)
  1016. {
  1017. return headers_sent($Filename, $Linenum);
  1018. }
  1019. /**
  1020. * Send header
  1021. *
  1022. * @param string $Name
  1023. * @param string $Value
  1024. */
  1025. protected function setHeader($Name, $Value)
  1026. {
  1027. return header($Name.': '.$Value);
  1028. }
  1029. /**
  1030. * Get user agent
  1031. *
  1032. * @return string|false
  1033. */
  1034. protected function getUserAgent()
  1035. {
  1036. if (!isset($_SERVER['HTTP_USER_AGENT'])) return false;
  1037. return $_SERVER['HTTP_USER_AGENT'];
  1038. }
  1039. /**
  1040. * Get all request headers
  1041. *
  1042. * @return array
  1043. */
  1044. public static function getAllRequestHeaders() {
  1045. static $_cached_headers = false;
  1046. if($_cached_headers!==false) {
  1047. return $_cached_headers;
  1048. }
  1049. $headers = array();
  1050. if(function_exists('getallheaders')) {
  1051. foreach( getallheaders() as $name => $value ) {
  1052. $headers[strtolower($name)] = $value;
  1053. }
  1054. } else {
  1055. foreach($_SERVER as $name => $value) {
  1056. if(substr($name, 0, 5) == 'HTTP_') {
  1057. $headers[strtolower(str_replace(' ', '-', str_replace('_', ' ', substr($name, 5))))] = $value;
  1058. }
  1059. }
  1060. }
  1061. return $_cached_headers = $headers;
  1062. }
  1063. /**
  1064. * Get a request header
  1065. *
  1066. * @return string|false
  1067. */
  1068. protected function getRequestHeader($Name)
  1069. {
  1070. $headers = self::getAllRequestHeaders();
  1071. if (isset($headers[strtolower($Name)])) {
  1072. return $headers[strtolower($Name)];
  1073. }
  1074. return false;
  1075. }
  1076. /**
  1077. * Returns a new exception
  1078. *
  1079. * @param string $Message
  1080. * @return Exception
  1081. */
  1082. protected function newException($Message)
  1083. {
  1084. return new Exception($Message);
  1085. }
  1086. /**
  1087. * Encode an object into a JSON string
  1088. *
  1089. * Uses PHP's jeson_encode() if available
  1090. *
  1091. * @param object $Object The object to be encoded
  1092. * @return string The JSON string
  1093. */
  1094. public function jsonEncode($Object, $skipObjectEncode = false)
  1095. {
  1096. if (!$skipObjectEncode) {
  1097. $Object = $this->encodeObject($Object);
  1098. }
  1099. if (function_exists('json_encode')
  1100. && $this->options['useNativeJsonEncode']!=false) {
  1101. return json_encode($Object);
  1102. } else {
  1103. return $this->json_encode($Object);
  1104. }
  1105. }
  1106. /**
  1107. * Encodes a table by encoding each row and column with encodeObject()
  1108. *
  1109. * @param array $Table The table to be encoded
  1110. * @return array
  1111. */
  1112. protected function encodeTable($Table)
  1113. {
  1114. if (!$Table) return $Table;
  1115. $new_table = array();
  1116. foreach($Table as $row) {
  1117. if (is_array($row)) {
  1118. $new_row = array();
  1119. foreach($row as $item) {
  1120. $new_row[] = $this->encodeObject($item);
  1121. }
  1122. $new_table[] = $new_row;
  1123. }
  1124. }
  1125. return $new_table;
  1126. }
  1127. /**
  1128. * Encodes an object including members with
  1129. * protected and private visibility
  1130. *
  1131. * @param Object $Object The object to be encoded
  1132. * @param int $Depth The current traversal depth
  1133. * @return array All members of the object
  1134. */
  1135. protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1)
  1136. {
  1137. if ($MaxDepth > $this->options['maxDepth']) {
  1138. return '** Max Depth ('.$this->options['maxDepth'].') **';
  1139. }
  1140. $return = array();
  1141. if (is_resource($Object)) {
  1142. return '** '.(string)$Object.' **';
  1143. } else
  1144. if (is_object($Object)) {
  1145. if ($ObjectDepth > $this->options['maxObjectDepth']) {
  1146. return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **';
  1147. }
  1148. foreach ($this->objectStack as $refVal) {
  1149. if ($refVal === $Object) {
  1150. return '** Recursion ('.get_class($Object).') **';
  1151. }
  1152. }
  1153. array_push($this->objectStack, $Object);
  1154. $return['__className'] = $class = get_class($Object);
  1155. $class_lower = strtolower($class);
  1156. $reflectionClass = new ReflectionClass($class);
  1157. $properties = array();
  1158. foreach( $reflectionClass->getProperties() as $property) {
  1159. $properties[$property->getName()] = $property;
  1160. }
  1161. $members = (array)$Object;
  1162. foreach( $properties as $plain_name => $property ) {
  1163. $name = $raw_name = $plain_name;
  1164. if ($property->isStatic()) {
  1165. $name = 'static:'.$name;
  1166. }
  1167. if ($property->isPublic()) {
  1168. $name = 'public:'.$name;
  1169. } else
  1170. if ($property->isPrivate()) {
  1171. $name = 'private:'.$name;
  1172. $raw_name = "\0".$class."\0".$raw_name;
  1173. } else
  1174. if ($property->isProtected()) {
  1175. $name = 'protected:'.$name;
  1176. $raw_name = "\0".'*'."\0".$raw_name;
  1177. }
  1178. if (!(isset($this->objectFilters[$class_lower])
  1179. && is_array($this->objectFilters[$class_lower])
  1180. && in_array($plain_name,$this->objectFilters[$class_lower]))) {
  1181. if (array_key_exists($raw_name,$members)
  1182. && !$property->isStatic()) {
  1183. $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1, $MaxDepth + 1);
  1184. } else {
  1185. if (method_exists($property,'setAccessible')) {
  1186. $property->setAccessible(true);
  1187. $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1);
  1188. } else
  1189. if ($property->isPublic()) {
  1190. $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1);
  1191. } else {
  1192. $return[$name] = '** Need PHP 5.3 to get value **';
  1193. }
  1194. }
  1195. } else {
  1196. $return[$name] = '** Excluded by Filter **';
  1197. }
  1198. }
  1199. // Include all members that are not defined in the class
  1200. // but exist in the object
  1201. foreach( $members as $raw_name => $value ) {
  1202. $name = $raw_name;
  1203. if ($name{0} == "\0") {
  1204. $parts = explode("\0", $name);
  1205. $name = $parts[2];
  1206. }
  1207. $plain_name = $name;
  1208. if (!isset($properties[$name])) {
  1209. $name = 'undeclared:'.$name;
  1210. if (!(isset($this->objectFilters[$class_lower])
  1211. && is_array($this->objectFilters[$class_lower])
  1212. && in_array($plain_name,$this->objectFilters[$class_lower]))) {
  1213. $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1, $MaxDepth + 1);
  1214. } else {
  1215. $return[$name] = '** Excluded by Filter **';
  1216. }
  1217. }
  1218. }
  1219. array_pop($this->objectStack);
  1220. } elseif (is_array($Object)) {
  1221. if ($ArrayDepth > $this->options['maxArrayDepth']) {
  1222. return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **';
  1223. }
  1224. foreach ($Object as $key => $val) {
  1225. // Encoding the $GLOBALS PHP array causes an infinite loop
  1226. // if the recursion is not reset here as it contains
  1227. // a reference to itself. This is the only way I have come up
  1228. // with to stop infinite recursion in this case.
  1229. if ($key=='GLOBALS'
  1230. && is_array($val)
  1231. && array_key_exists('GLOBALS',$val)) {
  1232. $val['GLOBALS'] = '** Recursion (GLOBALS) **';
  1233. }
  1234. $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1, $MaxDepth + 1);
  1235. }
  1236. } else {
  1237. if (self::is_utf8($Object)) {
  1238. return $Object;
  1239. } else {
  1240. return utf8_encode($Object);
  1241. }
  1242. }
  1243. return $return;
  1244. }
  1245. /**
  1246. * Returns true if $string is valid UTF-8 and false otherwise.
  1247. *
  1248. * @param mixed $str String to be tested
  1249. * @return boolean
  1250. */
  1251. protected static function is_utf8($str)
  1252. {
  1253. if(function_exists('mb_detect_encoding')) {
  1254. return (mb_detect_encoding($str) == 'UTF-8');
  1255. }
  1256. $c=0; $b=0;
  1257. $bits=0;
  1258. $len=strlen($str);
  1259. for($i=0; $i<$len; $i++){
  1260. $c=ord($str[$i]);
  1261. if ($c > 128){
  1262. if (($c >= 254)) return false;
  1263. elseif ($c >= 252) $bits=6;
  1264. elseif ($c >= 248) $bits=5;
  1265. elseif ($c >= 240) $bits=4;
  1266. elseif ($c >= 224) $bits=3;
  1267. elseif ($c >= 192) $bits=2;
  1268. else return false;
  1269. if (($i+$bits) > $len) return false;
  1270. while($bits > 1){
  1271. $i++;
  1272. $b=ord($str[$i]);
  1273. if ($b < 128 || $b > 191) return false;
  1274. $bits--;
  1275. }
  1276. }
  1277. }
  1278. return true;
  1279. }
  1280. /**
  1281. * Converts to and from JSON format.
  1282. *
  1283. * JSON (JavaScript Object Notation) is a lightweight data-interchange
  1284. * format. It is easy for humans to read and write. It is easy for machines
  1285. * to parse and generate. It is based on a subset of the JavaScript
  1286. * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
  1287. * This feature can also be found in Python. JSON is a text format that is
  1288. * completely language independent but uses conventions that are familiar
  1289. * to programmers of the C-family of languages, including C, C++, C#, Java,
  1290. * JavaScript, Perl, TCL, and many others. These properties make JSON an
  1291. * ideal data-interchange language.
  1292. *
  1293. * This package provides a simple encoder and decoder for JSON notation. It
  1294. * is intended for use with client-side Javascript applications that make
  1295. * use of HTTPRequest to perform server communication functions - data can
  1296. * be encoded into JSON notation for use in a client-side javascript, or
  1297. * decoded from incoming Javascript requests. JSON format is native to
  1298. * Javascript, and can be directly eval()'ed with no further parsing
  1299. * overhead
  1300. *
  1301. * All strings should be in ASCII or UTF-8 format!
  1302. *
  1303. * LICENSE: Redistribution and use in source and binary forms, with or
  1304. * without modification, are permitted provided that the following
  1305. * conditions are met: Redistributions of source code must retain the
  1306. * above copyright notice, this list of conditions and the following
  1307. * disclaimer. Redistributions in binary form must reproduce the above
  1308. * copyright notice, this list of conditions and the following disclaimer
  1309. * in the documentation and/or other materials provided with the
  1310. * distribution.
  1311. *
  1312. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  1313. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  1314. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  1315. * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1316. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  1317. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  1318. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  1319. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  1320. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  1321. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  1322. * DAMAGE.
  1323. *
  1324. * @category
  1325. * @package Services_JSON
  1326. * @author Michal Migurski <mike-json@teczno.com>
  1327. * @author Matt Knapp <mdknapp[at]gmail[dot]com>
  1328. * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
  1329. * @author Christoph Dorn <christoph@christophdorn.com>
  1330. * @copyright 2005 Michal Migurski
  1331. * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
  1332. * @license http://www.opensource.org/licenses/bsd-license.php
  1333. * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
  1334. */
  1335. /**
  1336. * Keep a list of objects as we descend into the array so we can detect recursion.
  1337. */
  1338. private $json_obje

Large files files are truncated, but you can click here to view the full file