diff options
Diffstat (limited to 'lib/private/AppFramework/Bootstrap/RegistrationContext.php')
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 179 |
1 files changed, 78 insertions, 101 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index d2dc365d835..619e4f55011 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -34,50 +34,58 @@ use Closure; use OC\Support\CrashReport\Registry; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\Middleware; +use OCP\Authentication\IAlternativeLogin; +use OCP\Capabilities\ICapability; use OCP\Dashboard\IManager; +use OCP\Dashboard\IWidget; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Template\ICustomTemplateProvider; +use OCP\Http\WellKnown\IHandler; use OCP\ILogger; +use OCP\Search\IProvider; +use OCP\Support\CrashReport\IReporter; use Throwable; class RegistrationContext { - /** @var array[] */ + /** @var ServiceRegistration<ICapability>[] */ private $capabilities = []; - /** @var array[] */ + /** @var ServiceRegistration<IReporter>[] */ private $crashReporters = []; - /** @var array[] */ + /** @var ServiceRegistration<IWidget>[] */ private $dashboardPanels = []; - /** @var array[] */ + /** @var ServiceFactoryRegistration[] */ private $services = []; - /** @var array[] */ + /** @var ServiceAliasRegistration[] */ private $aliases = []; - /** @var array[] */ + /** @var ParameterRegistration[] */ private $parameters = []; - /** @var array[] */ + /** @var EventListenerRegistration[] */ private $eventListeners = []; - /** @var array[] */ + /** @var ServiceRegistration<Middleware>[] */ private $middlewares = []; - /** @var array[] */ + /** @var ServiceRegistration<IProvider>[] */ private $searchProviders = []; - /** @var array[] */ + /** @var ServiceRegistration<IAlternativeLogin>[] */ private $alternativeLogins = []; /** @var array[] */ private $initialStates = []; - /** @var array[] */ + /** @var ServiceRegistration<IHandler>[] */ private $wellKnownHandlers = []; - /** @var array[] */ + /** @var ServiceRegistration<ICustomTemplateProvider>[] */ private $templateProviders = []; /** @var ILogger */ @@ -199,80 +207,56 @@ class RegistrationContext { }; } + /** + * @psalm-param class-string<ICapability> $capability + */ public function registerCapability(string $appId, string $capability): void { - $this->capabilities[] = [ - 'appId' => $appId, - 'capability' => $capability - ]; + $this->capabilities[] = new ServiceRegistration($appId, $capability); } + /** + * @psalm-param class-string<IReporter> $capability + */ public function registerCrashReporter(string $appId, string $reporterClass): void { - $this->crashReporters[] = [ - 'appId' => $appId, - 'class' => $reporterClass, - ]; + $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); } + /** + * @psalm-param class-string<IWidget> $capability + */ public function registerDashboardPanel(string $appId, string $panelClass): void { - $this->dashboardPanels[] = [ - 'appId' => $appId, - 'class' => $panelClass - ]; + $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); } public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { - $this->services[] = [ - "appId" => $appId, - "name" => $name, - "factory" => $factory, - "shared" => $shared, - ]; + $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); } public function registerServiceAlias(string $appId, string $alias, string $target): void { - $this->aliases[] = [ - "appId" => $appId, - "alias" => $alias, - "target" => $target, - ]; + $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); } public function registerParameter(string $appId, string $name, $value): void { - $this->parameters[] = [ - "appId" => $appId, - "name" => $name, - "value" => $value, - ]; + $this->parameters[] = new ParameterRegistration($appId, $name, $value); } public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { - $this->eventListeners[] = [ - "appId" => $appId, - "event" => $event, - "listener" => $listener, - "priority" => $priority, - ]; + $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); } + /** + * @psalm-param class-string<Middleware> $class + */ public function registerMiddleware(string $appId, string $class): void { - $this->middlewares[] = [ - "appId" => $appId, - "class" => $class, - ]; + $this->middlewares[] = new ServiceRegistration($appId, $class); } public function registerSearchProvider(string $appId, string $class) { - $this->searchProviders[] = [ - 'appId' => $appId, - 'class' => $class, - ]; + $this->searchProviders[] = new ServiceRegistration($appId, $class); } public function registerAlternativeLogin(string $appId, string $class): void { - $this->alternativeLogins[] = [ - 'appId' => $appId, - 'class' => $class, - ]; + $this->alternativeLogins[] = new ServiceRegistration($appId, $class); } public function registerInitialState(string $appId, string $class): void { @@ -283,10 +267,7 @@ class RegistrationContext { } public function registerWellKnown(string $appId, string $class): void { - $this->wellKnownHandlers[] = [ - 'appId' => $appId, - 'class' => $class, - ]; + $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); } public function registerTemplateProvider(string $appId, string $class): void { @@ -302,11 +283,11 @@ class RegistrationContext { public function delegateCapabilityRegistrations(array $apps): void { while (($registration = array_shift($this->capabilities)) !== null) { try { - $apps[$registration['appId']] + $apps[$registration->getAppId()] ->getContainer() - ->registerCapability($registration['capability']); + ->registerCapability($registration->getService()); } catch (Throwable $e) { - $appId = $registration['appId']; + $appId = $registration->getAppId(); $this->logger->logException($e, [ 'message' => "Error during capability registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -321,9 +302,9 @@ class RegistrationContext { public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { while (($registration = array_shift($this->crashReporters)) !== null) { try { - $registry->registerLazy($registration['class']); + $registry->registerLazy($registration->getService()); } catch (Throwable $e) { - $appId = $registration['appId']; + $appId = $registration->getAppId(); $this->logger->logException($e, [ 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -338,9 +319,9 @@ class RegistrationContext { public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { while (($panel = array_shift($this->dashboardPanels)) !== null) { try { - $dashboardManager->lazyRegisterWidget($panel['class']); + $dashboardManager->lazyRegisterWidget($panel->getService()); } catch (Throwable $e) { - $appId = $panel['appId']; + $appId = $panel->getAppId(); $this->logger->logException($e, [ 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -352,20 +333,13 @@ class RegistrationContext { public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { while (($registration = array_shift($this->eventListeners)) !== null) { try { - if (isset($registration['priority'])) { - $eventDispatcher->addServiceListener( - $registration['event'], - $registration['listener'], - $registration['priority'] - ); - } else { - $eventDispatcher->addServiceListener( - $registration['event'], - $registration['listener'] - ); - } + $eventDispatcher->addServiceListener( + $registration->getEvent(), + $registration->getService(), + $registration->getPriority() + ); } catch (Throwable $e) { - $appId = $registration['appId']; + $appId = $registration->getAppId(); $this->logger->logException($e, [ 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -383,15 +357,15 @@ class RegistrationContext { /** * Register the service and convert the callable into a \Closure if necessary */ - $apps[$registration['appId']] + $apps[$registration->getAppId()] ->getContainer() ->registerService( - $registration['name'], - Closure::fromCallable($registration['factory']), - $registration['shared'] ?? true + $registration->getName(), + Closure::fromCallable($registration->getFactory()), + $registration->isShared() ); } catch (Throwable $e) { - $appId = $registration['appId']; + $appId = $registration->getAppId(); $this->logger->logException($e, [ 'message' => "Error during service registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -401,14 +375,14 @@ class RegistrationContext { foreach ($this->aliases as $registration) { try { - $apps[$registration['appId']] + $apps[$registration->getAppId()] ->getContainer() ->registerAlias( - $registration['alias'], - $registration['target'] + $registration->getAlias(), + $registration->getTarget() ); } catch (Throwable $e) { - $appId = $registration['appId']; + $appId = $registration->getAppId(); $this->logger->logException($e, [ 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -418,14 +392,14 @@ class RegistrationContext { foreach ($this->parameters as $registration) { try { - $apps[$registration['appId']] + $apps[$registration->getAppId()] ->getContainer() ->registerParameter( - $registration['name'], - $registration['value'] + $registration->getName(), + $registration->getValue() ); } catch (Throwable $e) { - $appId = $registration['appId']; + $appId = $registration->getAppId(); $this->logger->logException($e, [ 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -440,11 +414,11 @@ class RegistrationContext { public function delegateMiddlewareRegistrations(array $apps): void { while (($middleware = array_shift($this->middlewares)) !== null) { try { - $apps[$middleware['appId']] + $apps[$middleware->getAppId()] ->getContainer() - ->registerMiddleWare($middleware['class']); + ->registerMiddleWare($middleware->getService()); } catch (Throwable $e) { - $appId = $middleware['appId']; + $appId = $middleware->getAppId(); $this->logger->logException($e, [ 'message' => "Error during capability registration of $appId: " . $e->getMessage(), 'level' => ILogger::ERROR, @@ -454,14 +428,14 @@ class RegistrationContext { } /** - * @return array[] + * @return ServiceRegistration<IProvider>[] */ public function getSearchProviders(): array { return $this->searchProviders; } /** - * @return array[] + * @return ServiceRegistration<IAlternativeLogin>[] */ public function getAlternativeLogins(): array { return $this->alternativeLogins; @@ -475,12 +449,15 @@ class RegistrationContext { } /** - * @return array[] + * @return ServiceRegistration<IHandler>[] */ public function getWellKnownHandlers(): array { return $this->wellKnownHandlers; } + /** + * @return ServiceRegistration<ICustomTemplateProvider>[] + */ public function getTemplateProviders(): array { return $this->templateProviders; } |