. * * PHP version 5.1.6+ * * @category Security * @package PHPIDS * @author Mario Heiderich * @author Christian Matthies * @author Lars Strojny * @license http://www.gnu.org/licenses/lgpl.html LGPL * @link http://php-ids.org/ */ namespace IDS; /** * PHPIDS event object * * This class represents a certain event that occured while applying the filters * to the supplied data. It aggregates a bunch of IDS_Filter implementations and * is a assembled in IDS_Report. * * Note that this class implements both Countable and IteratorAggregate * * @category Security * @package PHPIDS * @author Christian Matthies * @author Mario Heiderich * @author Lars Strojny * @copyright 2007-2009 The PHPIDS Group * @license http://www.gnu.org/licenses/lgpl.html LGPL * @link http://php-ids.org/ */ class Event implements \Countable, \IteratorAggregate { /** * Event name * * @var string */ protected $name = null; /** * Value of the event * * @var mixed */ protected $value = null; /** * List of filter objects * * Filter objects in this array are those that matched the events value * * @var Filter[]|array */ protected $filters = array(); /** * Calculated impact * * Total impact of the event * * @var integer */ protected $impact = 0; /** * Affecte tags * * @var string[]|array */ protected $tags = array(); /** * Constructor * * Fills event properties * * @param string $name the event name * @param mixed $value the event value * @param Filter[]|array $filters the corresponding filters * * @throws \InvalidArgumentException * @return \IDS\Event */ public function __construct($name, $value, array $filters) { if (!is_scalar($name)) { throw new \InvalidArgumentException( 'Expected $name to be a scalar,' . gettype($name) . ' given' ); } if (!is_scalar($value)) { throw new \InvalidArgumentException( 'Expected $value to be a scalar,' . gettype($value) . ' given' ); } $this->name = $name; $this->value = $value; foreach ($filters as $filter) { if (!$filter instanceof Filter) { throw new \InvalidArgumentException( 'Filter must be derived from IDS_Filter' ); } $this->filters[] = $filter; } } /** * Returns event name * * The name of the event usually is the key of the variable that was * considered to be malicious * * @return string */ public function getName() { return $this->name; } /** * Returns event value * * @return mixed */ public function getValue() { return $this->value; } /** * Returns calculated impact * * @return integer */ public function getImpact() { if (!$this->impact) { $this->impact = 0; foreach ($this->filters as $filter) { $this->impact += $filter->getImpact(); } } return $this->impact; } /** * Returns affected tags * * @return string[]|array */ public function getTags() { foreach ($this->getFilters() as $filter) { $this->tags = array_merge($this->tags, $filter->getTags()); } return $this->tags = array_values(array_unique($this->tags)); } /** * Returns list of filter objects * * @return Filter[]|array */ public function getFilters() { return $this->filters; } /** * Returns number of filters * * To implement interface Countable this returns the number of filters * appended. * * @return integer */ public function count() { return count($this->getFilters()); } /** * IteratorAggregate iterator getter * * Returns an iterator to iterate over the appended filters. * * @return \Iterator the filter collection */ public function getIterator() { return new \ArrayIterator($this->getFilters()); } }