@@ -39,117 +39,117 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Registry implements IRegistry { |
| 41 | 41 | |
| 42 | - /** @var string[] */ |
|
| 43 | - private $lazyReporters = []; |
|
| 44 | - |
|
| 45 | - /** @var IReporter[] */ |
|
| 46 | - private $reporters = []; |
|
| 47 | - |
|
| 48 | - /** @var IServerContainer */ |
|
| 49 | - private $serverContainer; |
|
| 50 | - |
|
| 51 | - /** @var ILogger */ |
|
| 52 | - private $logger; |
|
| 53 | - |
|
| 54 | - public function __construct(IServerContainer $serverContainer) { |
|
| 55 | - $this->serverContainer = $serverContainer; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Register a reporter instance |
|
| 60 | - * |
|
| 61 | - * @param IReporter $reporter |
|
| 62 | - */ |
|
| 63 | - public function register(IReporter $reporter): void { |
|
| 64 | - $this->reporters[] = $reporter; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function registerLazy(string $class): void { |
|
| 68 | - $this->lazyReporters[] = $class; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Delegate breadcrumb collection to all registered reporters |
|
| 73 | - * |
|
| 74 | - * @param string $message |
|
| 75 | - * @param string $category |
|
| 76 | - * @param array $context |
|
| 77 | - * |
|
| 78 | - * @since 15.0.0 |
|
| 79 | - */ |
|
| 80 | - public function delegateBreadcrumb(string $message, string $category, array $context = []): void { |
|
| 81 | - $this->loadLazyProviders(); |
|
| 82 | - |
|
| 83 | - foreach ($this->reporters as $reporter) { |
|
| 84 | - if ($reporter instanceof ICollectBreadcrumbs) { |
|
| 85 | - $reporter->collect($message, $category, $context); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Delegate crash reporting to all registered reporters |
|
| 92 | - * |
|
| 93 | - * @param Exception|Throwable $exception |
|
| 94 | - * @param array $context |
|
| 95 | - */ |
|
| 96 | - public function delegateReport($exception, array $context = []): void { |
|
| 97 | - $this->loadLazyProviders(); |
|
| 98 | - |
|
| 99 | - foreach ($this->reporters as $reporter) { |
|
| 100 | - $reporter->report($exception, $context); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Delegate a message to all reporters that implement IMessageReporter |
|
| 106 | - * |
|
| 107 | - * @param string $message |
|
| 108 | - * @param array $context |
|
| 109 | - * |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function delegateMessage(string $message, array $context = []): void { |
|
| 113 | - $this->loadLazyProviders(); |
|
| 114 | - |
|
| 115 | - foreach ($this->reporters as $reporter) { |
|
| 116 | - if ($reporter instanceof IMessageReporter) { |
|
| 117 | - $reporter->reportMessage($message, $context); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - private function loadLazyProviders(): void { |
|
| 123 | - while (($class = array_shift($this->lazyReporters)) !== null) { |
|
| 124 | - try { |
|
| 125 | - /** @var IReporter $reporter */ |
|
| 126 | - $reporter = $this->serverContainer->query($class); |
|
| 127 | - } catch (QueryException $e) { |
|
| 128 | - /* |
|
| 42 | + /** @var string[] */ |
|
| 43 | + private $lazyReporters = []; |
|
| 44 | + |
|
| 45 | + /** @var IReporter[] */ |
|
| 46 | + private $reporters = []; |
|
| 47 | + |
|
| 48 | + /** @var IServerContainer */ |
|
| 49 | + private $serverContainer; |
|
| 50 | + |
|
| 51 | + /** @var ILogger */ |
|
| 52 | + private $logger; |
|
| 53 | + |
|
| 54 | + public function __construct(IServerContainer $serverContainer) { |
|
| 55 | + $this->serverContainer = $serverContainer; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Register a reporter instance |
|
| 60 | + * |
|
| 61 | + * @param IReporter $reporter |
|
| 62 | + */ |
|
| 63 | + public function register(IReporter $reporter): void { |
|
| 64 | + $this->reporters[] = $reporter; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function registerLazy(string $class): void { |
|
| 68 | + $this->lazyReporters[] = $class; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Delegate breadcrumb collection to all registered reporters |
|
| 73 | + * |
|
| 74 | + * @param string $message |
|
| 75 | + * @param string $category |
|
| 76 | + * @param array $context |
|
| 77 | + * |
|
| 78 | + * @since 15.0.0 |
|
| 79 | + */ |
|
| 80 | + public function delegateBreadcrumb(string $message, string $category, array $context = []): void { |
|
| 81 | + $this->loadLazyProviders(); |
|
| 82 | + |
|
| 83 | + foreach ($this->reporters as $reporter) { |
|
| 84 | + if ($reporter instanceof ICollectBreadcrumbs) { |
|
| 85 | + $reporter->collect($message, $category, $context); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Delegate crash reporting to all registered reporters |
|
| 92 | + * |
|
| 93 | + * @param Exception|Throwable $exception |
|
| 94 | + * @param array $context |
|
| 95 | + */ |
|
| 96 | + public function delegateReport($exception, array $context = []): void { |
|
| 97 | + $this->loadLazyProviders(); |
|
| 98 | + |
|
| 99 | + foreach ($this->reporters as $reporter) { |
|
| 100 | + $reporter->report($exception, $context); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Delegate a message to all reporters that implement IMessageReporter |
|
| 106 | + * |
|
| 107 | + * @param string $message |
|
| 108 | + * @param array $context |
|
| 109 | + * |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function delegateMessage(string $message, array $context = []): void { |
|
| 113 | + $this->loadLazyProviders(); |
|
| 114 | + |
|
| 115 | + foreach ($this->reporters as $reporter) { |
|
| 116 | + if ($reporter instanceof IMessageReporter) { |
|
| 117 | + $reporter->reportMessage($message, $context); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + private function loadLazyProviders(): void { |
|
| 123 | + while (($class = array_shift($this->lazyReporters)) !== null) { |
|
| 124 | + try { |
|
| 125 | + /** @var IReporter $reporter */ |
|
| 126 | + $reporter = $this->serverContainer->query($class); |
|
| 127 | + } catch (QueryException $e) { |
|
| 128 | + /* |
|
| 129 | 129 | * There is a circular dependency between the logger and the registry, so |
| 130 | 130 | * we can not inject it. Thus the static call. |
| 131 | 131 | */ |
| 132 | - \OC::$server->getLogger()->logException($e, [ |
|
| 133 | - 'message' => 'Could not load lazy crash reporter: ' . $e->getMessage(), |
|
| 134 | - 'level' => ILogger::FATAL, |
|
| 135 | - ]); |
|
| 136 | - } |
|
| 137 | - /** |
|
| 138 | - * Try to register the loaded reporter. Theoretically it could be of a wrong |
|
| 139 | - * type, so we might get a TypeError here that we should catch. |
|
| 140 | - */ |
|
| 141 | - try { |
|
| 142 | - $this->register($reporter); |
|
| 143 | - } catch (Throwable $e) { |
|
| 144 | - /* |
|
| 132 | + \OC::$server->getLogger()->logException($e, [ |
|
| 133 | + 'message' => 'Could not load lazy crash reporter: ' . $e->getMessage(), |
|
| 134 | + 'level' => ILogger::FATAL, |
|
| 135 | + ]); |
|
| 136 | + } |
|
| 137 | + /** |
|
| 138 | + * Try to register the loaded reporter. Theoretically it could be of a wrong |
|
| 139 | + * type, so we might get a TypeError here that we should catch. |
|
| 140 | + */ |
|
| 141 | + try { |
|
| 142 | + $this->register($reporter); |
|
| 143 | + } catch (Throwable $e) { |
|
| 144 | + /* |
|
| 145 | 145 | * There is a circular dependency between the logger and the registry, so |
| 146 | 146 | * we can not inject it. Thus the static call. |
| 147 | 147 | */ |
| 148 | - \OC::$server->getLogger()->logException($e, [ |
|
| 149 | - 'message' => 'Could not register lazy crash reporter: ' . $e->getMessage(), |
|
| 150 | - 'level' => ILogger::FATAL, |
|
| 151 | - ]); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 148 | + \OC::$server->getLogger()->logException($e, [ |
|
| 149 | + 'message' => 'Could not register lazy crash reporter: ' . $e->getMessage(), |
|
| 150 | + 'level' => ILogger::FATAL, |
|
| 151 | + ]); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | } |