commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / IDS / Event.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 /**
35 * PHPIDS event object
36 *
37 * This class represents a certain event that occured while applying the filters
38 * to the supplied data. It aggregates a bunch of IDS_Filter implementations and
39 * is a assembled in IDS_Report.
40 *
41 * Note that this class implements both Countable and IteratorAggregate
42 *
43 * @category Security
44 * @package PHPIDS
45 * @author Christian Matthies <ch0012@gmail.com>
46 * @author Mario Heiderich <mario.heiderich@gmail.com>
47 * @author Lars Strojny <lars@strojny.net>
48 * @copyright 2007-2009 The PHPIDS Group
49 * @license http://www.gnu.org/licenses/lgpl.html LGPL
50 * @version Release: $Id:Event.php 517 2007-09-15 15:04:13Z mario $
51 * @link http://php-ids.org/
52 */
53 class IDS_Event implements Countable, IteratorAggregate
54 {
55
56 /**
57 * Event name
58 *
59 * @var scalar
60 */
61 protected $name = null;
62
63 /**
64 * Value of the event
65 *
66 * @var scalar
67 */
68 protected $value = null;
69
70 /**
71 * List of filter objects
72 *
73 * Filter objects in this array are those that matched the events value
74 *
75 * @var array
76 */
77 protected $filters = array();
78
79 /**
80 * Calculated impact
81 *
82 * Total impact of the event
83 *
84 * @var integer
85 */
86 protected $impact = 0;
87
88 /**
89 * Affecte tags
90 *
91 * @var array
92 */
93 protected $tags = array();
94
95 /**
96 * Constructor
97 *
98 * Fills event properties
99 *
100 * @param scalar $name the event name
101 * @param scalar $value the event value
102 * @param array $filters the corresponding filters
103 *
104 * @return void
105 */
106 public function __construct($name, $value, Array $filters)
107 {
108 if (!is_scalar($name)) {
109 throw new InvalidArgumentException(
110 'Expected $name to be a scalar,' . gettype($name) . ' given'
111 );
112 }
113
114 if (!is_scalar($value)) {
115 throw new InvalidArgumentException('
116 Expected $value to be a scalar,' . gettype($value) . ' given'
117 );
118 }
119
120 $this->name = $name;
121 $this->value = $value;
122
123 foreach ($filters as $filter) {
124 if (!$filter instanceof IDS_Filter) {
125 throw new InvalidArgumentException(
126 'Filter must be derived from IDS_Filter'
127 );
128 }
129
130 $this->filters[] = $filter;
131 }
132 }
133
134 /**
135 * Returns event name
136 *
137 * The name of the event usually is the key of the variable that was
138 * considered to be malicious
139 *
140 * @return scalar
141 */
142 public function getName()
143 {
144 return $this->name;
145 }
146
147 /**
148 * Returns event value
149 *
150 * @return scalar
151 */
152 public function getValue()
153 {
154 return $this->value;
155 }
156
157 /**
158 * Returns calculated impact
159 *
160 * @return integer
161 */
162 public function getImpact()
163 {
164 if (!$this->impact) {
165 $this->impact = 0;
166 foreach ($this->filters as $filter) {
167 $this->impact += $filter->getImpact();
168 }
169 }
170
171 return $this->impact;
172 }
173
174 /**
175 * Returns affected tags
176 *
177 * @return array
178 */
179 public function getTags()
180 {
181 $filters = $this->getFilters();
182
183 foreach ($filters as $filter) {
184 $this->tags = array_merge($this->tags,
185 $filter->getTags());
186 }
187
188 $this->tags = array_values(array_unique($this->tags));
189
190 return $this->tags;
191 }
192
193 /**
194 * Returns list of filter objects
195 *
196 * @return array
197 */
198 public function getFilters()
199 {
200 return $this->filters;
201 }
202
203 /**
204 * Returns number of filters
205 *
206 * To implement interface Countable this returns the number of filters
207 * appended.
208 *
209 * @return integer
210 */
211 public function count()
212 {
213 return count($this->getFilters());
214 }
215
216 /**
217 * IteratorAggregate iterator getter
218 *
219 * Returns an iterator to iterate over the appended filters.
220 *
221 * @return ArrayObject the filter collection
222 */
223 public function getIterator()
224 {
225 return new ArrayObject($this->getFilters());
226 }
227 }
228
229 /**
230 * Local variables:
231 * tab-width: 4
232 * c-basic-offset: 4
233 * End:
234 * vim600: sw=4 ts=4 expandtab
235 */