1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 13:16:39 +02:00

Tweak patch a bit, refs #617

This commit is contained in:
Jordi Boggiano
2015-08-09 18:28:21 +01:00
parent eabe95f9f0
commit 419ca7ac25
2 changed files with 8 additions and 9 deletions

View File

@@ -176,20 +176,19 @@ class Logger implements LoggerInterface
} }
/** /**
* Set handlers, removing all existing ones. * Set handlers, replacing all existing ones.
* Falsey values will be ignored, and if a map is passed, keys will be ignored.
* *
* @param array $handlers All elements must be of type HandlerInterface * If a map is passed, keys will be ignored.
*
* @param HandlerInterface[] $handlers
* @return $this * @return $this
*/ */
public function setHandlers(array $handlers) public function setHandlers(array $handlers)
{ {
$this->handlers = array(); $this->handlers = array();
foreach ($handlers as $handler) { foreach (array_reverse($handlers) as $handler) {
if ($handler) {
$this->pushHandler($handler); $this->pushHandler($handler);
} }
}
return $this; return $this;
} }

View File

@@ -156,11 +156,11 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger->setHandlers(array( $logger->setHandlers(array(
"AMapKey" => $handler1, "AMapKey" => $handler1,
"Falsey" => null, "Woop" => $handler2,
)); ));
// Keys have been scrubbed // Keys have been scrubbed
$this->assertEquals(array($handler1), $logger->getHandlers()); $this->assertEquals(array($handler1, $handler2), $logger->getHandlers());
} }
/** /**