ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Registry.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog;
13
14use InvalidArgumentException;
15
39{
45 private static $loggers = array();
46
55 public static function addLogger(Logger $logger, $name = null, $overwrite = false)
56 {
57 $name = $name ?: $logger->getName();
58
59 if (isset(self::$loggers[$name]) && !$overwrite) {
60 throw new InvalidArgumentException('Logger with the given name already exists');
61 }
62
63 self::$loggers[$name] = $logger;
64 }
65
71 public static function hasLogger($logger)
72 {
73 if ($logger instanceof Logger) {
74 $index = array_search($logger, self::$loggers, true);
75
76 return false !== $index;
77 } else {
78 return isset(self::$loggers[$logger]);
79 }
80 }
81
87 public static function removeLogger($logger)
88 {
89 if ($logger instanceof Logger) {
90 if (false !== ($idx = array_search($logger, self::$loggers, true))) {
91 unset(self::$loggers[$idx]);
92 }
93 } else {
94 unset(self::$loggers[$logger]);
95 }
96 }
97
101 public static function clear()
102 {
103 self::$loggers = array();
104 }
105
113 public static function getInstance($name)
114 {
115 if (!isset(self::$loggers[$name])) {
116 throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name));
117 }
118
119 return self::$loggers[$name];
120 }
121
130 public static function __callStatic($name, $arguments)
131 {
132 return self::getInstance($name);
133 }
134}
Monolog log channel.
Definition: Logger.php:28
Monolog log registry.
Definition: Registry.php:39
static __callStatic($name, $arguments)
Gets Logger instance from the registry via static method call.
Definition: Registry.php:130
static addLogger(Logger $logger, $name=null, $overwrite=false)
Adds new logging channel to the registry.
Definition: Registry.php:55
static getInstance($name)
Gets Logger instance from the registry.
Definition: Registry.php:113
static hasLogger($logger)
Checks if such logging channel exists by name or instance.
Definition: Registry.php:71
static removeLogger($logger)
Removes instance from registry by name or instance.
Definition: Registry.php:87
static clear()
Clears the registry.
Definition: Registry.php:101