Skip to content
This repository
Browse code

Merge branch 'hotfix/3594'

Close #3594
  • Loading branch information...
commit 7045795a7181b449834a629cc8cf8d1ead32647b 2 parents d5dc7f8 + 0769bf4
Matthew Weier O'Phinney authored January 29, 2013
24  library/Zend/Log/Filter/SuppressFilter.php
@@ -10,6 +10,7 @@
10 10
 
11 11
 namespace Zend\Log\Filter;
12 12
 
  13
+use Zend\Log\Exception;
13 14
 
14 15
 /**
15 16
  * @category   Zend
@@ -26,6 +27,29 @@ class SuppressFilter implements FilterInterface
26 27
     /**
27 28
      * This is a simple boolean filter.
28 29
      *
  30
+     * @param int|array|Traversable $suppress
  31
+     * @throws Exception\InvalidArgumentException
  32
+     */
  33
+    public function __construct($suppress = false)
  34
+    {
  35
+        if ($suppress instanceof Traversable) {
  36
+            $suppress = iterator_to_array($suppress);
  37
+        }
  38
+        if (is_array($suppress)) {
  39
+            $suppress = isset($suppress['suppress']) ? $suppress['suppress'] : false;
  40
+        }
  41
+        if (!is_bool($suppress)) {
  42
+            throw new Exception\InvalidArgumentException(sprintf(
  43
+                    'Suppress must be an boolean; received "%s"', gettype($suppress)
  44
+            ));
  45
+        }
  46
+
  47
+        $this->suppress($suppress);
  48
+    }
  49
+
  50
+    /**
  51
+     * This is a simple boolean filter.
  52
+     *
29 53
      * Call suppress(true) to suppress all log events.
30 54
      * Call suppress(false) to accept all log events.
31 55
      *
20  tests/ZendTest/Log/Filter/SuppressFilterTest.php
@@ -30,6 +30,26 @@ public function testSuppressIsInitiallyOff()
30 30
         $this->assertTrue($this->filter->filter(array()));
31 31
     }
32 32
 
  33
+    public function testSuppressByConstructorBoolean()
  34
+    {
  35
+        $this->filter = new SuppressFilter(true);
  36
+        $this->assertFalse($this->filter->filter(array()));
  37
+        $this->assertFalse($this->filter->filter(array()));
  38
+    }
  39
+
  40
+    public function testSuppressByConstructorArray()
  41
+    {
  42
+        $this->filter = new SuppressFilter(array('suppress' => true));
  43
+        $this->assertFalse($this->filter->filter(array()));
  44
+        $this->assertFalse($this->filter->filter(array()));
  45
+    }
  46
+
  47
+     public function testConstructorThrowsOnInvalidSuppressValue()
  48
+    {
  49
+        $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Suppress must be an boolean');
  50
+        new SuppressFilter('foo');
  51
+    }
  52
+
33 53
     public function testSuppressOn()
34 54
     {
35 55
         $this->filter->suppress(true);

0 notes on commit 7045795

Please sign in to comment.
Something went wrong with that request. Please try again.