From: Mike Naberezny Date: Tue, 10 Feb 2009 04:54:19 +0000 (-0800) Subject: Added Horde_Log_Filter_Suppress. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=79176634bcec327bf1cf6e76c10cc35779671bc2;p=horde.git Added Horde_Log_Filter_Suppress. --- diff --git a/framework/Log/lib/Horde/Log/Filter/Suppress.php b/framework/Log/lib/Horde/Log/Filter/Suppress.php new file mode 100644 index 000000000..ed430fdfd --- /dev/null +++ b/framework/Log/lib/Horde/Log/Filter/Suppress.php @@ -0,0 +1,57 @@ + + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + */ + +/** + * @category Horde + * @package Horde_Log + * @subpackage Filters + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + */ +class Horde_Log_Filter_Suppress implements Horde_Log_Filter_Interface +{ + /** + * @var boolean + */ + protected $_accept = true; + + /** + * This is a simple boolean filter. + * + * Call suppress(true) to suppress all log events. + * Call suppress(false) to accept all log events. + * + * @param boolean $suppress Should all log events be suppressed? + * @return void + */ + public function suppress($suppress) + { + $this->_accept = (! $suppress); + } + + /** + * Returns TRUE to accept the message, FALSE to block it. + * + * @param array $event event data + * @return boolean accepted? + */ + public function accept($event) + { + return $this->_accept; + } + +} diff --git a/framework/Log/package.xml b/framework/Log/package.xml index e502fa22f..153e123e8 100644 --- a/framework/Log/package.xml +++ b/framework/Log/package.xml @@ -20,18 +20,18 @@ http://pear.php.net/dtd/package-2.0.xsd"> mike@maintainable.com yes - 2007-10-21 + 2009-02-09 - 0.1.0 - 0.1.0 + 0.2.0 + 0.2.0 beta beta BSD - Initial Horde_Log release + * Added Horde_Log_Filter_Suppress. @@ -42,6 +42,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -80,6 +81,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/framework/Log/test/Horde/Log/Filter/SuppressTest.php b/framework/Log/test/Horde/Log/Filter/SuppressTest.php new file mode 100644 index 000000000..a6b4fb4d8 --- /dev/null +++ b/framework/Log/test/Horde/Log/Filter/SuppressTest.php @@ -0,0 +1,60 @@ + + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + */ + +/** + * @category Horde + * @package Horde_Log + * @subpackage UnitTests + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + */ +class Horde_Log_Filter_SuppressTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->filter = new Horde_Log_Filter_Suppress(); + } + + public function testSuppressIsInitiallyOff() + { + $this->assertTrue($this->filter->accept(array())); + } + + public function testSuppressOn() + { + $this->filter->suppress(true); + $this->assertFalse($this->filter->accept(array())); + $this->assertFalse($this->filter->accept(array())); + } + + public function testSuppressOff() + { + $this->filter->suppress(false); + $this->assertTrue($this->filter->accept(array())); + $this->assertTrue($this->filter->accept(array())); + } + + public function testSuppressCanBeReset() + { + $this->filter->suppress(true); + $this->assertFalse($this->filter->accept(array())); + $this->filter->suppress(false); + $this->assertTrue($this->filter->accept(array())); + $this->filter->suppress(true); + $this->assertFalse($this->filter->accept(array())); + } +}