PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/library/Zend/Wildfire/Plugin/FirePhp.php

https://bitbucket.org/hamidrezas/melobit
PHP | 823 lines | 449 code | 127 blank | 247 comment | 93 complexity | e63b7dc07b6dca055715a022c5a8d8a3 MD5 | raw file
Possible License(s): AGPL-1.0
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: FirePhp.php 24594 2012-01-05 21:27:01Z matthew $
  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-2012 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. $trace = array_splice($trace, 2);
  455. }
  456. }
  457. return array_splice($trace, 0, $options['maxTraceDepth']);
  458. }
  459. /**
  460. * Record a message with the given data in the given structure
  461. *
  462. * @param string $structure The structure to be used for the data
  463. * @param array $data The data to be recorded
  464. * @param boolean $skipEncode TRUE if variable encoding should be skipped
  465. * @return boolean Returns TRUE if message was recorded
  466. * @throws Zend_Wildfire_Exception
  467. */
  468. protected function _recordMessage($structure, $data, $skipEncode=false)
  469. {
  470. switch($structure) {
  471. case self::STRUCTURE_URI_DUMP:
  472. if (!isset($data['key'])) {
  473. require_once 'Zend/Wildfire/Exception.php';
  474. throw new Zend_Wildfire_Exception('You must supply a key.');
  475. }
  476. if (!array_key_exists('data',$data)) {
  477. require_once 'Zend/Wildfire/Exception.php';
  478. throw new Zend_Wildfire_Exception('You must supply data.');
  479. }
  480. $value = $data['data'];
  481. if (!$skipEncode) {
  482. $value = $this->_encodeObject($data['data']);
  483. }
  484. return $this->_channel->getProtocol(self::PROTOCOL_URI)->
  485. recordMessage($this,
  486. $structure,
  487. array($data['key']=>$value));
  488. case self::STRUCTURE_URI_FIREBUGCONSOLE:
  489. if (!isset($data['meta']) ||
  490. !is_array($data['meta']) ||
  491. !array_key_exists('Type',$data['meta'])) {
  492. require_once 'Zend/Wildfire/Exception.php';
  493. throw new Zend_Wildfire_Exception('You must supply a "Type" in the meta information.');
  494. }
  495. if (!array_key_exists('data',$data)) {
  496. require_once 'Zend/Wildfire/Exception.php';
  497. throw new Zend_Wildfire_Exception('You must supply data.');
  498. }
  499. $value = $data['data'];
  500. if (!$skipEncode) {
  501. $value = $this->_encodeObject($data['data']);
  502. }
  503. return $this->_channel->getProtocol(self::PROTOCOL_URI)->
  504. recordMessage($this,
  505. $structure,
  506. array($data['meta'],
  507. $value));
  508. default:
  509. require_once 'Zend/Wildfire/Exception.php';
  510. throw new Zend_Wildfire_Exception('Structure of name "'.$structure.'" is not recognized.');
  511. break;
  512. }
  513. return false;
  514. }
  515. /**
  516. * Encodes a table by encoding each row and column with _encodeObject()
  517. *
  518. * @param array $Table The table to be encoded
  519. * @return array
  520. */
  521. protected function _encodeTable($table)
  522. {
  523. if (!$table) {
  524. return $table;
  525. }
  526. for ($i=0 ; $i<count($table) ; $i++) {
  527. if (is_array($table[$i])) {
  528. for ($j=0 ; $j<count($table[$i]) ; $j++) {
  529. $table[$i][$j] = $this->_encodeObject($table[$i][$j]);
  530. }
  531. }
  532. }
  533. return $table;
  534. }
  535. /**
  536. * Encodes a trace by encoding all "args" with _encodeObject()
  537. *
  538. * @param array $Trace The trace to be encoded
  539. * @return array The encoded trace
  540. */
  541. protected function _encodeTrace($trace)
  542. {
  543. if (!$trace) {
  544. return $trace;
  545. }
  546. for ($i=0 ; $i<sizeof($trace) ; $i++) {
  547. if (isset($trace[$i]['args'])) {
  548. $trace[$i]['args'] = $this->_encodeObject($trace[$i]['args']);
  549. }
  550. }
  551. return $trace;
  552. }
  553. /**
  554. * Encode an object by generating an array containing all object members.
  555. *
  556. * All private and protected members are included. Some meta info about
  557. * the object class is added.
  558. *
  559. * @param mixed $object The object/array/value to be encoded
  560. * @return array The encoded object
  561. */
  562. protected function _encodeObject($object, $objectDepth = 1, $arrayDepth = 1)
  563. {
  564. $return = array();
  565. if (is_resource($object)) {
  566. return '** '.(string)$object.' **';
  567. } else
  568. if (is_object($object)) {
  569. if ($objectDepth > $this->_options['maxObjectDepth']) {
  570. return '** Max Object Depth ('.$this->_options['maxObjectDepth'].') **';
  571. }
  572. foreach ($this->_objectStack as $refVal) {
  573. if ($refVal === $object) {
  574. return '** Recursion ('.get_class($object).') **';
  575. }
  576. }
  577. array_push($this->_objectStack, $object);
  578. $return['__className'] = $class = get_class($object);
  579. $reflectionClass = new ReflectionClass($class);
  580. $properties = array();
  581. foreach ( $reflectionClass->getProperties() as $property) {
  582. $properties[$property->getName()] = $property;
  583. }
  584. $members = (array)$object;
  585. foreach ($properties as $just_name => $property) {
  586. $name = $raw_name = $just_name;
  587. if ($property->isStatic()) {
  588. $name = 'static:'.$name;
  589. }
  590. if ($property->isPublic()) {
  591. $name = 'public:'.$name;
  592. } else
  593. if ($property->isPrivate()) {
  594. $name = 'private:'.$name;
  595. $raw_name = "\0".$class."\0".$raw_name;
  596. } else
  597. if ($property->isProtected()) {
  598. $name = 'protected:'.$name;
  599. $raw_name = "\0".'*'."\0".$raw_name;
  600. }
  601. if (!(isset($this->_objectFilters[$class])
  602. && is_array($this->_objectFilters[$class])
  603. && in_array($just_name,$this->_objectFilters[$class]))) {
  604. if (array_key_exists($raw_name,$members)
  605. && !$property->isStatic()) {
  606. $return[$name] = $this->_encodeObject($members[$raw_name], $objectDepth + 1, 1);
  607. } else {
  608. if (method_exists($property,'setAccessible')) {
  609. $property->setAccessible(true);
  610. $return[$name] = $this->_encodeObject($property->getValue($object), $objectDepth + 1, 1);
  611. } else
  612. if ($property->isPublic()) {
  613. $return[$name] = $this->_encodeObject($property->getValue($object), $objectDepth + 1, 1);
  614. } else {
  615. $return[$name] = '** Need PHP 5.3 to get value **';
  616. }
  617. }
  618. } else {
  619. $return[$name] = '** Excluded by Filter **';
  620. }
  621. }
  622. // Include all members that are not defined in the class
  623. // but exist in the object
  624. foreach($members as $just_name => $value) {
  625. $name = $raw_name = $just_name;
  626. if ($name{0} == "\0") {
  627. $parts = explode("\0", $name);
  628. $name = $parts[2];
  629. }
  630. if (!isset($properties[$name])) {
  631. $name = 'undeclared:'.$name;
  632. if (!(isset($this->objectFilters[$class])
  633. && is_array($this->objectFilters[$class])
  634. && in_array($just_name,$this->objectFilters[$class]))) {
  635. $return[$name] = $this->_encodeObject($value, $objectDepth + 1, 1);
  636. } else {
  637. $return[$name] = '** Excluded by Filter **';
  638. }
  639. }
  640. }
  641. array_pop($this->_objectStack);
  642. } elseif (is_array($object)) {
  643. if ($arrayDepth > $this->_options['maxArrayDepth']) {
  644. return '** Max Array Depth ('.$this->_options['maxArrayDepth'].') **';
  645. }
  646. foreach ($object as $key => $val) {
  647. // Encoding the $GLOBALS PHP array causes an infinite loop
  648. // if the recursion is not reset here as it contains
  649. // a reference to itself. This is the only way I have come up
  650. // with to stop infinite recursion in this case.
  651. if ($key=='GLOBALS'
  652. && is_array($val)
  653. && array_key_exists('GLOBALS',$val)) {
  654. $val['GLOBALS'] = '** Recursion (GLOBALS) **';
  655. }
  656. $return[$key] = $this->_encodeObject($val, 1, $arrayDepth + 1);
  657. }
  658. } else {
  659. return $object;
  660. }
  661. return $return;
  662. }
  663. /*
  664. * Zend_Wildfire_Plugin_Interface
  665. */
  666. /**
  667. * Get the unique indentifier for this plugin.
  668. *
  669. * @return string Returns the URI of the plugin.
  670. */
  671. public function getUri()
  672. {
  673. return self::PLUGIN_URI;
  674. }
  675. /**
  676. * Flush any buffered data.
  677. *
  678. * @param string $protocolUri The URI of the protocol that should be flushed to
  679. * @return void
  680. */
  681. public function flushMessages($protocolUri)
  682. {
  683. if (!$this->_messages || $protocolUri!=self::PROTOCOL_URI) {
  684. return;
  685. }
  686. foreach( $this->_messages as $message ) {
  687. if (!$message->getDestroy()) {
  688. $this->send($message->getMessage(),
  689. $message->getLabel(),
  690. $message->getStyle(),
  691. $message->getOptions());
  692. }
  693. }
  694. $this->_messages = array();
  695. }
  696. }