PluginProbe
Media Cloud Sync / 1.2.5
Media Cloud Sync v1.2.5
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / monolog / monolog / src / Monolog / Registry.php

Registry.php in Media Cloud Sync 1.2.5, at includes/sdk/google/monolog/monolog/src/Monolog/Registry.php

123 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 /*
5 * This file is part of the Monolog package.
6 *
7 * (c) Jordi Boggiano <[email protected]>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12 namespace Dudlewebs\WPMCS\Monolog;
13
14 use InvalidArgumentException;
15 /**
16 * Monolog log registry
17 *
18 * Allows to get `Logger` instances in the global scope
19 * via static method calls on this class.
20 *
21 * <code>
22 * $application = new Monolog\Logger('application');
23 * $api = new Monolog\Logger('api');
24 *
25 * Monolog\Registry::addLogger($application);
26 * Monolog\Registry::addLogger($api);
27 *
28 * function testLogger()
29 * {
30 * Monolog\Registry::api()->error('Sent to $api Logger instance');
31 * Monolog\Registry::application()->error('Sent to $application Logger instance');
32 * }
33 * </code>
34 *
35 * @author Tomas Tatarko <[email protected]>
36 */
37 class Registry
38 {
39 /**
40 * List of all loggers in the registry (by named indexes)
41 *
42 * @var Logger[]
43 */
44 private static $loggers = [];
45 /**
46 * Adds new logging channel to the registry
47 *
48 * @param Logger $logger Instance of the logging channel
49 * @param string|null $name Name of the logging channel ($logger->getName() by default)
50 * @param bool $overwrite Overwrite instance in the registry if the given name already exists?
51 * @throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists
52 * @return void
53 */
54 public static function addLogger(Logger $logger, ?string $name = null, bool $overwrite = \false)
55 {
56 $name = $name ?: $logger->getName();
57 if (isset(self::$loggers[$name]) && !$overwrite) {
58 throw new InvalidArgumentException('Logger with the given name already exists');
59 }
60 self::$loggers[$name] = $logger;
61 }
62 /**
63 * Checks if such logging channel exists by name or instance
64 *
65 * @param string|Logger $logger Name or logger instance
66 */
67 public static function hasLogger($logger): bool
68 {
69 if ($logger instanceof Logger) {
70 $index = array_search($logger, self::$loggers, \true);
71 return \false !== $index;
72 }
73 return isset(self::$loggers[$logger]);
74 }
75 /**
76 * Removes instance from registry by name or instance
77 *
78 * @param string|Logger $logger Name or logger instance
79 */
80 public static function removeLogger($logger): void
81 {
82 if ($logger instanceof Logger) {
83 if (\false !== $idx = array_search($logger, self::$loggers, \true)) {
84 unset(self::$loggers[$idx]);
85 }
86 } else {
87 unset(self::$loggers[$logger]);
88 }
89 }
90 /**
91 * Clears the registry
92 */
93 public static function clear(): void
94 {
95 self::$loggers = [];
96 }
97 /**
98 * Gets Logger instance from the registry
99 *
100 * @param string $name Name of the requested Logger instance
101 * @throws \InvalidArgumentException If named Logger instance is not in the registry
102 */
103 public static function getInstance($name): Logger
104 {
105 if (!isset(self::$loggers[$name])) {
106 throw new InvalidArgumentException(sprintf('Requested "%s" logger instance is not in the registry', $name));
107 }
108 return self::$loggers[$name];
109 }
110 /**
111 * Gets Logger instance from the registry via static method call
112 *
113 * @param string $name Name of the requested Logger instance
114 * @param mixed[] $arguments Arguments passed to static method call
115 * @throws \InvalidArgumentException If named Logger instance is not in the registry
116 * @return Logger Requested instance of Logger
117 */
118 public static function __callStatic($name, $arguments)
119 {
120 return self::getInstance($name);
121 }
122 }
123