From b6949fbf8fc9a6169c20b1d6cdaddb93a0820b0e Mon Sep 17 00:00:00 2001 From: lenar Date: Tue, 10 May 2011 18:07:42 +0300 Subject: [PATCH] Rename to GroupHandler, remove callback support, add couple of tests, try 2 --- src/Monolog/Handler/GroupHandler.php | 23 ++-------------------- tests/Monolog/Handler/GroupHandlerTest.php | 10 +++++----- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/Monolog/Handler/GroupHandler.php b/src/Monolog/Handler/GroupHandler.php index d34a1d00..27eb6959 100644 --- a/src/Monolog/Handler/GroupHandler.php +++ b/src/Monolog/Handler/GroupHandler.php @@ -18,9 +18,8 @@ use Monolog\Logger; * * @author Lenar Lõhmus */ -class ForwarderHandler extends AbstractHandler +class GroupHandler extends AbstractHandler { - private $handlersInitialized; protected $handlers; /** @@ -29,7 +28,6 @@ class ForwarderHandler extends AbstractHandler */ public function __construct(array $handlers, $bubble = false) { - $this->handlersInitialized = false; $this->handlers = $handlers; $this->bubble = $bubble; } @@ -39,8 +37,6 @@ class ForwarderHandler extends AbstractHandler */ public function handle(array $record) { - $this->handlersInitialized || $this->initializeHandlers(); - foreach ($this->handlers as $handler) { $handler->handle($record); } @@ -52,8 +48,6 @@ class ForwarderHandler extends AbstractHandler */ public function handleBatch(array $records) { - $this->handlersInitialized || $this->initializeHandlers(); - foreach ($this->handlers as $handler) { $handler->handleBatch($records); } @@ -64,19 +58,6 @@ class ForwarderHandler extends AbstractHandler */ protected function write(array $record) { - throw new \BadMethodCallException('This method should not be called directly on the ForwarderHandler.'); - } - - private function initializeHandlers() - { - foreach ($this->handlers as &$handler) { - if (!$handler instanceof HandlerInterface) { - $handler = call_user_func($handler, $record, $this); - if (!$handler instanceof HandlerInterface) { - throw new \RuntimeException("The factory callback should return a HandlerInterface"); - } - } - } - $this->handlersInitialized = true; + throw new \BadMethodCallException('This method should not be called directly on the GroupHandler.'); } } diff --git a/tests/Monolog/Handler/GroupHandlerTest.php b/tests/Monolog/Handler/GroupHandlerTest.php index fc7a186a..0eae4060 100644 --- a/tests/Monolog/Handler/GroupHandlerTest.php +++ b/tests/Monolog/Handler/GroupHandlerTest.php @@ -14,12 +14,12 @@ namespace Monolog\Handler; use Monolog\TestCase; use Monolog\Logger; -class ForwarderHandlerTest extends TestCase +class GroupHandlerTest extends TestCase { - public function testHandleForward() + public function testHandle() { $testHandlers = array(new TestHandler(), new TestHandler()); - $handler = new ForwarderHandler($testHandlers); + $handler = new GroupHandler($testHandlers); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::INFO)); foreach ($testHandlers as $test) { @@ -29,10 +29,10 @@ class ForwarderHandlerTest extends TestCase } } - public function testHandleBatchForward() + public function testHandleBatch() { $testHandlers = array(new TestHandler(), new TestHandler()); - $handler = new ForwarderHandler($testHandlers); + $handler = new GroupHandler($testHandlers); $handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO))); foreach ($testHandlers as $test) { $this->assertTrue($test->hasDebugRecords());