@@ -46,163 +46,163 @@ |
||
| 46 | 46 | use Throwable; |
| 47 | 47 | |
| 48 | 48 | class Coordinator { |
| 49 | - /** @var IServerContainer */ |
|
| 50 | - private $serverContainer; |
|
| 51 | - |
|
| 52 | - /** @var Registry */ |
|
| 53 | - private $registry; |
|
| 54 | - |
|
| 55 | - /** @var IManager */ |
|
| 56 | - private $dashboardManager; |
|
| 57 | - |
|
| 58 | - /** @var IEventDispatcher */ |
|
| 59 | - private $eventDispatcher; |
|
| 60 | - |
|
| 61 | - /** @var IEventLogger */ |
|
| 62 | - private $eventLogger; |
|
| 63 | - |
|
| 64 | - /** @var LoggerInterface */ |
|
| 65 | - private $logger; |
|
| 66 | - |
|
| 67 | - /** @var RegistrationContext|null */ |
|
| 68 | - private $registrationContext; |
|
| 69 | - |
|
| 70 | - /** @var string[] */ |
|
| 71 | - private $bootedApps = []; |
|
| 72 | - |
|
| 73 | - public function __construct( |
|
| 74 | - IServerContainer $container, |
|
| 75 | - Registry $registry, |
|
| 76 | - IManager $dashboardManager, |
|
| 77 | - IEventDispatcher $eventListener, |
|
| 78 | - IEventLogger $eventLogger, |
|
| 79 | - LoggerInterface $logger |
|
| 80 | - ) { |
|
| 81 | - $this->serverContainer = $container; |
|
| 82 | - $this->registry = $registry; |
|
| 83 | - $this->dashboardManager = $dashboardManager; |
|
| 84 | - $this->eventDispatcher = $eventListener; |
|
| 85 | - $this->eventLogger = $eventLogger; |
|
| 86 | - $this->logger = $logger; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function runInitialRegistration(): void { |
|
| 90 | - $this->registerApps(OC_App::getEnabledApps()); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function runLazyRegistration(string $appId): void { |
|
| 94 | - $this->registerApps([$appId]); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param string[] $appIds |
|
| 99 | - */ |
|
| 100 | - private function registerApps(array $appIds): void { |
|
| 101 | - if ($this->registrationContext === null) { |
|
| 102 | - $this->registrationContext = new RegistrationContext($this->logger); |
|
| 103 | - } |
|
| 104 | - $apps = []; |
|
| 105 | - foreach ($appIds as $appId) { |
|
| 106 | - /* |
|
| 49 | + /** @var IServerContainer */ |
|
| 50 | + private $serverContainer; |
|
| 51 | + |
|
| 52 | + /** @var Registry */ |
|
| 53 | + private $registry; |
|
| 54 | + |
|
| 55 | + /** @var IManager */ |
|
| 56 | + private $dashboardManager; |
|
| 57 | + |
|
| 58 | + /** @var IEventDispatcher */ |
|
| 59 | + private $eventDispatcher; |
|
| 60 | + |
|
| 61 | + /** @var IEventLogger */ |
|
| 62 | + private $eventLogger; |
|
| 63 | + |
|
| 64 | + /** @var LoggerInterface */ |
|
| 65 | + private $logger; |
|
| 66 | + |
|
| 67 | + /** @var RegistrationContext|null */ |
|
| 68 | + private $registrationContext; |
|
| 69 | + |
|
| 70 | + /** @var string[] */ |
|
| 71 | + private $bootedApps = []; |
|
| 72 | + |
|
| 73 | + public function __construct( |
|
| 74 | + IServerContainer $container, |
|
| 75 | + Registry $registry, |
|
| 76 | + IManager $dashboardManager, |
|
| 77 | + IEventDispatcher $eventListener, |
|
| 78 | + IEventLogger $eventLogger, |
|
| 79 | + LoggerInterface $logger |
|
| 80 | + ) { |
|
| 81 | + $this->serverContainer = $container; |
|
| 82 | + $this->registry = $registry; |
|
| 83 | + $this->dashboardManager = $dashboardManager; |
|
| 84 | + $this->eventDispatcher = $eventListener; |
|
| 85 | + $this->eventLogger = $eventLogger; |
|
| 86 | + $this->logger = $logger; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function runInitialRegistration(): void { |
|
| 90 | + $this->registerApps(OC_App::getEnabledApps()); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function runLazyRegistration(string $appId): void { |
|
| 94 | + $this->registerApps([$appId]); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param string[] $appIds |
|
| 99 | + */ |
|
| 100 | + private function registerApps(array $appIds): void { |
|
| 101 | + if ($this->registrationContext === null) { |
|
| 102 | + $this->registrationContext = new RegistrationContext($this->logger); |
|
| 103 | + } |
|
| 104 | + $apps = []; |
|
| 105 | + foreach ($appIds as $appId) { |
|
| 106 | + /* |
|
| 107 | 107 | * First, we have to enable the app's autoloader |
| 108 | 108 | * |
| 109 | 109 | * @todo use $this->appManager->getAppPath($appId) here |
| 110 | 110 | */ |
| 111 | - $path = OC_App::getAppPath($appId); |
|
| 112 | - if ($path === false) { |
|
| 113 | - // Ignore |
|
| 114 | - continue; |
|
| 115 | - } |
|
| 116 | - OC_App::registerAutoloading($appId, $path); |
|
| 117 | - |
|
| 118 | - /* |
|
| 111 | + $path = OC_App::getAppPath($appId); |
|
| 112 | + if ($path === false) { |
|
| 113 | + // Ignore |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 116 | + OC_App::registerAutoloading($appId, $path); |
|
| 117 | + |
|
| 118 | + /* |
|
| 119 | 119 | * Next we check if there is an application class and it implements |
| 120 | 120 | * the \OCP\AppFramework\Bootstrap\IBootstrap interface |
| 121 | 121 | */ |
| 122 | - $appNameSpace = App::buildAppNamespace($appId); |
|
| 123 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 124 | - try { |
|
| 125 | - if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
|
| 126 | - try { |
|
| 127 | - /** @var IBootstrap|App $application */ |
|
| 128 | - $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); |
|
| 129 | - } catch (QueryException $e) { |
|
| 130 | - // Weird, but ok |
|
| 131 | - continue; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $this->eventLogger->start('bootstrap:register_app_' . $appId, ''); |
|
| 135 | - $application->register($this->registrationContext->for($appId)); |
|
| 136 | - $this->eventLogger->end('bootstrap:register_app_' . $appId); |
|
| 137 | - } |
|
| 138 | - } catch (Throwable $e) { |
|
| 139 | - $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ |
|
| 140 | - 'exception' => $e, |
|
| 141 | - 'app' => $appId, |
|
| 142 | - ]); |
|
| 143 | - continue; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Now that all register methods have been called, we can delegate the registrations |
|
| 149 | - * to the actual services |
|
| 150 | - */ |
|
| 151 | - $this->registrationContext->delegateCapabilityRegistrations($apps); |
|
| 152 | - $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); |
|
| 153 | - $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager); |
|
| 154 | - $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); |
|
| 155 | - $this->registrationContext->delegateContainerRegistrations($apps); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function getRegistrationContext(): ?RegistrationContext { |
|
| 159 | - return $this->registrationContext; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function bootApp(string $appId): void { |
|
| 163 | - if (isset($this->bootedApps[$appId])) { |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - $this->bootedApps[$appId] = true; |
|
| 167 | - |
|
| 168 | - $appNameSpace = App::buildAppNamespace($appId); |
|
| 169 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 170 | - if (!class_exists($applicationClassName)) { |
|
| 171 | - // Nothing to boot |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /* |
|
| 122 | + $appNameSpace = App::buildAppNamespace($appId); |
|
| 123 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 124 | + try { |
|
| 125 | + if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
|
| 126 | + try { |
|
| 127 | + /** @var IBootstrap|App $application */ |
|
| 128 | + $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); |
|
| 129 | + } catch (QueryException $e) { |
|
| 130 | + // Weird, but ok |
|
| 131 | + continue; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $this->eventLogger->start('bootstrap:register_app_' . $appId, ''); |
|
| 135 | + $application->register($this->registrationContext->for($appId)); |
|
| 136 | + $this->eventLogger->end('bootstrap:register_app_' . $appId); |
|
| 137 | + } |
|
| 138 | + } catch (Throwable $e) { |
|
| 139 | + $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ |
|
| 140 | + 'exception' => $e, |
|
| 141 | + 'app' => $appId, |
|
| 142 | + ]); |
|
| 143 | + continue; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Now that all register methods have been called, we can delegate the registrations |
|
| 149 | + * to the actual services |
|
| 150 | + */ |
|
| 151 | + $this->registrationContext->delegateCapabilityRegistrations($apps); |
|
| 152 | + $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); |
|
| 153 | + $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager); |
|
| 154 | + $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); |
|
| 155 | + $this->registrationContext->delegateContainerRegistrations($apps); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function getRegistrationContext(): ?RegistrationContext { |
|
| 159 | + return $this->registrationContext; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + public function bootApp(string $appId): void { |
|
| 163 | + if (isset($this->bootedApps[$appId])) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + $this->bootedApps[$appId] = true; |
|
| 167 | + |
|
| 168 | + $appNameSpace = App::buildAppNamespace($appId); |
|
| 169 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 170 | + if (!class_exists($applicationClassName)) { |
|
| 171 | + // Nothing to boot |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /* |
|
| 176 | 176 | * Now it is time to fetch an instance of the App class. For classes |
| 177 | 177 | * that implement \OCP\AppFramework\Bootstrap\IBootstrap this means |
| 178 | 178 | * the instance was already created for register, but any other |
| 179 | 179 | * (legacy) code will now do their magic via the constructor. |
| 180 | 180 | */ |
| 181 | - $this->eventLogger->start('bootstrap:boot_app_' . $appId, ''); |
|
| 182 | - try { |
|
| 183 | - /** @var App $application */ |
|
| 184 | - $application = $this->serverContainer->query($applicationClassName); |
|
| 185 | - if ($application instanceof IBootstrap) { |
|
| 186 | - /** @var BootContext $context */ |
|
| 187 | - $context = new BootContext($application->getContainer()); |
|
| 188 | - $application->boot($context); |
|
| 189 | - } |
|
| 190 | - } catch (QueryException $e) { |
|
| 191 | - $this->logger->error("Could not boot $appId: " . $e->getMessage(), [ |
|
| 192 | - 'exception' => $e, |
|
| 193 | - ]); |
|
| 194 | - } catch (Throwable $e) { |
|
| 195 | - $this->logger->emergency("Could not boot $appId: " . $e->getMessage(), [ |
|
| 196 | - 'exception' => $e, |
|
| 197 | - ]); |
|
| 198 | - } |
|
| 199 | - $this->eventLogger->end('bootstrap:boot_app_' . $appId); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - public function isBootable(string $appId) { |
|
| 203 | - $appNameSpace = App::buildAppNamespace($appId); |
|
| 204 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 205 | - return class_exists($applicationClassName) && |
|
| 206 | - in_array(IBootstrap::class, class_implements($applicationClassName), true); |
|
| 207 | - } |
|
| 181 | + $this->eventLogger->start('bootstrap:boot_app_' . $appId, ''); |
|
| 182 | + try { |
|
| 183 | + /** @var App $application */ |
|
| 184 | + $application = $this->serverContainer->query($applicationClassName); |
|
| 185 | + if ($application instanceof IBootstrap) { |
|
| 186 | + /** @var BootContext $context */ |
|
| 187 | + $context = new BootContext($application->getContainer()); |
|
| 188 | + $application->boot($context); |
|
| 189 | + } |
|
| 190 | + } catch (QueryException $e) { |
|
| 191 | + $this->logger->error("Could not boot $appId: " . $e->getMessage(), [ |
|
| 192 | + 'exception' => $e, |
|
| 193 | + ]); |
|
| 194 | + } catch (Throwable $e) { |
|
| 195 | + $this->logger->emergency("Could not boot $appId: " . $e->getMessage(), [ |
|
| 196 | + 'exception' => $e, |
|
| 197 | + ]); |
|
| 198 | + } |
|
| 199 | + $this->eventLogger->end('bootstrap:boot_app_' . $appId); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + public function isBootable(string $appId) { |
|
| 203 | + $appNameSpace = App::buildAppNamespace($appId); |
|
| 204 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 205 | + return class_exists($applicationClassName) && |
|
| 206 | + in_array(IBootstrap::class, class_implements($applicationClassName), true); |
|
| 207 | + } |
|
| 208 | 208 | } |
@@ -58,683 +58,683 @@ |
||
| 58 | 58 | use Throwable; |
| 59 | 59 | |
| 60 | 60 | class RegistrationContext { |
| 61 | - /** @var ServiceRegistration<ICapability>[] */ |
|
| 62 | - private $capabilities = []; |
|
| 61 | + /** @var ServiceRegistration<ICapability>[] */ |
|
| 62 | + private $capabilities = []; |
|
| 63 | 63 | |
| 64 | - /** @var ServiceRegistration<IReporter>[] */ |
|
| 65 | - private $crashReporters = []; |
|
| 64 | + /** @var ServiceRegistration<IReporter>[] */ |
|
| 65 | + private $crashReporters = []; |
|
| 66 | 66 | |
| 67 | - /** @var ServiceRegistration<IWidget>[] */ |
|
| 68 | - private $dashboardPanels = []; |
|
| 67 | + /** @var ServiceRegistration<IWidget>[] */ |
|
| 68 | + private $dashboardPanels = []; |
|
| 69 | 69 | |
| 70 | - /** @var ServiceRegistration<ILinkAction>[] */ |
|
| 71 | - private $profileLinkActions = []; |
|
| 70 | + /** @var ServiceRegistration<ILinkAction>[] */ |
|
| 71 | + private $profileLinkActions = []; |
|
| 72 | 72 | |
| 73 | - /** @var null|ServiceRegistration<ITalkBackend> */ |
|
| 74 | - private $talkBackendRegistration = null; |
|
| 73 | + /** @var null|ServiceRegistration<ITalkBackend> */ |
|
| 74 | + private $talkBackendRegistration = null; |
|
| 75 | 75 | |
| 76 | - /** @var ServiceRegistration<IResourceBackend>[] */ |
|
| 77 | - private $calendarResourceBackendRegistrations = []; |
|
| 76 | + /** @var ServiceRegistration<IResourceBackend>[] */ |
|
| 77 | + private $calendarResourceBackendRegistrations = []; |
|
| 78 | 78 | |
| 79 | - /** @var ServiceRegistration<IRoomBackend>[] */ |
|
| 80 | - private $calendarRoomBackendRegistrations = []; |
|
| 79 | + /** @var ServiceRegistration<IRoomBackend>[] */ |
|
| 80 | + private $calendarRoomBackendRegistrations = []; |
|
| 81 | 81 | |
| 82 | - /** @var ServiceRegistration<IUserMigrator>[] */ |
|
| 83 | - private $userMigrators = []; |
|
| 82 | + /** @var ServiceRegistration<IUserMigrator>[] */ |
|
| 83 | + private $userMigrators = []; |
|
| 84 | 84 | |
| 85 | - /** @var ServiceFactoryRegistration[] */ |
|
| 86 | - private $services = []; |
|
| 85 | + /** @var ServiceFactoryRegistration[] */ |
|
| 86 | + private $services = []; |
|
| 87 | 87 | |
| 88 | - /** @var ServiceAliasRegistration[] */ |
|
| 89 | - private $aliases = []; |
|
| 88 | + /** @var ServiceAliasRegistration[] */ |
|
| 89 | + private $aliases = []; |
|
| 90 | 90 | |
| 91 | - /** @var ParameterRegistration[] */ |
|
| 92 | - private $parameters = []; |
|
| 91 | + /** @var ParameterRegistration[] */ |
|
| 92 | + private $parameters = []; |
|
| 93 | 93 | |
| 94 | - /** @var EventListenerRegistration[] */ |
|
| 95 | - private $eventListeners = []; |
|
| 94 | + /** @var EventListenerRegistration[] */ |
|
| 95 | + private $eventListeners = []; |
|
| 96 | 96 | |
| 97 | - /** @var ServiceRegistration<Middleware>[] */ |
|
| 98 | - private $middlewares = []; |
|
| 97 | + /** @var ServiceRegistration<Middleware>[] */ |
|
| 98 | + private $middlewares = []; |
|
| 99 | 99 | |
| 100 | - /** @var ServiceRegistration<IProvider>[] */ |
|
| 101 | - private $searchProviders = []; |
|
| 100 | + /** @var ServiceRegistration<IProvider>[] */ |
|
| 101 | + private $searchProviders = []; |
|
| 102 | 102 | |
| 103 | - /** @var ServiceRegistration<IAlternativeLogin>[] */ |
|
| 104 | - private $alternativeLogins = []; |
|
| 105 | - |
|
| 106 | - /** @var ServiceRegistration<InitialStateProvider>[] */ |
|
| 107 | - private $initialStates = []; |
|
| 108 | - |
|
| 109 | - /** @var ServiceRegistration<IHandler>[] */ |
|
| 110 | - private $wellKnownHandlers = []; |
|
| 111 | - |
|
| 112 | - /** @var ServiceRegistration<ICustomTemplateProvider>[] */ |
|
| 113 | - private $templateProviders = []; |
|
| 114 | - |
|
| 115 | - /** @var ServiceRegistration<INotifier>[] */ |
|
| 116 | - private $notifierServices = []; |
|
| 117 | - |
|
| 118 | - /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ |
|
| 119 | - private $twoFactorProviders = []; |
|
| 120 | - |
|
| 121 | - /** @var ServiceRegistration<ICalendarProvider>[] */ |
|
| 122 | - private $calendarProviders = []; |
|
| 123 | - |
|
| 124 | - /** @var ServiceRegistration<IReferenceProvider>[] */ |
|
| 125 | - private array $referenceProviders = []; |
|
| 126 | - |
|
| 127 | - /** @var ParameterRegistration[] */ |
|
| 128 | - private $sensitiveMethods = []; |
|
| 129 | - |
|
| 130 | - /** @var LoggerInterface */ |
|
| 131 | - private $logger; |
|
| 132 | - |
|
| 133 | - /** @var PreviewProviderRegistration[] */ |
|
| 134 | - private $previewProviders = []; |
|
| 135 | - |
|
| 136 | - public function __construct(LoggerInterface $logger) { |
|
| 137 | - $this->logger = $logger; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function for(string $appId): IRegistrationContext { |
|
| 141 | - return new class($appId, $this) implements IRegistrationContext { |
|
| 142 | - /** @var string */ |
|
| 143 | - private $appId; |
|
| 144 | - |
|
| 145 | - /** @var RegistrationContext */ |
|
| 146 | - private $context; |
|
| 147 | - |
|
| 148 | - public function __construct(string $appId, RegistrationContext $context) { |
|
| 149 | - $this->appId = $appId; |
|
| 150 | - $this->context = $context; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - public function registerCapability(string $capability): void { |
|
| 154 | - $this->context->registerCapability( |
|
| 155 | - $this->appId, |
|
| 156 | - $capability |
|
| 157 | - ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function registerCrashReporter(string $reporterClass): void { |
|
| 161 | - $this->context->registerCrashReporter( |
|
| 162 | - $this->appId, |
|
| 163 | - $reporterClass |
|
| 164 | - ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - public function registerDashboardWidget(string $widgetClass): void { |
|
| 168 | - $this->context->registerDashboardPanel( |
|
| 169 | - $this->appId, |
|
| 170 | - $widgetClass |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - public function registerService(string $name, callable $factory, bool $shared = true): void { |
|
| 175 | - $this->context->registerService( |
|
| 176 | - $this->appId, |
|
| 177 | - $name, |
|
| 178 | - $factory, |
|
| 179 | - $shared |
|
| 180 | - ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - public function registerServiceAlias(string $alias, string $target): void { |
|
| 184 | - $this->context->registerServiceAlias( |
|
| 185 | - $this->appId, |
|
| 186 | - $alias, |
|
| 187 | - $target |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - public function registerParameter(string $name, $value): void { |
|
| 192 | - $this->context->registerParameter( |
|
| 193 | - $this->appId, |
|
| 194 | - $name, |
|
| 195 | - $value |
|
| 196 | - ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
|
| 200 | - $this->context->registerEventListener( |
|
| 201 | - $this->appId, |
|
| 202 | - $event, |
|
| 203 | - $listener, |
|
| 204 | - $priority |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - public function registerMiddleware(string $class): void { |
|
| 209 | - $this->context->registerMiddleware( |
|
| 210 | - $this->appId, |
|
| 211 | - $class |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - public function registerSearchProvider(string $class): void { |
|
| 216 | - $this->context->registerSearchProvider( |
|
| 217 | - $this->appId, |
|
| 218 | - $class |
|
| 219 | - ); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - public function registerAlternativeLogin(string $class): void { |
|
| 223 | - $this->context->registerAlternativeLogin( |
|
| 224 | - $this->appId, |
|
| 225 | - $class |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - public function registerInitialStateProvider(string $class): void { |
|
| 230 | - $this->context->registerInitialState( |
|
| 231 | - $this->appId, |
|
| 232 | - $class |
|
| 233 | - ); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - public function registerWellKnownHandler(string $class): void { |
|
| 237 | - $this->context->registerWellKnown( |
|
| 238 | - $this->appId, |
|
| 239 | - $class |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - public function registerTemplateProvider(string $providerClass): void { |
|
| 244 | - $this->context->registerTemplateProvider( |
|
| 245 | - $this->appId, |
|
| 246 | - $providerClass |
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function registerNotifierService(string $notifierClass): void { |
|
| 251 | - $this->context->registerNotifierService( |
|
| 252 | - $this->appId, |
|
| 253 | - $notifierClass |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - public function registerTwoFactorProvider(string $twoFactorProviderClass): void { |
|
| 258 | - $this->context->registerTwoFactorProvider( |
|
| 259 | - $this->appId, |
|
| 260 | - $twoFactorProviderClass |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - public function registerPreviewProvider(string $previewProviderClass, string $mimeTypeRegex): void { |
|
| 265 | - $this->context->registerPreviewProvider( |
|
| 266 | - $this->appId, |
|
| 267 | - $previewProviderClass, |
|
| 268 | - $mimeTypeRegex |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - public function registerCalendarProvider(string $class): void { |
|
| 273 | - $this->context->registerCalendarProvider( |
|
| 274 | - $this->appId, |
|
| 275 | - $class |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - public function registerReferenceProvider(string $class): void { |
|
| 280 | - $this->context->registerReferenceProvider( |
|
| 281 | - $this->appId, |
|
| 282 | - $class |
|
| 283 | - ); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - public function registerProfileLinkAction(string $actionClass): void { |
|
| 287 | - $this->context->registerProfileLinkAction( |
|
| 288 | - $this->appId, |
|
| 289 | - $actionClass |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - public function registerTalkBackend(string $backend): void { |
|
| 294 | - $this->context->registerTalkBackend( |
|
| 295 | - $this->appId, |
|
| 296 | - $backend |
|
| 297 | - ); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - public function registerCalendarResourceBackend(string $class): void { |
|
| 301 | - $this->context->registerCalendarResourceBackend( |
|
| 302 | - $this->appId, |
|
| 303 | - $class |
|
| 304 | - ); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - public function registerCalendarRoomBackend(string $class): void { |
|
| 308 | - $this->context->registerCalendarRoomBackend( |
|
| 309 | - $this->appId, |
|
| 310 | - $class |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - public function registerUserMigrator(string $migratorClass): void { |
|
| 315 | - $this->context->registerUserMigrator( |
|
| 316 | - $this->appId, |
|
| 317 | - $migratorClass |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - public function registerSensitiveMethods(string $class, array $methods): void { |
|
| 322 | - $this->context->registerSensitiveMethods( |
|
| 323 | - $this->appId, |
|
| 324 | - $class, |
|
| 325 | - $methods |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - }; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @psalm-param class-string<ICapability> $capability |
|
| 333 | - */ |
|
| 334 | - public function registerCapability(string $appId, string $capability): void { |
|
| 335 | - $this->capabilities[] = new ServiceRegistration($appId, $capability); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @psalm-param class-string<IReporter> $capability |
|
| 340 | - */ |
|
| 341 | - public function registerCrashReporter(string $appId, string $reporterClass): void { |
|
| 342 | - $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @psalm-param class-string<IWidget> $capability |
|
| 347 | - */ |
|
| 348 | - public function registerDashboardPanel(string $appId, string $panelClass): void { |
|
| 349 | - $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
|
| 353 | - $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - public function registerServiceAlias(string $appId, string $alias, string $target): void { |
|
| 357 | - $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - public function registerParameter(string $appId, string $name, $value): void { |
|
| 361 | - $this->parameters[] = new ParameterRegistration($appId, $name, $value); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
|
| 365 | - $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @psalm-param class-string<Middleware> $class |
|
| 370 | - */ |
|
| 371 | - public function registerMiddleware(string $appId, string $class): void { |
|
| 372 | - $this->middlewares[] = new ServiceRegistration($appId, $class); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - public function registerSearchProvider(string $appId, string $class) { |
|
| 376 | - $this->searchProviders[] = new ServiceRegistration($appId, $class); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - public function registerAlternativeLogin(string $appId, string $class): void { |
|
| 380 | - $this->alternativeLogins[] = new ServiceRegistration($appId, $class); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - public function registerInitialState(string $appId, string $class): void { |
|
| 384 | - $this->initialStates[] = new ServiceRegistration($appId, $class); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - public function registerWellKnown(string $appId, string $class): void { |
|
| 388 | - $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - public function registerTemplateProvider(string $appId, string $class): void { |
|
| 392 | - $this->templateProviders[] = new ServiceRegistration($appId, $class); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - public function registerNotifierService(string $appId, string $class): void { |
|
| 396 | - $this->notifierServices[] = new ServiceRegistration($appId, $class); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - public function registerTwoFactorProvider(string $appId, string $class): void { |
|
| 400 | - $this->twoFactorProviders[] = new ServiceRegistration($appId, $class); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - public function registerPreviewProvider(string $appId, string $class, string $mimeTypeRegex): void { |
|
| 404 | - $this->previewProviders[] = new PreviewProviderRegistration($appId, $class, $mimeTypeRegex); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - public function registerCalendarProvider(string $appId, string $class): void { |
|
| 408 | - $this->calendarProviders[] = new ServiceRegistration($appId, $class); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - public function registerReferenceProvider(string $appId, string $class): void { |
|
| 412 | - $this->referenceProviders[] = new ServiceRegistration($appId, $class); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @psalm-param class-string<ILinkAction> $actionClass |
|
| 417 | - */ |
|
| 418 | - public function registerProfileLinkAction(string $appId, string $actionClass): void { |
|
| 419 | - $this->profileLinkActions[] = new ServiceRegistration($appId, $actionClass); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * @psalm-param class-string<ITalkBackend> $backend |
|
| 424 | - */ |
|
| 425 | - public function registerTalkBackend(string $appId, string $backend) { |
|
| 426 | - // Some safeguards for invalid registrations |
|
| 427 | - if ($appId !== 'spreed') { |
|
| 428 | - throw new RuntimeException("Only the Talk app is allowed to register a Talk backend"); |
|
| 429 | - } |
|
| 430 | - if ($this->talkBackendRegistration !== null) { |
|
| 431 | - throw new RuntimeException("There can only be one Talk backend"); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - $this->talkBackendRegistration = new ServiceRegistration($appId, $backend); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - public function registerCalendarResourceBackend(string $appId, string $class) { |
|
| 438 | - $this->calendarResourceBackendRegistrations[] = new ServiceRegistration( |
|
| 439 | - $appId, |
|
| 440 | - $class, |
|
| 441 | - ); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - public function registerCalendarRoomBackend(string $appId, string $class) { |
|
| 445 | - $this->calendarRoomBackendRegistrations[] = new ServiceRegistration( |
|
| 446 | - $appId, |
|
| 447 | - $class, |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @psalm-param class-string<IUserMigrator> $migratorClass |
|
| 453 | - */ |
|
| 454 | - public function registerUserMigrator(string $appId, string $migratorClass): void { |
|
| 455 | - $this->userMigrators[] = new ServiceRegistration($appId, $migratorClass); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - public function registerSensitiveMethods(string $appId, string $class, array $methods): void { |
|
| 459 | - $methods = array_filter($methods, 'is_string'); |
|
| 460 | - $this->sensitiveMethods[] = new ParameterRegistration($appId, $class, $methods); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @param App[] $apps |
|
| 465 | - */ |
|
| 466 | - public function delegateCapabilityRegistrations(array $apps): void { |
|
| 467 | - while (($registration = array_shift($this->capabilities)) !== null) { |
|
| 468 | - $appId = $registration->getAppId(); |
|
| 469 | - if (!isset($apps[$appId])) { |
|
| 470 | - // If we land here something really isn't right. But at least we caught the |
|
| 471 | - // notice that is otherwise emitted for the undefined index |
|
| 472 | - $this->logger->error("App $appId not loaded for the capability registration"); |
|
| 473 | - |
|
| 474 | - continue; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - try { |
|
| 478 | - $apps[$appId] |
|
| 479 | - ->getContainer() |
|
| 480 | - ->registerCapability($registration->getService()); |
|
| 481 | - } catch (Throwable $e) { |
|
| 482 | - $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ |
|
| 483 | - 'exception' => $e, |
|
| 484 | - ]); |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @param App[] $apps |
|
| 491 | - */ |
|
| 492 | - public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
| 493 | - while (($registration = array_shift($this->crashReporters)) !== null) { |
|
| 494 | - try { |
|
| 495 | - $registry->registerLazy($registration->getService()); |
|
| 496 | - } catch (Throwable $e) { |
|
| 497 | - $appId = $registration->getAppId(); |
|
| 498 | - $this->logger->error("Error during crash reporter registration of $appId: " . $e->getMessage(), [ |
|
| 499 | - 'exception' => $e, |
|
| 500 | - ]); |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * @param App[] $apps |
|
| 507 | - */ |
|
| 508 | - public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void { |
|
| 509 | - while (($panel = array_shift($this->dashboardPanels)) !== null) { |
|
| 510 | - try { |
|
| 511 | - $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId()); |
|
| 512 | - } catch (Throwable $e) { |
|
| 513 | - $appId = $panel->getAppId(); |
|
| 514 | - $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ |
|
| 515 | - 'exception' => $e, |
|
| 516 | - ]); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
|
| 522 | - while (($registration = array_shift($this->eventListeners)) !== null) { |
|
| 523 | - try { |
|
| 524 | - $eventDispatcher->addServiceListener( |
|
| 525 | - $registration->getEvent(), |
|
| 526 | - $registration->getService(), |
|
| 527 | - $registration->getPriority() |
|
| 528 | - ); |
|
| 529 | - } catch (Throwable $e) { |
|
| 530 | - $appId = $registration->getAppId(); |
|
| 531 | - $this->logger->error("Error during event listener registration of $appId: " . $e->getMessage(), [ |
|
| 532 | - 'exception' => $e, |
|
| 533 | - ]); |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @param App[] $apps |
|
| 540 | - */ |
|
| 541 | - public function delegateContainerRegistrations(array $apps): void { |
|
| 542 | - while (($registration = array_shift($this->services)) !== null) { |
|
| 543 | - $appId = $registration->getAppId(); |
|
| 544 | - if (!isset($apps[$appId])) { |
|
| 545 | - // If we land here something really isn't right. But at least we caught the |
|
| 546 | - // notice that is otherwise emitted for the undefined index |
|
| 547 | - $this->logger->error("App $appId not loaded for the container service registration"); |
|
| 548 | - |
|
| 549 | - continue; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - try { |
|
| 553 | - /** |
|
| 554 | - * Register the service and convert the callable into a \Closure if necessary |
|
| 555 | - */ |
|
| 556 | - $apps[$appId] |
|
| 557 | - ->getContainer() |
|
| 558 | - ->registerService( |
|
| 559 | - $registration->getName(), |
|
| 560 | - Closure::fromCallable($registration->getFactory()), |
|
| 561 | - $registration->isShared() |
|
| 562 | - ); |
|
| 563 | - } catch (Throwable $e) { |
|
| 564 | - $this->logger->error("Error during service registration of $appId: " . $e->getMessage(), [ |
|
| 565 | - 'exception' => $e, |
|
| 566 | - ]); |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - while (($registration = array_shift($this->aliases)) !== null) { |
|
| 571 | - $appId = $registration->getAppId(); |
|
| 572 | - if (!isset($apps[$appId])) { |
|
| 573 | - // If we land here something really isn't right. But at least we caught the |
|
| 574 | - // notice that is otherwise emitted for the undefined index |
|
| 575 | - $this->logger->error("App $appId not loaded for the container alias registration"); |
|
| 576 | - |
|
| 577 | - continue; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - try { |
|
| 581 | - $apps[$appId] |
|
| 582 | - ->getContainer() |
|
| 583 | - ->registerAlias( |
|
| 584 | - $registration->getAlias(), |
|
| 585 | - $registration->getTarget() |
|
| 586 | - ); |
|
| 587 | - } catch (Throwable $e) { |
|
| 588 | - $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ |
|
| 589 | - 'exception' => $e, |
|
| 590 | - ]); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - while (($registration = array_shift($this->parameters)) !== null) { |
|
| 595 | - $appId = $registration->getAppId(); |
|
| 596 | - if (!isset($apps[$appId])) { |
|
| 597 | - // If we land here something really isn't right. But at least we caught the |
|
| 598 | - // notice that is otherwise emitted for the undefined index |
|
| 599 | - $this->logger->error("App $appId not loaded for the container parameter registration"); |
|
| 600 | - |
|
| 601 | - continue; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - try { |
|
| 605 | - $apps[$appId] |
|
| 606 | - ->getContainer() |
|
| 607 | - ->registerParameter( |
|
| 608 | - $registration->getName(), |
|
| 609 | - $registration->getValue() |
|
| 610 | - ); |
|
| 611 | - } catch (Throwable $e) { |
|
| 612 | - $this->logger->error("Error during service parameter registration of $appId: " . $e->getMessage(), [ |
|
| 613 | - 'exception' => $e, |
|
| 614 | - ]); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * @return ServiceRegistration<Middleware>[] |
|
| 621 | - */ |
|
| 622 | - public function getMiddlewareRegistrations(): array { |
|
| 623 | - return $this->middlewares; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * @return ServiceRegistration<IProvider>[] |
|
| 628 | - */ |
|
| 629 | - public function getSearchProviders(): array { |
|
| 630 | - return $this->searchProviders; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * @return ServiceRegistration<IAlternativeLogin>[] |
|
| 635 | - */ |
|
| 636 | - public function getAlternativeLogins(): array { |
|
| 637 | - return $this->alternativeLogins; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * @return ServiceRegistration<InitialStateProvider>[] |
|
| 642 | - */ |
|
| 643 | - public function getInitialStates(): array { |
|
| 644 | - return $this->initialStates; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * @return ServiceRegistration<IHandler>[] |
|
| 649 | - */ |
|
| 650 | - public function getWellKnownHandlers(): array { |
|
| 651 | - return $this->wellKnownHandlers; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * @return ServiceRegistration<ICustomTemplateProvider>[] |
|
| 656 | - */ |
|
| 657 | - public function getTemplateProviders(): array { |
|
| 658 | - return $this->templateProviders; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @return ServiceRegistration<INotifier>[] |
|
| 663 | - */ |
|
| 664 | - public function getNotifierServices(): array { |
|
| 665 | - return $this->notifierServices; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] |
|
| 670 | - */ |
|
| 671 | - public function getTwoFactorProviders(): array { |
|
| 672 | - return $this->twoFactorProviders; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * @return PreviewProviderRegistration[] |
|
| 677 | - */ |
|
| 678 | - public function getPreviewProviders(): array { |
|
| 679 | - return $this->previewProviders; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @return ServiceRegistration<ICalendarProvider>[] |
|
| 684 | - */ |
|
| 685 | - public function getCalendarProviders(): array { |
|
| 686 | - return $this->calendarProviders; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * @return ServiceRegistration<IReferenceProvider>[] |
|
| 691 | - */ |
|
| 692 | - public function getReferenceProviders(): array { |
|
| 693 | - return $this->referenceProviders; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * @return ServiceRegistration<ILinkAction>[] |
|
| 698 | - */ |
|
| 699 | - public function getProfileLinkActions(): array { |
|
| 700 | - return $this->profileLinkActions; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * @return ServiceRegistration|null |
|
| 705 | - * @psalm-return ServiceRegistration<ITalkBackend>|null |
|
| 706 | - */ |
|
| 707 | - public function getTalkBackendRegistration(): ?ServiceRegistration { |
|
| 708 | - return $this->talkBackendRegistration; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * @return ServiceRegistration[] |
|
| 713 | - * @psalm-return ServiceRegistration<IResourceBackend>[] |
|
| 714 | - */ |
|
| 715 | - public function getCalendarResourceBackendRegistrations(): array { |
|
| 716 | - return $this->calendarResourceBackendRegistrations; |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * @return ServiceRegistration[] |
|
| 721 | - * @psalm-return ServiceRegistration<IRoomBackend>[] |
|
| 722 | - */ |
|
| 723 | - public function getCalendarRoomBackendRegistrations(): array { |
|
| 724 | - return $this->calendarRoomBackendRegistrations; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * @return ServiceRegistration<IUserMigrator>[] |
|
| 729 | - */ |
|
| 730 | - public function getUserMigrators(): array { |
|
| 731 | - return $this->userMigrators; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * @return ParameterRegistration[] |
|
| 736 | - */ |
|
| 737 | - public function getSensitiveMethods(): array { |
|
| 738 | - return $this->sensitiveMethods; |
|
| 739 | - } |
|
| 103 | + /** @var ServiceRegistration<IAlternativeLogin>[] */ |
|
| 104 | + private $alternativeLogins = []; |
|
| 105 | + |
|
| 106 | + /** @var ServiceRegistration<InitialStateProvider>[] */ |
|
| 107 | + private $initialStates = []; |
|
| 108 | + |
|
| 109 | + /** @var ServiceRegistration<IHandler>[] */ |
|
| 110 | + private $wellKnownHandlers = []; |
|
| 111 | + |
|
| 112 | + /** @var ServiceRegistration<ICustomTemplateProvider>[] */ |
|
| 113 | + private $templateProviders = []; |
|
| 114 | + |
|
| 115 | + /** @var ServiceRegistration<INotifier>[] */ |
|
| 116 | + private $notifierServices = []; |
|
| 117 | + |
|
| 118 | + /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ |
|
| 119 | + private $twoFactorProviders = []; |
|
| 120 | + |
|
| 121 | + /** @var ServiceRegistration<ICalendarProvider>[] */ |
|
| 122 | + private $calendarProviders = []; |
|
| 123 | + |
|
| 124 | + /** @var ServiceRegistration<IReferenceProvider>[] */ |
|
| 125 | + private array $referenceProviders = []; |
|
| 126 | + |
|
| 127 | + /** @var ParameterRegistration[] */ |
|
| 128 | + private $sensitiveMethods = []; |
|
| 129 | + |
|
| 130 | + /** @var LoggerInterface */ |
|
| 131 | + private $logger; |
|
| 132 | + |
|
| 133 | + /** @var PreviewProviderRegistration[] */ |
|
| 134 | + private $previewProviders = []; |
|
| 135 | + |
|
| 136 | + public function __construct(LoggerInterface $logger) { |
|
| 137 | + $this->logger = $logger; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function for(string $appId): IRegistrationContext { |
|
| 141 | + return new class($appId, $this) implements IRegistrationContext { |
|
| 142 | + /** @var string */ |
|
| 143 | + private $appId; |
|
| 144 | + |
|
| 145 | + /** @var RegistrationContext */ |
|
| 146 | + private $context; |
|
| 147 | + |
|
| 148 | + public function __construct(string $appId, RegistrationContext $context) { |
|
| 149 | + $this->appId = $appId; |
|
| 150 | + $this->context = $context; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + public function registerCapability(string $capability): void { |
|
| 154 | + $this->context->registerCapability( |
|
| 155 | + $this->appId, |
|
| 156 | + $capability |
|
| 157 | + ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function registerCrashReporter(string $reporterClass): void { |
|
| 161 | + $this->context->registerCrashReporter( |
|
| 162 | + $this->appId, |
|
| 163 | + $reporterClass |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + public function registerDashboardWidget(string $widgetClass): void { |
|
| 168 | + $this->context->registerDashboardPanel( |
|
| 169 | + $this->appId, |
|
| 170 | + $widgetClass |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + public function registerService(string $name, callable $factory, bool $shared = true): void { |
|
| 175 | + $this->context->registerService( |
|
| 176 | + $this->appId, |
|
| 177 | + $name, |
|
| 178 | + $factory, |
|
| 179 | + $shared |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + public function registerServiceAlias(string $alias, string $target): void { |
|
| 184 | + $this->context->registerServiceAlias( |
|
| 185 | + $this->appId, |
|
| 186 | + $alias, |
|
| 187 | + $target |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + public function registerParameter(string $name, $value): void { |
|
| 192 | + $this->context->registerParameter( |
|
| 193 | + $this->appId, |
|
| 194 | + $name, |
|
| 195 | + $value |
|
| 196 | + ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
|
| 200 | + $this->context->registerEventListener( |
|
| 201 | + $this->appId, |
|
| 202 | + $event, |
|
| 203 | + $listener, |
|
| 204 | + $priority |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + public function registerMiddleware(string $class): void { |
|
| 209 | + $this->context->registerMiddleware( |
|
| 210 | + $this->appId, |
|
| 211 | + $class |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + public function registerSearchProvider(string $class): void { |
|
| 216 | + $this->context->registerSearchProvider( |
|
| 217 | + $this->appId, |
|
| 218 | + $class |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + public function registerAlternativeLogin(string $class): void { |
|
| 223 | + $this->context->registerAlternativeLogin( |
|
| 224 | + $this->appId, |
|
| 225 | + $class |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + public function registerInitialStateProvider(string $class): void { |
|
| 230 | + $this->context->registerInitialState( |
|
| 231 | + $this->appId, |
|
| 232 | + $class |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + public function registerWellKnownHandler(string $class): void { |
|
| 237 | + $this->context->registerWellKnown( |
|
| 238 | + $this->appId, |
|
| 239 | + $class |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + public function registerTemplateProvider(string $providerClass): void { |
|
| 244 | + $this->context->registerTemplateProvider( |
|
| 245 | + $this->appId, |
|
| 246 | + $providerClass |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function registerNotifierService(string $notifierClass): void { |
|
| 251 | + $this->context->registerNotifierService( |
|
| 252 | + $this->appId, |
|
| 253 | + $notifierClass |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + public function registerTwoFactorProvider(string $twoFactorProviderClass): void { |
|
| 258 | + $this->context->registerTwoFactorProvider( |
|
| 259 | + $this->appId, |
|
| 260 | + $twoFactorProviderClass |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + public function registerPreviewProvider(string $previewProviderClass, string $mimeTypeRegex): void { |
|
| 265 | + $this->context->registerPreviewProvider( |
|
| 266 | + $this->appId, |
|
| 267 | + $previewProviderClass, |
|
| 268 | + $mimeTypeRegex |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + public function registerCalendarProvider(string $class): void { |
|
| 273 | + $this->context->registerCalendarProvider( |
|
| 274 | + $this->appId, |
|
| 275 | + $class |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + public function registerReferenceProvider(string $class): void { |
|
| 280 | + $this->context->registerReferenceProvider( |
|
| 281 | + $this->appId, |
|
| 282 | + $class |
|
| 283 | + ); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + public function registerProfileLinkAction(string $actionClass): void { |
|
| 287 | + $this->context->registerProfileLinkAction( |
|
| 288 | + $this->appId, |
|
| 289 | + $actionClass |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + public function registerTalkBackend(string $backend): void { |
|
| 294 | + $this->context->registerTalkBackend( |
|
| 295 | + $this->appId, |
|
| 296 | + $backend |
|
| 297 | + ); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + public function registerCalendarResourceBackend(string $class): void { |
|
| 301 | + $this->context->registerCalendarResourceBackend( |
|
| 302 | + $this->appId, |
|
| 303 | + $class |
|
| 304 | + ); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + public function registerCalendarRoomBackend(string $class): void { |
|
| 308 | + $this->context->registerCalendarRoomBackend( |
|
| 309 | + $this->appId, |
|
| 310 | + $class |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + public function registerUserMigrator(string $migratorClass): void { |
|
| 315 | + $this->context->registerUserMigrator( |
|
| 316 | + $this->appId, |
|
| 317 | + $migratorClass |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + public function registerSensitiveMethods(string $class, array $methods): void { |
|
| 322 | + $this->context->registerSensitiveMethods( |
|
| 323 | + $this->appId, |
|
| 324 | + $class, |
|
| 325 | + $methods |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + }; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @psalm-param class-string<ICapability> $capability |
|
| 333 | + */ |
|
| 334 | + public function registerCapability(string $appId, string $capability): void { |
|
| 335 | + $this->capabilities[] = new ServiceRegistration($appId, $capability); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @psalm-param class-string<IReporter> $capability |
|
| 340 | + */ |
|
| 341 | + public function registerCrashReporter(string $appId, string $reporterClass): void { |
|
| 342 | + $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @psalm-param class-string<IWidget> $capability |
|
| 347 | + */ |
|
| 348 | + public function registerDashboardPanel(string $appId, string $panelClass): void { |
|
| 349 | + $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
|
| 353 | + $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + public function registerServiceAlias(string $appId, string $alias, string $target): void { |
|
| 357 | + $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + public function registerParameter(string $appId, string $name, $value): void { |
|
| 361 | + $this->parameters[] = new ParameterRegistration($appId, $name, $value); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
|
| 365 | + $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @psalm-param class-string<Middleware> $class |
|
| 370 | + */ |
|
| 371 | + public function registerMiddleware(string $appId, string $class): void { |
|
| 372 | + $this->middlewares[] = new ServiceRegistration($appId, $class); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + public function registerSearchProvider(string $appId, string $class) { |
|
| 376 | + $this->searchProviders[] = new ServiceRegistration($appId, $class); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + public function registerAlternativeLogin(string $appId, string $class): void { |
|
| 380 | + $this->alternativeLogins[] = new ServiceRegistration($appId, $class); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + public function registerInitialState(string $appId, string $class): void { |
|
| 384 | + $this->initialStates[] = new ServiceRegistration($appId, $class); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + public function registerWellKnown(string $appId, string $class): void { |
|
| 388 | + $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + public function registerTemplateProvider(string $appId, string $class): void { |
|
| 392 | + $this->templateProviders[] = new ServiceRegistration($appId, $class); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + public function registerNotifierService(string $appId, string $class): void { |
|
| 396 | + $this->notifierServices[] = new ServiceRegistration($appId, $class); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + public function registerTwoFactorProvider(string $appId, string $class): void { |
|
| 400 | + $this->twoFactorProviders[] = new ServiceRegistration($appId, $class); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + public function registerPreviewProvider(string $appId, string $class, string $mimeTypeRegex): void { |
|
| 404 | + $this->previewProviders[] = new PreviewProviderRegistration($appId, $class, $mimeTypeRegex); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + public function registerCalendarProvider(string $appId, string $class): void { |
|
| 408 | + $this->calendarProviders[] = new ServiceRegistration($appId, $class); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + public function registerReferenceProvider(string $appId, string $class): void { |
|
| 412 | + $this->referenceProviders[] = new ServiceRegistration($appId, $class); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @psalm-param class-string<ILinkAction> $actionClass |
|
| 417 | + */ |
|
| 418 | + public function registerProfileLinkAction(string $appId, string $actionClass): void { |
|
| 419 | + $this->profileLinkActions[] = new ServiceRegistration($appId, $actionClass); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @psalm-param class-string<ITalkBackend> $backend |
|
| 424 | + */ |
|
| 425 | + public function registerTalkBackend(string $appId, string $backend) { |
|
| 426 | + // Some safeguards for invalid registrations |
|
| 427 | + if ($appId !== 'spreed') { |
|
| 428 | + throw new RuntimeException("Only the Talk app is allowed to register a Talk backend"); |
|
| 429 | + } |
|
| 430 | + if ($this->talkBackendRegistration !== null) { |
|
| 431 | + throw new RuntimeException("There can only be one Talk backend"); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + $this->talkBackendRegistration = new ServiceRegistration($appId, $backend); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + public function registerCalendarResourceBackend(string $appId, string $class) { |
|
| 438 | + $this->calendarResourceBackendRegistrations[] = new ServiceRegistration( |
|
| 439 | + $appId, |
|
| 440 | + $class, |
|
| 441 | + ); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + public function registerCalendarRoomBackend(string $appId, string $class) { |
|
| 445 | + $this->calendarRoomBackendRegistrations[] = new ServiceRegistration( |
|
| 446 | + $appId, |
|
| 447 | + $class, |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @psalm-param class-string<IUserMigrator> $migratorClass |
|
| 453 | + */ |
|
| 454 | + public function registerUserMigrator(string $appId, string $migratorClass): void { |
|
| 455 | + $this->userMigrators[] = new ServiceRegistration($appId, $migratorClass); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + public function registerSensitiveMethods(string $appId, string $class, array $methods): void { |
|
| 459 | + $methods = array_filter($methods, 'is_string'); |
|
| 460 | + $this->sensitiveMethods[] = new ParameterRegistration($appId, $class, $methods); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @param App[] $apps |
|
| 465 | + */ |
|
| 466 | + public function delegateCapabilityRegistrations(array $apps): void { |
|
| 467 | + while (($registration = array_shift($this->capabilities)) !== null) { |
|
| 468 | + $appId = $registration->getAppId(); |
|
| 469 | + if (!isset($apps[$appId])) { |
|
| 470 | + // If we land here something really isn't right. But at least we caught the |
|
| 471 | + // notice that is otherwise emitted for the undefined index |
|
| 472 | + $this->logger->error("App $appId not loaded for the capability registration"); |
|
| 473 | + |
|
| 474 | + continue; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + try { |
|
| 478 | + $apps[$appId] |
|
| 479 | + ->getContainer() |
|
| 480 | + ->registerCapability($registration->getService()); |
|
| 481 | + } catch (Throwable $e) { |
|
| 482 | + $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ |
|
| 483 | + 'exception' => $e, |
|
| 484 | + ]); |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @param App[] $apps |
|
| 491 | + */ |
|
| 492 | + public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
| 493 | + while (($registration = array_shift($this->crashReporters)) !== null) { |
|
| 494 | + try { |
|
| 495 | + $registry->registerLazy($registration->getService()); |
|
| 496 | + } catch (Throwable $e) { |
|
| 497 | + $appId = $registration->getAppId(); |
|
| 498 | + $this->logger->error("Error during crash reporter registration of $appId: " . $e->getMessage(), [ |
|
| 499 | + 'exception' => $e, |
|
| 500 | + ]); |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * @param App[] $apps |
|
| 507 | + */ |
|
| 508 | + public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void { |
|
| 509 | + while (($panel = array_shift($this->dashboardPanels)) !== null) { |
|
| 510 | + try { |
|
| 511 | + $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId()); |
|
| 512 | + } catch (Throwable $e) { |
|
| 513 | + $appId = $panel->getAppId(); |
|
| 514 | + $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ |
|
| 515 | + 'exception' => $e, |
|
| 516 | + ]); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
|
| 522 | + while (($registration = array_shift($this->eventListeners)) !== null) { |
|
| 523 | + try { |
|
| 524 | + $eventDispatcher->addServiceListener( |
|
| 525 | + $registration->getEvent(), |
|
| 526 | + $registration->getService(), |
|
| 527 | + $registration->getPriority() |
|
| 528 | + ); |
|
| 529 | + } catch (Throwable $e) { |
|
| 530 | + $appId = $registration->getAppId(); |
|
| 531 | + $this->logger->error("Error during event listener registration of $appId: " . $e->getMessage(), [ |
|
| 532 | + 'exception' => $e, |
|
| 533 | + ]); |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @param App[] $apps |
|
| 540 | + */ |
|
| 541 | + public function delegateContainerRegistrations(array $apps): void { |
|
| 542 | + while (($registration = array_shift($this->services)) !== null) { |
|
| 543 | + $appId = $registration->getAppId(); |
|
| 544 | + if (!isset($apps[$appId])) { |
|
| 545 | + // If we land here something really isn't right. But at least we caught the |
|
| 546 | + // notice that is otherwise emitted for the undefined index |
|
| 547 | + $this->logger->error("App $appId not loaded for the container service registration"); |
|
| 548 | + |
|
| 549 | + continue; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + try { |
|
| 553 | + /** |
|
| 554 | + * Register the service and convert the callable into a \Closure if necessary |
|
| 555 | + */ |
|
| 556 | + $apps[$appId] |
|
| 557 | + ->getContainer() |
|
| 558 | + ->registerService( |
|
| 559 | + $registration->getName(), |
|
| 560 | + Closure::fromCallable($registration->getFactory()), |
|
| 561 | + $registration->isShared() |
|
| 562 | + ); |
|
| 563 | + } catch (Throwable $e) { |
|
| 564 | + $this->logger->error("Error during service registration of $appId: " . $e->getMessage(), [ |
|
| 565 | + 'exception' => $e, |
|
| 566 | + ]); |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + while (($registration = array_shift($this->aliases)) !== null) { |
|
| 571 | + $appId = $registration->getAppId(); |
|
| 572 | + if (!isset($apps[$appId])) { |
|
| 573 | + // If we land here something really isn't right. But at least we caught the |
|
| 574 | + // notice that is otherwise emitted for the undefined index |
|
| 575 | + $this->logger->error("App $appId not loaded for the container alias registration"); |
|
| 576 | + |
|
| 577 | + continue; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + try { |
|
| 581 | + $apps[$appId] |
|
| 582 | + ->getContainer() |
|
| 583 | + ->registerAlias( |
|
| 584 | + $registration->getAlias(), |
|
| 585 | + $registration->getTarget() |
|
| 586 | + ); |
|
| 587 | + } catch (Throwable $e) { |
|
| 588 | + $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ |
|
| 589 | + 'exception' => $e, |
|
| 590 | + ]); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + while (($registration = array_shift($this->parameters)) !== null) { |
|
| 595 | + $appId = $registration->getAppId(); |
|
| 596 | + if (!isset($apps[$appId])) { |
|
| 597 | + // If we land here something really isn't right. But at least we caught the |
|
| 598 | + // notice that is otherwise emitted for the undefined index |
|
| 599 | + $this->logger->error("App $appId not loaded for the container parameter registration"); |
|
| 600 | + |
|
| 601 | + continue; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + try { |
|
| 605 | + $apps[$appId] |
|
| 606 | + ->getContainer() |
|
| 607 | + ->registerParameter( |
|
| 608 | + $registration->getName(), |
|
| 609 | + $registration->getValue() |
|
| 610 | + ); |
|
| 611 | + } catch (Throwable $e) { |
|
| 612 | + $this->logger->error("Error during service parameter registration of $appId: " . $e->getMessage(), [ |
|
| 613 | + 'exception' => $e, |
|
| 614 | + ]); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * @return ServiceRegistration<Middleware>[] |
|
| 621 | + */ |
|
| 622 | + public function getMiddlewareRegistrations(): array { |
|
| 623 | + return $this->middlewares; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * @return ServiceRegistration<IProvider>[] |
|
| 628 | + */ |
|
| 629 | + public function getSearchProviders(): array { |
|
| 630 | + return $this->searchProviders; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * @return ServiceRegistration<IAlternativeLogin>[] |
|
| 635 | + */ |
|
| 636 | + public function getAlternativeLogins(): array { |
|
| 637 | + return $this->alternativeLogins; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * @return ServiceRegistration<InitialStateProvider>[] |
|
| 642 | + */ |
|
| 643 | + public function getInitialStates(): array { |
|
| 644 | + return $this->initialStates; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * @return ServiceRegistration<IHandler>[] |
|
| 649 | + */ |
|
| 650 | + public function getWellKnownHandlers(): array { |
|
| 651 | + return $this->wellKnownHandlers; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * @return ServiceRegistration<ICustomTemplateProvider>[] |
|
| 656 | + */ |
|
| 657 | + public function getTemplateProviders(): array { |
|
| 658 | + return $this->templateProviders; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @return ServiceRegistration<INotifier>[] |
|
| 663 | + */ |
|
| 664 | + public function getNotifierServices(): array { |
|
| 665 | + return $this->notifierServices; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] |
|
| 670 | + */ |
|
| 671 | + public function getTwoFactorProviders(): array { |
|
| 672 | + return $this->twoFactorProviders; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * @return PreviewProviderRegistration[] |
|
| 677 | + */ |
|
| 678 | + public function getPreviewProviders(): array { |
|
| 679 | + return $this->previewProviders; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @return ServiceRegistration<ICalendarProvider>[] |
|
| 684 | + */ |
|
| 685 | + public function getCalendarProviders(): array { |
|
| 686 | + return $this->calendarProviders; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * @return ServiceRegistration<IReferenceProvider>[] |
|
| 691 | + */ |
|
| 692 | + public function getReferenceProviders(): array { |
|
| 693 | + return $this->referenceProviders; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * @return ServiceRegistration<ILinkAction>[] |
|
| 698 | + */ |
|
| 699 | + public function getProfileLinkActions(): array { |
|
| 700 | + return $this->profileLinkActions; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * @return ServiceRegistration|null |
|
| 705 | + * @psalm-return ServiceRegistration<ITalkBackend>|null |
|
| 706 | + */ |
|
| 707 | + public function getTalkBackendRegistration(): ?ServiceRegistration { |
|
| 708 | + return $this->talkBackendRegistration; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * @return ServiceRegistration[] |
|
| 713 | + * @psalm-return ServiceRegistration<IResourceBackend>[] |
|
| 714 | + */ |
|
| 715 | + public function getCalendarResourceBackendRegistrations(): array { |
|
| 716 | + return $this->calendarResourceBackendRegistrations; |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * @return ServiceRegistration[] |
|
| 721 | + * @psalm-return ServiceRegistration<IRoomBackend>[] |
|
| 722 | + */ |
|
| 723 | + public function getCalendarRoomBackendRegistrations(): array { |
|
| 724 | + return $this->calendarRoomBackendRegistrations; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * @return ServiceRegistration<IUserMigrator>[] |
|
| 729 | + */ |
|
| 730 | + public function getUserMigrators(): array { |
|
| 731 | + return $this->userMigrators; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * @return ParameterRegistration[] |
|
| 736 | + */ |
|
| 737 | + public function getSensitiveMethods(): array { |
|
| 738 | + return $this->sensitiveMethods; |
|
| 739 | + } |
|
| 740 | 740 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $this->logger = $logger; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public function for(string $appId): IRegistrationContext { |
|
| 140 | + public function for (string $appId): IRegistrationContext { |
|
| 141 | 141 | return new class($appId, $this) implements IRegistrationContext { |
| 142 | 142 | /** @var string */ |
| 143 | 143 | private $appId; |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | ->getContainer() |
| 480 | 480 | ->registerCapability($registration->getService()); |
| 481 | 481 | } catch (Throwable $e) { |
| 482 | - $this->logger->error("Error during capability registration of $appId: " . $e->getMessage(), [ |
|
| 482 | + $this->logger->error("Error during capability registration of $appId: ".$e->getMessage(), [ |
|
| 483 | 483 | 'exception' => $e, |
| 484 | 484 | ]); |
| 485 | 485 | } |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | $registry->registerLazy($registration->getService()); |
| 496 | 496 | } catch (Throwable $e) { |
| 497 | 497 | $appId = $registration->getAppId(); |
| 498 | - $this->logger->error("Error during crash reporter registration of $appId: " . $e->getMessage(), [ |
|
| 498 | + $this->logger->error("Error during crash reporter registration of $appId: ".$e->getMessage(), [ |
|
| 499 | 499 | 'exception' => $e, |
| 500 | 500 | ]); |
| 501 | 501 | } |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId()); |
| 512 | 512 | } catch (Throwable $e) { |
| 513 | 513 | $appId = $panel->getAppId(); |
| 514 | - $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ |
|
| 514 | + $this->logger->error("Error during dashboard registration of $appId: ".$e->getMessage(), [ |
|
| 515 | 515 | 'exception' => $e, |
| 516 | 516 | ]); |
| 517 | 517 | } |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | ); |
| 529 | 529 | } catch (Throwable $e) { |
| 530 | 530 | $appId = $registration->getAppId(); |
| 531 | - $this->logger->error("Error during event listener registration of $appId: " . $e->getMessage(), [ |
|
| 531 | + $this->logger->error("Error during event listener registration of $appId: ".$e->getMessage(), [ |
|
| 532 | 532 | 'exception' => $e, |
| 533 | 533 | ]); |
| 534 | 534 | } |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | $registration->isShared() |
| 562 | 562 | ); |
| 563 | 563 | } catch (Throwable $e) { |
| 564 | - $this->logger->error("Error during service registration of $appId: " . $e->getMessage(), [ |
|
| 564 | + $this->logger->error("Error during service registration of $appId: ".$e->getMessage(), [ |
|
| 565 | 565 | 'exception' => $e, |
| 566 | 566 | ]); |
| 567 | 567 | } |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | $registration->getTarget() |
| 586 | 586 | ); |
| 587 | 587 | } catch (Throwable $e) { |
| 588 | - $this->logger->error("Error during service alias registration of $appId: " . $e->getMessage(), [ |
|
| 588 | + $this->logger->error("Error during service alias registration of $appId: ".$e->getMessage(), [ |
|
| 589 | 589 | 'exception' => $e, |
| 590 | 590 | ]); |
| 591 | 591 | } |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | $registration->getValue() |
| 610 | 610 | ); |
| 611 | 611 | } catch (Throwable $e) { |
| 612 | - $this->logger->error("Error during service parameter registration of $appId: " . $e->getMessage(), [ |
|
| 612 | + $this->logger->error("Error during service parameter registration of $appId: ".$e->getMessage(), [ |
|
| 613 | 613 | 'exception' => $e, |
| 614 | 614 | ]); |
| 615 | 615 | } |
@@ -79,420 +79,420 @@ |
||
| 79 | 79 | * @deprecated 20.0.0 |
| 80 | 80 | */ |
| 81 | 81 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 82 | - private string $appName; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - private $middleWares = []; |
|
| 88 | - |
|
| 89 | - /** @var ServerContainer */ |
|
| 90 | - private $server; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Put your class dependencies in here |
|
| 94 | - * @param string $appName the name of the app |
|
| 95 | - * @param array $urlParams |
|
| 96 | - * @param ServerContainer|null $server |
|
| 97 | - */ |
|
| 98 | - public function __construct(string $appName, array $urlParams = [], ServerContainer $server = null) { |
|
| 99 | - parent::__construct(); |
|
| 100 | - $this->appName = $appName; |
|
| 101 | - $this['appName'] = $appName; |
|
| 102 | - $this['urlParams'] = $urlParams; |
|
| 103 | - |
|
| 104 | - $this->registerAlias('Request', IRequest::class); |
|
| 105 | - |
|
| 106 | - /** @var \OC\ServerContainer $server */ |
|
| 107 | - if ($server === null) { |
|
| 108 | - $server = \OC::$server; |
|
| 109 | - } |
|
| 110 | - $this->server = $server; |
|
| 111 | - $this->server->registerAppContainer($appName, $this); |
|
| 112 | - |
|
| 113 | - // aliases |
|
| 114 | - /** @deprecated inject $appName */ |
|
| 115 | - $this->registerAlias('AppName', 'appName'); |
|
| 116 | - /** @deprecated inject $webRoot*/ |
|
| 117 | - $this->registerAlias('WebRoot', 'webRoot'); |
|
| 118 | - /** @deprecated inject $userId */ |
|
| 119 | - $this->registerAlias('UserId', 'userId'); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Core services |
|
| 123 | - */ |
|
| 124 | - $this->registerService(IOutput::class, function () { |
|
| 125 | - return new Output($this->getServer()->getWebRoot()); |
|
| 126 | - }); |
|
| 127 | - |
|
| 128 | - $this->registerService(Folder::class, function () { |
|
| 129 | - return $this->getServer()->getUserFolder(); |
|
| 130 | - }); |
|
| 131 | - |
|
| 132 | - $this->registerService(IAppData::class, function (ContainerInterface $c) { |
|
| 133 | - return $this->getServer()->getAppDataDir($c->get('AppName')); |
|
| 134 | - }); |
|
| 135 | - |
|
| 136 | - $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
| 137 | - return $this->getServer()->getL10N($c->get('AppName')); |
|
| 138 | - }); |
|
| 139 | - |
|
| 140 | - // Log wrappers |
|
| 141 | - $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
| 142 | - return new ScopedPsrLogger( |
|
| 143 | - $c->get(PsrLoggerAdapter::class), |
|
| 144 | - $c->get('AppName') |
|
| 145 | - ); |
|
| 146 | - }); |
|
| 147 | - $this->registerService(ILogger::class, function (ContainerInterface $c) { |
|
| 148 | - return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); |
|
| 149 | - }); |
|
| 150 | - |
|
| 151 | - $this->registerService(IServerContainer::class, function () { |
|
| 152 | - return $this->getServer(); |
|
| 153 | - }); |
|
| 154 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 155 | - |
|
| 156 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { |
|
| 157 | - return $c->get(Manager::class); |
|
| 158 | - }); |
|
| 159 | - |
|
| 160 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 161 | - return $c; |
|
| 162 | - }); |
|
| 163 | - $this->registerAlias(IAppContainer::class, ContainerInterface::class); |
|
| 164 | - |
|
| 165 | - // commonly used attributes |
|
| 166 | - $this->registerService('userId', function (ContainerInterface $c) { |
|
| 167 | - return $c->get(IUserSession::class)->getSession()->get('user_id'); |
|
| 168 | - }); |
|
| 169 | - |
|
| 170 | - $this->registerService('webRoot', function (ContainerInterface $c) { |
|
| 171 | - return $c->get(IServerContainer::class)->getWebRoot(); |
|
| 172 | - }); |
|
| 173 | - |
|
| 174 | - $this->registerService('OC_Defaults', function (ContainerInterface $c) { |
|
| 175 | - return $c->get(IServerContainer::class)->getThemingDefaults(); |
|
| 176 | - }); |
|
| 177 | - |
|
| 178 | - $this->registerService('Protocol', function (ContainerInterface $c) { |
|
| 179 | - /** @var \OC\Server $server */ |
|
| 180 | - $server = $c->get(IServerContainer::class); |
|
| 181 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 182 | - return new Http($_SERVER, $protocol); |
|
| 183 | - }); |
|
| 184 | - |
|
| 185 | - $this->registerService('Dispatcher', function (ContainerInterface $c) { |
|
| 186 | - return new Dispatcher( |
|
| 187 | - $c->get('Protocol'), |
|
| 188 | - $c->get(MiddlewareDispatcher::class), |
|
| 189 | - $c->get(IControllerMethodReflector::class), |
|
| 190 | - $c->get(IRequest::class), |
|
| 191 | - $c->get(IConfig::class), |
|
| 192 | - $c->get(IDBConnection::class), |
|
| 193 | - $c->get(LoggerInterface::class), |
|
| 194 | - $c->get(EventLogger::class), |
|
| 195 | - $c, |
|
| 196 | - ); |
|
| 197 | - }); |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * App Framework default arguments |
|
| 201 | - */ |
|
| 202 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 203 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 204 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Middleware |
|
| 208 | - */ |
|
| 209 | - $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
|
| 210 | - $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
| 211 | - $server = $this->getServer(); |
|
| 212 | - |
|
| 213 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 214 | - |
|
| 215 | - $dispatcher->registerMiddleware( |
|
| 216 | - $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) |
|
| 217 | - ); |
|
| 218 | - |
|
| 219 | - $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); |
|
| 220 | - |
|
| 221 | - $dispatcher->registerMiddleware( |
|
| 222 | - $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - $dispatcher->registerMiddleware( |
|
| 226 | - new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 227 | - $c->get(IRequest::class), |
|
| 228 | - $c->get(IControllerMethodReflector::class) |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - $dispatcher->registerMiddleware( |
|
| 232 | - new CORSMiddleware( |
|
| 233 | - $c->get(IRequest::class), |
|
| 234 | - $c->get(IControllerMethodReflector::class), |
|
| 235 | - $c->get(IUserSession::class), |
|
| 236 | - $c->get(OC\Security\Bruteforce\Throttler::class) |
|
| 237 | - ) |
|
| 238 | - ); |
|
| 239 | - $dispatcher->registerMiddleware( |
|
| 240 | - new OCSMiddleware( |
|
| 241 | - $c->get(IRequest::class) |
|
| 242 | - ) |
|
| 243 | - ); |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - $securityMiddleware = new SecurityMiddleware( |
|
| 248 | - $c->get(IRequest::class), |
|
| 249 | - $c->get(IControllerMethodReflector::class), |
|
| 250 | - $c->get(INavigationManager::class), |
|
| 251 | - $c->get(IURLGenerator::class), |
|
| 252 | - $server->get(LoggerInterface::class), |
|
| 253 | - $c->get('AppName'), |
|
| 254 | - $server->getUserSession()->isLoggedIn(), |
|
| 255 | - $this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 256 | - $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
|
| 257 | - $server->getAppManager(), |
|
| 258 | - $server->getL10N('lib'), |
|
| 259 | - $c->get(AuthorizedGroupMapper::class), |
|
| 260 | - $server->get(IUserSession::class) |
|
| 261 | - ); |
|
| 262 | - $dispatcher->registerMiddleware($securityMiddleware); |
|
| 263 | - $dispatcher->registerMiddleware( |
|
| 264 | - new OC\AppFramework\Middleware\Security\CSPMiddleware( |
|
| 265 | - $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
|
| 266 | - $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
|
| 267 | - $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
|
| 268 | - ) |
|
| 269 | - ); |
|
| 270 | - $dispatcher->registerMiddleware( |
|
| 271 | - $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
|
| 272 | - ); |
|
| 273 | - $dispatcher->registerMiddleware( |
|
| 274 | - new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 275 | - $c->get(IControllerMethodReflector::class), |
|
| 276 | - $c->get(ISession::class), |
|
| 277 | - $c->get(IUserSession::class), |
|
| 278 | - $c->get(ITimeFactory::class) |
|
| 279 | - ) |
|
| 280 | - ); |
|
| 281 | - $dispatcher->registerMiddleware( |
|
| 282 | - new TwoFactorMiddleware( |
|
| 283 | - $c->get(OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 284 | - $c->get(IUserSession::class), |
|
| 285 | - $c->get(ISession::class), |
|
| 286 | - $c->get(IURLGenerator::class), |
|
| 287 | - $c->get(IControllerMethodReflector::class), |
|
| 288 | - $c->get(IRequest::class) |
|
| 289 | - ) |
|
| 290 | - ); |
|
| 291 | - $dispatcher->registerMiddleware( |
|
| 292 | - new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 293 | - $c->get(IControllerMethodReflector::class), |
|
| 294 | - $c->get(OC\Security\Bruteforce\Throttler::class), |
|
| 295 | - $c->get(IRequest::class) |
|
| 296 | - ) |
|
| 297 | - ); |
|
| 298 | - $dispatcher->registerMiddleware( |
|
| 299 | - new RateLimitingMiddleware( |
|
| 300 | - $c->get(IRequest::class), |
|
| 301 | - $c->get(IUserSession::class), |
|
| 302 | - $c->get(IControllerMethodReflector::class), |
|
| 303 | - $c->get(OC\Security\RateLimiting\Limiter::class) |
|
| 304 | - ) |
|
| 305 | - ); |
|
| 306 | - $dispatcher->registerMiddleware( |
|
| 307 | - new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 308 | - $c->get(IRequest::class), |
|
| 309 | - $c->get(ISession::class), |
|
| 310 | - $c->get(\OCP\IConfig::class), |
|
| 311 | - $c->get(OC\Security\Bruteforce\Throttler::class) |
|
| 312 | - ) |
|
| 313 | - ); |
|
| 314 | - $dispatcher->registerMiddleware( |
|
| 315 | - $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - /** @var \OC\AppFramework\Bootstrap\Coordinator $coordinator */ |
|
| 319 | - $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 320 | - $registrationContext = $coordinator->getRegistrationContext(); |
|
| 321 | - if ($registrationContext !== null) { |
|
| 322 | - $appId = $this->getAppName(); |
|
| 323 | - foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { |
|
| 324 | - if ($middlewareRegistration->getAppId() === $appId) { |
|
| 325 | - $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - foreach ($this->middleWares as $middleWare) { |
|
| 330 | - $dispatcher->registerMiddleware($c->get($middleWare)); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $dispatcher->registerMiddleware( |
|
| 334 | - new SessionMiddleware( |
|
| 335 | - $c->get(IControllerMethodReflector::class), |
|
| 336 | - $c->get(ISession::class) |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - return $dispatcher; |
|
| 340 | - }); |
|
| 341 | - |
|
| 342 | - $this->registerService(IAppConfig::class, function (ContainerInterface $c) { |
|
| 343 | - return new OC\AppFramework\Services\AppConfig( |
|
| 344 | - $c->get(IConfig::class), |
|
| 345 | - $c->get('AppName') |
|
| 346 | - ); |
|
| 347 | - }); |
|
| 348 | - $this->registerService(IInitialState::class, function (ContainerInterface $c) { |
|
| 349 | - return new OC\AppFramework\Services\InitialState( |
|
| 350 | - $c->get(IInitialStateService::class), |
|
| 351 | - $c->get('AppName') |
|
| 352 | - ); |
|
| 353 | - }); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * @return \OCP\IServerContainer |
|
| 358 | - */ |
|
| 359 | - public function getServer() { |
|
| 360 | - return $this->server; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @param string $middleWare |
|
| 365 | - * @return boolean|null |
|
| 366 | - */ |
|
| 367 | - public function registerMiddleWare($middleWare) { |
|
| 368 | - if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
| 369 | - return false; |
|
| 370 | - } |
|
| 371 | - $this->middleWares[] = $middleWare; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * used to return the appname of the set application |
|
| 376 | - * @return string the name of your application |
|
| 377 | - */ |
|
| 378 | - public function getAppName() { |
|
| 379 | - return $this->query('AppName'); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 384 | - * @return boolean |
|
| 385 | - */ |
|
| 386 | - public function isLoggedIn() { |
|
| 387 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 392 | - * @return boolean |
|
| 393 | - */ |
|
| 394 | - public function isAdminUser() { |
|
| 395 | - $uid = $this->getUserId(); |
|
| 396 | - return \OC_User::isAdminUser($uid); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - private function getUserId() { |
|
| 400 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @deprecated use the ILogger instead |
|
| 405 | - * @param string $message |
|
| 406 | - * @param string $level |
|
| 407 | - * @return mixed |
|
| 408 | - */ |
|
| 409 | - public function log($message, $level) { |
|
| 410 | - switch ($level) { |
|
| 411 | - case 'debug': |
|
| 412 | - $level = ILogger::DEBUG; |
|
| 413 | - break; |
|
| 414 | - case 'info': |
|
| 415 | - $level = ILogger::INFO; |
|
| 416 | - break; |
|
| 417 | - case 'warn': |
|
| 418 | - $level = ILogger::WARN; |
|
| 419 | - break; |
|
| 420 | - case 'fatal': |
|
| 421 | - $level = ILogger::FATAL; |
|
| 422 | - break; |
|
| 423 | - default: |
|
| 424 | - $level = ILogger::ERROR; |
|
| 425 | - break; |
|
| 426 | - } |
|
| 427 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Register a capability |
|
| 432 | - * |
|
| 433 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 434 | - */ |
|
| 435 | - public function registerCapability($serviceName) { |
|
| 436 | - $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
| 437 | - return $this->query($serviceName); |
|
| 438 | - }); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - public function has($id): bool { |
|
| 442 | - if (parent::has($id)) { |
|
| 443 | - return true; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - if ($this->server->has($id, true)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return false; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - public function query(string $name, bool $autoload = true) { |
|
| 454 | - if ($name === 'AppName' || $name === 'appName') { |
|
| 455 | - return $this->appName; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); |
|
| 459 | - if ($isServerClass && !$this->has($name)) { |
|
| 460 | - return $this->getServer()->query($name, $autoload); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - try { |
|
| 464 | - return $this->queryNoFallback($name); |
|
| 465 | - } catch (QueryException $firstException) { |
|
| 466 | - try { |
|
| 467 | - return $this->getServer()->query($name, $autoload); |
|
| 468 | - } catch (QueryException $secondException) { |
|
| 469 | - if ($firstException->getCode() === 1) { |
|
| 470 | - throw $secondException; |
|
| 471 | - } |
|
| 472 | - throw $firstException; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * @param string $name |
|
| 479 | - * @return mixed |
|
| 480 | - * @throws QueryException if the query could not be resolved |
|
| 481 | - */ |
|
| 482 | - public function queryNoFallback($name) { |
|
| 483 | - $name = $this->sanitizeName($name); |
|
| 484 | - |
|
| 485 | - if ($this->offsetExists($name)) { |
|
| 486 | - return parent::query($name); |
|
| 487 | - } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { |
|
| 488 | - return parent::query($name); |
|
| 489 | - } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { |
|
| 490 | - return parent::query($name); |
|
| 491 | - } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { |
|
| 492 | - return parent::query($name); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 496 | - ' Class can not be instantiated', 1); |
|
| 497 | - } |
|
| 82 | + private string $appName; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + private $middleWares = []; |
|
| 88 | + |
|
| 89 | + /** @var ServerContainer */ |
|
| 90 | + private $server; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Put your class dependencies in here |
|
| 94 | + * @param string $appName the name of the app |
|
| 95 | + * @param array $urlParams |
|
| 96 | + * @param ServerContainer|null $server |
|
| 97 | + */ |
|
| 98 | + public function __construct(string $appName, array $urlParams = [], ServerContainer $server = null) { |
|
| 99 | + parent::__construct(); |
|
| 100 | + $this->appName = $appName; |
|
| 101 | + $this['appName'] = $appName; |
|
| 102 | + $this['urlParams'] = $urlParams; |
|
| 103 | + |
|
| 104 | + $this->registerAlias('Request', IRequest::class); |
|
| 105 | + |
|
| 106 | + /** @var \OC\ServerContainer $server */ |
|
| 107 | + if ($server === null) { |
|
| 108 | + $server = \OC::$server; |
|
| 109 | + } |
|
| 110 | + $this->server = $server; |
|
| 111 | + $this->server->registerAppContainer($appName, $this); |
|
| 112 | + |
|
| 113 | + // aliases |
|
| 114 | + /** @deprecated inject $appName */ |
|
| 115 | + $this->registerAlias('AppName', 'appName'); |
|
| 116 | + /** @deprecated inject $webRoot*/ |
|
| 117 | + $this->registerAlias('WebRoot', 'webRoot'); |
|
| 118 | + /** @deprecated inject $userId */ |
|
| 119 | + $this->registerAlias('UserId', 'userId'); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Core services |
|
| 123 | + */ |
|
| 124 | + $this->registerService(IOutput::class, function () { |
|
| 125 | + return new Output($this->getServer()->getWebRoot()); |
|
| 126 | + }); |
|
| 127 | + |
|
| 128 | + $this->registerService(Folder::class, function () { |
|
| 129 | + return $this->getServer()->getUserFolder(); |
|
| 130 | + }); |
|
| 131 | + |
|
| 132 | + $this->registerService(IAppData::class, function (ContainerInterface $c) { |
|
| 133 | + return $this->getServer()->getAppDataDir($c->get('AppName')); |
|
| 134 | + }); |
|
| 135 | + |
|
| 136 | + $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
| 137 | + return $this->getServer()->getL10N($c->get('AppName')); |
|
| 138 | + }); |
|
| 139 | + |
|
| 140 | + // Log wrappers |
|
| 141 | + $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
| 142 | + return new ScopedPsrLogger( |
|
| 143 | + $c->get(PsrLoggerAdapter::class), |
|
| 144 | + $c->get('AppName') |
|
| 145 | + ); |
|
| 146 | + }); |
|
| 147 | + $this->registerService(ILogger::class, function (ContainerInterface $c) { |
|
| 148 | + return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); |
|
| 149 | + }); |
|
| 150 | + |
|
| 151 | + $this->registerService(IServerContainer::class, function () { |
|
| 152 | + return $this->getServer(); |
|
| 153 | + }); |
|
| 154 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 155 | + |
|
| 156 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { |
|
| 157 | + return $c->get(Manager::class); |
|
| 158 | + }); |
|
| 159 | + |
|
| 160 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 161 | + return $c; |
|
| 162 | + }); |
|
| 163 | + $this->registerAlias(IAppContainer::class, ContainerInterface::class); |
|
| 164 | + |
|
| 165 | + // commonly used attributes |
|
| 166 | + $this->registerService('userId', function (ContainerInterface $c) { |
|
| 167 | + return $c->get(IUserSession::class)->getSession()->get('user_id'); |
|
| 168 | + }); |
|
| 169 | + |
|
| 170 | + $this->registerService('webRoot', function (ContainerInterface $c) { |
|
| 171 | + return $c->get(IServerContainer::class)->getWebRoot(); |
|
| 172 | + }); |
|
| 173 | + |
|
| 174 | + $this->registerService('OC_Defaults', function (ContainerInterface $c) { |
|
| 175 | + return $c->get(IServerContainer::class)->getThemingDefaults(); |
|
| 176 | + }); |
|
| 177 | + |
|
| 178 | + $this->registerService('Protocol', function (ContainerInterface $c) { |
|
| 179 | + /** @var \OC\Server $server */ |
|
| 180 | + $server = $c->get(IServerContainer::class); |
|
| 181 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 182 | + return new Http($_SERVER, $protocol); |
|
| 183 | + }); |
|
| 184 | + |
|
| 185 | + $this->registerService('Dispatcher', function (ContainerInterface $c) { |
|
| 186 | + return new Dispatcher( |
|
| 187 | + $c->get('Protocol'), |
|
| 188 | + $c->get(MiddlewareDispatcher::class), |
|
| 189 | + $c->get(IControllerMethodReflector::class), |
|
| 190 | + $c->get(IRequest::class), |
|
| 191 | + $c->get(IConfig::class), |
|
| 192 | + $c->get(IDBConnection::class), |
|
| 193 | + $c->get(LoggerInterface::class), |
|
| 194 | + $c->get(EventLogger::class), |
|
| 195 | + $c, |
|
| 196 | + ); |
|
| 197 | + }); |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * App Framework default arguments |
|
| 201 | + */ |
|
| 202 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 203 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 204 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Middleware |
|
| 208 | + */ |
|
| 209 | + $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
|
| 210 | + $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
| 211 | + $server = $this->getServer(); |
|
| 212 | + |
|
| 213 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 214 | + |
|
| 215 | + $dispatcher->registerMiddleware( |
|
| 216 | + $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) |
|
| 217 | + ); |
|
| 218 | + |
|
| 219 | + $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); |
|
| 220 | + |
|
| 221 | + $dispatcher->registerMiddleware( |
|
| 222 | + $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + $dispatcher->registerMiddleware( |
|
| 226 | + new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 227 | + $c->get(IRequest::class), |
|
| 228 | + $c->get(IControllerMethodReflector::class) |
|
| 229 | + ) |
|
| 230 | + ); |
|
| 231 | + $dispatcher->registerMiddleware( |
|
| 232 | + new CORSMiddleware( |
|
| 233 | + $c->get(IRequest::class), |
|
| 234 | + $c->get(IControllerMethodReflector::class), |
|
| 235 | + $c->get(IUserSession::class), |
|
| 236 | + $c->get(OC\Security\Bruteforce\Throttler::class) |
|
| 237 | + ) |
|
| 238 | + ); |
|
| 239 | + $dispatcher->registerMiddleware( |
|
| 240 | + new OCSMiddleware( |
|
| 241 | + $c->get(IRequest::class) |
|
| 242 | + ) |
|
| 243 | + ); |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + $securityMiddleware = new SecurityMiddleware( |
|
| 248 | + $c->get(IRequest::class), |
|
| 249 | + $c->get(IControllerMethodReflector::class), |
|
| 250 | + $c->get(INavigationManager::class), |
|
| 251 | + $c->get(IURLGenerator::class), |
|
| 252 | + $server->get(LoggerInterface::class), |
|
| 253 | + $c->get('AppName'), |
|
| 254 | + $server->getUserSession()->isLoggedIn(), |
|
| 255 | + $this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 256 | + $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
|
| 257 | + $server->getAppManager(), |
|
| 258 | + $server->getL10N('lib'), |
|
| 259 | + $c->get(AuthorizedGroupMapper::class), |
|
| 260 | + $server->get(IUserSession::class) |
|
| 261 | + ); |
|
| 262 | + $dispatcher->registerMiddleware($securityMiddleware); |
|
| 263 | + $dispatcher->registerMiddleware( |
|
| 264 | + new OC\AppFramework\Middleware\Security\CSPMiddleware( |
|
| 265 | + $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
|
| 266 | + $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
|
| 267 | + $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
|
| 268 | + ) |
|
| 269 | + ); |
|
| 270 | + $dispatcher->registerMiddleware( |
|
| 271 | + $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
|
| 272 | + ); |
|
| 273 | + $dispatcher->registerMiddleware( |
|
| 274 | + new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 275 | + $c->get(IControllerMethodReflector::class), |
|
| 276 | + $c->get(ISession::class), |
|
| 277 | + $c->get(IUserSession::class), |
|
| 278 | + $c->get(ITimeFactory::class) |
|
| 279 | + ) |
|
| 280 | + ); |
|
| 281 | + $dispatcher->registerMiddleware( |
|
| 282 | + new TwoFactorMiddleware( |
|
| 283 | + $c->get(OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 284 | + $c->get(IUserSession::class), |
|
| 285 | + $c->get(ISession::class), |
|
| 286 | + $c->get(IURLGenerator::class), |
|
| 287 | + $c->get(IControllerMethodReflector::class), |
|
| 288 | + $c->get(IRequest::class) |
|
| 289 | + ) |
|
| 290 | + ); |
|
| 291 | + $dispatcher->registerMiddleware( |
|
| 292 | + new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 293 | + $c->get(IControllerMethodReflector::class), |
|
| 294 | + $c->get(OC\Security\Bruteforce\Throttler::class), |
|
| 295 | + $c->get(IRequest::class) |
|
| 296 | + ) |
|
| 297 | + ); |
|
| 298 | + $dispatcher->registerMiddleware( |
|
| 299 | + new RateLimitingMiddleware( |
|
| 300 | + $c->get(IRequest::class), |
|
| 301 | + $c->get(IUserSession::class), |
|
| 302 | + $c->get(IControllerMethodReflector::class), |
|
| 303 | + $c->get(OC\Security\RateLimiting\Limiter::class) |
|
| 304 | + ) |
|
| 305 | + ); |
|
| 306 | + $dispatcher->registerMiddleware( |
|
| 307 | + new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 308 | + $c->get(IRequest::class), |
|
| 309 | + $c->get(ISession::class), |
|
| 310 | + $c->get(\OCP\IConfig::class), |
|
| 311 | + $c->get(OC\Security\Bruteforce\Throttler::class) |
|
| 312 | + ) |
|
| 313 | + ); |
|
| 314 | + $dispatcher->registerMiddleware( |
|
| 315 | + $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + /** @var \OC\AppFramework\Bootstrap\Coordinator $coordinator */ |
|
| 319 | + $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 320 | + $registrationContext = $coordinator->getRegistrationContext(); |
|
| 321 | + if ($registrationContext !== null) { |
|
| 322 | + $appId = $this->getAppName(); |
|
| 323 | + foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { |
|
| 324 | + if ($middlewareRegistration->getAppId() === $appId) { |
|
| 325 | + $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + foreach ($this->middleWares as $middleWare) { |
|
| 330 | + $dispatcher->registerMiddleware($c->get($middleWare)); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $dispatcher->registerMiddleware( |
|
| 334 | + new SessionMiddleware( |
|
| 335 | + $c->get(IControllerMethodReflector::class), |
|
| 336 | + $c->get(ISession::class) |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + return $dispatcher; |
|
| 340 | + }); |
|
| 341 | + |
|
| 342 | + $this->registerService(IAppConfig::class, function (ContainerInterface $c) { |
|
| 343 | + return new OC\AppFramework\Services\AppConfig( |
|
| 344 | + $c->get(IConfig::class), |
|
| 345 | + $c->get('AppName') |
|
| 346 | + ); |
|
| 347 | + }); |
|
| 348 | + $this->registerService(IInitialState::class, function (ContainerInterface $c) { |
|
| 349 | + return new OC\AppFramework\Services\InitialState( |
|
| 350 | + $c->get(IInitialStateService::class), |
|
| 351 | + $c->get('AppName') |
|
| 352 | + ); |
|
| 353 | + }); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * @return \OCP\IServerContainer |
|
| 358 | + */ |
|
| 359 | + public function getServer() { |
|
| 360 | + return $this->server; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @param string $middleWare |
|
| 365 | + * @return boolean|null |
|
| 366 | + */ |
|
| 367 | + public function registerMiddleWare($middleWare) { |
|
| 368 | + if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
| 369 | + return false; |
|
| 370 | + } |
|
| 371 | + $this->middleWares[] = $middleWare; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * used to return the appname of the set application |
|
| 376 | + * @return string the name of your application |
|
| 377 | + */ |
|
| 378 | + public function getAppName() { |
|
| 379 | + return $this->query('AppName'); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 384 | + * @return boolean |
|
| 385 | + */ |
|
| 386 | + public function isLoggedIn() { |
|
| 387 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 392 | + * @return boolean |
|
| 393 | + */ |
|
| 394 | + public function isAdminUser() { |
|
| 395 | + $uid = $this->getUserId(); |
|
| 396 | + return \OC_User::isAdminUser($uid); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + private function getUserId() { |
|
| 400 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @deprecated use the ILogger instead |
|
| 405 | + * @param string $message |
|
| 406 | + * @param string $level |
|
| 407 | + * @return mixed |
|
| 408 | + */ |
|
| 409 | + public function log($message, $level) { |
|
| 410 | + switch ($level) { |
|
| 411 | + case 'debug': |
|
| 412 | + $level = ILogger::DEBUG; |
|
| 413 | + break; |
|
| 414 | + case 'info': |
|
| 415 | + $level = ILogger::INFO; |
|
| 416 | + break; |
|
| 417 | + case 'warn': |
|
| 418 | + $level = ILogger::WARN; |
|
| 419 | + break; |
|
| 420 | + case 'fatal': |
|
| 421 | + $level = ILogger::FATAL; |
|
| 422 | + break; |
|
| 423 | + default: |
|
| 424 | + $level = ILogger::ERROR; |
|
| 425 | + break; |
|
| 426 | + } |
|
| 427 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Register a capability |
|
| 432 | + * |
|
| 433 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 434 | + */ |
|
| 435 | + public function registerCapability($serviceName) { |
|
| 436 | + $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
| 437 | + return $this->query($serviceName); |
|
| 438 | + }); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + public function has($id): bool { |
|
| 442 | + if (parent::has($id)) { |
|
| 443 | + return true; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + if ($this->server->has($id, true)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + public function query(string $name, bool $autoload = true) { |
|
| 454 | + if ($name === 'AppName' || $name === 'appName') { |
|
| 455 | + return $this->appName; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); |
|
| 459 | + if ($isServerClass && !$this->has($name)) { |
|
| 460 | + return $this->getServer()->query($name, $autoload); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + try { |
|
| 464 | + return $this->queryNoFallback($name); |
|
| 465 | + } catch (QueryException $firstException) { |
|
| 466 | + try { |
|
| 467 | + return $this->getServer()->query($name, $autoload); |
|
| 468 | + } catch (QueryException $secondException) { |
|
| 469 | + if ($firstException->getCode() === 1) { |
|
| 470 | + throw $secondException; |
|
| 471 | + } |
|
| 472 | + throw $firstException; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * @param string $name |
|
| 479 | + * @return mixed |
|
| 480 | + * @throws QueryException if the query could not be resolved |
|
| 481 | + */ |
|
| 482 | + public function queryNoFallback($name) { |
|
| 483 | + $name = $this->sanitizeName($name); |
|
| 484 | + |
|
| 485 | + if ($this->offsetExists($name)) { |
|
| 486 | + return parent::query($name); |
|
| 487 | + } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { |
|
| 488 | + return parent::query($name); |
|
| 489 | + } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { |
|
| 490 | + return parent::query($name); |
|
| 491 | + } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { |
|
| 492 | + return parent::query($name); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 496 | + ' Class can not be instantiated', 1); |
|
| 497 | + } |
|
| 498 | 498 | } |