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