PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/php-ids/lib/IDS/Log/Composite.php

https://bitbucket.org/syahzul/blog
PHP | 136 lines | 40 code | 14 blank | 82 comment | 7 complexity | 4ddfe782f533a065cc8d81fba0b55298 MD5 | raw file
  1. <?php
  2. /**
  3. * PHPIDS
  4. *
  5. * Requirements: PHP5, SimpleXML
  6. *
  7. * Copyright (c) 2008 PHPIDS group (http://php-ids.org)
  8. *
  9. * PHPIDS is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation, version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * PHPIDS is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * PHP version 5.1.6+
  23. *
  24. * @category Security
  25. * @package PHPIDS
  26. * @author Mario Heiderich <mario.heiderich@gmail.com>
  27. * @author Christian Matthies <ch0012@gmail.com>
  28. * @author Lars Strojny <lars@strojny.net>
  29. * @license http://www.gnu.org/licenses/lgpl.html LGPL
  30. * @link http://php-ids.org/
  31. */
  32. require_once 'IDS/Log/Interface.php';
  33. /**
  34. * Log Composite
  35. *
  36. * This class implements the composite pattern to allow to work with multiple
  37. * logging wrappers at once.
  38. *
  39. * @category Security
  40. * @package PHPIDS
  41. * @author Christian Matthies <ch0012@gmail.com>
  42. * @author Mario Heiderich <mario.heiderich@gmail.com>
  43. * @author Lars Strojny <lars@strojny.net>
  44. * @copyright 2007-2009 The PHPIDS Group
  45. * @license http://www.gnu.org/licenses/lgpl.html LGPL
  46. * @version Release: $Id:Composite.php 517 2007-09-15 15:04:13Z mario $
  47. * @link http://php-ids.org/
  48. */
  49. class IDS_Log_Composite
  50. {
  51. /**
  52. * Holds registered logging wrapper
  53. *
  54. * @var array
  55. */
  56. public $loggers = array();
  57. /**
  58. * Iterates through registered loggers and executes them
  59. *
  60. * @param object $data IDS_Report object
  61. *
  62. * @return void
  63. */
  64. public function execute(IDS_Report $data)
  65. {
  66. // make sure request uri is set right on IIS
  67. if (!isset($_SERVER['REQUEST_URI'])) {
  68. $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
  69. if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
  70. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  71. }
  72. }
  73. // make sure server address is set right on IIS
  74. if (isset($_SERVER['LOCAL_ADDR'])) {
  75. $_SERVER['SERVER_ADDR'] = $_SERVER['LOCAL_ADDR'];
  76. }
  77. foreach ($this->loggers as $logger) {
  78. $logger->execute($data);
  79. }
  80. }
  81. /**
  82. * Registers a new logging wrapper
  83. *
  84. * Only valid IDS_Log_Interface instances passed to this function will be
  85. * registered
  86. *
  87. * @return void
  88. */
  89. public function addLogger()
  90. {
  91. $args = func_get_args();
  92. foreach ($args as $class) {
  93. if (!in_array($class, $this->loggers) &&
  94. ($class instanceof IDS_Log_Interface)) {
  95. $this->loggers[] = $class;
  96. }
  97. }
  98. }
  99. /**
  100. * Removes a logger
  101. *
  102. * @param object $logger IDS_Log_Interface object
  103. *
  104. * @return boolean
  105. */
  106. public function removeLogger(IDS_Log_Interface $logger)
  107. {
  108. $key = array_search($logger, $this->loggers);
  109. if (isset($this->loggers[$key])) {
  110. unset($this->loggers[$key]);
  111. return true;
  112. }
  113. return false;
  114. }
  115. }
  116. /**
  117. * Local variables:
  118. * tab-width: 4
  119. * c-basic-offset: 4
  120. * End:
  121. * vim600: sw=4 ts=4 expandtab
  122. */