* $application = new Monolog\Logger('application'); * $api = new Monolog\Logger('api'); * * Monolog\Registry::addLogger($application); * Monolog\Registry::addLogger($api); * * function testLogger() * { * Monolog\Registry::api()->error('Sent to $api Logger instance'); * Monolog\Registry::application()->error('Sent to $application Logger instance'); * } * * * @author Tomas Tatarko */ class Registry { /** * List of all loggers in the registry (by named indexes) * * @var Logger[] */ private static $loggers = []; /** * Adds new logging channel to the registry * * @param Logger $logger Instance of the logging channel * @param string|null $name Name of the logging channel ($logger->getName() by default) * @param bool $overwrite Overwrite instance in the registry if the given name already exists? * @throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists * @return void */ public static function addLogger(Logger $logger, ?string $name = null, bool $overwrite = false) { $name = $name ?: $logger->getName(); if (isset(self::$loggers[$name]) && !$overwrite) { throw new InvalidArgumentException('Logger with the given name already exists'); } self::$loggers[$name] = $logger; } /** * Checks if such logging channel exists by name or instance * * @param string|Logger $logger Name or logger instance */ public static function hasLogger($logger): bool { if ($logger instanceof Logger) { $index = array_search($logger, self::$loggers, true); return false !== $index; } return isset(self::$loggers[$logger]); } /** * Removes instance from registry by name or instance * * @param string|Logger $logger Name or logger instance */ public static function removeLogger($logger): void { if ($logger instanceof Logger) { if (false !== ($idx = array_search($logger, self::$loggers, true))) { unset(self::$loggers[$idx]); } } else { unset(self::$loggers[$logger]); } } /** * Clears the registry */ public static function clear(): void { self::$loggers = []; } /** * Gets Logger instance from the registry * * @param string $name Name of the requested Logger instance * @throws \InvalidArgumentException If named Logger instance is not in the registry */ public static function getInstance($name): Logger { if (!isset(self::$loggers[$name])) { throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name)); } return self::$loggers[$name]; } /** * Gets Logger instance from the registry via static method call * * @param string $name Name of the requested Logger instance * @param mixed[] $arguments Arguments passed to static method call * @throws \InvalidArgumentException If named Logger instance is not in the registry * @return Logger Requested instance of Logger */ public static function __callStatic($name, $arguments) { return self::getInstance($name); } } __halt_compiler();----SIGNATURE:----H8prqMCkOQT/X0P8HK5HCbyV/4cbvvF9KjkgrdHsqVNAZrytXPMa00SDn/IwBa4Gd73dmqQE0AIlSGjWch8xsMXgc0s/ShlxggyrbMJtVqwaQVGjC7b4g5PnSI9SQMEfegNQRlJVlKYXETUOhOwub6kHJqh2jVXvjI/+dI17KDz172SaxaqcDpk+WEqldM7IYdpg1ciyUN1wTFNgylI0eMjOi4LqFRhZhQUmtm5V1XguXtE+JWClpHEp3kRW/280RAjzZvqHVoL3XQJoMEV28Fn6N/Rl+YtcspYa/HHc52rMgaWdTCTdyTC++zUtCCTXWt8MKsptBlceHKaDgSWBGGma12tz/M7Xq7OC1BVZXXnRdz9kEcFffmtvQjzfKSk91Ia4xXMXeb+YlEfAIfbeMKeI1IwO6jgoK+Toza5p5AKZ4OV4cUzUu5iNuIwsls8BszBpFkVKaaFRMDt6B7wrr5q3cgJhZKKlccgIGLCIrKJvCwcYWIn6B7Ox6NQezDsXB3bYz8/usQRMPPbMIGutdirBYhVJc1DElO3vk+5WRHa3zuUuDOS6g6lnU01S4J9txN4MQ8nhUHHYVbb2Jk0b7YEDMes8c8xRBo4BOdP2pqYa5EzpObySNCvcBB4AsacqWUzVX4UPdgCWLx2j8u5kqXMXss1Iq95LJ1wug+95Ie4=----ATTACHMENT:----Mjk3MTIwMzIyMTU3MTYwOSA4Nzc2NDUxMTcwODQ4MTI4IDc4NDE3OTE1MTkxMjg2MzU=