From 8ee130dd242d82ff848d72978d741b66cc907fb0 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Wed, 21 Mar 2012 20:16:42 -0600 Subject: [PATCH] made change BC --- src/Monolog/Handler/FingersCrossedHandler.php | 15 ++++++++++----- .../Monolog/Handler/FingersCrossedHandlerTest.php | 8 +++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 3d7bb412..3731fa8c 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -12,9 +12,7 @@ namespace Monolog\Handler; use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; - use Monolog\Handler\FingersCrossed\ActivationStrategyInterface; - use Monolog\Logger; /** @@ -37,15 +35,22 @@ class FingersCrossedHandler extends AbstractHandler /** * @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler). - * @param ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action + * @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action * @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not * @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true) */ - public function __construct($handler, ActivationStrategyInterface $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true) + public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true) { + if (null === $activationStrategy) { + $activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING); + } + if (!$activationStrategy instanceof ActivationStrategyInterface) { + $activationStrategy = new ErrorLevelActivationStrategy($activationStrategy); + } + $this->handler = $handler; - $this->activationStrategy = $activationStrategy ?: new ErrorLevelActivationStrategy(Logger::WARNING); + $this->activationStrategy = $activationStrategy; $this->bufferSize = $bufferSize; $this->bubble = $bubble; $this->stopBuffering = $stopBuffering; diff --git a/tests/Monolog/Handler/FingersCrossedHandlerTest.php b/tests/Monolog/Handler/FingersCrossedHandlerTest.php index 88a44d0f..a26ebb06 100644 --- a/tests/Monolog/Handler/FingersCrossedHandlerTest.php +++ b/tests/Monolog/Handler/FingersCrossedHandlerTest.php @@ -11,8 +11,6 @@ namespace Monolog\Handler; -use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; - use Monolog\TestCase; use Monolog\Logger; @@ -71,7 +69,7 @@ class FingersCrossedHandlerTest extends TestCase public function testHandleRestartBufferingAfterBeingTriggeredWhenStopBufferingIsDisabled() { $test = new TestHandler(); - $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING), 0, false, false); + $handler = new FingersCrossedHandler($test, Logger::WARNING, 0, false, false); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::WARNING)); $handler->handle($this->getRecord(Logger::INFO)); @@ -86,7 +84,7 @@ class FingersCrossedHandlerTest extends TestCase public function testHandleBufferLimit() { $test = new TestHandler(); - $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING), 2); + $handler = new FingersCrossedHandler($test, Logger::WARNING, 2); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::INFO)); @@ -132,7 +130,7 @@ class FingersCrossedHandlerTest extends TestCase public function testIsHandlingAlways() { $test = new TestHandler(); - $handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::ERROR)); + $handler = new FingersCrossedHandler($test, Logger::ERROR); $this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG))); } }