1<?php 2/** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10namespace Zend\Log\Filter; 11 12use Traversable; 13use Zend\Log\Exception; 14 15class SuppressFilter implements FilterInterface 16{ 17 /** 18 * @var bool 19 */ 20 protected $accept = true; 21 22 /** 23 * This is a simple boolean filter. 24 * 25 * @param int|array|Traversable $suppress 26 * @throws Exception\InvalidArgumentException 27 */ 28 public function __construct($suppress = false) 29 { 30 if ($suppress instanceof Traversable) { 31 $suppress = iterator_to_array($suppress); 32 } 33 if (is_array($suppress)) { 34 $suppress = isset($suppress['suppress']) ? $suppress['suppress'] : false; 35 } 36 if (!is_bool($suppress)) { 37 throw new Exception\InvalidArgumentException( 38 sprintf('Suppress must be a boolean; received "%s"', gettype($suppress)) 39 ); 40 } 41 42 $this->suppress($suppress); 43 } 44 45 /** 46 * This is a simple boolean filter. 47 * 48 * Call suppress(true) to suppress all log events. 49 * Call suppress(false) to accept all log events. 50 * 51 * @param bool $suppress Should all log events be suppressed? 52 * @return void 53 */ 54 public function suppress($suppress) 55 { 56 $this->accept = ! (bool) $suppress; 57 } 58 59 /** 60 * Returns TRUE to accept the message, FALSE to block it. 61 * 62 * @param array $event event data 63 * @return bool accepted? 64 */ 65 public function filter(array $event) 66 { 67 return $this->accept; 68 } 69} 70