@@ -45,26 +45,26 @@ |
||
45 | 45 | use OCP\User\Events\UserDeletedEvent; |
46 | 46 | |
47 | 47 | class Application extends App implements IBootstrap { |
48 | - public const APP_ID = 'twofactor_backupcodes'; |
|
48 | + public const APP_ID = 'twofactor_backupcodes'; |
|
49 | 49 | |
50 | - public function __construct() { |
|
51 | - parent::__construct(self::APP_ID); |
|
52 | - } |
|
50 | + public function __construct() { |
|
51 | + parent::__construct(self::APP_ID); |
|
52 | + } |
|
53 | 53 | |
54 | - public function register(IRegistrationContext $context): void { |
|
55 | - $context->registerNotifierService(Notifier::class); |
|
54 | + public function register(IRegistrationContext $context): void { |
|
55 | + $context->registerNotifierService(Notifier::class); |
|
56 | 56 | |
57 | - $context->registerEventListener(CodesGenerated::class, ActivityPublisher::class); |
|
58 | - $context->registerEventListener(CodesGenerated::class, RegistryUpdater::class); |
|
59 | - $context->registerEventListener(CodesGenerated::class, ClearNotifications::class); |
|
60 | - $context->registerEventListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); |
|
61 | - $context->registerEventListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); |
|
62 | - $context->registerEventListener(UserDeletedEvent::class, UserDeleted::class); |
|
57 | + $context->registerEventListener(CodesGenerated::class, ActivityPublisher::class); |
|
58 | + $context->registerEventListener(CodesGenerated::class, RegistryUpdater::class); |
|
59 | + $context->registerEventListener(CodesGenerated::class, ClearNotifications::class); |
|
60 | + $context->registerEventListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); |
|
61 | + $context->registerEventListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); |
|
62 | + $context->registerEventListener(UserDeletedEvent::class, UserDeleted::class); |
|
63 | 63 | |
64 | 64 | |
65 | - $context->registerTwoFactorProvider(BackupCodesProvider::class); |
|
66 | - } |
|
65 | + $context->registerTwoFactorProvider(BackupCodesProvider::class); |
|
66 | + } |
|
67 | 67 | |
68 | - public function boot(IBootContext $context): void { |
|
69 | - } |
|
68 | + public function boot(IBootContext $context): void { |
|
69 | + } |
|
70 | 70 | } |
@@ -45,188 +45,188 @@ |
||
45 | 45 | */ |
46 | 46 | interface IRegistrationContext { |
47 | 47 | |
48 | - /** |
|
49 | - * @param string $capability |
|
50 | - * @psalm-param class-string<ICapability> $capability |
|
51 | - * @see IAppContainer::registerCapability |
|
52 | - * |
|
53 | - * @since 20.0.0 |
|
54 | - */ |
|
55 | - public function registerCapability(string $capability): void; |
|
56 | - |
|
57 | - /** |
|
58 | - * Register an implementation of \OCP\Support\CrashReport\IReporter that |
|
59 | - * will receive unhandled exceptions and throwables |
|
60 | - * |
|
61 | - * @param string $reporterClass |
|
62 | - * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass |
|
63 | - * @return void |
|
64 | - * @since 20.0.0 |
|
65 | - */ |
|
66 | - public function registerCrashReporter(string $reporterClass): void; |
|
67 | - |
|
68 | - /** |
|
69 | - * Register an implementation of \OCP\Dashboard\IWidget that |
|
70 | - * will handle the implementation of a dashboard widget |
|
71 | - * |
|
72 | - * @param string $widgetClass |
|
73 | - * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass |
|
74 | - * @return void |
|
75 | - * @since 20.0.0 |
|
76 | - */ |
|
77 | - public function registerDashboardWidget(string $widgetClass): void; |
|
78 | - /** |
|
79 | - * Register a service |
|
80 | - * |
|
81 | - * @param string $name |
|
82 | - * @param callable $factory |
|
83 | - * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory |
|
84 | - * @param bool $shared |
|
85 | - * |
|
86 | - * @return void |
|
87 | - * @see IContainer::registerService() |
|
88 | - * |
|
89 | - * @since 20.0.0 |
|
90 | - */ |
|
91 | - public function registerService(string $name, callable $factory, bool $shared = true): void; |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $alias |
|
95 | - * @psalm-param string|class-string $alias |
|
96 | - * @param string $target |
|
97 | - * @psalm-param string|class-string $target |
|
98 | - * |
|
99 | - * @return void |
|
100 | - * @see IContainer::registerAlias() |
|
101 | - * |
|
102 | - * @since 20.0.0 |
|
103 | - */ |
|
104 | - public function registerServiceAlias(string $alias, string $target): void; |
|
105 | - |
|
106 | - /** |
|
107 | - * @param string $name |
|
108 | - * @param mixed $value |
|
109 | - * |
|
110 | - * @return void |
|
111 | - * @see IContainer::registerParameter() |
|
112 | - * |
|
113 | - * @since 20.0.0 |
|
114 | - */ |
|
115 | - public function registerParameter(string $name, $value): void; |
|
116 | - |
|
117 | - /** |
|
118 | - * Register a service listener |
|
119 | - * |
|
120 | - * This is equivalent to calling IEventDispatcher::addServiceListener |
|
121 | - * |
|
122 | - * @template T of \OCP\EventDispatcher\Event |
|
123 | - * @param string $event preferably the fully-qualified class name of the Event sub class to listen for |
|
124 | - * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for |
|
125 | - * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
126 | - * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container |
|
127 | - * @param int $priority The higher this value, the earlier an event |
|
128 | - * listener will be triggered in the chain (defaults to 0) |
|
129 | - * |
|
130 | - * @see IEventDispatcher::addServiceListener() |
|
131 | - * |
|
132 | - * @since 20.0.0 |
|
133 | - */ |
|
134 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void; |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $class |
|
138 | - * @psalm-param class-string<\OCP\AppFramework\Middleware> $class |
|
139 | - * |
|
140 | - * @return void |
|
141 | - * @see IAppContainer::registerMiddleWare() |
|
142 | - * |
|
143 | - * @since 20.0.0 |
|
144 | - */ |
|
145 | - public function registerMiddleware(string $class): void; |
|
146 | - |
|
147 | - /** |
|
148 | - * Register a search provider for the unified search |
|
149 | - * |
|
150 | - * It is allowed to register more than one provider per app as the search |
|
151 | - * results can go into distinct sections, e.g. "Files" and "Files shared |
|
152 | - * with you" in the Files app. |
|
153 | - * |
|
154 | - * @param string $class |
|
155 | - * @psalm-param class-string<\OCP\Search\IProvider> $class |
|
156 | - * |
|
157 | - * @return void |
|
158 | - * |
|
159 | - * @since 20.0.0 |
|
160 | - */ |
|
161 | - public function registerSearchProvider(string $class): void; |
|
162 | - |
|
163 | - /** |
|
164 | - * Register an alternative login option |
|
165 | - * |
|
166 | - * It is allowed to register more than one option per app. |
|
167 | - * |
|
168 | - * @param string $class |
|
169 | - * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class |
|
170 | - * |
|
171 | - * @return void |
|
172 | - * |
|
173 | - * @since 20.0.0 |
|
174 | - */ |
|
175 | - public function registerAlternativeLogin(string $class): void; |
|
176 | - |
|
177 | - /** |
|
178 | - * Register an initialstate provider |
|
179 | - * |
|
180 | - * It is allowed to register more than one provider per app. |
|
181 | - * |
|
182 | - * @param string $class |
|
183 | - * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class |
|
184 | - * |
|
185 | - * @return void |
|
186 | - * |
|
187 | - * @since 21.0.0 |
|
188 | - */ |
|
189 | - public function registerInitialStateProvider(string $class): void; |
|
190 | - |
|
191 | - /** |
|
192 | - * Register a well known protocol handler |
|
193 | - * |
|
194 | - * It is allowed to register more than one handler per app. |
|
195 | - * |
|
196 | - * @param string $class |
|
197 | - * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class |
|
198 | - * |
|
199 | - * @return void |
|
200 | - * |
|
201 | - * @since 21.0.0 |
|
202 | - */ |
|
203 | - public function registerWellKnownHandler(string $class): void; |
|
204 | - |
|
205 | - /** |
|
206 | - * Register a custom template provider class that is able to inject custom templates |
|
207 | - * in addition to the user defined ones |
|
208 | - * |
|
209 | - * @param string $providerClass |
|
210 | - * @psalm-param class-string<ICustomTemplateProvider> $providerClass |
|
211 | - * @since 21.0.0 |
|
212 | - */ |
|
213 | - public function registerTemplateProvider(string $providerClass): void; |
|
214 | - |
|
215 | - /** |
|
216 | - * Register an INotifier class |
|
217 | - * |
|
218 | - * @param string $notifierClass |
|
219 | - * @psalm-param class-string<INotifier> $notifierClass |
|
220 | - * @since 22.0.0 |
|
221 | - */ |
|
222 | - public function registerNotifierService(string $notifierClass): void; |
|
223 | - |
|
224 | - /** |
|
225 | - * Register a two-factor provider |
|
226 | - * |
|
227 | - * @param string $twoFactorProviderClass |
|
228 | - * @psalm-param class-string<IProvider> $twoFactorProviderClass |
|
229 | - * @since 22.0.0 |
|
230 | - */ |
|
231 | - public function registerTwoFactorProvider(string $twoFactorProviderClass): void; |
|
48 | + /** |
|
49 | + * @param string $capability |
|
50 | + * @psalm-param class-string<ICapability> $capability |
|
51 | + * @see IAppContainer::registerCapability |
|
52 | + * |
|
53 | + * @since 20.0.0 |
|
54 | + */ |
|
55 | + public function registerCapability(string $capability): void; |
|
56 | + |
|
57 | + /** |
|
58 | + * Register an implementation of \OCP\Support\CrashReport\IReporter that |
|
59 | + * will receive unhandled exceptions and throwables |
|
60 | + * |
|
61 | + * @param string $reporterClass |
|
62 | + * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass |
|
63 | + * @return void |
|
64 | + * @since 20.0.0 |
|
65 | + */ |
|
66 | + public function registerCrashReporter(string $reporterClass): void; |
|
67 | + |
|
68 | + /** |
|
69 | + * Register an implementation of \OCP\Dashboard\IWidget that |
|
70 | + * will handle the implementation of a dashboard widget |
|
71 | + * |
|
72 | + * @param string $widgetClass |
|
73 | + * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass |
|
74 | + * @return void |
|
75 | + * @since 20.0.0 |
|
76 | + */ |
|
77 | + public function registerDashboardWidget(string $widgetClass): void; |
|
78 | + /** |
|
79 | + * Register a service |
|
80 | + * |
|
81 | + * @param string $name |
|
82 | + * @param callable $factory |
|
83 | + * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory |
|
84 | + * @param bool $shared |
|
85 | + * |
|
86 | + * @return void |
|
87 | + * @see IContainer::registerService() |
|
88 | + * |
|
89 | + * @since 20.0.0 |
|
90 | + */ |
|
91 | + public function registerService(string $name, callable $factory, bool $shared = true): void; |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $alias |
|
95 | + * @psalm-param string|class-string $alias |
|
96 | + * @param string $target |
|
97 | + * @psalm-param string|class-string $target |
|
98 | + * |
|
99 | + * @return void |
|
100 | + * @see IContainer::registerAlias() |
|
101 | + * |
|
102 | + * @since 20.0.0 |
|
103 | + */ |
|
104 | + public function registerServiceAlias(string $alias, string $target): void; |
|
105 | + |
|
106 | + /** |
|
107 | + * @param string $name |
|
108 | + * @param mixed $value |
|
109 | + * |
|
110 | + * @return void |
|
111 | + * @see IContainer::registerParameter() |
|
112 | + * |
|
113 | + * @since 20.0.0 |
|
114 | + */ |
|
115 | + public function registerParameter(string $name, $value): void; |
|
116 | + |
|
117 | + /** |
|
118 | + * Register a service listener |
|
119 | + * |
|
120 | + * This is equivalent to calling IEventDispatcher::addServiceListener |
|
121 | + * |
|
122 | + * @template T of \OCP\EventDispatcher\Event |
|
123 | + * @param string $event preferably the fully-qualified class name of the Event sub class to listen for |
|
124 | + * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for |
|
125 | + * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
126 | + * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container |
|
127 | + * @param int $priority The higher this value, the earlier an event |
|
128 | + * listener will be triggered in the chain (defaults to 0) |
|
129 | + * |
|
130 | + * @see IEventDispatcher::addServiceListener() |
|
131 | + * |
|
132 | + * @since 20.0.0 |
|
133 | + */ |
|
134 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void; |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $class |
|
138 | + * @psalm-param class-string<\OCP\AppFramework\Middleware> $class |
|
139 | + * |
|
140 | + * @return void |
|
141 | + * @see IAppContainer::registerMiddleWare() |
|
142 | + * |
|
143 | + * @since 20.0.0 |
|
144 | + */ |
|
145 | + public function registerMiddleware(string $class): void; |
|
146 | + |
|
147 | + /** |
|
148 | + * Register a search provider for the unified search |
|
149 | + * |
|
150 | + * It is allowed to register more than one provider per app as the search |
|
151 | + * results can go into distinct sections, e.g. "Files" and "Files shared |
|
152 | + * with you" in the Files app. |
|
153 | + * |
|
154 | + * @param string $class |
|
155 | + * @psalm-param class-string<\OCP\Search\IProvider> $class |
|
156 | + * |
|
157 | + * @return void |
|
158 | + * |
|
159 | + * @since 20.0.0 |
|
160 | + */ |
|
161 | + public function registerSearchProvider(string $class): void; |
|
162 | + |
|
163 | + /** |
|
164 | + * Register an alternative login option |
|
165 | + * |
|
166 | + * It is allowed to register more than one option per app. |
|
167 | + * |
|
168 | + * @param string $class |
|
169 | + * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class |
|
170 | + * |
|
171 | + * @return void |
|
172 | + * |
|
173 | + * @since 20.0.0 |
|
174 | + */ |
|
175 | + public function registerAlternativeLogin(string $class): void; |
|
176 | + |
|
177 | + /** |
|
178 | + * Register an initialstate provider |
|
179 | + * |
|
180 | + * It is allowed to register more than one provider per app. |
|
181 | + * |
|
182 | + * @param string $class |
|
183 | + * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class |
|
184 | + * |
|
185 | + * @return void |
|
186 | + * |
|
187 | + * @since 21.0.0 |
|
188 | + */ |
|
189 | + public function registerInitialStateProvider(string $class): void; |
|
190 | + |
|
191 | + /** |
|
192 | + * Register a well known protocol handler |
|
193 | + * |
|
194 | + * It is allowed to register more than one handler per app. |
|
195 | + * |
|
196 | + * @param string $class |
|
197 | + * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class |
|
198 | + * |
|
199 | + * @return void |
|
200 | + * |
|
201 | + * @since 21.0.0 |
|
202 | + */ |
|
203 | + public function registerWellKnownHandler(string $class): void; |
|
204 | + |
|
205 | + /** |
|
206 | + * Register a custom template provider class that is able to inject custom templates |
|
207 | + * in addition to the user defined ones |
|
208 | + * |
|
209 | + * @param string $providerClass |
|
210 | + * @psalm-param class-string<ICustomTemplateProvider> $providerClass |
|
211 | + * @since 21.0.0 |
|
212 | + */ |
|
213 | + public function registerTemplateProvider(string $providerClass): void; |
|
214 | + |
|
215 | + /** |
|
216 | + * Register an INotifier class |
|
217 | + * |
|
218 | + * @param string $notifierClass |
|
219 | + * @psalm-param class-string<INotifier> $notifierClass |
|
220 | + * @since 22.0.0 |
|
221 | + */ |
|
222 | + public function registerNotifierService(string $notifierClass): void; |
|
223 | + |
|
224 | + /** |
|
225 | + * Register a two-factor provider |
|
226 | + * |
|
227 | + * @param string $twoFactorProviderClass |
|
228 | + * @psalm-param class-string<IProvider> $twoFactorProviderClass |
|
229 | + * @since 22.0.0 |
|
230 | + */ |
|
231 | + public function registerTwoFactorProvider(string $twoFactorProviderClass): void; |
|
232 | 232 | } |
@@ -35,70 +35,70 @@ |
||
35 | 35 | use OCP\IUser; |
36 | 36 | |
37 | 37 | class ProviderLoader { |
38 | - public const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
38 | + public const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
39 | 39 | |
40 | - /** @var IAppManager */ |
|
41 | - private $appManager; |
|
40 | + /** @var IAppManager */ |
|
41 | + private $appManager; |
|
42 | 42 | |
43 | - /** @var OC\AppFramework\Bootstrap\Coordinator */ |
|
44 | - private $coordinator; |
|
43 | + /** @var OC\AppFramework\Bootstrap\Coordinator */ |
|
44 | + private $coordinator; |
|
45 | 45 | |
46 | - public function __construct(IAppManager $appManager, OC\AppFramework\Bootstrap\Coordinator $coordinator) { |
|
47 | - $this->appManager = $appManager; |
|
48 | - $this->coordinator = $coordinator; |
|
49 | - } |
|
46 | + public function __construct(IAppManager $appManager, OC\AppFramework\Bootstrap\Coordinator $coordinator) { |
|
47 | + $this->appManager = $appManager; |
|
48 | + $this->coordinator = $coordinator; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Get the list of 2FA providers for the given user |
|
53 | - * |
|
54 | - * @return IProvider[] |
|
55 | - * @throws Exception |
|
56 | - */ |
|
57 | - public function getProviders(IUser $user): array { |
|
58 | - $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
59 | - $providers = []; |
|
51 | + /** |
|
52 | + * Get the list of 2FA providers for the given user |
|
53 | + * |
|
54 | + * @return IProvider[] |
|
55 | + * @throws Exception |
|
56 | + */ |
|
57 | + public function getProviders(IUser $user): array { |
|
58 | + $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
59 | + $providers = []; |
|
60 | 60 | |
61 | - foreach ($allApps as $appId) { |
|
62 | - $info = $this->appManager->getAppInfo($appId); |
|
63 | - if (isset($info['two-factor-providers'])) { |
|
64 | - /** @var string[] $providerClasses */ |
|
65 | - $providerClasses = $info['two-factor-providers']; |
|
66 | - foreach ($providerClasses as $class) { |
|
67 | - try { |
|
68 | - $this->loadTwoFactorApp($appId); |
|
69 | - $provider = OC::$server->query($class); |
|
70 | - $providers[$provider->getId()] = $provider; |
|
71 | - } catch (QueryException $exc) { |
|
72 | - // Provider class can not be resolved |
|
73 | - throw new Exception("Could not load two-factor auth provider $class"); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
61 | + foreach ($allApps as $appId) { |
|
62 | + $info = $this->appManager->getAppInfo($appId); |
|
63 | + if (isset($info['two-factor-providers'])) { |
|
64 | + /** @var string[] $providerClasses */ |
|
65 | + $providerClasses = $info['two-factor-providers']; |
|
66 | + foreach ($providerClasses as $class) { |
|
67 | + try { |
|
68 | + $this->loadTwoFactorApp($appId); |
|
69 | + $provider = OC::$server->query($class); |
|
70 | + $providers[$provider->getId()] = $provider; |
|
71 | + } catch (QueryException $exc) { |
|
72 | + // Provider class can not be resolved |
|
73 | + throw new Exception("Could not load two-factor auth provider $class"); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - $registeredProviders = $this->coordinator->getRegistrationContext()->getTwoFactorProviders(); |
|
80 | - foreach ($registeredProviders as $provider) { |
|
81 | - try { |
|
82 | - $this->loadTwoFactorApp($provider->getAppId()); |
|
83 | - $provider = OC::$server->query($provider->getService()); |
|
84 | - $providers[$provider->getId()] = $provider; |
|
85 | - } catch (QueryException $exc) { |
|
86 | - // Provider class can not be resolved |
|
87 | - throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); |
|
88 | - } |
|
89 | - } |
|
79 | + $registeredProviders = $this->coordinator->getRegistrationContext()->getTwoFactorProviders(); |
|
80 | + foreach ($registeredProviders as $provider) { |
|
81 | + try { |
|
82 | + $this->loadTwoFactorApp($provider->getAppId()); |
|
83 | + $provider = OC::$server->query($provider->getService()); |
|
84 | + $providers[$provider->getId()] = $provider; |
|
85 | + } catch (QueryException $exc) { |
|
86 | + // Provider class can not be resolved |
|
87 | + throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - return $providers; |
|
92 | - } |
|
91 | + return $providers; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Load an app by ID if it has not been loaded yet |
|
96 | - * |
|
97 | - * @param string $appId |
|
98 | - */ |
|
99 | - protected function loadTwoFactorApp(string $appId) { |
|
100 | - if (!OC_App::isAppLoaded($appId)) { |
|
101 | - OC_App::loadApp($appId); |
|
102 | - } |
|
103 | - } |
|
94 | + /** |
|
95 | + * Load an app by ID if it has not been loaded yet |
|
96 | + * |
|
97 | + * @param string $appId |
|
98 | + */ |
|
99 | + protected function loadTwoFactorApp(string $appId) { |
|
100 | + if (!OC_App::isAppLoaded($appId)) { |
|
101 | + OC_App::loadApp($appId); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | $providers[$provider->getId()] = $provider; |
85 | 85 | } catch (QueryException $exc) { |
86 | 86 | // Provider class can not be resolved |
87 | - throw new Exception('Could not load two-factor auth provider ' . $provider->getService()); |
|
87 | + throw new Exception('Could not load two-factor auth provider '.$provider->getService()); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 |
@@ -52,452 +52,452 @@ |
||
52 | 52 | |
53 | 53 | class RegistrationContext { |
54 | 54 | |
55 | - /** @var ServiceRegistration<ICapability>[] */ |
|
56 | - private $capabilities = []; |
|
55 | + /** @var ServiceRegistration<ICapability>[] */ |
|
56 | + private $capabilities = []; |
|
57 | 57 | |
58 | - /** @var ServiceRegistration<IReporter>[] */ |
|
59 | - private $crashReporters = []; |
|
60 | - |
|
61 | - /** @var ServiceRegistration<IWidget>[] */ |
|
62 | - private $dashboardPanels = []; |
|
63 | - |
|
64 | - /** @var ServiceFactoryRegistration[] */ |
|
65 | - private $services = []; |
|
66 | - |
|
67 | - /** @var ServiceAliasRegistration[] */ |
|
68 | - private $aliases = []; |
|
69 | - |
|
70 | - /** @var ParameterRegistration[] */ |
|
71 | - private $parameters = []; |
|
72 | - |
|
73 | - /** @var EventListenerRegistration[] */ |
|
74 | - private $eventListeners = []; |
|
75 | - |
|
76 | - /** @var ServiceRegistration<Middleware>[] */ |
|
77 | - private $middlewares = []; |
|
78 | - |
|
79 | - /** @var ServiceRegistration<IProvider>[] */ |
|
80 | - private $searchProviders = []; |
|
81 | - |
|
82 | - /** @var ServiceRegistration<IAlternativeLogin>[] */ |
|
83 | - private $alternativeLogins = []; |
|
84 | - |
|
85 | - /** @var ServiceRegistration<InitialStateProvider>[] */ |
|
86 | - private $initialStates = []; |
|
87 | - |
|
88 | - /** @var ServiceRegistration<IHandler>[] */ |
|
89 | - private $wellKnownHandlers = []; |
|
90 | - |
|
91 | - /** @var ServiceRegistration<ICustomTemplateProvider>[] */ |
|
92 | - private $templateProviders = []; |
|
93 | - |
|
94 | - /** @var ServiceRegistration<INotifier>[] */ |
|
95 | - private $notifierServices = []; |
|
96 | - |
|
97 | - /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ |
|
98 | - private $twoFactorProviders = []; |
|
99 | - |
|
100 | - /** @var ILogger */ |
|
101 | - private $logger; |
|
102 | - |
|
103 | - public function __construct(ILogger $logger) { |
|
104 | - $this->logger = $logger; |
|
105 | - } |
|
106 | - |
|
107 | - public function for(string $appId): IRegistrationContext { |
|
108 | - return new class($appId, $this) implements IRegistrationContext { |
|
109 | - /** @var string */ |
|
110 | - private $appId; |
|
111 | - |
|
112 | - /** @var RegistrationContext */ |
|
113 | - private $context; |
|
114 | - |
|
115 | - public function __construct(string $appId, RegistrationContext $context) { |
|
116 | - $this->appId = $appId; |
|
117 | - $this->context = $context; |
|
118 | - } |
|
119 | - |
|
120 | - public function registerCapability(string $capability): void { |
|
121 | - $this->context->registerCapability( |
|
122 | - $this->appId, |
|
123 | - $capability |
|
124 | - ); |
|
125 | - } |
|
126 | - |
|
127 | - public function registerCrashReporter(string $reporterClass): void { |
|
128 | - $this->context->registerCrashReporter( |
|
129 | - $this->appId, |
|
130 | - $reporterClass |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - public function registerDashboardWidget(string $widgetClass): void { |
|
135 | - $this->context->registerDashboardPanel( |
|
136 | - $this->appId, |
|
137 | - $widgetClass |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - public function registerService(string $name, callable $factory, bool $shared = true): void { |
|
142 | - $this->context->registerService( |
|
143 | - $this->appId, |
|
144 | - $name, |
|
145 | - $factory, |
|
146 | - $shared |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - public function registerServiceAlias(string $alias, string $target): void { |
|
151 | - $this->context->registerServiceAlias( |
|
152 | - $this->appId, |
|
153 | - $alias, |
|
154 | - $target |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - public function registerParameter(string $name, $value): void { |
|
159 | - $this->context->registerParameter( |
|
160 | - $this->appId, |
|
161 | - $name, |
|
162 | - $value |
|
163 | - ); |
|
164 | - } |
|
165 | - |
|
166 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
|
167 | - $this->context->registerEventListener( |
|
168 | - $this->appId, |
|
169 | - $event, |
|
170 | - $listener, |
|
171 | - $priority |
|
172 | - ); |
|
173 | - } |
|
174 | - |
|
175 | - public function registerMiddleware(string $class): void { |
|
176 | - $this->context->registerMiddleware( |
|
177 | - $this->appId, |
|
178 | - $class |
|
179 | - ); |
|
180 | - } |
|
181 | - |
|
182 | - public function registerSearchProvider(string $class): void { |
|
183 | - $this->context->registerSearchProvider( |
|
184 | - $this->appId, |
|
185 | - $class |
|
186 | - ); |
|
187 | - } |
|
188 | - |
|
189 | - public function registerAlternativeLogin(string $class): void { |
|
190 | - $this->context->registerAlternativeLogin( |
|
191 | - $this->appId, |
|
192 | - $class |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - public function registerInitialStateProvider(string $class): void { |
|
197 | - $this->context->registerInitialState( |
|
198 | - $this->appId, |
|
199 | - $class |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - public function registerWellKnownHandler(string $class): void { |
|
204 | - $this->context->registerWellKnown( |
|
205 | - $this->appId, |
|
206 | - $class |
|
207 | - ); |
|
208 | - } |
|
209 | - |
|
210 | - public function registerTemplateProvider(string $providerClass): void { |
|
211 | - $this->context->registerTemplateProvider( |
|
212 | - $this->appId, |
|
213 | - $providerClass |
|
214 | - ); |
|
215 | - } |
|
216 | - |
|
217 | - public function registerNotifierService(string $notifierClass): void { |
|
218 | - $this->context->registerNotifierService( |
|
219 | - $this->appId, |
|
220 | - $notifierClass |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - public function registerTwoFactorProvider(string $twoFactorProviderClass): void { |
|
225 | - $this->context->registerTwoFactorProvider( |
|
226 | - $this->appId, |
|
227 | - $twoFactorProviderClass |
|
228 | - ); |
|
229 | - } |
|
230 | - }; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @psalm-param class-string<ICapability> $capability |
|
235 | - */ |
|
236 | - public function registerCapability(string $appId, string $capability): void { |
|
237 | - $this->capabilities[] = new ServiceRegistration($appId, $capability); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @psalm-param class-string<IReporter> $capability |
|
242 | - */ |
|
243 | - public function registerCrashReporter(string $appId, string $reporterClass): void { |
|
244 | - $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @psalm-param class-string<IWidget> $capability |
|
249 | - */ |
|
250 | - public function registerDashboardPanel(string $appId, string $panelClass): void { |
|
251 | - $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); |
|
252 | - } |
|
253 | - |
|
254 | - public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
|
255 | - $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); |
|
256 | - } |
|
257 | - |
|
258 | - public function registerServiceAlias(string $appId, string $alias, string $target): void { |
|
259 | - $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); |
|
260 | - } |
|
261 | - |
|
262 | - public function registerParameter(string $appId, string $name, $value): void { |
|
263 | - $this->parameters[] = new ParameterRegistration($appId, $name, $value); |
|
264 | - } |
|
265 | - |
|
266 | - public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
|
267 | - $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @psalm-param class-string<Middleware> $class |
|
272 | - */ |
|
273 | - public function registerMiddleware(string $appId, string $class): void { |
|
274 | - $this->middlewares[] = new ServiceRegistration($appId, $class); |
|
275 | - } |
|
276 | - |
|
277 | - public function registerSearchProvider(string $appId, string $class) { |
|
278 | - $this->searchProviders[] = new ServiceRegistration($appId, $class); |
|
279 | - } |
|
280 | - |
|
281 | - public function registerAlternativeLogin(string $appId, string $class): void { |
|
282 | - $this->alternativeLogins[] = new ServiceRegistration($appId, $class); |
|
283 | - } |
|
284 | - |
|
285 | - public function registerInitialState(string $appId, string $class): void { |
|
286 | - $this->initialStates[] = new ServiceRegistration($appId, $class); |
|
287 | - } |
|
288 | - |
|
289 | - public function registerWellKnown(string $appId, string $class): void { |
|
290 | - $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); |
|
291 | - } |
|
292 | - |
|
293 | - public function registerTemplateProvider(string $appId, string $class): void { |
|
294 | - $this->templateProviders[] = new ServiceRegistration($appId, $class); |
|
295 | - } |
|
296 | - |
|
297 | - public function registerNotifierService(string $appId, string $class): void { |
|
298 | - $this->notifierServices[] = new ServiceRegistration($appId, $class); |
|
299 | - } |
|
300 | - |
|
301 | - public function registerTwoFactorProvider(string $appId, string $class): void { |
|
302 | - $this->twoFactorProviders[] = new ServiceRegistration($appId, $class); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * @param App[] $apps |
|
307 | - */ |
|
308 | - public function delegateCapabilityRegistrations(array $apps): void { |
|
309 | - while (($registration = array_shift($this->capabilities)) !== null) { |
|
310 | - try { |
|
311 | - $apps[$registration->getAppId()] |
|
312 | - ->getContainer() |
|
313 | - ->registerCapability($registration->getService()); |
|
314 | - } catch (Throwable $e) { |
|
315 | - $appId = $registration->getAppId(); |
|
316 | - $this->logger->logException($e, [ |
|
317 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
318 | - 'level' => ILogger::ERROR, |
|
319 | - ]); |
|
320 | - } |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @param App[] $apps |
|
326 | - */ |
|
327 | - public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
328 | - while (($registration = array_shift($this->crashReporters)) !== null) { |
|
329 | - try { |
|
330 | - $registry->registerLazy($registration->getService()); |
|
331 | - } catch (Throwable $e) { |
|
332 | - $appId = $registration->getAppId(); |
|
333 | - $this->logger->logException($e, [ |
|
334 | - 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), |
|
335 | - 'level' => ILogger::ERROR, |
|
336 | - ]); |
|
337 | - } |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * @param App[] $apps |
|
343 | - */ |
|
344 | - public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { |
|
345 | - while (($panel = array_shift($this->dashboardPanels)) !== null) { |
|
346 | - try { |
|
347 | - $dashboardManager->lazyRegisterWidget($panel->getService()); |
|
348 | - } catch (Throwable $e) { |
|
349 | - $appId = $panel->getAppId(); |
|
350 | - $this->logger->logException($e, [ |
|
351 | - 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), |
|
352 | - 'level' => ILogger::ERROR, |
|
353 | - ]); |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
|
359 | - while (($registration = array_shift($this->eventListeners)) !== null) { |
|
360 | - try { |
|
361 | - $eventDispatcher->addServiceListener( |
|
362 | - $registration->getEvent(), |
|
363 | - $registration->getService(), |
|
364 | - $registration->getPriority() |
|
365 | - ); |
|
366 | - } catch (Throwable $e) { |
|
367 | - $appId = $registration->getAppId(); |
|
368 | - $this->logger->logException($e, [ |
|
369 | - 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), |
|
370 | - 'level' => ILogger::ERROR, |
|
371 | - ]); |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * @param App[] $apps |
|
378 | - */ |
|
379 | - public function delegateContainerRegistrations(array $apps): void { |
|
380 | - while (($registration = array_shift($this->services)) !== null) { |
|
381 | - try { |
|
382 | - /** |
|
383 | - * Register the service and convert the callable into a \Closure if necessary |
|
384 | - */ |
|
385 | - $apps[$registration->getAppId()] |
|
386 | - ->getContainer() |
|
387 | - ->registerService( |
|
388 | - $registration->getName(), |
|
389 | - Closure::fromCallable($registration->getFactory()), |
|
390 | - $registration->isShared() |
|
391 | - ); |
|
392 | - } catch (Throwable $e) { |
|
393 | - $appId = $registration->getAppId(); |
|
394 | - $this->logger->logException($e, [ |
|
395 | - 'message' => "Error during service registration of $appId: " . $e->getMessage(), |
|
396 | - 'level' => ILogger::ERROR, |
|
397 | - ]); |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - while (($registration = array_shift($this->aliases)) !== null) { |
|
402 | - try { |
|
403 | - $apps[$registration->getAppId()] |
|
404 | - ->getContainer() |
|
405 | - ->registerAlias( |
|
406 | - $registration->getAlias(), |
|
407 | - $registration->getTarget() |
|
408 | - ); |
|
409 | - } catch (Throwable $e) { |
|
410 | - $appId = $registration->getAppId(); |
|
411 | - $this->logger->logException($e, [ |
|
412 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
413 | - 'level' => ILogger::ERROR, |
|
414 | - ]); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - while (($registration = array_shift($this->parameters)) !== null) { |
|
419 | - try { |
|
420 | - $apps[$registration->getAppId()] |
|
421 | - ->getContainer() |
|
422 | - ->registerParameter( |
|
423 | - $registration->getName(), |
|
424 | - $registration->getValue() |
|
425 | - ); |
|
426 | - } catch (Throwable $e) { |
|
427 | - $appId = $registration->getAppId(); |
|
428 | - $this->logger->logException($e, [ |
|
429 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
430 | - 'level' => ILogger::ERROR, |
|
431 | - ]); |
|
432 | - } |
|
433 | - } |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * @param App[] $apps |
|
438 | - */ |
|
439 | - public function delegateMiddlewareRegistrations(array $apps): void { |
|
440 | - while (($middleware = array_shift($this->middlewares)) !== null) { |
|
441 | - try { |
|
442 | - $apps[$middleware->getAppId()] |
|
443 | - ->getContainer() |
|
444 | - ->registerMiddleWare($middleware->getService()); |
|
445 | - } catch (Throwable $e) { |
|
446 | - $appId = $middleware->getAppId(); |
|
447 | - $this->logger->logException($e, [ |
|
448 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
449 | - 'level' => ILogger::ERROR, |
|
450 | - ]); |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * @return ServiceRegistration<IProvider>[] |
|
457 | - */ |
|
458 | - public function getSearchProviders(): array { |
|
459 | - return $this->searchProviders; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * @return ServiceRegistration<IAlternativeLogin>[] |
|
464 | - */ |
|
465 | - public function getAlternativeLogins(): array { |
|
466 | - return $this->alternativeLogins; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * @return ServiceRegistration<InitialStateProvider>[] |
|
471 | - */ |
|
472 | - public function getInitialStates(): array { |
|
473 | - return $this->initialStates; |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * @return ServiceRegistration<IHandler>[] |
|
478 | - */ |
|
479 | - public function getWellKnownHandlers(): array { |
|
480 | - return $this->wellKnownHandlers; |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * @return ServiceRegistration<ICustomTemplateProvider>[] |
|
485 | - */ |
|
486 | - public function getTemplateProviders(): array { |
|
487 | - return $this->templateProviders; |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * @return ServiceRegistration<INotifier>[] |
|
492 | - */ |
|
493 | - public function getNotifierServices(): array { |
|
494 | - return $this->notifierServices; |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] |
|
499 | - */ |
|
500 | - public function getTwoFactorProviders(): array { |
|
501 | - return $this->twoFactorProviders; |
|
502 | - } |
|
58 | + /** @var ServiceRegistration<IReporter>[] */ |
|
59 | + private $crashReporters = []; |
|
60 | + |
|
61 | + /** @var ServiceRegistration<IWidget>[] */ |
|
62 | + private $dashboardPanels = []; |
|
63 | + |
|
64 | + /** @var ServiceFactoryRegistration[] */ |
|
65 | + private $services = []; |
|
66 | + |
|
67 | + /** @var ServiceAliasRegistration[] */ |
|
68 | + private $aliases = []; |
|
69 | + |
|
70 | + /** @var ParameterRegistration[] */ |
|
71 | + private $parameters = []; |
|
72 | + |
|
73 | + /** @var EventListenerRegistration[] */ |
|
74 | + private $eventListeners = []; |
|
75 | + |
|
76 | + /** @var ServiceRegistration<Middleware>[] */ |
|
77 | + private $middlewares = []; |
|
78 | + |
|
79 | + /** @var ServiceRegistration<IProvider>[] */ |
|
80 | + private $searchProviders = []; |
|
81 | + |
|
82 | + /** @var ServiceRegistration<IAlternativeLogin>[] */ |
|
83 | + private $alternativeLogins = []; |
|
84 | + |
|
85 | + /** @var ServiceRegistration<InitialStateProvider>[] */ |
|
86 | + private $initialStates = []; |
|
87 | + |
|
88 | + /** @var ServiceRegistration<IHandler>[] */ |
|
89 | + private $wellKnownHandlers = []; |
|
90 | + |
|
91 | + /** @var ServiceRegistration<ICustomTemplateProvider>[] */ |
|
92 | + private $templateProviders = []; |
|
93 | + |
|
94 | + /** @var ServiceRegistration<INotifier>[] */ |
|
95 | + private $notifierServices = []; |
|
96 | + |
|
97 | + /** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */ |
|
98 | + private $twoFactorProviders = []; |
|
99 | + |
|
100 | + /** @var ILogger */ |
|
101 | + private $logger; |
|
102 | + |
|
103 | + public function __construct(ILogger $logger) { |
|
104 | + $this->logger = $logger; |
|
105 | + } |
|
106 | + |
|
107 | + public function for(string $appId): IRegistrationContext { |
|
108 | + return new class($appId, $this) implements IRegistrationContext { |
|
109 | + /** @var string */ |
|
110 | + private $appId; |
|
111 | + |
|
112 | + /** @var RegistrationContext */ |
|
113 | + private $context; |
|
114 | + |
|
115 | + public function __construct(string $appId, RegistrationContext $context) { |
|
116 | + $this->appId = $appId; |
|
117 | + $this->context = $context; |
|
118 | + } |
|
119 | + |
|
120 | + public function registerCapability(string $capability): void { |
|
121 | + $this->context->registerCapability( |
|
122 | + $this->appId, |
|
123 | + $capability |
|
124 | + ); |
|
125 | + } |
|
126 | + |
|
127 | + public function registerCrashReporter(string $reporterClass): void { |
|
128 | + $this->context->registerCrashReporter( |
|
129 | + $this->appId, |
|
130 | + $reporterClass |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + public function registerDashboardWidget(string $widgetClass): void { |
|
135 | + $this->context->registerDashboardPanel( |
|
136 | + $this->appId, |
|
137 | + $widgetClass |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + public function registerService(string $name, callable $factory, bool $shared = true): void { |
|
142 | + $this->context->registerService( |
|
143 | + $this->appId, |
|
144 | + $name, |
|
145 | + $factory, |
|
146 | + $shared |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + public function registerServiceAlias(string $alias, string $target): void { |
|
151 | + $this->context->registerServiceAlias( |
|
152 | + $this->appId, |
|
153 | + $alias, |
|
154 | + $target |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + public function registerParameter(string $name, $value): void { |
|
159 | + $this->context->registerParameter( |
|
160 | + $this->appId, |
|
161 | + $name, |
|
162 | + $value |
|
163 | + ); |
|
164 | + } |
|
165 | + |
|
166 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
|
167 | + $this->context->registerEventListener( |
|
168 | + $this->appId, |
|
169 | + $event, |
|
170 | + $listener, |
|
171 | + $priority |
|
172 | + ); |
|
173 | + } |
|
174 | + |
|
175 | + public function registerMiddleware(string $class): void { |
|
176 | + $this->context->registerMiddleware( |
|
177 | + $this->appId, |
|
178 | + $class |
|
179 | + ); |
|
180 | + } |
|
181 | + |
|
182 | + public function registerSearchProvider(string $class): void { |
|
183 | + $this->context->registerSearchProvider( |
|
184 | + $this->appId, |
|
185 | + $class |
|
186 | + ); |
|
187 | + } |
|
188 | + |
|
189 | + public function registerAlternativeLogin(string $class): void { |
|
190 | + $this->context->registerAlternativeLogin( |
|
191 | + $this->appId, |
|
192 | + $class |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + public function registerInitialStateProvider(string $class): void { |
|
197 | + $this->context->registerInitialState( |
|
198 | + $this->appId, |
|
199 | + $class |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + public function registerWellKnownHandler(string $class): void { |
|
204 | + $this->context->registerWellKnown( |
|
205 | + $this->appId, |
|
206 | + $class |
|
207 | + ); |
|
208 | + } |
|
209 | + |
|
210 | + public function registerTemplateProvider(string $providerClass): void { |
|
211 | + $this->context->registerTemplateProvider( |
|
212 | + $this->appId, |
|
213 | + $providerClass |
|
214 | + ); |
|
215 | + } |
|
216 | + |
|
217 | + public function registerNotifierService(string $notifierClass): void { |
|
218 | + $this->context->registerNotifierService( |
|
219 | + $this->appId, |
|
220 | + $notifierClass |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + public function registerTwoFactorProvider(string $twoFactorProviderClass): void { |
|
225 | + $this->context->registerTwoFactorProvider( |
|
226 | + $this->appId, |
|
227 | + $twoFactorProviderClass |
|
228 | + ); |
|
229 | + } |
|
230 | + }; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @psalm-param class-string<ICapability> $capability |
|
235 | + */ |
|
236 | + public function registerCapability(string $appId, string $capability): void { |
|
237 | + $this->capabilities[] = new ServiceRegistration($appId, $capability); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @psalm-param class-string<IReporter> $capability |
|
242 | + */ |
|
243 | + public function registerCrashReporter(string $appId, string $reporterClass): void { |
|
244 | + $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @psalm-param class-string<IWidget> $capability |
|
249 | + */ |
|
250 | + public function registerDashboardPanel(string $appId, string $panelClass): void { |
|
251 | + $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); |
|
252 | + } |
|
253 | + |
|
254 | + public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
|
255 | + $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); |
|
256 | + } |
|
257 | + |
|
258 | + public function registerServiceAlias(string $appId, string $alias, string $target): void { |
|
259 | + $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); |
|
260 | + } |
|
261 | + |
|
262 | + public function registerParameter(string $appId, string $name, $value): void { |
|
263 | + $this->parameters[] = new ParameterRegistration($appId, $name, $value); |
|
264 | + } |
|
265 | + |
|
266 | + public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
|
267 | + $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @psalm-param class-string<Middleware> $class |
|
272 | + */ |
|
273 | + public function registerMiddleware(string $appId, string $class): void { |
|
274 | + $this->middlewares[] = new ServiceRegistration($appId, $class); |
|
275 | + } |
|
276 | + |
|
277 | + public function registerSearchProvider(string $appId, string $class) { |
|
278 | + $this->searchProviders[] = new ServiceRegistration($appId, $class); |
|
279 | + } |
|
280 | + |
|
281 | + public function registerAlternativeLogin(string $appId, string $class): void { |
|
282 | + $this->alternativeLogins[] = new ServiceRegistration($appId, $class); |
|
283 | + } |
|
284 | + |
|
285 | + public function registerInitialState(string $appId, string $class): void { |
|
286 | + $this->initialStates[] = new ServiceRegistration($appId, $class); |
|
287 | + } |
|
288 | + |
|
289 | + public function registerWellKnown(string $appId, string $class): void { |
|
290 | + $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); |
|
291 | + } |
|
292 | + |
|
293 | + public function registerTemplateProvider(string $appId, string $class): void { |
|
294 | + $this->templateProviders[] = new ServiceRegistration($appId, $class); |
|
295 | + } |
|
296 | + |
|
297 | + public function registerNotifierService(string $appId, string $class): void { |
|
298 | + $this->notifierServices[] = new ServiceRegistration($appId, $class); |
|
299 | + } |
|
300 | + |
|
301 | + public function registerTwoFactorProvider(string $appId, string $class): void { |
|
302 | + $this->twoFactorProviders[] = new ServiceRegistration($appId, $class); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * @param App[] $apps |
|
307 | + */ |
|
308 | + public function delegateCapabilityRegistrations(array $apps): void { |
|
309 | + while (($registration = array_shift($this->capabilities)) !== null) { |
|
310 | + try { |
|
311 | + $apps[$registration->getAppId()] |
|
312 | + ->getContainer() |
|
313 | + ->registerCapability($registration->getService()); |
|
314 | + } catch (Throwable $e) { |
|
315 | + $appId = $registration->getAppId(); |
|
316 | + $this->logger->logException($e, [ |
|
317 | + 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
318 | + 'level' => ILogger::ERROR, |
|
319 | + ]); |
|
320 | + } |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @param App[] $apps |
|
326 | + */ |
|
327 | + public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
328 | + while (($registration = array_shift($this->crashReporters)) !== null) { |
|
329 | + try { |
|
330 | + $registry->registerLazy($registration->getService()); |
|
331 | + } catch (Throwable $e) { |
|
332 | + $appId = $registration->getAppId(); |
|
333 | + $this->logger->logException($e, [ |
|
334 | + 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), |
|
335 | + 'level' => ILogger::ERROR, |
|
336 | + ]); |
|
337 | + } |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * @param App[] $apps |
|
343 | + */ |
|
344 | + public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { |
|
345 | + while (($panel = array_shift($this->dashboardPanels)) !== null) { |
|
346 | + try { |
|
347 | + $dashboardManager->lazyRegisterWidget($panel->getService()); |
|
348 | + } catch (Throwable $e) { |
|
349 | + $appId = $panel->getAppId(); |
|
350 | + $this->logger->logException($e, [ |
|
351 | + 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), |
|
352 | + 'level' => ILogger::ERROR, |
|
353 | + ]); |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
|
359 | + while (($registration = array_shift($this->eventListeners)) !== null) { |
|
360 | + try { |
|
361 | + $eventDispatcher->addServiceListener( |
|
362 | + $registration->getEvent(), |
|
363 | + $registration->getService(), |
|
364 | + $registration->getPriority() |
|
365 | + ); |
|
366 | + } catch (Throwable $e) { |
|
367 | + $appId = $registration->getAppId(); |
|
368 | + $this->logger->logException($e, [ |
|
369 | + 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), |
|
370 | + 'level' => ILogger::ERROR, |
|
371 | + ]); |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * @param App[] $apps |
|
378 | + */ |
|
379 | + public function delegateContainerRegistrations(array $apps): void { |
|
380 | + while (($registration = array_shift($this->services)) !== null) { |
|
381 | + try { |
|
382 | + /** |
|
383 | + * Register the service and convert the callable into a \Closure if necessary |
|
384 | + */ |
|
385 | + $apps[$registration->getAppId()] |
|
386 | + ->getContainer() |
|
387 | + ->registerService( |
|
388 | + $registration->getName(), |
|
389 | + Closure::fromCallable($registration->getFactory()), |
|
390 | + $registration->isShared() |
|
391 | + ); |
|
392 | + } catch (Throwable $e) { |
|
393 | + $appId = $registration->getAppId(); |
|
394 | + $this->logger->logException($e, [ |
|
395 | + 'message' => "Error during service registration of $appId: " . $e->getMessage(), |
|
396 | + 'level' => ILogger::ERROR, |
|
397 | + ]); |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + while (($registration = array_shift($this->aliases)) !== null) { |
|
402 | + try { |
|
403 | + $apps[$registration->getAppId()] |
|
404 | + ->getContainer() |
|
405 | + ->registerAlias( |
|
406 | + $registration->getAlias(), |
|
407 | + $registration->getTarget() |
|
408 | + ); |
|
409 | + } catch (Throwable $e) { |
|
410 | + $appId = $registration->getAppId(); |
|
411 | + $this->logger->logException($e, [ |
|
412 | + 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
413 | + 'level' => ILogger::ERROR, |
|
414 | + ]); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + while (($registration = array_shift($this->parameters)) !== null) { |
|
419 | + try { |
|
420 | + $apps[$registration->getAppId()] |
|
421 | + ->getContainer() |
|
422 | + ->registerParameter( |
|
423 | + $registration->getName(), |
|
424 | + $registration->getValue() |
|
425 | + ); |
|
426 | + } catch (Throwable $e) { |
|
427 | + $appId = $registration->getAppId(); |
|
428 | + $this->logger->logException($e, [ |
|
429 | + 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
430 | + 'level' => ILogger::ERROR, |
|
431 | + ]); |
|
432 | + } |
|
433 | + } |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * @param App[] $apps |
|
438 | + */ |
|
439 | + public function delegateMiddlewareRegistrations(array $apps): void { |
|
440 | + while (($middleware = array_shift($this->middlewares)) !== null) { |
|
441 | + try { |
|
442 | + $apps[$middleware->getAppId()] |
|
443 | + ->getContainer() |
|
444 | + ->registerMiddleWare($middleware->getService()); |
|
445 | + } catch (Throwable $e) { |
|
446 | + $appId = $middleware->getAppId(); |
|
447 | + $this->logger->logException($e, [ |
|
448 | + 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
449 | + 'level' => ILogger::ERROR, |
|
450 | + ]); |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * @return ServiceRegistration<IProvider>[] |
|
457 | + */ |
|
458 | + public function getSearchProviders(): array { |
|
459 | + return $this->searchProviders; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * @return ServiceRegistration<IAlternativeLogin>[] |
|
464 | + */ |
|
465 | + public function getAlternativeLogins(): array { |
|
466 | + return $this->alternativeLogins; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * @return ServiceRegistration<InitialStateProvider>[] |
|
471 | + */ |
|
472 | + public function getInitialStates(): array { |
|
473 | + return $this->initialStates; |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * @return ServiceRegistration<IHandler>[] |
|
478 | + */ |
|
479 | + public function getWellKnownHandlers(): array { |
|
480 | + return $this->wellKnownHandlers; |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * @return ServiceRegistration<ICustomTemplateProvider>[] |
|
485 | + */ |
|
486 | + public function getTemplateProviders(): array { |
|
487 | + return $this->templateProviders; |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * @return ServiceRegistration<INotifier>[] |
|
492 | + */ |
|
493 | + public function getNotifierServices(): array { |
|
494 | + return $this->notifierServices; |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * @return ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] |
|
499 | + */ |
|
500 | + public function getTwoFactorProviders(): array { |
|
501 | + return $this->twoFactorProviders; |
|
502 | + } |
|
503 | 503 | } |