Skip to content
This repository

Added contstructor to suppressfilter #3594

Closed
wants to merge 1 commit into from

2 participants

YoungGuns Matthew Weier O'Phinney
YoungGuns

Added a constructor to SuppressFilter class to allow setting the accept value by constructor options. All Zend\Log\Filter classes can be configured by passing options to the constructor except this class.

Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3594'
Close #3594
7ec6fae
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3594' into develop
Forward port #3594
b94884c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 29, 2013
JustInVTime Added contstructor to suppressfilter 9f6ac1e
This page is out of date. Refresh to see the latest.
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);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.