6 * Requirements: PHP5, SimpleXML
8 * Copyright (c) 2008 PHPIDS group (https://phpids.org)
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.
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.
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/>.
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/
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.
41 * Note that this class implements both Countable and IteratorAggregate
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/
53 class IDS_Event
implements Countable
, IteratorAggregate
61 protected $name = null;
68 protected $value = null;
71 * List of filter objects
73 * Filter objects in this array are those that matched the events value
77 protected $filters = array();
82 * Total impact of the event
86 protected $impact = 0;
93 protected $tags = array();
98 * Fills event properties
100 * @param scalar $name the event name
101 * @param scalar $value the event value
102 * @param array $filters the corresponding filters
106 public function __construct($name, $value, Array $filters)
108 if (!is_scalar($name)) {
109 throw new InvalidArgumentException(
110 'Expected $name to be a scalar,' . gettype($name) . ' given'
114 if (!is_scalar($value)) {
115 throw new InvalidArgumentException('
116 Expected $value to be a scalar,' . gettype($value) . ' given'
121 $this->value
= $value;
123 foreach ($filters as $filter) {
124 if (!$filter instanceof IDS_Filter
) {
125 throw new InvalidArgumentException(
126 'Filter must be derived from IDS_Filter'
130 $this->filters
[] = $filter;
137 * The name of the event usually is the key of the variable that was
138 * considered to be malicious
142 public function getName()
148 * Returns event value
152 public function getValue()
158 * Returns calculated impact
162 public function getImpact()
164 if (!$this->impact
) {
166 foreach ($this->filters
as $filter) {
167 $this->impact +
= $filter->getImpact();
171 return $this->impact
;
175 * Returns affected tags
179 public function getTags()
181 $filters = $this->getFilters();
183 foreach ($filters as $filter) {
184 $this->tags
= array_merge($this->tags
,
188 $this->tags
= array_values(array_unique($this->tags
));
194 * Returns list of filter objects
198 public function getFilters()
200 return $this->filters
;
204 * Returns number of filters
206 * To implement interface Countable this returns the number of filters
211 public function count()
213 return count($this->getFilters());
217 * IteratorAggregate iterator getter
219 * Returns an iterator to iterate over the appended filters.
221 * @return ArrayObject the filter collection
223 public function getIterator()
225 return new ArrayObject($this->getFilters());
234 * vim600: sw=4 ts=4 expandtab