You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
7.3 KiB

13 years ago
  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-2010, 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 FirePHPCore
  42. */
  43. if(!class_exists('FirePHP')) {
  44. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'FirePHP.class.php';
  45. }
  46. /**
  47. * Sends the given data to the FirePHP Firefox Extension.
  48. * The data can be displayed in the Firebug Console or in the
  49. * "Server" request tab.
  50. *
  51. * @see http://www.firephp.org/Wiki/Reference/Fb
  52. * @param mixed $Object
  53. * @return true
  54. * @throws Exception
  55. */
  56. function fb()
  57. {
  58. $instance = FirePHP::getInstance(true);
  59. $args = func_get_args();
  60. return call_user_func_array(array($instance,'fb'),$args);
  61. }
  62. class FB
  63. {
  64. /**
  65. * Enable and disable logging to Firebug
  66. *
  67. * @see FirePHP->setEnabled()
  68. * @param boolean $Enabled TRUE to enable, FALSE to disable
  69. * @return void
  70. */
  71. public static function setEnabled($Enabled)
  72. {
  73. $instance = FirePHP::getInstance(true);
  74. $instance->setEnabled($Enabled);
  75. }
  76. /**
  77. * Check if logging is enabled
  78. *
  79. * @see FirePHP->getEnabled()
  80. * @return boolean TRUE if enabled
  81. */
  82. public static function getEnabled()
  83. {
  84. $instance = FirePHP::getInstance(true);
  85. return $instance->getEnabled();
  86. }
  87. /**
  88. * Specify a filter to be used when encoding an object
  89. *
  90. * Filters are used to exclude object members.
  91. *
  92. * @see FirePHP->setObjectFilter()
  93. * @param string $Class The class name of the object
  94. * @param array $Filter An array or members to exclude
  95. * @return void
  96. */
  97. public static function setObjectFilter($Class, $Filter)
  98. {
  99. $instance = FirePHP::getInstance(true);
  100. $instance->setObjectFilter($Class, $Filter);
  101. }
  102. /**
  103. * Set some options for the library
  104. *
  105. * @see FirePHP->setOptions()
  106. * @param array $Options The options to be set
  107. * @return void
  108. */
  109. public static function setOptions($Options)
  110. {
  111. $instance = FirePHP::getInstance(true);
  112. $instance->setOptions($Options);
  113. }
  114. /**
  115. * Get options for the library
  116. *
  117. * @see FirePHP->getOptions()
  118. * @return array The options
  119. */
  120. public static function getOptions()
  121. {
  122. $instance = FirePHP::getInstance(true);
  123. return $instance->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. $instance = FirePHP::getInstance(true);
  136. $args = func_get_args();
  137. return call_user_func_array(array($instance,'fb'),$args);
  138. }
  139. /**
  140. * Start a group for following messages
  141. *
  142. * Options:
  143. * Collapsed: [true|false]
  144. * Color: [#RRGGBB|ColorName]
  145. *
  146. * @param string $Name
  147. * @param array $Options OPTIONAL Instructions on how to log the group
  148. * @return true
  149. */
  150. public static function group($Name, $Options=null)
  151. {
  152. $instance = FirePHP::getInstance(true);
  153. return $instance->group($Name, $Options);
  154. }
  155. /**
  156. * Ends a group you have started before
  157. *
  158. * @return true
  159. * @throws Exception
  160. */
  161. public static function groupEnd()
  162. {
  163. return self::send(null, null, FirePHP::GROUP_END);
  164. }
  165. /**
  166. * Log object with label to firebug console
  167. *
  168. * @see FirePHP::LOG
  169. * @param mixes $Object
  170. * @param string $Label
  171. * @return true
  172. * @throws Exception
  173. */
  174. public static function log($Object, $Label=null)
  175. {
  176. return self::send($Object, $Label, FirePHP::LOG);
  177. }
  178. /**
  179. * Log object with label to firebug console
  180. *
  181. * @see FirePHP::INFO
  182. * @param mixes $Object
  183. * @param string $Label
  184. * @return true
  185. * @throws Exception
  186. */
  187. public static function info($Object, $Label=null)
  188. {
  189. return self::send($Object, $Label, FirePHP::INFO);
  190. }
  191. /**
  192. * Log object with label to firebug console
  193. *
  194. * @see FirePHP::WARN
  195. * @param mixes $Object
  196. * @param string $Label
  197. * @return true
  198. * @throws Exception
  199. */
  200. public static function warn($Object, $Label=null)
  201. {
  202. return self::send($Object, $Label, FirePHP::WARN);
  203. }
  204. /**
  205. * Log object with label to firebug console
  206. *
  207. * @see FirePHP::ERROR
  208. * @param mixes $Object
  209. * @param string $Label
  210. * @return true
  211. * @throws Exception
  212. */
  213. public static function error($Object, $Label=null)
  214. {
  215. return self::send($Object, $Label, FirePHP::ERROR);
  216. }
  217. /**
  218. * Dumps key and variable to firebug server panel
  219. *
  220. * @see FirePHP::DUMP
  221. * @param string $Key
  222. * @param mixed $Variable
  223. * @return true
  224. * @throws Exception
  225. */
  226. public static function dump($Key, $Variable)
  227. {
  228. return self::send($Variable, $Key, FirePHP::DUMP);
  229. }
  230. /**
  231. * Log a trace in the firebug console
  232. *
  233. * @see FirePHP::TRACE
  234. * @param string $Label
  235. * @return true
  236. * @throws Exception
  237. */
  238. public static function trace($Label)
  239. {
  240. return self::send($Label, FirePHP::TRACE);
  241. }
  242. /**
  243. * Log a table in the firebug console
  244. *
  245. * @see FirePHP::TABLE
  246. * @param string $Label
  247. * @param string $Table
  248. * @return true
  249. * @throws Exception
  250. */
  251. public static function table($Label, $Table)
  252. {
  253. return self::send($Table, $Label, FirePHP::TABLE);
  254. }
  255. }