From 193e627a0b510f314e73d7988cef648b36b541b1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 25 Nov 2013 14:22:15 +0100 Subject: [PATCH] Merge removeLogger* methods in a simpler one, refs #273 --- src/Monolog/Registry.php | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Monolog/Registry.php b/src/Monolog/Registry.php index 327435f7..095223fb 100644 --- a/src/Monolog/Registry.php +++ b/src/Monolog/Registry.php @@ -39,12 +39,14 @@ class Registry { /** * List of all loggers in the registry (ba named indexes) + * * @var array of Logger */ - protected static $loggers = array(); + private static $loggers = array(); /** * Adds new logging channel to the registry + * * @param Logger $logger Instance of the logging channel * @param string $name Name of the logging channel ($logger->getName() by default) * @param boolean $overwrite Overwrite instance in the registry if the given name already exists? @@ -52,7 +54,7 @@ class Registry */ public static function addLogger(Logger $logger, $name = null, $overwrite = false) { - $name = $name ? : $logger->getName(); + $name = $name ?: $logger->getName(); if (isset(self::$loggers[$name]) && !$overwrite) { throw new InvalidArgumentException('Logger with the given name already exists'); @@ -62,24 +64,18 @@ class Registry } /** - * Removes instance from registry by the given name - * @param string $name Named index to remove + * Removes instance from registry by name or instance + * + * @param string|Logger $logger Name or logger instance */ - public static function removeLoggerByName($name) + public static function removeLogger($logger) { - unset(self::$loggers[$name]); - } - - /** - * Removes instance from registry by the given instance - * @param Logger $instance Instance thats pointer should be removed from the registry - */ - public static function removeLoggerByInstance(Logger $instance) - { - foreach (self::$loggers as $key => $logger) { - if ($logger === $instance) { - self::removeLoggerByName($key); + if ($logger instanceof Logger) { + if (false !== ($idx = array_search($logger, self::$loggers, true))) { + unset(self::$loggers[$idx]); } + } else { + unset(self::$loggers[$logger]); } } @@ -93,6 +89,7 @@ class Registry /** * Gets Logger instance from the registry + * * @param string $name Name of the requested Logger instance * @return Logger Requested instance of Logger * @throws \InvalidArgumentException If named Logger instance is not in the registry @@ -108,6 +105,7 @@ class Registry /** * Gets Logger instance from the registry via static method call + * * @param string $name Name of the requested Logger instance * @param array $arguments Arguments passed to static method call * @return Logger Requested instance of Logger @@ -117,4 +115,4 @@ class Registry { return self::getInstance($name); } -} \ No newline at end of file +}