fb.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. *
  4. * This file is part of FirePHP (http://www.firephp.org/).
  5. *
  6. * Software License Agreement (New BSD License)
  7. *
  8. * Copyright (c) 2006-2009, Christoph Dorn
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. *
  21. * * Neither the name of Christoph Dorn nor the names of its
  22. * contributors may be used to endorse or promote products derived from this
  23. * software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  27. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  29. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * ***** END LICENSE BLOCK *****
  37. *
  38. * @copyright Copyright (C) 2007-2009 Christoph Dorn
  39. * @author Christoph Dorn <christoph@christophdorn.com>
  40. * @license http://www.opensource.org/licenses/bsd-license.php
  41. * @package FirePHP
  42. */
  43. require_once dirname(__FILE__).'/FirePHP.class.php';
  44. /**
  45. * Sends the given data to the FirePHP Firefox Extension.
  46. * The data can be displayed in the Firebug Console or in the
  47. * "Server" request tab.
  48. *
  49. * @see http://www.firephp.org/Wiki/Reference/Fb
  50. * @param mixed $Object
  51. * @return true
  52. * @throws Exception
  53. */
  54. function fb()
  55. {
  56. $instance = FirePHP::getInstance(true);
  57. $args = func_get_args();
  58. return call_user_func_array(array($instance,'fb'),$args);
  59. }
  60. class FB
  61. {
  62. /**
  63. * Enable and disable logging to Firebug
  64. *
  65. * @see FirePHP->setEnabled()
  66. * @param boolean $Enabled TRUE to enable, FALSE to disable
  67. * @return void
  68. */
  69. public static function setEnabled($Enabled) {
  70. $instance = FirePHP::getInstance(true);
  71. $instance->setEnabled($Enabled);
  72. }
  73. /**
  74. * Check if logging is enabled
  75. *
  76. * @see FirePHP->getEnabled()
  77. * @return boolean TRUE if enabled
  78. */
  79. public static function getEnabled() {
  80. $instance = FirePHP::getInstance(true);
  81. return $instance->getEnabled();
  82. }
  83. /**
  84. * Specify a filter to be used when encoding an object
  85. *
  86. * Filters are used to exclude object members.
  87. *
  88. * @see FirePHP->setObjectFilter()
  89. * @param string $Class The class name of the object
  90. * @param array $Filter An array or members to exclude
  91. * @return void
  92. */
  93. public static function setObjectFilter($Class, $Filter) {
  94. $instance = FirePHP::getInstance(true);
  95. $instance->setObjectFilter($Class, $Filter);
  96. }
  97. /**
  98. * Set some options for the library
  99. *
  100. * @see FirePHP->setOptions()
  101. * @param array $Options The options to be set
  102. * @return void
  103. */
  104. public static function setOptions($Options) {
  105. $instance = FirePHP::getInstance(true);
  106. $instance->setOptions($Options);
  107. }
  108. /**
  109. * Get options for the library
  110. *
  111. * @see FirePHP->getOptions()
  112. * @return array The options
  113. */
  114. public static function getOptions() {
  115. $instance = FirePHP::getInstance(true);
  116. return $instance->getOptions();
  117. }
  118. /**
  119. * Log object to firebug
  120. *
  121. * @see http://www.firephp.org/Wiki/Reference/Fb
  122. * @param mixed $Object
  123. * @return true
  124. * @throws Exception
  125. */
  126. public static function send()
  127. {
  128. $instance = FirePHP::getInstance(true);
  129. $args = func_get_args();
  130. return call_user_func_array(array($instance,'fb'),$args);
  131. }
  132. /**
  133. * Start a group for following messages
  134. *
  135. * Options:
  136. * Collapsed: [true|false]
  137. * Color: [#RRGGBB|ColorName]
  138. *
  139. * @param string $Name
  140. * @param array $Options OPTIONAL Instructions on how to log the group
  141. * @return true
  142. */
  143. public static function group($Name, $Options=null) {
  144. $instance = FirePHP::getInstance(true);
  145. return $instance->group($Name, $Options);
  146. }
  147. /**
  148. * Ends a group you have started before
  149. *
  150. * @return true
  151. * @throws Exception
  152. */
  153. public static function groupEnd() {
  154. return self::send(null, null, FirePHP::GROUP_END);
  155. }
  156. /**
  157. * Log object with label to firebug console
  158. *
  159. * @see FirePHP::LOG
  160. * @param mixes $Object
  161. * @param string $Label
  162. * @return true
  163. * @throws Exception
  164. */
  165. public static function log($Object, $Label=null) {
  166. return self::send($Object, $Label, FirePHP::LOG);
  167. }
  168. /**
  169. * Log object with label to firebug console
  170. *
  171. * @see FirePHP::INFO
  172. * @param mixes $Object
  173. * @param string $Label
  174. * @return true
  175. * @throws Exception
  176. */
  177. public static function info($Object, $Label=null) {
  178. return self::send($Object, $Label, FirePHP::INFO);
  179. }
  180. /**
  181. * Log object with label to firebug console
  182. *
  183. * @see FirePHP::WARN
  184. * @param mixes $Object
  185. * @param string $Label
  186. * @return true
  187. * @throws Exception
  188. */
  189. public static function warn($Object, $Label=null) {
  190. return self::send($Object, $Label, FirePHP::WARN);
  191. }
  192. /**
  193. * Log object with label to firebug console
  194. *
  195. * @see FirePHP::ERROR
  196. * @param mixes $Object
  197. * @param string $Label
  198. * @return true
  199. * @throws Exception
  200. */
  201. public static function error($Object, $Label=null) {
  202. return self::send($Object, $Label, FirePHP::ERROR);
  203. }
  204. /**
  205. * Dumps key and variable to firebug server panel
  206. *
  207. * @see FirePHP::DUMP
  208. * @param string $Key
  209. * @param mixed $Variable
  210. * @return true
  211. * @throws Exception
  212. */
  213. public static function dump($Key, $Variable) {
  214. return self::send($Variable, $Key, FirePHP::DUMP);
  215. }
  216. /**
  217. * Log a trace in the firebug console
  218. *
  219. * @see FirePHP::TRACE
  220. * @param string $Label
  221. * @return true
  222. * @throws Exception
  223. */
  224. public static function trace($Label) {
  225. return self::send($Label, FirePHP::TRACE);
  226. }
  227. /**
  228. * Log a table in the firebug console
  229. *
  230. * @see FirePHP::TABLE
  231. * @param string $Label
  232. * @param string $Table
  233. * @return true
  234. * @throws Exception
  235. */
  236. public static function table($Label, $Table) {
  237. return self::send($Table, $Label, FirePHP::TABLE);
  238. }
  239. }