PageRenderTime 25ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Plugins/Firebug/Init.php

https://github.com/predakanga/fossil
PHP | 82 lines | 32 code | 9 blank | 41 comment | 7 complexity | 3946dc31f9333849bd3c70ed1740fc87 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * Copyright (c) 2011, predakanga
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of the <organization> nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. namespace Fossil\Plugins\Firebug;
  29. use Fossil\BaseInit,
  30. Fossil\Plugins\Users\Models\User;
  31. /**
  32. * Description of Init
  33. *
  34. * @author predakanga
  35. */
  36. class Init extends BaseInit {
  37. /**
  38. * @var FireFossil
  39. */
  40. protected $firephp;
  41. public function everyTimeInit() {
  42. if(PHP_SAPI == "cli") {
  43. return;
  44. }
  45. // If we're not a dev, quit immediately
  46. $user = User::me($this->container, false);
  47. if($user && $user->isDev()) {
  48. $this->firephp = FireFossil::getInstance();
  49. // Only continue if we've detected the client extension
  50. if($this->firephp->detectClientExtension()) {
  51. $this->firephp->setIsActive(true);
  52. // Register our own error manager
  53. $this->container->registerType("ErrorManager", "Fossil\Plugins\Firebug\ErrorManager");
  54. // And our own debug logger
  55. $this->container->registerType("DebugLogger", "Fossil\Plugins\Firebug\Logging\Debug\FirebugDebugLogger", true, true);
  56. // Inject FirePHP into the error manager and logger
  57. $this->container->get("ErrorManager")->setFirephp($this->firephp);
  58. $this->container->get("DebugLogger")->setFirephp($this->firephp);
  59. $this->container->get("Dispatcher")->setFirephp($this->firephp);
  60. // Set the log level
  61. if(isset($_GET['FOSSIL_LOG']) && is_numeric($_GET['FOSSIL_LOG'])) {
  62. $this->container->get("DebugLogger")->setLevel((int)$_GET['FOSSIL_LOG']);
  63. }
  64. // Set the SQL logger up
  65. $oldLogger = $this->container->get("ORM")->getLogger();
  66. $newLogger = new FirePHPSqlLogger($this->firephp, $oldLogger);
  67. $this->container->get("ORM")->setLogger($newLogger);
  68. }
  69. }
  70. parent::everyTimeInit();
  71. }
  72. }
  73. ?>