FirePhp.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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_Wildfire
  17. * @subpackage Plugin
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Zend_Controller_Request_Abstract */
  23. require_once('Zend/Controller/Request/Abstract.php');
  24. /** Zend_Controller_Response_Abstract */
  25. require_once('Zend/Controller/Response/Abstract.php');
  26. /** Zend_Wildfire_Channel_HttpHeaders */
  27. require_once 'Zend/Wildfire/Channel/HttpHeaders.php';
  28. /** Zend_Wildfire_Protocol_JsonStream */
  29. require_once 'Zend/Wildfire/Protocol/JsonStream.php';
  30. /** Zend_Wildfire_Plugin_Interface */
  31. require_once 'Zend/Wildfire/Plugin/Interface.php';
  32. /**
  33. * Primary class for communicating with the FirePHP Firefox Extension.
  34. *
  35. * @category Zend
  36. * @package Zend_Wildfire
  37. * @subpackage Plugin
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Wildfire_Plugin_FirePhp implements Zend_Wildfire_Plugin_Interface
  42. {
  43. /**
  44. * Plain log style.
  45. */
  46. const LOG = 'LOG';
  47. /**
  48. * Information style.
  49. */
  50. const INFO = 'INFO';
  51. /**
  52. * Warning style.
  53. */
  54. const WARN = 'WARN';
  55. /**
  56. * Error style that increments Firebug's error counter.
  57. */
  58. const ERROR = 'ERROR';
  59. /**
  60. * Trace style showing message and expandable full stack trace.
  61. */
  62. const TRACE = 'TRACE';
  63. /**
  64. * Exception style showing message and expandable full stack trace.
  65. * Also increments Firebug's error counter.
  66. */
  67. const EXCEPTION = 'EXCEPTION';
  68. /**
  69. * Table style showing summary line and expandable table
  70. */
  71. const TABLE = 'TABLE';
  72. /**
  73. * Dump variable to Server panel in Firebug Request Inspector
  74. */
  75. const DUMP = 'DUMP';
  76. /**
  77. * Start a group in the Firebug Console
  78. */
  79. const GROUP_START = 'GROUP_START';
  80. /**
  81. * End a group in the Firebug Console
  82. */
  83. const GROUP_END = 'GROUP_END';
  84. /**
  85. * The plugin URI for this plugin
  86. */
  87. const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  88. /**
  89. * The protocol URI for this plugin
  90. */
  91. const PROTOCOL_URI = Zend_Wildfire_Protocol_JsonStream::PROTOCOL_URI;
  92. /**
  93. * The structure URI for the Dump structure
  94. */
  95. const STRUCTURE_URI_DUMP = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1';
  96. /**
  97. * The structure URI for the Firebug Console structure
  98. */
  99. const STRUCTURE_URI_FIREBUGCONSOLE = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  100. /**
  101. * Singleton instance
  102. * @var Zend_Wildfire_Plugin_FirePhp
  103. */
  104. protected static $_instance = null;
  105. /**
  106. * Flag indicating whether FirePHP should send messages to the user-agent.
  107. * @var boolean
  108. */
  109. protected $_enabled = true;
  110. /**
  111. * The channel via which to send the encoded messages.
  112. * @var Zend_Wildfire_Channel_Interface
  113. */
  114. protected $_channel = null;
  115. /**
  116. * Messages that are buffered to be sent when protocol flushes
  117. * @var array
  118. */
  119. protected $_messages = array();
  120. /**
  121. * Options for the object
  122. * @var array
  123. */
  124. protected $_options = array(
  125. 'traceOffset' => 1, /* The offset in the trace which identifies the source of the message */
  126. 'maxTraceDepth' => 99, /* Maximum depth for stack traces */
  127. 'maxObjectDepth' => 10, /* The maximum depth to traverse objects when encoding */
  128. 'maxArrayDepth' => 20, /* The maximum depth to traverse nested arrays when encoding */
  129. 'includeLineNumbers' => true /* Whether to include line and file info for each message */
  130. );
  131. /**
  132. * Filters used to exclude object members when encoding
  133. * @var array
  134. */
  135. protected $_objectFilters = array();
  136. /**
  137. * A stack of objects used during encoding to detect recursion
  138. * @var array
  139. */
  140. protected $_objectStack = array();
  141. /**
  142. * Create singleton instance.
  143. *
  144. * @param string $class OPTIONAL Subclass of Zend_Wildfire_Plugin_FirePhp
  145. * @return Zend_Wildfire_Plugin_FirePhp Returns the singleton Zend_Wildfire_Plugin_FirePhp instance
  146. * @throws Zend_Wildfire_Exception
  147. */
  148. public static function init($class = null)
  149. {
  150. if (self::$_instance !== null) {
  151. require_once 'Zend/Wildfire/Exception.php';
  152. throw new Zend_Wildfire_Exception('Singleton instance of Zend_Wildfire_Plugin_FirePhp already exists!');
  153. }
  154. if ($class !== null) {
  155. if (!is_string($class)) {
  156. require_once 'Zend/Wildfire/Exception.php';
  157. throw new Zend_Wildfire_Exception('Third argument is not a class string');
  158. }
  159. if (!class_exists($class)) {
  160. require_once 'Zend/Loader.php';
  161. Zend_Loader::loadClass($class);
  162. }
  163. self::$_instance = new $class();
  164. if (!self::$_instance instanceof Zend_Wildfire_Plugin_FirePhp) {
  165. self::$_instance = null;
  166. require_once 'Zend/Wildfire/Exception.php';
  167. throw new Zend_Wildfire_Exception('Invalid class to third argument. Must be subclass of Zend_Wildfire_Plugin_FirePhp.');
  168. }
  169. } else {
  170. self::$_instance = new self();
  171. }
  172. return self::$_instance;
  173. }
  174. /**
  175. * Constructor
  176. * @return void
  177. */
  178. protected function __construct()
  179. {
  180. $this->_channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  181. $this->_channel->getProtocol(self::PROTOCOL_URI)->registerPlugin($this);
  182. }
  183. /**
  184. * Get or create singleton instance
  185. *
  186. * @param bool $skipCreate True if an instance should not be created
  187. * @return Zend_Wildfire_Plugin_FirePhp
  188. */
  189. public static function getInstance($skipCreate=false)
  190. {
  191. if (self::$_instance===null && $skipCreate!==true) {
  192. return self::init();
  193. }
  194. return self::$_instance;
  195. }
  196. /**
  197. * Destroys the singleton instance
  198. *
  199. * Primarily used for testing.
  200. *
  201. * @return void
  202. */
  203. public static function destroyInstance()
  204. {
  205. self::$_instance = null;
  206. }
  207. /**
  208. * Enable or disable sending of messages to user-agent.
  209. * If disabled all headers to be sent will be removed.
  210. *
  211. * @param boolean $enabled Set to TRUE to enable sending of messages.
  212. * @return boolean The previous value.
  213. */
  214. public function setEnabled($enabled)
  215. {
  216. $previous = $this->_enabled;
  217. $this->_enabled = $enabled;
  218. if (!$this->_enabled) {
  219. $this->_messages = array();
  220. $this->_channel->getProtocol(self::PROTOCOL_URI)->clearMessages($this);
  221. }
  222. return $previous;
  223. }
  224. /**
  225. * Determine if logging to user-agent is enabled.
  226. *
  227. * @return boolean Returns TRUE if logging is enabled.
  228. */
  229. public function getEnabled()
  230. {
  231. return $this->_enabled;
  232. }
  233. /**
  234. * Set a single option
  235. *
  236. * @param string $key The name of the option
  237. * @param mixed $value The value of the option
  238. * @return mixed The previous value of the option
  239. */
  240. public function setOption($key, $value)
  241. {
  242. if (!array_key_exists($key,$this->_options)) {
  243. throw new Zend_Wildfire_Exception('Option with name "'.$key.'" does not exist!');
  244. }
  245. $previous = $this->_options[$key];
  246. $this->_options[$key] = $value;
  247. return $previous;
  248. }
  249. /**
  250. * Retrieve a single option
  251. *
  252. * @param string $key The name of the option
  253. * @return mixed The value of the option
  254. */
  255. public function getOption($key)
  256. {
  257. if (!array_key_exists($key,$this->_options)) {
  258. throw new Zend_Wildfire_Exception('Option with name "'.$key.'" does not exist!');
  259. }
  260. return $this->_options[$key];
  261. }
  262. /**
  263. * Retrieve all options
  264. *
  265. * @return array All options
  266. */
  267. public function getOptions()
  268. {
  269. return $this->_options;
  270. }
  271. /**
  272. * Specify a filter to be used when encoding an object
  273. *
  274. * Filters are used to exclude object members.
  275. *
  276. * @param string $Class The class name of the object
  277. * @param array $Filter An array of members to exclude
  278. * @return void
  279. */
  280. public function setObjectFilter($class, $filter) {
  281. $this->_objectFilters[$class] = $filter;
  282. }
  283. /**
  284. * Starts a group in the Firebug Console
  285. *
  286. * @param string $title The title of the group
  287. * @param array $options OPTIONAL Setting 'Collapsed' to true will initialize group collapsed instead of expanded
  288. * @return TRUE if the group instruction was added to the response headers or buffered.
  289. */
  290. public static function group($title, $options=array())
  291. {
  292. return self::send(null, $title, self::GROUP_START, $options);
  293. }
  294. /**
  295. * Ends a group in the Firebug Console
  296. *
  297. * @return TRUE if the group instruction was added to the response headers or buffered.
  298. */
  299. public static function groupEnd()
  300. {
  301. return self::send(null, null, self::GROUP_END);
  302. }
  303. /**
  304. * Logs variables to the Firebug Console
  305. * via HTTP response headers and the FirePHP Firefox Extension.
  306. *
  307. * @param mixed $var The variable to log.
  308. * @param string $label OPTIONAL Label to prepend to the log event.
  309. * @param string $style OPTIONAL Style of the log event.
  310. * @param array $options OPTIONAL Options to change how messages are processed and sent
  311. * @return boolean Returns TRUE if the variable was added to the response headers or buffered.
  312. * @throws Zend_Wildfire_Exception
  313. */
  314. public static function send($var, $label=null, $style=null, $options=array())
  315. {
  316. $firephp = self::getInstance();
  317. if (!$firephp->getEnabled()) {
  318. return false;
  319. }
  320. if ($var instanceof Zend_Wildfire_Plugin_FirePhp_Message) {
  321. if ($var->getBuffered()) {
  322. if (!in_array($var, self::$_instance->_messages)) {
  323. self::$_instance->_messages[] = $var;
  324. }
  325. return true;
  326. }
  327. if ($var->getDestroy()) {
  328. return false;
  329. }
  330. $style = $var->getStyle();
  331. $label = $var->getLabel();
  332. $options = $var->getOptions();
  333. $var = $var->getMessage();
  334. }
  335. if (!self::$_instance->_channel->isReady()) {
  336. return false;
  337. }
  338. foreach ($options as $name => $value) {
  339. if ($value===null) {
  340. unset($options[$name]);
  341. }
  342. }
  343. $options = array_merge($firephp->getOptions(), $options);
  344. $trace = null;
  345. $skipFinalEncode = false;
  346. $meta = array();
  347. $meta['Type'] = $style;
  348. if ($var instanceof Exception) {
  349. $eTrace = $var->getTrace();
  350. $eTrace = array_splice($eTrace, 0, $options['maxTraceDepth']);
  351. $var = array('Class'=>get_class($var),
  352. 'Message'=>$var->getMessage(),
  353. 'File'=>$var->getFile(),
  354. 'Line'=>$var->getLine(),
  355. 'Type'=>'throw',
  356. 'Trace'=>$firephp->_encodeTrace($eTrace));
  357. $meta['Type'] = self::EXCEPTION;
  358. $skipFinalEncode = true;
  359. } else
  360. if ($meta['Type']==self::TRACE) {
  361. if (!$label && $var) {
  362. $label = $var;
  363. $var = null;
  364. }
  365. if (!$trace) {
  366. $trace = $firephp->_getStackTrace(array_merge($options,
  367. array('maxTraceDepth'=>$options['maxTraceDepth']+1)));
  368. }
  369. $var = array('Class'=>$trace[0]['class'],
  370. 'Type'=>$trace[0]['type'],
  371. 'Function'=>$trace[0]['function'],
  372. 'Message'=>$label,
  373. 'File'=>isset($trace[0]['file'])?$trace[0]['file']:'',
  374. 'Line'=>isset($trace[0]['line'])?$trace[0]['line']:'',
  375. 'Args'=>isset($trace[0]['args'])?$firephp->_encodeObject($trace[0]['args']):'',
  376. 'Trace'=>$firephp->_encodeTrace(array_splice($trace,1)));
  377. $skipFinalEncode = true;
  378. } else
  379. if ($meta['Type']==self::TABLE) {
  380. $var = $firephp->_encodeTable($var);
  381. $skipFinalEncode = true;
  382. } else {
  383. if ($meta['Type']===null) {
  384. $meta['Type'] = self::LOG;
  385. }
  386. }
  387. if ($label!=null) {
  388. $meta['Label'] = $label;
  389. }
  390. switch ($meta['Type']) {
  391. case self::LOG:
  392. case self::INFO:
  393. case self::WARN:
  394. case self::ERROR:
  395. case self::EXCEPTION:
  396. case self::TRACE:
  397. case self::TABLE:
  398. case self::DUMP:
  399. case self::GROUP_START:
  400. case self::GROUP_END:
  401. break;
  402. default:
  403. require_once 'Zend/Wildfire/Exception.php';
  404. throw new Zend_Wildfire_Exception('Log style "'.$meta['Type'].'" not recognized!');
  405. break;
  406. }
  407. if ($meta['Type'] != self::DUMP && $options['includeLineNumbers']) {
  408. if (!isset($meta['File']) || !isset($meta['Line'])) {
  409. if (!$trace) {
  410. $trace = $firephp->_getStackTrace(array_merge($options,
  411. array('maxTraceDepth'=>$options['maxTraceDepth']+1)));
  412. }
  413. $meta['File'] = isset($trace[0]['file'])?$trace[0]['file']:'';
  414. $meta['Line'] = isset($trace[0]['line'])?$trace[0]['line']:'';
  415. }
  416. } else {
  417. unset($meta['File']);
  418. unset($meta['Line']);
  419. }
  420. if ($meta['Type'] == self::GROUP_START) {
  421. if (isset($options['Collapsed'])) {
  422. $meta['Collapsed'] = ($options['Collapsed'])?'true':'false';
  423. }
  424. }
  425. if ($meta['Type'] == self::DUMP) {
  426. return $firephp->_recordMessage(self::STRUCTURE_URI_DUMP,
  427. array('key'=>$meta['Label'],
  428. 'data'=>$var),
  429. $skipFinalEncode);
  430. } else {
  431. return $firephp->_recordMessage(self::STRUCTURE_URI_FIREBUGCONSOLE,
  432. array('data'=>$var,
  433. 'meta'=>$meta),
  434. $skipFinalEncode);
  435. }
  436. }
  437. /**
  438. * Gets a stack trace
  439. *
  440. * @param array $options Options to change how the stack trace is returned
  441. * @return array The stack trace
  442. */
  443. protected function _getStackTrace($options)
  444. {
  445. $trace = debug_backtrace();
  446. $trace = array_splice($trace, $options['traceOffset']);
  447. if (!count($trace)) {
  448. return $trace;
  449. }
  450. if (isset($options['fixZendLogOffsetIfApplicable']) && $options['fixZendLogOffsetIfApplicable']) {
  451. if (count($trace) >=3 &&
  452. isset($trace[0]['file']) && substr($trace[0]['file'], -7, 7)=='Log.php' &&
  453. isset($trace[1]['function']) && $trace[1]['function']=='__call') {
  454. $spliceOffset = 2;
  455. //Debug backtrace changed in PHP 7.0.0
  456. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  457. $spliceOffset = 1;
  458. }
  459. $trace = array_splice($trace, $spliceOffset);
  460. }
  461. }
  462. return array_splice($trace, 0, $options['maxTraceDepth']);
  463. }
  464. /**
  465. * Record a message with the given data in the given structure
  466. *
  467. * @param string $structure The structure to be used for the data
  468. * @param array $data The data to be recorded
  469. * @param boolean $skipEncode TRUE if variable encoding should be skipped
  470. * @return boolean Returns TRUE if message was recorded
  471. * @throws Zend_Wildfire_Exception
  472. */
  473. protected function _recordMessage($structure, $data, $skipEncode=false)
  474. {
  475. switch($structure) {
  476. case self::STRUCTURE_URI_DUMP:
  477. if (!isset($data['key'])) {
  478. require_once 'Zend/Wildfire/Exception.php';
  479. throw new Zend_Wildfire_Exception('You must supply a key.');
  480. }
  481. if (!array_key_exists('data',$data)) {
  482. require_once 'Zend/Wildfire/Exception.php';
  483. throw new Zend_Wildfire_Exception('You must supply data.');
  484. }
  485. $value = $data['data'];
  486. if (!$skipEncode) {
  487. $value = $this->_encodeObject($data['data']);
  488. }
  489. return $this->_channel->getProtocol(self::PROTOCOL_URI)->
  490. recordMessage($this,
  491. $structure,
  492. array($data['key']=>$value));
  493. case self::STRUCTURE_URI_FIREBUGCONSOLE:
  494. if (!isset($data['meta']) ||
  495. !is_array($data['meta']) ||
  496. !array_key_exists('Type',$data['meta'])) {
  497. require_once 'Zend/Wildfire/Exception.php';
  498. throw new Zend_Wildfire_Exception('You must supply a "Type" in the meta information.');
  499. }
  500. if (!array_key_exists('data',$data)) {
  501. require_once 'Zend/Wildfire/Exception.php';
  502. throw new Zend_Wildfire_Exception('You must supply data.');
  503. }
  504. $value = $data['data'];
  505. if (!$skipEncode) {
  506. $value = $this->_encodeObject($data['data']);
  507. }
  508. return $this->_channel->getProtocol(self::PROTOCOL_URI)->
  509. recordMessage($this,
  510. $structure,
  511. array($data['meta'],
  512. $value));
  513. default:
  514. require_once 'Zend/Wildfire/Exception.php';
  515. throw new Zend_Wildfire_Exception('Structure of name "'.$structure.'" is not recognized.');
  516. break;
  517. }
  518. return false;
  519. }
  520. /**
  521. * Encodes a table by encoding each row and column with _encodeObject()
  522. *
  523. * @param array $Table The table to be encoded
  524. * @return array
  525. */
  526. protected function _encodeTable($table)
  527. {
  528. if (!$table) {
  529. return $table;
  530. }
  531. for ($i=0 ; $i<count($table) ; $i++) {
  532. if (is_array($table[$i])) {
  533. for ($j=0 ; $j<count($table[$i]) ; $j++) {
  534. $table[$i][$j] = $this->_encodeObject($table[$i][$j]);
  535. }
  536. }
  537. }
  538. return $table;
  539. }
  540. /**
  541. * Encodes a trace by encoding all "args" with _encodeObject()
  542. *
  543. * @param array $Trace The trace to be encoded
  544. * @return array The encoded trace
  545. */
  546. protected function _encodeTrace($trace)
  547. {
  548. if (!$trace) {
  549. return $trace;
  550. }
  551. for ($i=0 ; $i<sizeof($trace) ; $i++) {
  552. if (isset($trace[$i]['args'])) {
  553. $trace[$i]['args'] = $this->_encodeObject($trace[$i]['args']);
  554. }
  555. }
  556. return $trace;
  557. }
  558. /**
  559. * Encode an object by generating an array containing all object members.
  560. *
  561. * All private and protected members are included. Some meta info about
  562. * the object class is added.
  563. *
  564. * @param mixed $object The object/array/value to be encoded
  565. * @return array The encoded object
  566. */
  567. protected function _encodeObject($object, $objectDepth = 1, $arrayDepth = 1)
  568. {
  569. $return = array();
  570. if (is_resource($object)) {
  571. return '** '.(string)$object.' **';
  572. } else
  573. if (is_object($object)) {
  574. if ($objectDepth > $this->_options['maxObjectDepth']) {
  575. return '** Max Object Depth ('.$this->_options['maxObjectDepth'].') **';
  576. }
  577. foreach ($this->_objectStack as $refVal) {
  578. if ($refVal === $object) {
  579. return '** Recursion ('.get_class($object).') **';
  580. }
  581. }
  582. array_push($this->_objectStack, $object);
  583. $return['__className'] = $class = get_class($object);
  584. $reflectionClass = new ReflectionClass($class);
  585. $properties = array();
  586. foreach ( $reflectionClass->getProperties() as $property) {
  587. $properties[$property->getName()] = $property;
  588. }
  589. $members = (array)$object;
  590. foreach ($properties as $just_name => $property) {
  591. $name = $raw_name = $just_name;
  592. if ($property->isStatic()) {
  593. $name = 'static:'.$name;
  594. }
  595. if ($property->isPublic()) {
  596. $name = 'public:'.$name;
  597. } else
  598. if ($property->isPrivate()) {
  599. $name = 'private:'.$name;
  600. $raw_name = "\0".$class."\0".$raw_name;
  601. } else
  602. if ($property->isProtected()) {
  603. $name = 'protected:'.$name;
  604. $raw_name = "\0".'*'."\0".$raw_name;
  605. }
  606. if (!(isset($this->_objectFilters[$class])
  607. && is_array($this->_objectFilters[$class])
  608. && in_array($just_name,$this->_objectFilters[$class]))) {
  609. if (array_key_exists($raw_name,$members)
  610. && !$property->isStatic()) {
  611. $return[$name] = $this->_encodeObject($members[$raw_name], $objectDepth + 1, 1);
  612. } else {
  613. if (method_exists($property,'setAccessible')) {
  614. $property->setAccessible(true);
  615. $return[$name] = $this->_encodeObject($property->getValue($object), $objectDepth + 1, 1);
  616. } else
  617. if ($property->isPublic()) {
  618. $return[$name] = $this->_encodeObject($property->getValue($object), $objectDepth + 1, 1);
  619. } else {
  620. $return[$name] = '** Need PHP 5.3 to get value **';
  621. }
  622. }
  623. } else {
  624. $return[$name] = '** Excluded by Filter **';
  625. }
  626. }
  627. // Include all members that are not defined in the class
  628. // but exist in the object
  629. foreach($members as $just_name => $value) {
  630. $name = $raw_name = $just_name;
  631. if ($name{0} == "\0") {
  632. $parts = explode("\0", $name);
  633. $name = $parts[2];
  634. }
  635. if (!isset($properties[$name])) {
  636. $name = 'undeclared:'.$name;
  637. if (!(isset($this->objectFilters[$class])
  638. && is_array($this->objectFilters[$class])
  639. && in_array($just_name,$this->objectFilters[$class]))) {
  640. $return[$name] = $this->_encodeObject($value, $objectDepth + 1, 1);
  641. } else {
  642. $return[$name] = '** Excluded by Filter **';
  643. }
  644. }
  645. }
  646. array_pop($this->_objectStack);
  647. } elseif (is_array($object)) {
  648. if ($arrayDepth > $this->_options['maxArrayDepth']) {
  649. return '** Max Array Depth ('.$this->_options['maxArrayDepth'].') **';
  650. }
  651. foreach ($object as $key => $val) {
  652. // Encoding the $GLOBALS PHP array causes an infinite loop
  653. // if the recursion is not reset here as it contains
  654. // a reference to itself. This is the only way I have come up
  655. // with to stop infinite recursion in this case.
  656. if ($key=='GLOBALS'
  657. && is_array($val)
  658. && array_key_exists('GLOBALS',$val)) {
  659. $val['GLOBALS'] = '** Recursion (GLOBALS) **';
  660. }
  661. $return[$key] = $this->_encodeObject($val, 1, $arrayDepth + 1);
  662. }
  663. } else {
  664. return $object;
  665. }
  666. return $return;
  667. }
  668. /*
  669. * Zend_Wildfire_Plugin_Interface
  670. */
  671. /**
  672. * Get the unique indentifier for this plugin.
  673. *
  674. * @return string Returns the URI of the plugin.
  675. */
  676. public function getUri()
  677. {
  678. return self::PLUGIN_URI;
  679. }
  680. /**
  681. * Flush any buffered data.
  682. *
  683. * @param string $protocolUri The URI of the protocol that should be flushed to
  684. * @return void
  685. */
  686. public function flushMessages($protocolUri)
  687. {
  688. if (!$this->_messages || $protocolUri!=self::PROTOCOL_URI) {
  689. return;
  690. }
  691. foreach( $this->_messages as $message ) {
  692. if (!$message->getDestroy()) {
  693. $this->send($message->getMessage(),
  694. $message->getLabel(),
  695. $message->getStyle(),
  696. $message->getOptions());
  697. }
  698. }
  699. $this->_messages = array();
  700. }
  701. }