FirePhp.php 25 KB

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