* $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:----QByOJrIqN5/T5eHFIg9i/7KCqZRj5PNB5fulOrG77zDDFRU5dcb8SS0+zN2JxRaceOZKCus0MfsNRrQEHoKLDb1FMc4vFOEs7x1uGIX++EY3THvtfptsjkp2pf8PNrC+ysKuEcwRk3TnCO+vWHvs41YBjQDELG7JCeCFimtlRkU4LXnE/YAHnjOUZTmqkrLmnRdLAmlVU5OGv4sq5UlKJ2pyNejMAmz7qKqBytJzWvnjTaR9JxntvzM+0DQjpBf+OVW8WsnQ/9n3vsgEMrB3bLboB8bcbaiLwN1G2jaLIU9OOSr68a7HWmXYAgIg8F1iONG/5v4x8D+0cXmWb2I/K0geZIgVl+u6IkeVFrar03rJ21paTW+3djcMFwTpaS37ZjGpSXyr7JRkiLcvumTBeSkM2/FASTW44HuMyf7Aq5zAhoNX5yRg6DaNIzc+4ndgWLOELM/IM905CFWyzgeFrsZDtYPw/06jlMKDGrxQ/yYIpy7Bixn+X7Fpggw45GorYmNs4/44wKFkZQx1Cr6GQqtWkQ93yD5yMrsL1ZdAO+plk7PlBY/0xO/rgjXYYhBq2s8rc9uEJpkzuQiywElUS24yIRKoel1bSssjXodW7jaMA9WGjHR/zwN7XTR787IEGDpdHCqjkoWpVFMdJ3SFmVAtO7etiLa6cPWiAQja9cg=----ATTACHMENT:----ODQxMDk0Nzc0MDc2MTk5OSAxMjM4MjczNzAzMTQ3NDAyIDU0NDY1Mjg0NDQwMjM0NDY=