| 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\IMessageReporter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use OCP\Support\CrashReport\IRegistry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use OCP\Support\CrashReport\IReporter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Throwable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | class Registry implements IRegistry { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	/** @var IReporter[] */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	private $reporters = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * Register a reporter instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * @param IReporter $reporter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	public function register(IReporter $reporter): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$this->reporters[] = $reporter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * Delegate breadcrumb collection to all registered reporters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 * @param string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	 * @param string $category | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	 * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 * @since 15.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	public function delegateBreadcrumb(string $message, string $category, array $context = []): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		foreach ($this->reporters as $reporter) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			if ($reporter instanceof ICollectBreadcrumbs) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 				$reporter->collect($message, $category, $context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * Delegate crash reporting to all registered reporters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * @param Exception|Throwable $exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	public function delegateReport($exception, array $context = []): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		/** @var IReporter $reporter */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		foreach ($this->reporters as $reporter) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			$reporter->report($exception, $context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * Delegate a message to all reporters that implement IMessageReporter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * @param string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 	public function delegateMessage(string $message, array $context = []): void { | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 		foreach ($this->reporters as $reporter) { | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 			if ($reporter instanceof IMessageReporter) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 				$reporter->reportMessage($message, $context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |  |