3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Log\Filter
;
13 use Zend\Log\Exception
;
15 class Priority
implements FilterInterface
28 * Filter logging by $priority. By default, it will accept any log
29 * event whose priority value is less than or equal to $priority.
31 * @param int|array|Traversable $priority Priority
32 * @param string $operator Comparison operator
34 * @throws Exception\InvalidArgumentException
36 public function __construct($priority, $operator = null)
38 if ($priority instanceof Traversable
) {
39 $priority = iterator_to_array($priority);
41 if (is_array($priority)) {
42 $operator = isset($priority['operator']) ?
$priority['operator'] : null;
43 $priority = isset($priority['priority']) ?
$priority['priority'] : null;
45 if (!is_int($priority)) {
46 throw new Exception\
InvalidArgumentException(sprintf(
47 'Priority must be an integer; received "%s"',
52 $this->priority
= $priority;
53 $this->operator
= $operator === null ?
'<=' : $operator;
57 * Returns TRUE to accept the message, FALSE to block it.
59 * @param array $event event data
60 * @return bool accepted?
62 public function filter(array $event)
64 return version_compare($event['priority'], $this->priority
, $this->operator
);