Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added contstructor to suppressfilter

  • Loading branch information...
commit 9f6ac1e0882476d5bd9a4f48fa208213d4ec8294 1 parent a1a31fe
JustInVTime authored
24 library/Zend/Log/Filter/SuppressFilter.php
View
@@ -10,6 +10,7 @@
namespace Zend\Log\Filter;
+use Zend\Log\Exception;
/**
* @category Zend
@@ -26,6 +27,29 @@ class SuppressFilter implements FilterInterface
/**
* This is a simple boolean filter.
*
+ * @param int|array|Traversable $suppress
+ * @throws Exception\InvalidArgumentException
+ */
+ public function __construct($suppress = false)
+ {
+ if ($suppress instanceof Traversable) {
+ $suppress = iterator_to_array($suppress);
+ }
+ if (is_array($suppress)) {
+ $suppress = isset($suppress['suppress']) ? $suppress['suppress'] : false;
+ }
+ if (!is_bool($suppress)) {
+ throw new Exception\InvalidArgumentException(sprintf(
+ 'Suppress must be an boolean; received "%s"', gettype($suppress)
+ ));
+ }
+
+ $this->suppress($suppress);
+ }
+
+ /**
+ * This is a simple boolean filter.
+ *
* Call suppress(true) to suppress all log events.
* Call suppress(false) to accept all log events.
*
20 tests/ZendTest/Log/Filter/SuppressFilterTest.php
View
@@ -30,6 +30,26 @@ public function testSuppressIsInitiallyOff()
$this->assertTrue($this->filter->filter(array()));
}
+ public function testSuppressByConstructorBoolean()
+ {
+ $this->filter = new SuppressFilter(true);
+ $this->assertFalse($this->filter->filter(array()));
+ $this->assertFalse($this->filter->filter(array()));
+ }
+
+ public function testSuppressByConstructorArray()
+ {
+ $this->filter = new SuppressFilter(array('suppress' => true));
+ $this->assertFalse($this->filter->filter(array()));
+ $this->assertFalse($this->filter->filter(array()));
+ }
+
+ public function testConstructorThrowsOnInvalidSuppressValue()
+ {
+ $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Suppress must be an boolean');
+ new SuppressFilter('foo');
+ }
+
public function testSuppressOn()
{
$this->filter->suppress(true);
Please sign in to comment.
Something went wrong with that request. Please try again.