fb.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. // Authors:
  3. // - cadorn, Christoph Dorn <christoph@christophdorn.com>, Copyright 2007, New BSD License
  4. // - qbbr, Sokolov Innokenty <sokolov.innokenty@gmail.com>, Copyright 2011, New BSD License
  5. // - cadorn, Christoph Dorn <christoph@christophdorn.com>, Copyright 2011, MIT License
  6. /**
  7. * ***** BEGIN LICENSE BLOCK *****
  8. *
  9. * [MIT License](http://www.opensource.org/licenses/mit-license.php)
  10. *
  11. * Copyright (c) 2007+ [Christoph Dorn](http://www.christophdorn.com/)
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a copy
  14. * of this software and associated documentation files (the "Software"), to deal
  15. * in the Software without restriction, including without limitation the rights
  16. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. * copies of the Software, and to permit persons to whom the Software is
  18. * furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in
  21. * all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. * THE SOFTWARE.
  30. *
  31. * ***** END LICENSE BLOCK *****
  32. *
  33. * @copyright Copyright (C) 2007+ Christoph Dorn
  34. * @author Christoph Dorn <christoph@christophdorn.com>
  35. * @license [MIT License](http://www.opensource.org/licenses/mit-license.php)
  36. * @package FirePHPCore
  37. */
  38. if (!class_exists('FirePHP', false)) {
  39. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'FirePHP.class.php';
  40. }
  41. /**
  42. * Sends the given data to the FirePHP Firefox Extension.
  43. * The data can be displayed in the Firebug Console or in the
  44. * "Server" request tab.
  45. *
  46. * @see http://www.firephp.org/Wiki/Reference/Fb
  47. * @param mixed $Object
  48. * @return true
  49. * @throws Exception
  50. */
  51. function fb()
  52. {
  53. $instance = FirePHP::getInstance(true);
  54. $args = func_get_args();
  55. return call_user_func_array(array($instance, 'fb'), $args);
  56. }
  57. class FB
  58. {
  59. /**
  60. * Set an Insight console to direct all logging calls to
  61. *
  62. * @param object $console The console object to log to
  63. * @return void
  64. */
  65. public static function setLogToInsightConsole($console)
  66. {
  67. FirePHP::getInstance(true)->setLogToInsightConsole($console);
  68. }
  69. /**
  70. * Enable and disable logging to Firebug
  71. *
  72. * @see FirePHP->setEnabled()
  73. * @param boolean $enabled TRUE to enable, FALSE to disable
  74. * @return void
  75. */
  76. public static function setEnabled($enabled)
  77. {
  78. FirePHP::getInstance(true)->setEnabled($enabled);
  79. }
  80. /**
  81. * Check if logging is enabled
  82. *
  83. * @see FirePHP->getEnabled()
  84. * @return boolean TRUE if enabled
  85. */
  86. public static function getEnabled()
  87. {
  88. return FirePHP::getInstance(true)->getEnabled();
  89. }
  90. /**
  91. * Specify a filter to be used when encoding an object
  92. *
  93. * Filters are used to exclude object members.
  94. *
  95. * @see FirePHP->setObjectFilter()
  96. * @param string $class The class name of the object
  97. * @param array $filter An array or members to exclude
  98. * @return void
  99. */
  100. public static function setObjectFilter($class, $filter)
  101. {
  102. FirePHP::getInstance(true)->setObjectFilter($class, $filter);
  103. }
  104. /**
  105. * Set some options for the library
  106. *
  107. * @see FirePHP->setOptions()
  108. * @param array $options The options to be set
  109. * @return void
  110. */
  111. public static function setOptions($options)
  112. {
  113. FirePHP::getInstance(true)->setOptions($options);
  114. }
  115. /**
  116. * Get options for the library
  117. *
  118. * @see FirePHP->getOptions()
  119. * @return array The options
  120. */
  121. public static function getOptions()
  122. {
  123. return FirePHP::getInstance(true)->getOptions();
  124. }
  125. /**
  126. * Log object to firebug
  127. *
  128. * @see http://www.firephp.org/Wiki/Reference/Fb
  129. * @param mixed $object
  130. * @return true
  131. * @throws Exception
  132. */
  133. public static function send()
  134. {
  135. $args = func_get_args();
  136. return call_user_func_array(array(FirePHP::getInstance(true), 'fb'), $args);
  137. }
  138. /**
  139. * Start a group for following messages
  140. *
  141. * Options:
  142. * Collapsed: [true|false]
  143. * Color: [#RRGGBB|ColorName]
  144. *
  145. * @param string $name
  146. * @param array $options OPTIONAL Instructions on how to log the group
  147. * @return true
  148. */
  149. public static function group($name, $options=null)
  150. {
  151. return FirePHP::getInstance(true)->group($name, $options);
  152. }
  153. /**
  154. * Ends a group you have started before
  155. *
  156. * @return true
  157. * @throws Exception
  158. */
  159. public static function groupEnd()
  160. {
  161. return self::send(null, null, FirePHP::GROUP_END);
  162. }
  163. /**
  164. * Log object with label to firebug console
  165. *
  166. * @see FirePHP::LOG
  167. * @param mixes $object
  168. * @param string $label
  169. * @return true
  170. * @throws Exception
  171. */
  172. public static function log($object, $label=null)
  173. {
  174. return self::send($object, $label, FirePHP::LOG);
  175. }
  176. /**
  177. * Log object with label to firebug console
  178. *
  179. * @see FirePHP::INFO
  180. * @param mixes $object
  181. * @param string $label
  182. * @return true
  183. * @throws Exception
  184. */
  185. public static function info($object, $label=null)
  186. {
  187. return self::send($object, $label, FirePHP::INFO);
  188. }
  189. /**
  190. * Log object with label to firebug console
  191. *
  192. * @see FirePHP::WARN
  193. * @param mixes $object
  194. * @param string $label
  195. * @return true
  196. * @throws Exception
  197. */
  198. public static function warn($object, $label=null)
  199. {
  200. return self::send($object, $label, FirePHP::WARN);
  201. }
  202. /**
  203. * Log object with label to firebug console
  204. *
  205. * @see FirePHP::ERROR
  206. * @param mixes $object
  207. * @param string $label
  208. * @return true
  209. * @throws Exception
  210. */
  211. public static function error($object, $label=null)
  212. {
  213. return self::send($object, $label, FirePHP::ERROR);
  214. }
  215. /**
  216. * Dumps key and variable to firebug server panel
  217. *
  218. * @see FirePHP::DUMP
  219. * @param string $key
  220. * @param mixed $variable
  221. * @return true
  222. * @throws Exception
  223. */
  224. public static function dump($key, $variable)
  225. {
  226. return self::send($variable, $key, FirePHP::DUMP);
  227. }
  228. /**
  229. * Log a trace in the firebug console
  230. *
  231. * @see FirePHP::TRACE
  232. * @param string $label
  233. * @return true
  234. * @throws Exception
  235. */
  236. public static function trace($label)
  237. {
  238. return self::send($label, FirePHP::TRACE);
  239. }
  240. /**
  241. * Log a table in the firebug console
  242. *
  243. * @see FirePHP::TABLE
  244. * @param string $label
  245. * @param string $table
  246. * @return true
  247. * @throws Exception
  248. */
  249. public static function table($label, $table)
  250. {
  251. return self::send($table, $label, FirePHP::TABLE);
  252. }
  253. }