Completed
Push — master ( f778da...5767f1 )
by Roeland
12:07
created

Registry::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
namespace OC\Support\CrashReport;
24
25
use Exception;
26
use OCP\Support\CrashReport\ICollectBreadcrumbs;
27
use OCP\Support\CrashReport\IRegistry;
28
use OCP\Support\CrashReport\IReporter;
29
use Throwable;
30
31
class Registry implements IRegistry {
32
33
	/** @var IReporter[] */
34
	private $reporters = [];
35
36
	/**
37
	 * Register a reporter instance
38
	 *
39
	 * @param IReporter $reporter
40
	 */
41
	public function register(IReporter $reporter) {
42
		$this->reporters[] = $reporter;
43
	}
44
45
	/**
46
	 * Delegate breadcrumb collection to all registered reporters
47
	 *
48
	 * @param string $message
49
	 * @param string $category
50
	 * @param array $context
51
	 *
52
	 * @since 15.0.0
53
	 */
54
	public function delegateBreadcrumb(string $message, string $category, array $context = []) {
55
		foreach ($this->reporters as $reporter) {
56
			if ($reporter instanceof ICollectBreadcrumbs) {
57
				$reporter->collect($message, $category, $context);
58
			}
59
		}
60
	}
61
62
	/**
63
	 * Delegate crash reporting to all registered reporters
64
	 *
65
	 * @param Exception|Throwable $exception
66
	 * @param array $context
67
	 */
68
	public function delegateReport($exception, array $context = []) {
69
		/** @var IReporter $reporter */
70
		foreach ($this->reporters as $reporter) {
71
			$reporter->report($exception, $context);
72
		}
73
	}
74
75
}
76