Passed
Push — master ( 84ca58...9ae75a )
by Morris
12:29 queued 55s
created
lib/public/Authentication/IAlternativeLogin.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,30 +29,30 @@
 block discarded – undo
29 29
  */
30 30
 interface IAlternativeLogin {
31 31
 
32
-	/**
33
-	 * Label shown on the login option
34
-	 * @return string
35
-	 * @since 20.0.0
36
-	 */
37
-	public function getLabel(): string;
38
-
39
-	/**
40
-	 * Relative link to the login option
41
-	 * @return string
42
-	 * @since 20.0.0
43
-	 */
44
-	public function getLink(): string;
45
-
46
-	/**
47
-	 * CSS classes added to the alternative login option on the login screen
48
-	 * @return string
49
-	 * @since 20.0.0
50
-	 */
51
-	public function getClass(): string;
52
-
53
-	/**
54
-	 * Load necessary resources to present the login option, e.g. style-file to style the getClass()
55
-	 * @since 20.0.0
56
-	 */
57
-	public function load(): void;
32
+    /**
33
+     * Label shown on the login option
34
+     * @return string
35
+     * @since 20.0.0
36
+     */
37
+    public function getLabel(): string;
38
+
39
+    /**
40
+     * Relative link to the login option
41
+     * @return string
42
+     * @since 20.0.0
43
+     */
44
+    public function getLink(): string;
45
+
46
+    /**
47
+     * CSS classes added to the alternative login option on the login screen
48
+     * @return string
49
+     * @since 20.0.0
50
+     */
51
+    public function getClass(): string;
52
+
53
+    /**
54
+     * Load necessary resources to present the login option, e.g. style-file to style the getClass()
55
+     * @since 20.0.0
56
+     */
57
+    public function load(): void;
58 58
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Bootstrap/IRegistrationContext.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -37,119 +37,119 @@
 block discarded – undo
37 37
  */
38 38
 interface IRegistrationContext {
39 39
 
40
-	/**
41
-	 * @param string $capability
42
-	 * @see IAppContainer::registerCapability
43
-	 *
44
-	 * @since 20.0.0
45
-	 */
46
-	public function registerCapability(string $capability): void;
40
+    /**
41
+     * @param string $capability
42
+     * @see IAppContainer::registerCapability
43
+     *
44
+     * @since 20.0.0
45
+     */
46
+    public function registerCapability(string $capability): void;
47 47
 
48
-	/**
49
-	 * Register an implementation of \OCP\Support\CrashReport\IReporter that
50
-	 * will receive unhandled exceptions and throwables
51
-	 *
52
-	 * @param string $reporterClass
53
-	 * @return void
54
-	 * @since 20.0.0
55
-	 */
56
-	public function registerCrashReporter(string $reporterClass): void;
48
+    /**
49
+     * Register an implementation of \OCP\Support\CrashReport\IReporter that
50
+     * will receive unhandled exceptions and throwables
51
+     *
52
+     * @param string $reporterClass
53
+     * @return void
54
+     * @since 20.0.0
55
+     */
56
+    public function registerCrashReporter(string $reporterClass): void;
57 57
 
58
-	/**
59
-	 * Register an implementation of \OCP\Dashboard\IPanel that
60
-	 * will handle the implementation of a dashboard panel
61
-	 *
62
-	 * @param string $panelClass
63
-	 * @return void
64
-	 * @since 20.0.0
65
-	 */
66
-	public function registerDashboardPanel(string $panelClass): void;
67
-	/**
68
-	 * Register a service
69
-	 *
70
-	 * @param string $name
71
-	 * @param callable $factory
72
-	 * @param bool $shared
73
-	 *
74
-	 * @return void
75
-	 * @see IContainer::registerService()
76
-	 *
77
-	 * @since 20.0.0
78
-	 */
79
-	public function registerService(string $name, callable $factory, bool $shared = true): void;
58
+    /**
59
+     * Register an implementation of \OCP\Dashboard\IPanel that
60
+     * will handle the implementation of a dashboard panel
61
+     *
62
+     * @param string $panelClass
63
+     * @return void
64
+     * @since 20.0.0
65
+     */
66
+    public function registerDashboardPanel(string $panelClass): void;
67
+    /**
68
+     * Register a service
69
+     *
70
+     * @param string $name
71
+     * @param callable $factory
72
+     * @param bool $shared
73
+     *
74
+     * @return void
75
+     * @see IContainer::registerService()
76
+     *
77
+     * @since 20.0.0
78
+     */
79
+    public function registerService(string $name, callable $factory, bool $shared = true): void;
80 80
 
81
-	/**
82
-	 * @param string $alias
83
-	 * @param string $target
84
-	 *
85
-	 * @return void
86
-	 * @see IContainer::registerAlias()
87
-	 *
88
-	 * @since 20.0.0
89
-	 */
90
-	public function registerServiceAlias(string $alias, string $target): void;
81
+    /**
82
+     * @param string $alias
83
+     * @param string $target
84
+     *
85
+     * @return void
86
+     * @see IContainer::registerAlias()
87
+     *
88
+     * @since 20.0.0
89
+     */
90
+    public function registerServiceAlias(string $alias, string $target): void;
91 91
 
92
-	/**
93
-	 * @param string $name
94
-	 * @param mixed $value
95
-	 *
96
-	 * @return void
97
-	 * @see IContainer::registerParameter()
98
-	 *
99
-	 * @since 20.0.0
100
-	 */
101
-	public function registerParameter(string $name, $value): void;
92
+    /**
93
+     * @param string $name
94
+     * @param mixed $value
95
+     *
96
+     * @return void
97
+     * @see IContainer::registerParameter()
98
+     *
99
+     * @since 20.0.0
100
+     */
101
+    public function registerParameter(string $name, $value): void;
102 102
 
103
-	/**
104
-	 * Register a service listener
105
-	 *
106
-	 * This is equivalent to calling IEventDispatcher::addServiceListener
107
-	 *
108
-	 * @param string $event preferably the fully-qualified class name of the Event sub class to listen for
109
-	 * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
110
-	 * @param int $priority
111
-	 *
112
-	 * @see IEventDispatcher::addServiceListener()
113
-	 *
114
-	 * @since 20.0.0
115
-	 */
116
-	public function registerEventListener(string $event, string $listener, int $priority = 0): void;
103
+    /**
104
+     * Register a service listener
105
+     *
106
+     * This is equivalent to calling IEventDispatcher::addServiceListener
107
+     *
108
+     * @param string $event preferably the fully-qualified class name of the Event sub class to listen for
109
+     * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
110
+     * @param int $priority
111
+     *
112
+     * @see IEventDispatcher::addServiceListener()
113
+     *
114
+     * @since 20.0.0
115
+     */
116
+    public function registerEventListener(string $event, string $listener, int $priority = 0): void;
117 117
 
118
-	/**
119
-	 * @param string $class
120
-	 *
121
-	 * @return void
122
-	 * @see IAppContainer::registerMiddleWare()
123
-	 *
124
-	 * @since 20.0.0
125
-	 */
126
-	public function registerMiddleware(string $class): void;
118
+    /**
119
+     * @param string $class
120
+     *
121
+     * @return void
122
+     * @see IAppContainer::registerMiddleWare()
123
+     *
124
+     * @since 20.0.0
125
+     */
126
+    public function registerMiddleware(string $class): void;
127 127
 
128
-	/**
129
-	 * Register a search provider for the unified search
130
-	 *
131
-	 * It is allowed to register more than one provider per app as the search
132
-	 * results can go into distinct sections, e.g. "Files" and "Files shared
133
-	 * with you" in the Files app.
134
-	 *
135
-	 * @param string $class
136
-	 *
137
-	 * @return void
138
-	 *
139
-	 * @since 20.0.0
140
-	 */
141
-	public function registerSearchProvider(string $class): void;
128
+    /**
129
+     * Register a search provider for the unified search
130
+     *
131
+     * It is allowed to register more than one provider per app as the search
132
+     * results can go into distinct sections, e.g. "Files" and "Files shared
133
+     * with you" in the Files app.
134
+     *
135
+     * @param string $class
136
+     *
137
+     * @return void
138
+     *
139
+     * @since 20.0.0
140
+     */
141
+    public function registerSearchProvider(string $class): void;
142 142
 
143
-	/**
144
-	 * Register an alternative login option
145
-	 *
146
-	 * It is allowed to register more than one option per app.
147
-	 *
148
-	 * @param string $class
149
-	 *
150
-	 * @return void
151
-	 *
152
-	 * @since 20.0.0
153
-	 */
154
-	public function registerAlternativeLogin(string $class): void;
143
+    /**
144
+     * Register an alternative login option
145
+     *
146
+     * It is allowed to register more than one option per app.
147
+     *
148
+     * @param string $class
149
+     *
150
+     * @return void
151
+     *
152
+     * @since 20.0.0
153
+     */
154
+    public function registerAlternativeLogin(string $class): void;
155 155
 }
Please login to merge, or discard this patch.
lib/private/legacy/OC_App.php 2 patches
Indentation   +1109 added lines, -1109 removed lines patch added patch discarded remove patch
@@ -68,1113 +68,1113 @@
 block discarded – undo
68 68
  * upgrading and removing apps.
69 69
  */
70 70
 class OC_App {
71
-	private static $adminForms = [];
72
-	private static $personalForms = [];
73
-	private static $appTypes = [];
74
-	private static $loadedApps = [];
75
-	private static $altLogin = [];
76
-	private static $alreadyRegistered = [];
77
-	public const supportedApp = 300;
78
-	public const officialApp = 200;
79
-
80
-	/**
81
-	 * clean the appId
82
-	 *
83
-	 * @param string $app AppId that needs to be cleaned
84
-	 * @return string
85
-	 */
86
-	public static function cleanAppId(string $app): string {
87
-		return str_replace(['\0', '/', '\\', '..'], '', $app);
88
-	}
89
-
90
-	/**
91
-	 * Check if an app is loaded
92
-	 *
93
-	 * @param string $app
94
-	 * @return bool
95
-	 */
96
-	public static function isAppLoaded(string $app): bool {
97
-		return in_array($app, self::$loadedApps, true);
98
-	}
99
-
100
-	/**
101
-	 * loads all apps
102
-	 *
103
-	 * @param string[] $types
104
-	 * @return bool
105
-	 *
106
-	 * This function walks through the ownCloud directory and loads all apps
107
-	 * it can find. A directory contains an app if the file /appinfo/info.xml
108
-	 * exists.
109
-	 *
110
-	 * if $types is set to non-empty array, only apps of those types will be loaded
111
-	 */
112
-	public static function loadApps(array $types = []): bool {
113
-		if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) {
114
-			return false;
115
-		}
116
-		// Load the enabled apps here
117
-		$apps = self::getEnabledApps();
118
-
119
-		// Add each apps' folder as allowed class path
120
-		foreach ($apps as $app) {
121
-			$path = self::getAppPath($app);
122
-			if ($path !== false) {
123
-				self::registerAutoloading($app, $path);
124
-			}
125
-		}
126
-
127
-		// prevent app.php from printing output
128
-		ob_start();
129
-		foreach ($apps as $app) {
130
-			if (($types === [] or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
131
-				self::loadApp($app);
132
-			}
133
-		}
134
-		ob_end_clean();
135
-
136
-		return true;
137
-	}
138
-
139
-	/**
140
-	 * load a single app
141
-	 *
142
-	 * @param string $app
143
-	 * @throws Exception
144
-	 */
145
-	public static function loadApp(string $app) {
146
-		self::$loadedApps[] = $app;
147
-		$appPath = self::getAppPath($app);
148
-		if ($appPath === false) {
149
-			return;
150
-		}
151
-
152
-		// in case someone calls loadApp() directly
153
-		self::registerAutoloading($app, $appPath);
154
-
155
-		/** @var Coordinator $coordinator */
156
-		$coordinator = \OC::$server->query(Coordinator::class);
157
-		$isBootable = $coordinator->isBootable($app);
158
-
159
-		$hasAppPhpFile = is_file($appPath . '/appinfo/app.php');
160
-
161
-		if ($isBootable && $hasAppPhpFile) {
162
-			\OC::$server->getLogger()->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [
163
-				'app' => $app,
164
-			]);
165
-		} elseif ($hasAppPhpFile) {
166
-			\OC::$server->getLogger()->debug('/appinfo/app.php is deprecated, use \OCP\AppFramework\Bootstrap\IBootstrap on the application class instead.', [
167
-				'app' => $app,
168
-			]);
169
-			\OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
170
-			try {
171
-				self::requireAppFile($app);
172
-			} catch (Throwable $ex) {
173
-				if ($ex instanceof ServerNotAvailableException) {
174
-					throw $ex;
175
-				}
176
-				if (!\OC::$server->getAppManager()->isShipped($app) && !self::isType($app, ['authentication'])) {
177
-					\OC::$server->getLogger()->logException($ex, [
178
-						'message' => "App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(),
179
-					]);
180
-
181
-					// Only disable apps which are not shipped and that are not authentication apps
182
-					\OC::$server->getAppManager()->disableApp($app, true);
183
-				} else {
184
-					\OC::$server->getLogger()->logException($ex, [
185
-						'message' => "App $app threw an error during app.php load: " . $ex->getMessage(),
186
-					]);
187
-				}
188
-			}
189
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
190
-		}
191
-		$coordinator->bootApp($app);
192
-
193
-		$info = self::getAppInfo($app);
194
-		if (!empty($info['activity']['filters'])) {
195
-			foreach ($info['activity']['filters'] as $filter) {
196
-				\OC::$server->getActivityManager()->registerFilter($filter);
197
-			}
198
-		}
199
-		if (!empty($info['activity']['settings'])) {
200
-			foreach ($info['activity']['settings'] as $setting) {
201
-				\OC::$server->getActivityManager()->registerSetting($setting);
202
-			}
203
-		}
204
-		if (!empty($info['activity']['providers'])) {
205
-			foreach ($info['activity']['providers'] as $provider) {
206
-				\OC::$server->getActivityManager()->registerProvider($provider);
207
-			}
208
-		}
209
-
210
-		if (!empty($info['settings']['admin'])) {
211
-			foreach ($info['settings']['admin'] as $setting) {
212
-				\OC::$server->getSettingsManager()->registerSetting('admin', $setting);
213
-			}
214
-		}
215
-		if (!empty($info['settings']['admin-section'])) {
216
-			foreach ($info['settings']['admin-section'] as $section) {
217
-				\OC::$server->getSettingsManager()->registerSection('admin', $section);
218
-			}
219
-		}
220
-		if (!empty($info['settings']['personal'])) {
221
-			foreach ($info['settings']['personal'] as $setting) {
222
-				\OC::$server->getSettingsManager()->registerSetting('personal', $setting);
223
-			}
224
-		}
225
-		if (!empty($info['settings']['personal-section'])) {
226
-			foreach ($info['settings']['personal-section'] as $section) {
227
-				\OC::$server->getSettingsManager()->registerSection('personal', $section);
228
-			}
229
-		}
230
-
231
-		if (!empty($info['collaboration']['plugins'])) {
232
-			// deal with one or many plugin entries
233
-			$plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
234
-				[$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
235
-			foreach ($plugins as $plugin) {
236
-				if ($plugin['@attributes']['type'] === 'collaborator-search') {
237
-					$pluginInfo = [
238
-						'shareType' => $plugin['@attributes']['share-type'],
239
-						'class' => $plugin['@value'],
240
-					];
241
-					\OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
242
-				} elseif ($plugin['@attributes']['type'] === 'autocomplete-sort') {
243
-					\OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']);
244
-				}
245
-			}
246
-		}
247
-	}
248
-
249
-	/**
250
-	 * @internal
251
-	 * @param string $app
252
-	 * @param string $path
253
-	 * @param bool $force
254
-	 */
255
-	public static function registerAutoloading(string $app, string $path, bool $force = false) {
256
-		$key = $app . '-' . $path;
257
-		if (!$force && isset(self::$alreadyRegistered[$key])) {
258
-			return;
259
-		}
260
-
261
-		self::$alreadyRegistered[$key] = true;
262
-
263
-		// Register on PSR-4 composer autoloader
264
-		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
265
-		\OC::$server->registerNamespace($app, $appNamespace);
266
-
267
-		if (file_exists($path . '/composer/autoload.php')) {
268
-			require_once $path . '/composer/autoload.php';
269
-		} else {
270
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
271
-			// Register on legacy autoloader
272
-			\OC::$loader->addValidRoot($path);
273
-		}
274
-
275
-		// Register Test namespace only when testing
276
-		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
277
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
278
-		}
279
-	}
280
-
281
-	/**
282
-	 * Load app.php from the given app
283
-	 *
284
-	 * @param string $app app name
285
-	 * @throws Error
286
-	 */
287
-	private static function requireAppFile(string $app) {
288
-		// encapsulated here to avoid variable scope conflicts
289
-		require_once $app . '/appinfo/app.php';
290
-	}
291
-
292
-	/**
293
-	 * check if an app is of a specific type
294
-	 *
295
-	 * @param string $app
296
-	 * @param array $types
297
-	 * @return bool
298
-	 */
299
-	public static function isType(string $app, array $types): bool {
300
-		$appTypes = self::getAppTypes($app);
301
-		foreach ($types as $type) {
302
-			if (array_search($type, $appTypes) !== false) {
303
-				return true;
304
-			}
305
-		}
306
-		return false;
307
-	}
308
-
309
-	/**
310
-	 * get the types of an app
311
-	 *
312
-	 * @param string $app
313
-	 * @return array
314
-	 */
315
-	private static function getAppTypes(string $app): array {
316
-		//load the cache
317
-		if (count(self::$appTypes) == 0) {
318
-			self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
319
-		}
320
-
321
-		if (isset(self::$appTypes[$app])) {
322
-			return explode(',', self::$appTypes[$app]);
323
-		}
324
-
325
-		return [];
326
-	}
327
-
328
-	/**
329
-	 * read app types from info.xml and cache them in the database
330
-	 */
331
-	public static function setAppTypes(string $app) {
332
-		$appManager = \OC::$server->getAppManager();
333
-		$appData = $appManager->getAppInfo($app);
334
-		if (!is_array($appData)) {
335
-			return;
336
-		}
337
-
338
-		if (isset($appData['types'])) {
339
-			$appTypes = implode(',', $appData['types']);
340
-		} else {
341
-			$appTypes = '';
342
-			$appData['types'] = [];
343
-		}
344
-
345
-		$config = \OC::$server->getConfig();
346
-		$config->setAppValue($app, 'types', $appTypes);
347
-
348
-		if ($appManager->hasProtectedAppType($appData['types'])) {
349
-			$enabled = $config->getAppValue($app, 'enabled', 'yes');
350
-			if ($enabled !== 'yes' && $enabled !== 'no') {
351
-				$config->setAppValue($app, 'enabled', 'yes');
352
-			}
353
-		}
354
-	}
355
-
356
-	/**
357
-	 * Returns apps enabled for the current user.
358
-	 *
359
-	 * @param bool $forceRefresh whether to refresh the cache
360
-	 * @param bool $all whether to return apps for all users, not only the
361
-	 * currently logged in one
362
-	 * @return string[]
363
-	 */
364
-	public static function getEnabledApps(bool $forceRefresh = false, bool $all = false): array {
365
-		if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
366
-			return [];
367
-		}
368
-		// in incognito mode or when logged out, $user will be false,
369
-		// which is also the case during an upgrade
370
-		$appManager = \OC::$server->getAppManager();
371
-		if ($all) {
372
-			$user = null;
373
-		} else {
374
-			$user = \OC::$server->getUserSession()->getUser();
375
-		}
376
-
377
-		if (is_null($user)) {
378
-			$apps = $appManager->getInstalledApps();
379
-		} else {
380
-			$apps = $appManager->getEnabledAppsForUser($user);
381
-		}
382
-		$apps = array_filter($apps, function ($app) {
383
-			return $app !== 'files';//we add this manually
384
-		});
385
-		sort($apps);
386
-		array_unshift($apps, 'files');
387
-		return $apps;
388
-	}
389
-
390
-	/**
391
-	 * checks whether or not an app is enabled
392
-	 *
393
-	 * @param string $app app
394
-	 * @return bool
395
-	 * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
396
-	 *
397
-	 * This function checks whether or not an app is enabled.
398
-	 */
399
-	public static function isEnabled(string $app): bool {
400
-		return \OC::$server->getAppManager()->isEnabledForUser($app);
401
-	}
402
-
403
-	/**
404
-	 * enables an app
405
-	 *
406
-	 * @param string $appId
407
-	 * @param array $groups (optional) when set, only these groups will have access to the app
408
-	 * @throws \Exception
409
-	 * @return void
410
-	 *
411
-	 * This function set an app as enabled in appconfig.
412
-	 */
413
-	public function enable(string $appId,
414
-						   array $groups = []) {
415
-
416
-		// Check if app is already downloaded
417
-		/** @var Installer $installer */
418
-		$installer = \OC::$server->query(Installer::class);
419
-		$isDownloaded = $installer->isDownloaded($appId);
420
-
421
-		if (!$isDownloaded) {
422
-			$installer->downloadApp($appId);
423
-		}
424
-
425
-		$installer->installApp($appId);
426
-
427
-		$appManager = \OC::$server->getAppManager();
428
-		if ($groups !== []) {
429
-			$groupManager = \OC::$server->getGroupManager();
430
-			$groupsList = [];
431
-			foreach ($groups as $group) {
432
-				$groupItem = $groupManager->get($group);
433
-				if ($groupItem instanceof \OCP\IGroup) {
434
-					$groupsList[] = $groupManager->get($group);
435
-				}
436
-			}
437
-			$appManager->enableAppForGroups($appId, $groupsList);
438
-		} else {
439
-			$appManager->enableApp($appId);
440
-		}
441
-	}
442
-
443
-	/**
444
-	 * Get the path where to install apps
445
-	 *
446
-	 * @return string|false
447
-	 */
448
-	public static function getInstallPath() {
449
-		if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
450
-			return false;
451
-		}
452
-
453
-		foreach (OC::$APPSROOTS as $dir) {
454
-			if (isset($dir['writable']) && $dir['writable'] === true) {
455
-				return $dir['path'];
456
-			}
457
-		}
458
-
459
-		\OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR);
460
-		return null;
461
-	}
462
-
463
-
464
-	/**
465
-	 * search for an app in all app-directories
466
-	 *
467
-	 * @param string $appId
468
-	 * @return false|string
469
-	 */
470
-	public static function findAppInDirectories(string $appId) {
471
-		$sanitizedAppId = self::cleanAppId($appId);
472
-		if ($sanitizedAppId !== $appId) {
473
-			return false;
474
-		}
475
-		static $app_dir = [];
476
-
477
-		if (isset($app_dir[$appId])) {
478
-			return $app_dir[$appId];
479
-		}
480
-
481
-		$possibleApps = [];
482
-		foreach (OC::$APPSROOTS as $dir) {
483
-			if (file_exists($dir['path'] . '/' . $appId)) {
484
-				$possibleApps[] = $dir;
485
-			}
486
-		}
487
-
488
-		if (empty($possibleApps)) {
489
-			return false;
490
-		} elseif (count($possibleApps) === 1) {
491
-			$dir = array_shift($possibleApps);
492
-			$app_dir[$appId] = $dir;
493
-			return $dir;
494
-		} else {
495
-			$versionToLoad = [];
496
-			foreach ($possibleApps as $possibleApp) {
497
-				$version = self::getAppVersionByPath($possibleApp['path'] . '/' . $appId);
498
-				if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
499
-					$versionToLoad = [
500
-						'dir' => $possibleApp,
501
-						'version' => $version,
502
-					];
503
-				}
504
-			}
505
-			$app_dir[$appId] = $versionToLoad['dir'];
506
-			return $versionToLoad['dir'];
507
-			//TODO - write test
508
-		}
509
-	}
510
-
511
-	/**
512
-	 * Get the directory for the given app.
513
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
514
-	 *
515
-	 * @param string $appId
516
-	 * @return string|false
517
-	 * @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath()
518
-	 */
519
-	public static function getAppPath(string $appId) {
520
-		if ($appId === null || trim($appId) === '') {
521
-			return false;
522
-		}
523
-
524
-		if (($dir = self::findAppInDirectories($appId)) != false) {
525
-			return $dir['path'] . '/' . $appId;
526
-		}
527
-		return false;
528
-	}
529
-
530
-	/**
531
-	 * Get the path for the given app on the access
532
-	 * If the app is defined in multiple directories, the first one is taken. (false if not found)
533
-	 *
534
-	 * @param string $appId
535
-	 * @return string|false
536
-	 * @deprecated 18.0.0 use \OC::$server->getAppManager()->getAppWebPath()
537
-	 */
538
-	public static function getAppWebPath(string $appId) {
539
-		if (($dir = self::findAppInDirectories($appId)) != false) {
540
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
541
-		}
542
-		return false;
543
-	}
544
-
545
-	/**
546
-	 * get the last version of the app from appinfo/info.xml
547
-	 *
548
-	 * @param string $appId
549
-	 * @param bool $useCache
550
-	 * @return string
551
-	 * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion()
552
-	 */
553
-	public static function getAppVersion(string $appId, bool $useCache = true): string {
554
-		return \OC::$server->getAppManager()->getAppVersion($appId, $useCache);
555
-	}
556
-
557
-	/**
558
-	 * get app's version based on it's path
559
-	 *
560
-	 * @param string $path
561
-	 * @return string
562
-	 */
563
-	public static function getAppVersionByPath(string $path): string {
564
-		$infoFile = $path . '/appinfo/info.xml';
565
-		$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
566
-		return isset($appData['version']) ? $appData['version'] : '';
567
-	}
568
-
569
-
570
-	/**
571
-	 * Read all app metadata from the info.xml file
572
-	 *
573
-	 * @param string $appId id of the app or the path of the info.xml file
574
-	 * @param bool $path
575
-	 * @param string $lang
576
-	 * @return array|null
577
-	 * @note all data is read from info.xml, not just pre-defined fields
578
-	 * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo()
579
-	 */
580
-	public static function getAppInfo(string $appId, bool $path = false, string $lang = null) {
581
-		return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang);
582
-	}
583
-
584
-	/**
585
-	 * Returns the navigation
586
-	 *
587
-	 * @return array
588
-	 * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
589
-	 *
590
-	 * This function returns an array containing all entries added. The
591
-	 * entries are sorted by the key 'order' ascending. Additional to the keys
592
-	 * given for each app the following keys exist:
593
-	 *   - active: boolean, signals if the user is on this navigation entry
594
-	 */
595
-	public static function getNavigation(): array {
596
-		return OC::$server->getNavigationManager()->getAll();
597
-	}
598
-
599
-	/**
600
-	 * Returns the Settings Navigation
601
-	 *
602
-	 * @return string[]
603
-	 * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
604
-	 *
605
-	 * This function returns an array containing all settings pages added. The
606
-	 * entries are sorted by the key 'order' ascending.
607
-	 */
608
-	public static function getSettingsNavigation(): array {
609
-		return OC::$server->getNavigationManager()->getAll('settings');
610
-	}
611
-
612
-	/**
613
-	 * get the id of loaded app
614
-	 *
615
-	 * @return string
616
-	 */
617
-	public static function getCurrentApp(): string {
618
-		$request = \OC::$server->getRequest();
619
-		$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
620
-		$topFolder = substr($script, 0, strpos($script, '/') ?: 0);
621
-		if (empty($topFolder)) {
622
-			$path_info = $request->getPathInfo();
623
-			if ($path_info) {
624
-				$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
625
-			}
626
-		}
627
-		if ($topFolder == 'apps') {
628
-			$length = strlen($topFolder);
629
-			return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1) ?: '';
630
-		} else {
631
-			return $topFolder;
632
-		}
633
-	}
634
-
635
-	/**
636
-	 * @param string $type
637
-	 * @return array
638
-	 */
639
-	public static function getForms(string $type): array {
640
-		$forms = [];
641
-		switch ($type) {
642
-			case 'admin':
643
-				$source = self::$adminForms;
644
-				break;
645
-			case 'personal':
646
-				$source = self::$personalForms;
647
-				break;
648
-			default:
649
-				return [];
650
-		}
651
-		foreach ($source as $form) {
652
-			$forms[] = include $form;
653
-		}
654
-		return $forms;
655
-	}
656
-
657
-	/**
658
-	 * register an admin form to be shown
659
-	 *
660
-	 * @param string $app
661
-	 * @param string $page
662
-	 */
663
-	public static function registerAdmin(string $app, string $page) {
664
-		self::$adminForms[] = $app . '/' . $page . '.php';
665
-	}
666
-
667
-	/**
668
-	 * register a personal form to be shown
669
-	 * @param string $app
670
-	 * @param string $page
671
-	 */
672
-	public static function registerPersonal(string $app, string $page) {
673
-		self::$personalForms[] = $app . '/' . $page . '.php';
674
-	}
675
-
676
-	/**
677
-	 * @param array $entry
678
-	 * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface
679
-	 */
680
-	public static function registerLogIn(array $entry) {
681
-		\OC::$server->getLogger()->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface');
682
-		self::$altLogin[] = $entry;
683
-	}
684
-
685
-	/**
686
-	 * @return array
687
-	 */
688
-	public static function getAlternativeLogIns(): array {
689
-		/** @var Coordinator $bootstrapCoordinator */
690
-		$bootstrapCoordinator = \OC::$server->query(Coordinator::class);
691
-
692
-		foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) {
693
-			if (!in_array(IAlternativeLogin::class, class_implements($registration['class']), true)) {
694
-				\OC::$server->getLogger()->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [
695
-					'option' => $registration['class'],
696
-					'interface' => IAlternativeLogin::class,
697
-					'app' => $registration['app'],
698
-				]);
699
-				continue;
700
-			}
701
-
702
-			try {
703
-				/** @var IAlternativeLogin $provider */
704
-				$provider = \OC::$server->query($registration['class']);
705
-			} catch (QueryException $e) {
706
-				\OC::$server->getLogger()->logException($e, [
707
-					'message' => 'Alternative login option {option} can not be initialised.',
708
-					'option' => $registration['class'],
709
-					'app' => $registration['app'],
710
-				]);
711
-			}
712
-
713
-			try {
714
-				$provider->load();
715
-
716
-				self::$altLogin[] = [
717
-					'name' => $provider->getLabel(),
718
-					'href' => $provider->getLink(),
719
-					'style' => $provider->getClass(),
720
-				];
721
-			} catch (Throwable $e) {
722
-				\OC::$server->getLogger()->logException($e, [
723
-					'message' => 'Alternative login option {option} had an error while loading.',
724
-					'option' => $registration['class'],
725
-					'app' => $registration['app'],
726
-				]);
727
-			}
728
-		}
729
-
730
-		return self::$altLogin;
731
-	}
732
-
733
-	/**
734
-	 * get a list of all apps in the apps folder
735
-	 *
736
-	 * @return string[] an array of app names (string IDs)
737
-	 * @todo: change the name of this method to getInstalledApps, which is more accurate
738
-	 */
739
-	public static function getAllApps(): array {
740
-		$apps = [];
741
-
742
-		foreach (OC::$APPSROOTS as $apps_dir) {
743
-			if (!is_readable($apps_dir['path'])) {
744
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN);
745
-				continue;
746
-			}
747
-			$dh = opendir($apps_dir['path']);
748
-
749
-			if (is_resource($dh)) {
750
-				while (($file = readdir($dh)) !== false) {
751
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
752
-						$apps[] = $file;
753
-					}
754
-				}
755
-			}
756
-		}
757
-
758
-		$apps = array_unique($apps);
759
-
760
-		return $apps;
761
-	}
762
-
763
-	/**
764
-	 * List all apps, this is used in apps.php
765
-	 *
766
-	 * @return array
767
-	 */
768
-	public function listAllApps(): array {
769
-		$installedApps = OC_App::getAllApps();
770
-
771
-		$appManager = \OC::$server->getAppManager();
772
-		//we don't want to show configuration for these
773
-		$blacklist = $appManager->getAlwaysEnabledApps();
774
-		$appList = [];
775
-		$langCode = \OC::$server->getL10N('core')->getLanguageCode();
776
-		$urlGenerator = \OC::$server->getURLGenerator();
777
-		/** @var \OCP\Support\Subscription\IRegistry $subscriptionRegistry */
778
-		$subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
779
-		$supportedApps = $subscriptionRegistry->delegateGetSupportedApps();
780
-
781
-		foreach ($installedApps as $app) {
782
-			if (array_search($app, $blacklist) === false) {
783
-				$info = OC_App::getAppInfo($app, false, $langCode);
784
-				if (!is_array($info)) {
785
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR);
786
-					continue;
787
-				}
788
-
789
-				if (!isset($info['name'])) {
790
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR);
791
-					continue;
792
-				}
793
-
794
-				$enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no');
795
-				$info['groups'] = null;
796
-				if ($enabled === 'yes') {
797
-					$active = true;
798
-				} elseif ($enabled === 'no') {
799
-					$active = false;
800
-				} else {
801
-					$active = true;
802
-					$info['groups'] = $enabled;
803
-				}
804
-
805
-				$info['active'] = $active;
806
-
807
-				if ($appManager->isShipped($app)) {
808
-					$info['internal'] = true;
809
-					$info['level'] = self::officialApp;
810
-					$info['removable'] = false;
811
-				} else {
812
-					$info['internal'] = false;
813
-					$info['removable'] = true;
814
-				}
815
-
816
-				if (in_array($app, $supportedApps)) {
817
-					$info['level'] = self::supportedApp;
818
-				}
819
-
820
-				$appPath = self::getAppPath($app);
821
-				if ($appPath !== false) {
822
-					$appIcon = $appPath . '/img/' . $app . '.svg';
823
-					if (file_exists($appIcon)) {
824
-						$info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
825
-						$info['previewAsIcon'] = true;
826
-					} else {
827
-						$appIcon = $appPath . '/img/app.svg';
828
-						if (file_exists($appIcon)) {
829
-							$info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
830
-							$info['previewAsIcon'] = true;
831
-						}
832
-					}
833
-				}
834
-				// fix documentation
835
-				if (isset($info['documentation']) && is_array($info['documentation'])) {
836
-					foreach ($info['documentation'] as $key => $url) {
837
-						// If it is not an absolute URL we assume it is a key
838
-						// i.e. admin-ldap will get converted to go.php?to=admin-ldap
839
-						if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
840
-							$url = $urlGenerator->linkToDocs($url);
841
-						}
842
-
843
-						$info['documentation'][$key] = $url;
844
-					}
845
-				}
846
-
847
-				$info['version'] = OC_App::getAppVersion($app);
848
-				$appList[] = $info;
849
-			}
850
-		}
851
-
852
-		return $appList;
853
-	}
854
-
855
-	public static function shouldUpgrade(string $app): bool {
856
-		$versions = self::getAppVersions();
857
-		$currentVersion = OC_App::getAppVersion($app);
858
-		if ($currentVersion && isset($versions[$app])) {
859
-			$installedVersion = $versions[$app];
860
-			if (!version_compare($currentVersion, $installedVersion, '=')) {
861
-				return true;
862
-			}
863
-		}
864
-		return false;
865
-	}
866
-
867
-	/**
868
-	 * Adjust the number of version parts of $version1 to match
869
-	 * the number of version parts of $version2.
870
-	 *
871
-	 * @param string $version1 version to adjust
872
-	 * @param string $version2 version to take the number of parts from
873
-	 * @return string shortened $version1
874
-	 */
875
-	private static function adjustVersionParts(string $version1, string $version2): string {
876
-		$version1 = explode('.', $version1);
877
-		$version2 = explode('.', $version2);
878
-		// reduce $version1 to match the number of parts in $version2
879
-		while (count($version1) > count($version2)) {
880
-			array_pop($version1);
881
-		}
882
-		// if $version1 does not have enough parts, add some
883
-		while (count($version1) < count($version2)) {
884
-			$version1[] = '0';
885
-		}
886
-		return implode('.', $version1);
887
-	}
888
-
889
-	/**
890
-	 * Check whether the current ownCloud version matches the given
891
-	 * application's version requirements.
892
-	 *
893
-	 * The comparison is made based on the number of parts that the
894
-	 * app info version has. For example for ownCloud 6.0.3 if the
895
-	 * app info version is expecting version 6.0, the comparison is
896
-	 * made on the first two parts of the ownCloud version.
897
-	 * This means that it's possible to specify "requiremin" => 6
898
-	 * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
899
-	 *
900
-	 * @param string $ocVersion ownCloud version to check against
901
-	 * @param array $appInfo app info (from xml)
902
-	 *
903
-	 * @return boolean true if compatible, otherwise false
904
-	 */
905
-	public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool {
906
-		$requireMin = '';
907
-		$requireMax = '';
908
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
909
-			$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
910
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
911
-			$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
912
-		} elseif (isset($appInfo['requiremin'])) {
913
-			$requireMin = $appInfo['requiremin'];
914
-		} elseif (isset($appInfo['require'])) {
915
-			$requireMin = $appInfo['require'];
916
-		}
917
-
918
-		if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
919
-			$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
920
-		} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
921
-			$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
922
-		} elseif (isset($appInfo['requiremax'])) {
923
-			$requireMax = $appInfo['requiremax'];
924
-		}
925
-
926
-		if (!empty($requireMin)
927
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
928
-		) {
929
-			return false;
930
-		}
931
-
932
-		if (!$ignoreMax && !empty($requireMax)
933
-			&& version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
934
-		) {
935
-			return false;
936
-		}
937
-
938
-		return true;
939
-	}
940
-
941
-	/**
942
-	 * get the installed version of all apps
943
-	 */
944
-	public static function getAppVersions() {
945
-		static $versions;
946
-
947
-		if (!$versions) {
948
-			$appConfig = \OC::$server->getAppConfig();
949
-			$versions = $appConfig->getValues(false, 'installed_version');
950
-		}
951
-		return $versions;
952
-	}
953
-
954
-	/**
955
-	 * update the database for the app and call the update script
956
-	 *
957
-	 * @param string $appId
958
-	 * @return bool
959
-	 */
960
-	public static function updateApp(string $appId): bool {
961
-		$appPath = self::getAppPath($appId);
962
-		if ($appPath === false) {
963
-			return false;
964
-		}
965
-
966
-		\OC::$server->getAppManager()->clearAppsCache();
967
-		$appData = self::getAppInfo($appId);
968
-
969
-		self::registerAutoloading($appId, $appPath, true);
970
-		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
971
-
972
-		if (file_exists($appPath . '/appinfo/database.xml')) {
973
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
974
-		} else {
975
-			$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
976
-			$ms->migrate();
977
-		}
978
-
979
-		self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
980
-		self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
981
-		// update appversion in app manager
982
-		\OC::$server->getAppManager()->clearAppsCache();
983
-		\OC::$server->getAppManager()->getAppVersion($appId, false);
984
-
985
-		// run upgrade code
986
-		if (file_exists($appPath . '/appinfo/update.php')) {
987
-			self::loadApp($appId);
988
-			include $appPath . '/appinfo/update.php';
989
-		}
990
-		self::setupBackgroundJobs($appData['background-jobs']);
991
-
992
-		//set remote/public handlers
993
-		if (array_key_exists('ocsid', $appData)) {
994
-			\OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
995
-		} elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
996
-			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
997
-		}
998
-		foreach ($appData['remote'] as $name => $path) {
999
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1000
-		}
1001
-		foreach ($appData['public'] as $name => $path) {
1002
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1003
-		}
1004
-
1005
-		self::setAppTypes($appId);
1006
-
1007
-		$version = \OC_App::getAppVersion($appId);
1008
-		\OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
1009
-
1010
-		\OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1011
-			ManagerEvent::EVENT_APP_UPDATE, $appId
1012
-		));
1013
-
1014
-		return true;
1015
-	}
1016
-
1017
-	/**
1018
-	 * @param string $appId
1019
-	 * @param string[] $steps
1020
-	 * @throws \OC\NeedsUpdateException
1021
-	 */
1022
-	public static function executeRepairSteps(string $appId, array $steps) {
1023
-		if (empty($steps)) {
1024
-			return;
1025
-		}
1026
-		// load the app
1027
-		self::loadApp($appId);
1028
-
1029
-		$dispatcher = OC::$server->getEventDispatcher();
1030
-
1031
-		// load the steps
1032
-		$r = new Repair([], $dispatcher);
1033
-		foreach ($steps as $step) {
1034
-			try {
1035
-				$r->addStep($step);
1036
-			} catch (Exception $ex) {
1037
-				$r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1038
-				\OC::$server->getLogger()->logException($ex);
1039
-			}
1040
-		}
1041
-		// run the steps
1042
-		$r->run();
1043
-	}
1044
-
1045
-	public static function setupBackgroundJobs(array $jobs) {
1046
-		$queue = \OC::$server->getJobList();
1047
-		foreach ($jobs as $job) {
1048
-			$queue->add($job);
1049
-		}
1050
-	}
1051
-
1052
-	/**
1053
-	 * @param string $appId
1054
-	 * @param string[] $steps
1055
-	 */
1056
-	private static function setupLiveMigrations(string $appId, array $steps) {
1057
-		$queue = \OC::$server->getJobList();
1058
-		foreach ($steps as $step) {
1059
-			$queue->add('OC\Migration\BackgroundRepair', [
1060
-				'app' => $appId,
1061
-				'step' => $step]);
1062
-		}
1063
-	}
1064
-
1065
-	/**
1066
-	 * @param string $appId
1067
-	 * @return \OC\Files\View|false
1068
-	 */
1069
-	public static function getStorage(string $appId) {
1070
-		if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1071
-			if (\OC::$server->getUserSession()->isLoggedIn()) {
1072
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1073
-				if (!$view->file_exists($appId)) {
1074
-					$view->mkdir($appId);
1075
-				}
1076
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1077
-			} else {
1078
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR);
1079
-				return false;
1080
-			}
1081
-		} else {
1082
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR);
1083
-			return false;
1084
-		}
1085
-	}
1086
-
1087
-	protected static function findBestL10NOption(array $options, string $lang): string {
1088
-		// only a single option
1089
-		if (isset($options['@value'])) {
1090
-			return $options['@value'];
1091
-		}
1092
-
1093
-		$fallback = $similarLangFallback = $englishFallback = false;
1094
-
1095
-		$lang = strtolower($lang);
1096
-		$similarLang = $lang;
1097
-		if (strpos($similarLang, '_')) {
1098
-			// For "de_DE" we want to find "de" and the other way around
1099
-			$similarLang = substr($lang, 0, strpos($lang, '_'));
1100
-		}
1101
-
1102
-		foreach ($options as $option) {
1103
-			if (is_array($option)) {
1104
-				if ($fallback === false) {
1105
-					$fallback = $option['@value'];
1106
-				}
1107
-
1108
-				if (!isset($option['@attributes']['lang'])) {
1109
-					continue;
1110
-				}
1111
-
1112
-				$attributeLang = strtolower($option['@attributes']['lang']);
1113
-				if ($attributeLang === $lang) {
1114
-					return $option['@value'];
1115
-				}
1116
-
1117
-				if ($attributeLang === $similarLang) {
1118
-					$similarLangFallback = $option['@value'];
1119
-				} elseif (strpos($attributeLang, $similarLang . '_') === 0) {
1120
-					if ($similarLangFallback === false) {
1121
-						$similarLangFallback =  $option['@value'];
1122
-					}
1123
-				}
1124
-			} else {
1125
-				$englishFallback = $option;
1126
-			}
1127
-		}
1128
-
1129
-		if ($similarLangFallback !== false) {
1130
-			return $similarLangFallback;
1131
-		} elseif ($englishFallback !== false) {
1132
-			return $englishFallback;
1133
-		}
1134
-		return (string) $fallback;
1135
-	}
1136
-
1137
-	/**
1138
-	 * parses the app data array and enhanced the 'description' value
1139
-	 *
1140
-	 * @param array $data the app data
1141
-	 * @param string $lang
1142
-	 * @return array improved app data
1143
-	 */
1144
-	public static function parseAppInfo(array $data, $lang = null): array {
1145
-		if ($lang && isset($data['name']) && is_array($data['name'])) {
1146
-			$data['name'] = self::findBestL10NOption($data['name'], $lang);
1147
-		}
1148
-		if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1149
-			$data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1150
-		}
1151
-		if ($lang && isset($data['description']) && is_array($data['description'])) {
1152
-			$data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1153
-		} elseif (isset($data['description']) && is_string($data['description'])) {
1154
-			$data['description'] = trim($data['description']);
1155
-		} else {
1156
-			$data['description'] = '';
1157
-		}
1158
-
1159
-		return $data;
1160
-	}
1161
-
1162
-	/**
1163
-	 * @param \OCP\IConfig $config
1164
-	 * @param \OCP\IL10N $l
1165
-	 * @param array $info
1166
-	 * @throws \Exception
1167
-	 */
1168
-	public static function checkAppDependencies(\OCP\IConfig $config, \OCP\IL10N $l, array $info, bool $ignoreMax) {
1169
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1170
-		$missing = $dependencyAnalyzer->analyze($info, $ignoreMax);
1171
-		if (!empty($missing)) {
1172
-			$missingMsg = implode(PHP_EOL, $missing);
1173
-			throw new \Exception(
1174
-				$l->t('App "%1$s" cannot be installed because the following dependencies are not fulfilled: %2$s',
1175
-					[$info['name'], $missingMsg]
1176
-				)
1177
-			);
1178
-		}
1179
-	}
71
+    private static $adminForms = [];
72
+    private static $personalForms = [];
73
+    private static $appTypes = [];
74
+    private static $loadedApps = [];
75
+    private static $altLogin = [];
76
+    private static $alreadyRegistered = [];
77
+    public const supportedApp = 300;
78
+    public const officialApp = 200;
79
+
80
+    /**
81
+     * clean the appId
82
+     *
83
+     * @param string $app AppId that needs to be cleaned
84
+     * @return string
85
+     */
86
+    public static function cleanAppId(string $app): string {
87
+        return str_replace(['\0', '/', '\\', '..'], '', $app);
88
+    }
89
+
90
+    /**
91
+     * Check if an app is loaded
92
+     *
93
+     * @param string $app
94
+     * @return bool
95
+     */
96
+    public static function isAppLoaded(string $app): bool {
97
+        return in_array($app, self::$loadedApps, true);
98
+    }
99
+
100
+    /**
101
+     * loads all apps
102
+     *
103
+     * @param string[] $types
104
+     * @return bool
105
+     *
106
+     * This function walks through the ownCloud directory and loads all apps
107
+     * it can find. A directory contains an app if the file /appinfo/info.xml
108
+     * exists.
109
+     *
110
+     * if $types is set to non-empty array, only apps of those types will be loaded
111
+     */
112
+    public static function loadApps(array $types = []): bool {
113
+        if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) {
114
+            return false;
115
+        }
116
+        // Load the enabled apps here
117
+        $apps = self::getEnabledApps();
118
+
119
+        // Add each apps' folder as allowed class path
120
+        foreach ($apps as $app) {
121
+            $path = self::getAppPath($app);
122
+            if ($path !== false) {
123
+                self::registerAutoloading($app, $path);
124
+            }
125
+        }
126
+
127
+        // prevent app.php from printing output
128
+        ob_start();
129
+        foreach ($apps as $app) {
130
+            if (($types === [] or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
131
+                self::loadApp($app);
132
+            }
133
+        }
134
+        ob_end_clean();
135
+
136
+        return true;
137
+    }
138
+
139
+    /**
140
+     * load a single app
141
+     *
142
+     * @param string $app
143
+     * @throws Exception
144
+     */
145
+    public static function loadApp(string $app) {
146
+        self::$loadedApps[] = $app;
147
+        $appPath = self::getAppPath($app);
148
+        if ($appPath === false) {
149
+            return;
150
+        }
151
+
152
+        // in case someone calls loadApp() directly
153
+        self::registerAutoloading($app, $appPath);
154
+
155
+        /** @var Coordinator $coordinator */
156
+        $coordinator = \OC::$server->query(Coordinator::class);
157
+        $isBootable = $coordinator->isBootable($app);
158
+
159
+        $hasAppPhpFile = is_file($appPath . '/appinfo/app.php');
160
+
161
+        if ($isBootable && $hasAppPhpFile) {
162
+            \OC::$server->getLogger()->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [
163
+                'app' => $app,
164
+            ]);
165
+        } elseif ($hasAppPhpFile) {
166
+            \OC::$server->getLogger()->debug('/appinfo/app.php is deprecated, use \OCP\AppFramework\Bootstrap\IBootstrap on the application class instead.', [
167
+                'app' => $app,
168
+            ]);
169
+            \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
170
+            try {
171
+                self::requireAppFile($app);
172
+            } catch (Throwable $ex) {
173
+                if ($ex instanceof ServerNotAvailableException) {
174
+                    throw $ex;
175
+                }
176
+                if (!\OC::$server->getAppManager()->isShipped($app) && !self::isType($app, ['authentication'])) {
177
+                    \OC::$server->getLogger()->logException($ex, [
178
+                        'message' => "App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(),
179
+                    ]);
180
+
181
+                    // Only disable apps which are not shipped and that are not authentication apps
182
+                    \OC::$server->getAppManager()->disableApp($app, true);
183
+                } else {
184
+                    \OC::$server->getLogger()->logException($ex, [
185
+                        'message' => "App $app threw an error during app.php load: " . $ex->getMessage(),
186
+                    ]);
187
+                }
188
+            }
189
+            \OC::$server->getEventLogger()->end('load_app_' . $app);
190
+        }
191
+        $coordinator->bootApp($app);
192
+
193
+        $info = self::getAppInfo($app);
194
+        if (!empty($info['activity']['filters'])) {
195
+            foreach ($info['activity']['filters'] as $filter) {
196
+                \OC::$server->getActivityManager()->registerFilter($filter);
197
+            }
198
+        }
199
+        if (!empty($info['activity']['settings'])) {
200
+            foreach ($info['activity']['settings'] as $setting) {
201
+                \OC::$server->getActivityManager()->registerSetting($setting);
202
+            }
203
+        }
204
+        if (!empty($info['activity']['providers'])) {
205
+            foreach ($info['activity']['providers'] as $provider) {
206
+                \OC::$server->getActivityManager()->registerProvider($provider);
207
+            }
208
+        }
209
+
210
+        if (!empty($info['settings']['admin'])) {
211
+            foreach ($info['settings']['admin'] as $setting) {
212
+                \OC::$server->getSettingsManager()->registerSetting('admin', $setting);
213
+            }
214
+        }
215
+        if (!empty($info['settings']['admin-section'])) {
216
+            foreach ($info['settings']['admin-section'] as $section) {
217
+                \OC::$server->getSettingsManager()->registerSection('admin', $section);
218
+            }
219
+        }
220
+        if (!empty($info['settings']['personal'])) {
221
+            foreach ($info['settings']['personal'] as $setting) {
222
+                \OC::$server->getSettingsManager()->registerSetting('personal', $setting);
223
+            }
224
+        }
225
+        if (!empty($info['settings']['personal-section'])) {
226
+            foreach ($info['settings']['personal-section'] as $section) {
227
+                \OC::$server->getSettingsManager()->registerSection('personal', $section);
228
+            }
229
+        }
230
+
231
+        if (!empty($info['collaboration']['plugins'])) {
232
+            // deal with one or many plugin entries
233
+            $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ?
234
+                [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin'];
235
+            foreach ($plugins as $plugin) {
236
+                if ($plugin['@attributes']['type'] === 'collaborator-search') {
237
+                    $pluginInfo = [
238
+                        'shareType' => $plugin['@attributes']['share-type'],
239
+                        'class' => $plugin['@value'],
240
+                    ];
241
+                    \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
242
+                } elseif ($plugin['@attributes']['type'] === 'autocomplete-sort') {
243
+                    \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']);
244
+                }
245
+            }
246
+        }
247
+    }
248
+
249
+    /**
250
+     * @internal
251
+     * @param string $app
252
+     * @param string $path
253
+     * @param bool $force
254
+     */
255
+    public static function registerAutoloading(string $app, string $path, bool $force = false) {
256
+        $key = $app . '-' . $path;
257
+        if (!$force && isset(self::$alreadyRegistered[$key])) {
258
+            return;
259
+        }
260
+
261
+        self::$alreadyRegistered[$key] = true;
262
+
263
+        // Register on PSR-4 composer autoloader
264
+        $appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
265
+        \OC::$server->registerNamespace($app, $appNamespace);
266
+
267
+        if (file_exists($path . '/composer/autoload.php')) {
268
+            require_once $path . '/composer/autoload.php';
269
+        } else {
270
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
271
+            // Register on legacy autoloader
272
+            \OC::$loader->addValidRoot($path);
273
+        }
274
+
275
+        // Register Test namespace only when testing
276
+        if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
277
+            \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
278
+        }
279
+    }
280
+
281
+    /**
282
+     * Load app.php from the given app
283
+     *
284
+     * @param string $app app name
285
+     * @throws Error
286
+     */
287
+    private static function requireAppFile(string $app) {
288
+        // encapsulated here to avoid variable scope conflicts
289
+        require_once $app . '/appinfo/app.php';
290
+    }
291
+
292
+    /**
293
+     * check if an app is of a specific type
294
+     *
295
+     * @param string $app
296
+     * @param array $types
297
+     * @return bool
298
+     */
299
+    public static function isType(string $app, array $types): bool {
300
+        $appTypes = self::getAppTypes($app);
301
+        foreach ($types as $type) {
302
+            if (array_search($type, $appTypes) !== false) {
303
+                return true;
304
+            }
305
+        }
306
+        return false;
307
+    }
308
+
309
+    /**
310
+     * get the types of an app
311
+     *
312
+     * @param string $app
313
+     * @return array
314
+     */
315
+    private static function getAppTypes(string $app): array {
316
+        //load the cache
317
+        if (count(self::$appTypes) == 0) {
318
+            self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types');
319
+        }
320
+
321
+        if (isset(self::$appTypes[$app])) {
322
+            return explode(',', self::$appTypes[$app]);
323
+        }
324
+
325
+        return [];
326
+    }
327
+
328
+    /**
329
+     * read app types from info.xml and cache them in the database
330
+     */
331
+    public static function setAppTypes(string $app) {
332
+        $appManager = \OC::$server->getAppManager();
333
+        $appData = $appManager->getAppInfo($app);
334
+        if (!is_array($appData)) {
335
+            return;
336
+        }
337
+
338
+        if (isset($appData['types'])) {
339
+            $appTypes = implode(',', $appData['types']);
340
+        } else {
341
+            $appTypes = '';
342
+            $appData['types'] = [];
343
+        }
344
+
345
+        $config = \OC::$server->getConfig();
346
+        $config->setAppValue($app, 'types', $appTypes);
347
+
348
+        if ($appManager->hasProtectedAppType($appData['types'])) {
349
+            $enabled = $config->getAppValue($app, 'enabled', 'yes');
350
+            if ($enabled !== 'yes' && $enabled !== 'no') {
351
+                $config->setAppValue($app, 'enabled', 'yes');
352
+            }
353
+        }
354
+    }
355
+
356
+    /**
357
+     * Returns apps enabled for the current user.
358
+     *
359
+     * @param bool $forceRefresh whether to refresh the cache
360
+     * @param bool $all whether to return apps for all users, not only the
361
+     * currently logged in one
362
+     * @return string[]
363
+     */
364
+    public static function getEnabledApps(bool $forceRefresh = false, bool $all = false): array {
365
+        if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
366
+            return [];
367
+        }
368
+        // in incognito mode or when logged out, $user will be false,
369
+        // which is also the case during an upgrade
370
+        $appManager = \OC::$server->getAppManager();
371
+        if ($all) {
372
+            $user = null;
373
+        } else {
374
+            $user = \OC::$server->getUserSession()->getUser();
375
+        }
376
+
377
+        if (is_null($user)) {
378
+            $apps = $appManager->getInstalledApps();
379
+        } else {
380
+            $apps = $appManager->getEnabledAppsForUser($user);
381
+        }
382
+        $apps = array_filter($apps, function ($app) {
383
+            return $app !== 'files';//we add this manually
384
+        });
385
+        sort($apps);
386
+        array_unshift($apps, 'files');
387
+        return $apps;
388
+    }
389
+
390
+    /**
391
+     * checks whether or not an app is enabled
392
+     *
393
+     * @param string $app app
394
+     * @return bool
395
+     * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId)
396
+     *
397
+     * This function checks whether or not an app is enabled.
398
+     */
399
+    public static function isEnabled(string $app): bool {
400
+        return \OC::$server->getAppManager()->isEnabledForUser($app);
401
+    }
402
+
403
+    /**
404
+     * enables an app
405
+     *
406
+     * @param string $appId
407
+     * @param array $groups (optional) when set, only these groups will have access to the app
408
+     * @throws \Exception
409
+     * @return void
410
+     *
411
+     * This function set an app as enabled in appconfig.
412
+     */
413
+    public function enable(string $appId,
414
+                            array $groups = []) {
415
+
416
+        // Check if app is already downloaded
417
+        /** @var Installer $installer */
418
+        $installer = \OC::$server->query(Installer::class);
419
+        $isDownloaded = $installer->isDownloaded($appId);
420
+
421
+        if (!$isDownloaded) {
422
+            $installer->downloadApp($appId);
423
+        }
424
+
425
+        $installer->installApp($appId);
426
+
427
+        $appManager = \OC::$server->getAppManager();
428
+        if ($groups !== []) {
429
+            $groupManager = \OC::$server->getGroupManager();
430
+            $groupsList = [];
431
+            foreach ($groups as $group) {
432
+                $groupItem = $groupManager->get($group);
433
+                if ($groupItem instanceof \OCP\IGroup) {
434
+                    $groupsList[] = $groupManager->get($group);
435
+                }
436
+            }
437
+            $appManager->enableAppForGroups($appId, $groupsList);
438
+        } else {
439
+            $appManager->enableApp($appId);
440
+        }
441
+    }
442
+
443
+    /**
444
+     * Get the path where to install apps
445
+     *
446
+     * @return string|false
447
+     */
448
+    public static function getInstallPath() {
449
+        if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) {
450
+            return false;
451
+        }
452
+
453
+        foreach (OC::$APPSROOTS as $dir) {
454
+            if (isset($dir['writable']) && $dir['writable'] === true) {
455
+                return $dir['path'];
456
+            }
457
+        }
458
+
459
+        \OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR);
460
+        return null;
461
+    }
462
+
463
+
464
+    /**
465
+     * search for an app in all app-directories
466
+     *
467
+     * @param string $appId
468
+     * @return false|string
469
+     */
470
+    public static function findAppInDirectories(string $appId) {
471
+        $sanitizedAppId = self::cleanAppId($appId);
472
+        if ($sanitizedAppId !== $appId) {
473
+            return false;
474
+        }
475
+        static $app_dir = [];
476
+
477
+        if (isset($app_dir[$appId])) {
478
+            return $app_dir[$appId];
479
+        }
480
+
481
+        $possibleApps = [];
482
+        foreach (OC::$APPSROOTS as $dir) {
483
+            if (file_exists($dir['path'] . '/' . $appId)) {
484
+                $possibleApps[] = $dir;
485
+            }
486
+        }
487
+
488
+        if (empty($possibleApps)) {
489
+            return false;
490
+        } elseif (count($possibleApps) === 1) {
491
+            $dir = array_shift($possibleApps);
492
+            $app_dir[$appId] = $dir;
493
+            return $dir;
494
+        } else {
495
+            $versionToLoad = [];
496
+            foreach ($possibleApps as $possibleApp) {
497
+                $version = self::getAppVersionByPath($possibleApp['path'] . '/' . $appId);
498
+                if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
499
+                    $versionToLoad = [
500
+                        'dir' => $possibleApp,
501
+                        'version' => $version,
502
+                    ];
503
+                }
504
+            }
505
+            $app_dir[$appId] = $versionToLoad['dir'];
506
+            return $versionToLoad['dir'];
507
+            //TODO - write test
508
+        }
509
+    }
510
+
511
+    /**
512
+     * Get the directory for the given app.
513
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
514
+     *
515
+     * @param string $appId
516
+     * @return string|false
517
+     * @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath()
518
+     */
519
+    public static function getAppPath(string $appId) {
520
+        if ($appId === null || trim($appId) === '') {
521
+            return false;
522
+        }
523
+
524
+        if (($dir = self::findAppInDirectories($appId)) != false) {
525
+            return $dir['path'] . '/' . $appId;
526
+        }
527
+        return false;
528
+    }
529
+
530
+    /**
531
+     * Get the path for the given app on the access
532
+     * If the app is defined in multiple directories, the first one is taken. (false if not found)
533
+     *
534
+     * @param string $appId
535
+     * @return string|false
536
+     * @deprecated 18.0.0 use \OC::$server->getAppManager()->getAppWebPath()
537
+     */
538
+    public static function getAppWebPath(string $appId) {
539
+        if (($dir = self::findAppInDirectories($appId)) != false) {
540
+            return OC::$WEBROOT . $dir['url'] . '/' . $appId;
541
+        }
542
+        return false;
543
+    }
544
+
545
+    /**
546
+     * get the last version of the app from appinfo/info.xml
547
+     *
548
+     * @param string $appId
549
+     * @param bool $useCache
550
+     * @return string
551
+     * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion()
552
+     */
553
+    public static function getAppVersion(string $appId, bool $useCache = true): string {
554
+        return \OC::$server->getAppManager()->getAppVersion($appId, $useCache);
555
+    }
556
+
557
+    /**
558
+     * get app's version based on it's path
559
+     *
560
+     * @param string $path
561
+     * @return string
562
+     */
563
+    public static function getAppVersionByPath(string $path): string {
564
+        $infoFile = $path . '/appinfo/info.xml';
565
+        $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
566
+        return isset($appData['version']) ? $appData['version'] : '';
567
+    }
568
+
569
+
570
+    /**
571
+     * Read all app metadata from the info.xml file
572
+     *
573
+     * @param string $appId id of the app or the path of the info.xml file
574
+     * @param bool $path
575
+     * @param string $lang
576
+     * @return array|null
577
+     * @note all data is read from info.xml, not just pre-defined fields
578
+     * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo()
579
+     */
580
+    public static function getAppInfo(string $appId, bool $path = false, string $lang = null) {
581
+        return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang);
582
+    }
583
+
584
+    /**
585
+     * Returns the navigation
586
+     *
587
+     * @return array
588
+     * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
589
+     *
590
+     * This function returns an array containing all entries added. The
591
+     * entries are sorted by the key 'order' ascending. Additional to the keys
592
+     * given for each app the following keys exist:
593
+     *   - active: boolean, signals if the user is on this navigation entry
594
+     */
595
+    public static function getNavigation(): array {
596
+        return OC::$server->getNavigationManager()->getAll();
597
+    }
598
+
599
+    /**
600
+     * Returns the Settings Navigation
601
+     *
602
+     * @return string[]
603
+     * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
604
+     *
605
+     * This function returns an array containing all settings pages added. The
606
+     * entries are sorted by the key 'order' ascending.
607
+     */
608
+    public static function getSettingsNavigation(): array {
609
+        return OC::$server->getNavigationManager()->getAll('settings');
610
+    }
611
+
612
+    /**
613
+     * get the id of loaded app
614
+     *
615
+     * @return string
616
+     */
617
+    public static function getCurrentApp(): string {
618
+        $request = \OC::$server->getRequest();
619
+        $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
620
+        $topFolder = substr($script, 0, strpos($script, '/') ?: 0);
621
+        if (empty($topFolder)) {
622
+            $path_info = $request->getPathInfo();
623
+            if ($path_info) {
624
+                $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
625
+            }
626
+        }
627
+        if ($topFolder == 'apps') {
628
+            $length = strlen($topFolder);
629
+            return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1) ?: '';
630
+        } else {
631
+            return $topFolder;
632
+        }
633
+    }
634
+
635
+    /**
636
+     * @param string $type
637
+     * @return array
638
+     */
639
+    public static function getForms(string $type): array {
640
+        $forms = [];
641
+        switch ($type) {
642
+            case 'admin':
643
+                $source = self::$adminForms;
644
+                break;
645
+            case 'personal':
646
+                $source = self::$personalForms;
647
+                break;
648
+            default:
649
+                return [];
650
+        }
651
+        foreach ($source as $form) {
652
+            $forms[] = include $form;
653
+        }
654
+        return $forms;
655
+    }
656
+
657
+    /**
658
+     * register an admin form to be shown
659
+     *
660
+     * @param string $app
661
+     * @param string $page
662
+     */
663
+    public static function registerAdmin(string $app, string $page) {
664
+        self::$adminForms[] = $app . '/' . $page . '.php';
665
+    }
666
+
667
+    /**
668
+     * register a personal form to be shown
669
+     * @param string $app
670
+     * @param string $page
671
+     */
672
+    public static function registerPersonal(string $app, string $page) {
673
+        self::$personalForms[] = $app . '/' . $page . '.php';
674
+    }
675
+
676
+    /**
677
+     * @param array $entry
678
+     * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface
679
+     */
680
+    public static function registerLogIn(array $entry) {
681
+        \OC::$server->getLogger()->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface');
682
+        self::$altLogin[] = $entry;
683
+    }
684
+
685
+    /**
686
+     * @return array
687
+     */
688
+    public static function getAlternativeLogIns(): array {
689
+        /** @var Coordinator $bootstrapCoordinator */
690
+        $bootstrapCoordinator = \OC::$server->query(Coordinator::class);
691
+
692
+        foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) {
693
+            if (!in_array(IAlternativeLogin::class, class_implements($registration['class']), true)) {
694
+                \OC::$server->getLogger()->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [
695
+                    'option' => $registration['class'],
696
+                    'interface' => IAlternativeLogin::class,
697
+                    'app' => $registration['app'],
698
+                ]);
699
+                continue;
700
+            }
701
+
702
+            try {
703
+                /** @var IAlternativeLogin $provider */
704
+                $provider = \OC::$server->query($registration['class']);
705
+            } catch (QueryException $e) {
706
+                \OC::$server->getLogger()->logException($e, [
707
+                    'message' => 'Alternative login option {option} can not be initialised.',
708
+                    'option' => $registration['class'],
709
+                    'app' => $registration['app'],
710
+                ]);
711
+            }
712
+
713
+            try {
714
+                $provider->load();
715
+
716
+                self::$altLogin[] = [
717
+                    'name' => $provider->getLabel(),
718
+                    'href' => $provider->getLink(),
719
+                    'style' => $provider->getClass(),
720
+                ];
721
+            } catch (Throwable $e) {
722
+                \OC::$server->getLogger()->logException($e, [
723
+                    'message' => 'Alternative login option {option} had an error while loading.',
724
+                    'option' => $registration['class'],
725
+                    'app' => $registration['app'],
726
+                ]);
727
+            }
728
+        }
729
+
730
+        return self::$altLogin;
731
+    }
732
+
733
+    /**
734
+     * get a list of all apps in the apps folder
735
+     *
736
+     * @return string[] an array of app names (string IDs)
737
+     * @todo: change the name of this method to getInstalledApps, which is more accurate
738
+     */
739
+    public static function getAllApps(): array {
740
+        $apps = [];
741
+
742
+        foreach (OC::$APPSROOTS as $apps_dir) {
743
+            if (!is_readable($apps_dir['path'])) {
744
+                \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN);
745
+                continue;
746
+            }
747
+            $dh = opendir($apps_dir['path']);
748
+
749
+            if (is_resource($dh)) {
750
+                while (($file = readdir($dh)) !== false) {
751
+                    if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
752
+                        $apps[] = $file;
753
+                    }
754
+                }
755
+            }
756
+        }
757
+
758
+        $apps = array_unique($apps);
759
+
760
+        return $apps;
761
+    }
762
+
763
+    /**
764
+     * List all apps, this is used in apps.php
765
+     *
766
+     * @return array
767
+     */
768
+    public function listAllApps(): array {
769
+        $installedApps = OC_App::getAllApps();
770
+
771
+        $appManager = \OC::$server->getAppManager();
772
+        //we don't want to show configuration for these
773
+        $blacklist = $appManager->getAlwaysEnabledApps();
774
+        $appList = [];
775
+        $langCode = \OC::$server->getL10N('core')->getLanguageCode();
776
+        $urlGenerator = \OC::$server->getURLGenerator();
777
+        /** @var \OCP\Support\Subscription\IRegistry $subscriptionRegistry */
778
+        $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class);
779
+        $supportedApps = $subscriptionRegistry->delegateGetSupportedApps();
780
+
781
+        foreach ($installedApps as $app) {
782
+            if (array_search($app, $blacklist) === false) {
783
+                $info = OC_App::getAppInfo($app, false, $langCode);
784
+                if (!is_array($info)) {
785
+                    \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR);
786
+                    continue;
787
+                }
788
+
789
+                if (!isset($info['name'])) {
790
+                    \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR);
791
+                    continue;
792
+                }
793
+
794
+                $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no');
795
+                $info['groups'] = null;
796
+                if ($enabled === 'yes') {
797
+                    $active = true;
798
+                } elseif ($enabled === 'no') {
799
+                    $active = false;
800
+                } else {
801
+                    $active = true;
802
+                    $info['groups'] = $enabled;
803
+                }
804
+
805
+                $info['active'] = $active;
806
+
807
+                if ($appManager->isShipped($app)) {
808
+                    $info['internal'] = true;
809
+                    $info['level'] = self::officialApp;
810
+                    $info['removable'] = false;
811
+                } else {
812
+                    $info['internal'] = false;
813
+                    $info['removable'] = true;
814
+                }
815
+
816
+                if (in_array($app, $supportedApps)) {
817
+                    $info['level'] = self::supportedApp;
818
+                }
819
+
820
+                $appPath = self::getAppPath($app);
821
+                if ($appPath !== false) {
822
+                    $appIcon = $appPath . '/img/' . $app . '.svg';
823
+                    if (file_exists($appIcon)) {
824
+                        $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
825
+                        $info['previewAsIcon'] = true;
826
+                    } else {
827
+                        $appIcon = $appPath . '/img/app.svg';
828
+                        if (file_exists($appIcon)) {
829
+                            $info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
830
+                            $info['previewAsIcon'] = true;
831
+                        }
832
+                    }
833
+                }
834
+                // fix documentation
835
+                if (isset($info['documentation']) && is_array($info['documentation'])) {
836
+                    foreach ($info['documentation'] as $key => $url) {
837
+                        // If it is not an absolute URL we assume it is a key
838
+                        // i.e. admin-ldap will get converted to go.php?to=admin-ldap
839
+                        if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) {
840
+                            $url = $urlGenerator->linkToDocs($url);
841
+                        }
842
+
843
+                        $info['documentation'][$key] = $url;
844
+                    }
845
+                }
846
+
847
+                $info['version'] = OC_App::getAppVersion($app);
848
+                $appList[] = $info;
849
+            }
850
+        }
851
+
852
+        return $appList;
853
+    }
854
+
855
+    public static function shouldUpgrade(string $app): bool {
856
+        $versions = self::getAppVersions();
857
+        $currentVersion = OC_App::getAppVersion($app);
858
+        if ($currentVersion && isset($versions[$app])) {
859
+            $installedVersion = $versions[$app];
860
+            if (!version_compare($currentVersion, $installedVersion, '=')) {
861
+                return true;
862
+            }
863
+        }
864
+        return false;
865
+    }
866
+
867
+    /**
868
+     * Adjust the number of version parts of $version1 to match
869
+     * the number of version parts of $version2.
870
+     *
871
+     * @param string $version1 version to adjust
872
+     * @param string $version2 version to take the number of parts from
873
+     * @return string shortened $version1
874
+     */
875
+    private static function adjustVersionParts(string $version1, string $version2): string {
876
+        $version1 = explode('.', $version1);
877
+        $version2 = explode('.', $version2);
878
+        // reduce $version1 to match the number of parts in $version2
879
+        while (count($version1) > count($version2)) {
880
+            array_pop($version1);
881
+        }
882
+        // if $version1 does not have enough parts, add some
883
+        while (count($version1) < count($version2)) {
884
+            $version1[] = '0';
885
+        }
886
+        return implode('.', $version1);
887
+    }
888
+
889
+    /**
890
+     * Check whether the current ownCloud version matches the given
891
+     * application's version requirements.
892
+     *
893
+     * The comparison is made based on the number of parts that the
894
+     * app info version has. For example for ownCloud 6.0.3 if the
895
+     * app info version is expecting version 6.0, the comparison is
896
+     * made on the first two parts of the ownCloud version.
897
+     * This means that it's possible to specify "requiremin" => 6
898
+     * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
899
+     *
900
+     * @param string $ocVersion ownCloud version to check against
901
+     * @param array $appInfo app info (from xml)
902
+     *
903
+     * @return boolean true if compatible, otherwise false
904
+     */
905
+    public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool {
906
+        $requireMin = '';
907
+        $requireMax = '';
908
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
909
+            $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
910
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
911
+            $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
912
+        } elseif (isset($appInfo['requiremin'])) {
913
+            $requireMin = $appInfo['requiremin'];
914
+        } elseif (isset($appInfo['require'])) {
915
+            $requireMin = $appInfo['require'];
916
+        }
917
+
918
+        if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
919
+            $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
920
+        } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
921
+            $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
922
+        } elseif (isset($appInfo['requiremax'])) {
923
+            $requireMax = $appInfo['requiremax'];
924
+        }
925
+
926
+        if (!empty($requireMin)
927
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
928
+        ) {
929
+            return false;
930
+        }
931
+
932
+        if (!$ignoreMax && !empty($requireMax)
933
+            && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
934
+        ) {
935
+            return false;
936
+        }
937
+
938
+        return true;
939
+    }
940
+
941
+    /**
942
+     * get the installed version of all apps
943
+     */
944
+    public static function getAppVersions() {
945
+        static $versions;
946
+
947
+        if (!$versions) {
948
+            $appConfig = \OC::$server->getAppConfig();
949
+            $versions = $appConfig->getValues(false, 'installed_version');
950
+        }
951
+        return $versions;
952
+    }
953
+
954
+    /**
955
+     * update the database for the app and call the update script
956
+     *
957
+     * @param string $appId
958
+     * @return bool
959
+     */
960
+    public static function updateApp(string $appId): bool {
961
+        $appPath = self::getAppPath($appId);
962
+        if ($appPath === false) {
963
+            return false;
964
+        }
965
+
966
+        \OC::$server->getAppManager()->clearAppsCache();
967
+        $appData = self::getAppInfo($appId);
968
+
969
+        self::registerAutoloading($appId, $appPath, true);
970
+        self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
971
+
972
+        if (file_exists($appPath . '/appinfo/database.xml')) {
973
+            OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
974
+        } else {
975
+            $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
976
+            $ms->migrate();
977
+        }
978
+
979
+        self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
980
+        self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
981
+        // update appversion in app manager
982
+        \OC::$server->getAppManager()->clearAppsCache();
983
+        \OC::$server->getAppManager()->getAppVersion($appId, false);
984
+
985
+        // run upgrade code
986
+        if (file_exists($appPath . '/appinfo/update.php')) {
987
+            self::loadApp($appId);
988
+            include $appPath . '/appinfo/update.php';
989
+        }
990
+        self::setupBackgroundJobs($appData['background-jobs']);
991
+
992
+        //set remote/public handlers
993
+        if (array_key_exists('ocsid', $appData)) {
994
+            \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']);
995
+        } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) {
996
+            \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
997
+        }
998
+        foreach ($appData['remote'] as $name => $path) {
999
+            \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
1000
+        }
1001
+        foreach ($appData['public'] as $name => $path) {
1002
+            \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1003
+        }
1004
+
1005
+        self::setAppTypes($appId);
1006
+
1007
+        $version = \OC_App::getAppVersion($appId);
1008
+        \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);
1009
+
1010
+        \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent(
1011
+            ManagerEvent::EVENT_APP_UPDATE, $appId
1012
+        ));
1013
+
1014
+        return true;
1015
+    }
1016
+
1017
+    /**
1018
+     * @param string $appId
1019
+     * @param string[] $steps
1020
+     * @throws \OC\NeedsUpdateException
1021
+     */
1022
+    public static function executeRepairSteps(string $appId, array $steps) {
1023
+        if (empty($steps)) {
1024
+            return;
1025
+        }
1026
+        // load the app
1027
+        self::loadApp($appId);
1028
+
1029
+        $dispatcher = OC::$server->getEventDispatcher();
1030
+
1031
+        // load the steps
1032
+        $r = new Repair([], $dispatcher);
1033
+        foreach ($steps as $step) {
1034
+            try {
1035
+                $r->addStep($step);
1036
+            } catch (Exception $ex) {
1037
+                $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
1038
+                \OC::$server->getLogger()->logException($ex);
1039
+            }
1040
+        }
1041
+        // run the steps
1042
+        $r->run();
1043
+    }
1044
+
1045
+    public static function setupBackgroundJobs(array $jobs) {
1046
+        $queue = \OC::$server->getJobList();
1047
+        foreach ($jobs as $job) {
1048
+            $queue->add($job);
1049
+        }
1050
+    }
1051
+
1052
+    /**
1053
+     * @param string $appId
1054
+     * @param string[] $steps
1055
+     */
1056
+    private static function setupLiveMigrations(string $appId, array $steps) {
1057
+        $queue = \OC::$server->getJobList();
1058
+        foreach ($steps as $step) {
1059
+            $queue->add('OC\Migration\BackgroundRepair', [
1060
+                'app' => $appId,
1061
+                'step' => $step]);
1062
+        }
1063
+    }
1064
+
1065
+    /**
1066
+     * @param string $appId
1067
+     * @return \OC\Files\View|false
1068
+     */
1069
+    public static function getStorage(string $appId) {
1070
+        if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1071
+            if (\OC::$server->getUserSession()->isLoggedIn()) {
1072
+                $view = new \OC\Files\View('/' . OC_User::getUser());
1073
+                if (!$view->file_exists($appId)) {
1074
+                    $view->mkdir($appId);
1075
+                }
1076
+                return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1077
+            } else {
1078
+                \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR);
1079
+                return false;
1080
+            }
1081
+        } else {
1082
+            \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR);
1083
+            return false;
1084
+        }
1085
+    }
1086
+
1087
+    protected static function findBestL10NOption(array $options, string $lang): string {
1088
+        // only a single option
1089
+        if (isset($options['@value'])) {
1090
+            return $options['@value'];
1091
+        }
1092
+
1093
+        $fallback = $similarLangFallback = $englishFallback = false;
1094
+
1095
+        $lang = strtolower($lang);
1096
+        $similarLang = $lang;
1097
+        if (strpos($similarLang, '_')) {
1098
+            // For "de_DE" we want to find "de" and the other way around
1099
+            $similarLang = substr($lang, 0, strpos($lang, '_'));
1100
+        }
1101
+
1102
+        foreach ($options as $option) {
1103
+            if (is_array($option)) {
1104
+                if ($fallback === false) {
1105
+                    $fallback = $option['@value'];
1106
+                }
1107
+
1108
+                if (!isset($option['@attributes']['lang'])) {
1109
+                    continue;
1110
+                }
1111
+
1112
+                $attributeLang = strtolower($option['@attributes']['lang']);
1113
+                if ($attributeLang === $lang) {
1114
+                    return $option['@value'];
1115
+                }
1116
+
1117
+                if ($attributeLang === $similarLang) {
1118
+                    $similarLangFallback = $option['@value'];
1119
+                } elseif (strpos($attributeLang, $similarLang . '_') === 0) {
1120
+                    if ($similarLangFallback === false) {
1121
+                        $similarLangFallback =  $option['@value'];
1122
+                    }
1123
+                }
1124
+            } else {
1125
+                $englishFallback = $option;
1126
+            }
1127
+        }
1128
+
1129
+        if ($similarLangFallback !== false) {
1130
+            return $similarLangFallback;
1131
+        } elseif ($englishFallback !== false) {
1132
+            return $englishFallback;
1133
+        }
1134
+        return (string) $fallback;
1135
+    }
1136
+
1137
+    /**
1138
+     * parses the app data array and enhanced the 'description' value
1139
+     *
1140
+     * @param array $data the app data
1141
+     * @param string $lang
1142
+     * @return array improved app data
1143
+     */
1144
+    public static function parseAppInfo(array $data, $lang = null): array {
1145
+        if ($lang && isset($data['name']) && is_array($data['name'])) {
1146
+            $data['name'] = self::findBestL10NOption($data['name'], $lang);
1147
+        }
1148
+        if ($lang && isset($data['summary']) && is_array($data['summary'])) {
1149
+            $data['summary'] = self::findBestL10NOption($data['summary'], $lang);
1150
+        }
1151
+        if ($lang && isset($data['description']) && is_array($data['description'])) {
1152
+            $data['description'] = trim(self::findBestL10NOption($data['description'], $lang));
1153
+        } elseif (isset($data['description']) && is_string($data['description'])) {
1154
+            $data['description'] = trim($data['description']);
1155
+        } else {
1156
+            $data['description'] = '';
1157
+        }
1158
+
1159
+        return $data;
1160
+    }
1161
+
1162
+    /**
1163
+     * @param \OCP\IConfig $config
1164
+     * @param \OCP\IL10N $l
1165
+     * @param array $info
1166
+     * @throws \Exception
1167
+     */
1168
+    public static function checkAppDependencies(\OCP\IConfig $config, \OCP\IL10N $l, array $info, bool $ignoreMax) {
1169
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
1170
+        $missing = $dependencyAnalyzer->analyze($info, $ignoreMax);
1171
+        if (!empty($missing)) {
1172
+            $missingMsg = implode(PHP_EOL, $missing);
1173
+            throw new \Exception(
1174
+                $l->t('App "%1$s" cannot be installed because the following dependencies are not fulfilled: %2$s',
1175
+                    [$info['name'], $missingMsg]
1176
+                )
1177
+            );
1178
+        }
1179
+    }
1180 1180
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		$coordinator = \OC::$server->query(Coordinator::class);
157 157
 		$isBootable = $coordinator->isBootable($app);
158 158
 
159
-		$hasAppPhpFile = is_file($appPath . '/appinfo/app.php');
159
+		$hasAppPhpFile = is_file($appPath.'/appinfo/app.php');
160 160
 
161 161
 		if ($isBootable && $hasAppPhpFile) {
162 162
 			\OC::$server->getLogger()->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 			\OC::$server->getLogger()->debug('/appinfo/app.php is deprecated, use \OCP\AppFramework\Bootstrap\IBootstrap on the application class instead.', [
167 167
 				'app' => $app,
168 168
 			]);
169
-			\OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app);
169
+			\OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app);
170 170
 			try {
171 171
 				self::requireAppFile($app);
172 172
 			} catch (Throwable $ex) {
@@ -175,18 +175,18 @@  discard block
 block discarded – undo
175 175
 				}
176 176
 				if (!\OC::$server->getAppManager()->isShipped($app) && !self::isType($app, ['authentication'])) {
177 177
 					\OC::$server->getLogger()->logException($ex, [
178
-						'message' => "App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(),
178
+						'message' => "App $app threw an error during app.php load and will be disabled: ".$ex->getMessage(),
179 179
 					]);
180 180
 
181 181
 					// Only disable apps which are not shipped and that are not authentication apps
182 182
 					\OC::$server->getAppManager()->disableApp($app, true);
183 183
 				} else {
184 184
 					\OC::$server->getLogger()->logException($ex, [
185
-						'message' => "App $app threw an error during app.php load: " . $ex->getMessage(),
185
+						'message' => "App $app threw an error during app.php load: ".$ex->getMessage(),
186 186
 					]);
187 187
 				}
188 188
 			}
189
-			\OC::$server->getEventLogger()->end('load_app_' . $app);
189
+			\OC::$server->getEventLogger()->end('load_app_'.$app);
190 190
 		}
191 191
 		$coordinator->bootApp($app);
192 192
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * @param bool $force
254 254
 	 */
255 255
 	public static function registerAutoloading(string $app, string $path, bool $force = false) {
256
-		$key = $app . '-' . $path;
256
+		$key = $app.'-'.$path;
257 257
 		if (!$force && isset(self::$alreadyRegistered[$key])) {
258 258
 			return;
259 259
 		}
@@ -264,17 +264,17 @@  discard block
 block discarded – undo
264 264
 		$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
265 265
 		\OC::$server->registerNamespace($app, $appNamespace);
266 266
 
267
-		if (file_exists($path . '/composer/autoload.php')) {
268
-			require_once $path . '/composer/autoload.php';
267
+		if (file_exists($path.'/composer/autoload.php')) {
268
+			require_once $path.'/composer/autoload.php';
269 269
 		} else {
270
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
270
+			\OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true);
271 271
 			// Register on legacy autoloader
272 272
 			\OC::$loader->addValidRoot($path);
273 273
 		}
274 274
 
275 275
 		// Register Test namespace only when testing
276 276
 		if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
277
-			\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
277
+			\OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true);
278 278
 		}
279 279
 	}
280 280
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	private static function requireAppFile(string $app) {
288 288
 		// encapsulated here to avoid variable scope conflicts
289
-		require_once $app . '/appinfo/app.php';
289
+		require_once $app.'/appinfo/app.php';
290 290
 	}
291 291
 
292 292
 	/**
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 		} else {
380 380
 			$apps = $appManager->getEnabledAppsForUser($user);
381 381
 		}
382
-		$apps = array_filter($apps, function ($app) {
383
-			return $app !== 'files';//we add this manually
382
+		$apps = array_filter($apps, function($app) {
383
+			return $app !== 'files'; //we add this manually
384 384
 		});
385 385
 		sort($apps);
386 386
 		array_unshift($apps, 'files');
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 
481 481
 		$possibleApps = [];
482 482
 		foreach (OC::$APPSROOTS as $dir) {
483
-			if (file_exists($dir['path'] . '/' . $appId)) {
483
+			if (file_exists($dir['path'].'/'.$appId)) {
484 484
 				$possibleApps[] = $dir;
485 485
 			}
486 486
 		}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 		} else {
495 495
 			$versionToLoad = [];
496 496
 			foreach ($possibleApps as $possibleApp) {
497
-				$version = self::getAppVersionByPath($possibleApp['path'] . '/' . $appId);
497
+				$version = self::getAppVersionByPath($possibleApp['path'].'/'.$appId);
498 498
 				if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
499 499
 					$versionToLoad = [
500 500
 						'dir' => $possibleApp,
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		}
523 523
 
524 524
 		if (($dir = self::findAppInDirectories($appId)) != false) {
525
-			return $dir['path'] . '/' . $appId;
525
+			return $dir['path'].'/'.$appId;
526 526
 		}
527 527
 		return false;
528 528
 	}
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 	 */
538 538
 	public static function getAppWebPath(string $appId) {
539 539
 		if (($dir = self::findAppInDirectories($appId)) != false) {
540
-			return OC::$WEBROOT . $dir['url'] . '/' . $appId;
540
+			return OC::$WEBROOT.$dir['url'].'/'.$appId;
541 541
 		}
542 542
 		return false;
543 543
 	}
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 	 * @return string
562 562
 	 */
563 563
 	public static function getAppVersionByPath(string $path): string {
564
-		$infoFile = $path . '/appinfo/info.xml';
564
+		$infoFile = $path.'/appinfo/info.xml';
565 565
 		$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
566 566
 		return isset($appData['version']) ? $appData['version'] : '';
567 567
 	}
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 	 * @param string $page
662 662
 	 */
663 663
 	public static function registerAdmin(string $app, string $page) {
664
-		self::$adminForms[] = $app . '/' . $page . '.php';
664
+		self::$adminForms[] = $app.'/'.$page.'.php';
665 665
 	}
666 666
 
667 667
 	/**
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 	 * @param string $page
671 671
 	 */
672 672
 	public static function registerPersonal(string $app, string $page) {
673
-		self::$personalForms[] = $app . '/' . $page . '.php';
673
+		self::$personalForms[] = $app.'/'.$page.'.php';
674 674
 	}
675 675
 
676 676
 	/**
@@ -741,14 +741,14 @@  discard block
 block discarded – undo
741 741
 
742 742
 		foreach (OC::$APPSROOTS as $apps_dir) {
743 743
 			if (!is_readable($apps_dir['path'])) {
744
-				\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN);
744
+				\OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], ILogger::WARN);
745 745
 				continue;
746 746
 			}
747 747
 			$dh = opendir($apps_dir['path']);
748 748
 
749 749
 			if (is_resource($dh)) {
750 750
 				while (($file = readdir($dh)) !== false) {
751
-					if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
751
+					if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) {
752 752
 						$apps[] = $file;
753 753
 					}
754 754
 				}
@@ -782,12 +782,12 @@  discard block
 block discarded – undo
782 782
 			if (array_search($app, $blacklist) === false) {
783 783
 				$info = OC_App::getAppInfo($app, false, $langCode);
784 784
 				if (!is_array($info)) {
785
-					\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR);
785
+					\OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', ILogger::ERROR);
786 786
 					continue;
787 787
 				}
788 788
 
789 789
 				if (!isset($info['name'])) {
790
-					\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR);
790
+					\OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', ILogger::ERROR);
791 791
 					continue;
792 792
 				}
793 793
 
@@ -819,12 +819,12 @@  discard block
 block discarded – undo
819 819
 
820 820
 				$appPath = self::getAppPath($app);
821 821
 				if ($appPath !== false) {
822
-					$appIcon = $appPath . '/img/' . $app . '.svg';
822
+					$appIcon = $appPath.'/img/'.$app.'.svg';
823 823
 					if (file_exists($appIcon)) {
824
-						$info['preview'] = $urlGenerator->imagePath($app, $app . '.svg');
824
+						$info['preview'] = $urlGenerator->imagePath($app, $app.'.svg');
825 825
 						$info['previewAsIcon'] = true;
826 826
 					} else {
827
-						$appIcon = $appPath . '/img/app.svg';
827
+						$appIcon = $appPath.'/img/app.svg';
828 828
 						if (file_exists($appIcon)) {
829 829
 							$info['preview'] = $urlGenerator->imagePath($app, 'app.svg');
830 830
 							$info['previewAsIcon'] = true;
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 		self::registerAutoloading($appId, $appPath, true);
970 970
 		self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);
971 971
 
972
-		if (file_exists($appPath . '/appinfo/database.xml')) {
973
-			OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
972
+		if (file_exists($appPath.'/appinfo/database.xml')) {
973
+			OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml');
974 974
 		} else {
975 975
 			$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
976 976
 			$ms->migrate();
@@ -983,9 +983,9 @@  discard block
 block discarded – undo
983 983
 		\OC::$server->getAppManager()->getAppVersion($appId, false);
984 984
 
985 985
 		// run upgrade code
986
-		if (file_exists($appPath . '/appinfo/update.php')) {
986
+		if (file_exists($appPath.'/appinfo/update.php')) {
987 987
 			self::loadApp($appId);
988
-			include $appPath . '/appinfo/update.php';
988
+			include $appPath.'/appinfo/update.php';
989 989
 		}
990 990
 		self::setupBackgroundJobs($appData['background-jobs']);
991 991
 
@@ -996,10 +996,10 @@  discard block
 block discarded – undo
996 996
 			\OC::$server->getConfig()->deleteAppValue($appId, 'ocsid');
997 997
 		}
998 998
 		foreach ($appData['remote'] as $name => $path) {
999
-			\OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path);
999
+			\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path);
1000 1000
 		}
1001 1001
 		foreach ($appData['public'] as $name => $path) {
1002
-			\OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
1002
+			\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path);
1003 1003
 		}
1004 1004
 
1005 1005
 		self::setAppTypes($appId);
@@ -1069,17 +1069,17 @@  discard block
 block discarded – undo
1069 1069
 	public static function getStorage(string $appId) {
1070 1070
 		if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
1071 1071
 			if (\OC::$server->getUserSession()->isLoggedIn()) {
1072
-				$view = new \OC\Files\View('/' . OC_User::getUser());
1072
+				$view = new \OC\Files\View('/'.OC_User::getUser());
1073 1073
 				if (!$view->file_exists($appId)) {
1074 1074
 					$view->mkdir($appId);
1075 1075
 				}
1076
-				return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
1076
+				return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId);
1077 1077
 			} else {
1078
-				\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR);
1078
+				\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', ILogger::ERROR);
1079 1079
 				return false;
1080 1080
 			}
1081 1081
 		} else {
1082
-			\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR);
1082
+			\OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', ILogger::ERROR);
1083 1083
 			return false;
1084 1084
 		}
1085 1085
 	}
@@ -1116,9 +1116,9 @@  discard block
 block discarded – undo
1116 1116
 
1117 1117
 				if ($attributeLang === $similarLang) {
1118 1118
 					$similarLangFallback = $option['@value'];
1119
-				} elseif (strpos($attributeLang, $similarLang . '_') === 0) {
1119
+				} elseif (strpos($attributeLang, $similarLang.'_') === 0) {
1120 1120
 					if ($similarLangFallback === false) {
1121
-						$similarLangFallback =  $option['@value'];
1121
+						$similarLangFallback = $option['@value'];
1122 1122
 					}
1123 1123
 				}
1124 1124
 			} else {
Please login to merge, or discard this patch.
lib/private/AppFramework/Bootstrap/RegistrationContext.php 1 patch
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -36,378 +36,378 @@
 block discarded – undo
36 36
 
37 37
 class RegistrationContext {
38 38
 
39
-	/** @var array[] */
40
-	private $capabilities = [];
41
-
42
-	/** @var array[] */
43
-	private $crashReporters = [];
44
-
45
-	/** @var array[] */
46
-	private $dashboardPanels = [];
47
-
48
-	/** @var array[] */
49
-	private $services = [];
50
-
51
-	/** @var array[] */
52
-	private $aliases = [];
53
-
54
-	/** @var array[] */
55
-	private $parameters = [];
56
-
57
-	/** @var array[] */
58
-	private $eventListeners = [];
59
-
60
-	/** @var array[] */
61
-	private $middlewares = [];
62
-
63
-	/** @var array[] */
64
-	private $searchProviders = [];
65
-
66
-	/** @var array[] */
67
-	private $alternativeLogins = [];
68
-
69
-	/** @var ILogger */
70
-	private $logger;
71
-
72
-	public function __construct(ILogger $logger) {
73
-		$this->logger = $logger;
74
-	}
75
-
76
-	public function for(string $appId): IRegistrationContext {
77
-		return new class($appId, $this) implements IRegistrationContext {
78
-			/** @var string */
79
-			private $appId;
80
-
81
-			/** @var RegistrationContext */
82
-			private $context;
83
-
84
-			public function __construct(string $appId, RegistrationContext $context) {
85
-				$this->appId = $appId;
86
-				$this->context = $context;
87
-			}
88
-
89
-			public function registerCapability(string $capability): void {
90
-				$this->context->registerCapability(
91
-					$this->appId,
92
-					$capability
93
-				);
94
-			}
95
-
96
-			public function registerCrashReporter(string $reporterClass): void {
97
-				$this->context->registerCrashReporter(
98
-					$this->appId,
99
-					$reporterClass
100
-				);
101
-			}
102
-
103
-			public function registerDashboardPanel(string $panelClass): void {
104
-				$this->context->registerDashboardPanel(
105
-					$this->appId,
106
-					$panelClass
107
-				);
108
-			}
109
-
110
-			public function registerService(string $name, callable $factory, bool $shared = true): void {
111
-				$this->context->registerService(
112
-					$this->appId,
113
-					$name,
114
-					$factory,
115
-					$shared
116
-				);
117
-			}
118
-
119
-			public function registerServiceAlias(string $alias, string $target): void {
120
-				$this->context->registerServiceAlias(
121
-					$this->appId,
122
-					$alias,
123
-					$target
124
-				);
125
-			}
126
-
127
-			public function registerParameter(string $name, $value): void {
128
-				$this->context->registerParameter(
129
-					$this->appId,
130
-					$name,
131
-					$value
132
-				);
133
-			}
134
-
135
-			public function registerEventListener(string $event, string $listener, int $priority = 0): void {
136
-				$this->context->registerEventListener(
137
-					$this->appId,
138
-					$event,
139
-					$listener,
140
-					$priority
141
-				);
142
-			}
143
-
144
-			public function registerMiddleware(string $class): void {
145
-				$this->context->registerMiddleware(
146
-					$this->appId,
147
-					$class
148
-				);
149
-			}
150
-
151
-			public function registerSearchProvider(string $class): void {
152
-				$this->context->registerSearchProvider(
153
-					$this->appId,
154
-					$class
155
-				);
156
-			}
157
-
158
-			public function registerAlternativeLogin(string $class): void {
159
-				$this->context->registerAlternativeLogin(
160
-					$this->appId,
161
-					$class
162
-				);
163
-			}
164
-		};
165
-	}
166
-
167
-	public function registerCapability(string $appId, string $capability): void {
168
-		$this->capabilities[] = [
169
-			'appId' => $appId,
170
-			'capability' => $capability
171
-		];
172
-	}
173
-
174
-	public function registerCrashReporter(string $appId, string $reporterClass): void {
175
-		$this->crashReporters[] = [
176
-			'appId' => $appId,
177
-			'class' => $reporterClass,
178
-		];
179
-	}
180
-
181
-	public function registerDashboardPanel(string $appId, string $panelClass): void {
182
-		$this->dashboardPanels[] = [
183
-			'appId' => $appId,
184
-			'class' => $panelClass
185
-		];
186
-	}
187
-
188
-	public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void {
189
-		$this->services[] = [
190
-			"appId" => $appId,
191
-			"name" => $name,
192
-			"factory" => $factory,
193
-			"sharred" => $shared,
194
-		];
195
-	}
196
-
197
-	public function registerServiceAlias(string $appId, string $alias, string $target): void {
198
-		$this->aliases[] = [
199
-			"appId" => $appId,
200
-			"alias" => $alias,
201
-			"target" => $target,
202
-		];
203
-	}
204
-
205
-	public function registerParameter(string $appId, string $name, $value): void {
206
-		$this->parameters[] = [
207
-			"appId" => $appId,
208
-			"name" => $name,
209
-			"value" => $value,
210
-		];
211
-	}
212
-
213
-	public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void {
214
-		$this->eventListeners[] = [
215
-			"appId" => $appId,
216
-			"event" => $event,
217
-			"listener" => $listener,
218
-			"priority" => $priority,
219
-		];
220
-	}
221
-
222
-	public function registerMiddleware(string $appId, string $class): void {
223
-		$this->middlewares[] = [
224
-			"appId" => $appId,
225
-			"class" => $class,
226
-		];
227
-	}
228
-
229
-	public function registerSearchProvider(string $appId, string $class) {
230
-		$this->searchProviders[] = [
231
-			'appId' => $appId,
232
-			'class' => $class,
233
-		];
234
-	}
235
-
236
-	public function registerAlternativeLogin(string $appId, string $class): void {
237
-		$this->alternativeLogins[] = [
238
-			'appId' => $appId,
239
-			'class' => $class,
240
-		];
241
-	}
242
-
243
-	/**
244
-	 * @param App[] $apps
245
-	 */
246
-	public function delegateCapabilityRegistrations(array $apps): void {
247
-		foreach ($this->capabilities as $registration) {
248
-			try {
249
-				$apps[$registration['appId']]
250
-					->getContainer()
251
-					->registerCapability($registration['capability']);
252
-			} catch (Throwable $e) {
253
-				$appId = $registration['appId'];
254
-				$this->logger->logException($e, [
255
-					'message' => "Error during capability registration of $appId: " . $e->getMessage(),
256
-					'level' => ILogger::ERROR,
257
-				]);
258
-			}
259
-		}
260
-	}
261
-
262
-	/**
263
-	 * @param App[] $apps
264
-	 */
265
-	public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
266
-		foreach ($this->crashReporters as $registration) {
267
-			try {
268
-				$registry->registerLazy($registration['class']);
269
-			} catch (Throwable $e) {
270
-				$appId = $registration['appId'];
271
-				$this->logger->logException($e, [
272
-					'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(),
273
-					'level' => ILogger::ERROR,
274
-				]);
275
-			}
276
-		}
277
-	}
278
-
279
-	/**
280
-	 * @param App[] $apps
281
-	 */
282
-	public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
283
-		foreach ($this->dashboardPanels as $panel) {
284
-			try {
285
-				$dashboardManager->lazyRegisterPanel($panel['class']);
286
-			} catch (Throwable $e) {
287
-				$appId = $panel['appId'];
288
-				$this->logger->logException($e, [
289
-					'message' => "Error during dashboard registration of $appId: " . $e->getMessage(),
290
-					'level' => ILogger::ERROR,
291
-				]);
292
-			}
293
-		}
294
-	}
295
-
296
-	public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
297
-		foreach ($this->eventListeners as $registration) {
298
-			try {
299
-				if (isset($registration['priority'])) {
300
-					$eventDispatcher->addServiceListener(
301
-						$registration['event'],
302
-						$registration['listener'],
303
-						$registration['priority']
304
-					);
305
-				} else {
306
-					$eventDispatcher->addServiceListener(
307
-						$registration['event'],
308
-						$registration['listener']
309
-					);
310
-				}
311
-			} catch (Throwable $e) {
312
-				$appId = $registration['appId'];
313
-				$this->logger->logException($e, [
314
-					'message' => "Error during event listener registration of $appId: " . $e->getMessage(),
315
-					'level' => ILogger::ERROR,
316
-				]);
317
-			}
318
-		}
319
-	}
320
-
321
-	/**
322
-	 * @param App[] $apps
323
-	 */
324
-	public function delegateContainerRegistrations(array $apps): void {
325
-		foreach ($this->services as $registration) {
326
-			try {
327
-				/**
328
-				 * Register the service and convert the callable into a \Closure if necessary
329
-				 */
330
-				$apps[$registration['appId']]
331
-					->getContainer()
332
-					->registerService(
333
-						$registration['name'],
334
-						Closure::fromCallable($registration['factory']),
335
-						$registration['shared'] ?? true
336
-					);
337
-			} catch (Throwable $e) {
338
-				$appId = $registration['appId'];
339
-				$this->logger->logException($e, [
340
-					'message' => "Error during service registration of $appId: " . $e->getMessage(),
341
-					'level' => ILogger::ERROR,
342
-				]);
343
-			}
344
-		}
345
-
346
-		foreach ($this->aliases as $registration) {
347
-			try {
348
-				$apps[$registration['appId']]
349
-					->getContainer()
350
-					->registerAlias(
351
-						$registration['alias'],
352
-						$registration['target']
353
-					);
354
-			} catch (Throwable $e) {
355
-				$appId = $registration['appId'];
356
-				$this->logger->logException($e, [
357
-					'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
358
-					'level' => ILogger::ERROR,
359
-				]);
360
-			}
361
-		}
362
-
363
-		foreach ($this->parameters as $registration) {
364
-			try {
365
-				$apps[$registration['appId']]
366
-					->getContainer()
367
-					->registerParameter(
368
-						$registration['name'],
369
-						$registration['value']
370
-					);
371
-			} catch (Throwable $e) {
372
-				$appId = $registration['appId'];
373
-				$this->logger->logException($e, [
374
-					'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
375
-					'level' => ILogger::ERROR,
376
-				]);
377
-			}
378
-		}
379
-	}
380
-
381
-	/**
382
-	 * @param App[] $apps
383
-	 */
384
-	public function delegateMiddlewareRegistrations(array $apps): void {
385
-		foreach ($this->middlewares as $middleware) {
386
-			try {
387
-				$apps[$middleware['appId']]
388
-					->getContainer()
389
-					->registerMiddleWare($middleware['class']);
390
-			} catch (Throwable $e) {
391
-				$appId = $middleware['appId'];
392
-				$this->logger->logException($e, [
393
-					'message' => "Error during capability registration of $appId: " . $e->getMessage(),
394
-					'level' => ILogger::ERROR,
395
-				]);
396
-			}
397
-		}
398
-	}
399
-
400
-	/**
401
-	 * @return array[]
402
-	 */
403
-	public function getSearchProviders(): array {
404
-		return $this->searchProviders;
405
-	}
406
-
407
-	/**
408
-	 * @return array[]
409
-	 */
410
-	public function getAlternativeLogins(): array {
411
-		return $this->alternativeLogins;
412
-	}
39
+    /** @var array[] */
40
+    private $capabilities = [];
41
+
42
+    /** @var array[] */
43
+    private $crashReporters = [];
44
+
45
+    /** @var array[] */
46
+    private $dashboardPanels = [];
47
+
48
+    /** @var array[] */
49
+    private $services = [];
50
+
51
+    /** @var array[] */
52
+    private $aliases = [];
53
+
54
+    /** @var array[] */
55
+    private $parameters = [];
56
+
57
+    /** @var array[] */
58
+    private $eventListeners = [];
59
+
60
+    /** @var array[] */
61
+    private $middlewares = [];
62
+
63
+    /** @var array[] */
64
+    private $searchProviders = [];
65
+
66
+    /** @var array[] */
67
+    private $alternativeLogins = [];
68
+
69
+    /** @var ILogger */
70
+    private $logger;
71
+
72
+    public function __construct(ILogger $logger) {
73
+        $this->logger = $logger;
74
+    }
75
+
76
+    public function for(string $appId): IRegistrationContext {
77
+        return new class($appId, $this) implements IRegistrationContext {
78
+            /** @var string */
79
+            private $appId;
80
+
81
+            /** @var RegistrationContext */
82
+            private $context;
83
+
84
+            public function __construct(string $appId, RegistrationContext $context) {
85
+                $this->appId = $appId;
86
+                $this->context = $context;
87
+            }
88
+
89
+            public function registerCapability(string $capability): void {
90
+                $this->context->registerCapability(
91
+                    $this->appId,
92
+                    $capability
93
+                );
94
+            }
95
+
96
+            public function registerCrashReporter(string $reporterClass): void {
97
+                $this->context->registerCrashReporter(
98
+                    $this->appId,
99
+                    $reporterClass
100
+                );
101
+            }
102
+
103
+            public function registerDashboardPanel(string $panelClass): void {
104
+                $this->context->registerDashboardPanel(
105
+                    $this->appId,
106
+                    $panelClass
107
+                );
108
+            }
109
+
110
+            public function registerService(string $name, callable $factory, bool $shared = true): void {
111
+                $this->context->registerService(
112
+                    $this->appId,
113
+                    $name,
114
+                    $factory,
115
+                    $shared
116
+                );
117
+            }
118
+
119
+            public function registerServiceAlias(string $alias, string $target): void {
120
+                $this->context->registerServiceAlias(
121
+                    $this->appId,
122
+                    $alias,
123
+                    $target
124
+                );
125
+            }
126
+
127
+            public function registerParameter(string $name, $value): void {
128
+                $this->context->registerParameter(
129
+                    $this->appId,
130
+                    $name,
131
+                    $value
132
+                );
133
+            }
134
+
135
+            public function registerEventListener(string $event, string $listener, int $priority = 0): void {
136
+                $this->context->registerEventListener(
137
+                    $this->appId,
138
+                    $event,
139
+                    $listener,
140
+                    $priority
141
+                );
142
+            }
143
+
144
+            public function registerMiddleware(string $class): void {
145
+                $this->context->registerMiddleware(
146
+                    $this->appId,
147
+                    $class
148
+                );
149
+            }
150
+
151
+            public function registerSearchProvider(string $class): void {
152
+                $this->context->registerSearchProvider(
153
+                    $this->appId,
154
+                    $class
155
+                );
156
+            }
157
+
158
+            public function registerAlternativeLogin(string $class): void {
159
+                $this->context->registerAlternativeLogin(
160
+                    $this->appId,
161
+                    $class
162
+                );
163
+            }
164
+        };
165
+    }
166
+
167
+    public function registerCapability(string $appId, string $capability): void {
168
+        $this->capabilities[] = [
169
+            'appId' => $appId,
170
+            'capability' => $capability
171
+        ];
172
+    }
173
+
174
+    public function registerCrashReporter(string $appId, string $reporterClass): void {
175
+        $this->crashReporters[] = [
176
+            'appId' => $appId,
177
+            'class' => $reporterClass,
178
+        ];
179
+    }
180
+
181
+    public function registerDashboardPanel(string $appId, string $panelClass): void {
182
+        $this->dashboardPanels[] = [
183
+            'appId' => $appId,
184
+            'class' => $panelClass
185
+        ];
186
+    }
187
+
188
+    public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void {
189
+        $this->services[] = [
190
+            "appId" => $appId,
191
+            "name" => $name,
192
+            "factory" => $factory,
193
+            "sharred" => $shared,
194
+        ];
195
+    }
196
+
197
+    public function registerServiceAlias(string $appId, string $alias, string $target): void {
198
+        $this->aliases[] = [
199
+            "appId" => $appId,
200
+            "alias" => $alias,
201
+            "target" => $target,
202
+        ];
203
+    }
204
+
205
+    public function registerParameter(string $appId, string $name, $value): void {
206
+        $this->parameters[] = [
207
+            "appId" => $appId,
208
+            "name" => $name,
209
+            "value" => $value,
210
+        ];
211
+    }
212
+
213
+    public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void {
214
+        $this->eventListeners[] = [
215
+            "appId" => $appId,
216
+            "event" => $event,
217
+            "listener" => $listener,
218
+            "priority" => $priority,
219
+        ];
220
+    }
221
+
222
+    public function registerMiddleware(string $appId, string $class): void {
223
+        $this->middlewares[] = [
224
+            "appId" => $appId,
225
+            "class" => $class,
226
+        ];
227
+    }
228
+
229
+    public function registerSearchProvider(string $appId, string $class) {
230
+        $this->searchProviders[] = [
231
+            'appId' => $appId,
232
+            'class' => $class,
233
+        ];
234
+    }
235
+
236
+    public function registerAlternativeLogin(string $appId, string $class): void {
237
+        $this->alternativeLogins[] = [
238
+            'appId' => $appId,
239
+            'class' => $class,
240
+        ];
241
+    }
242
+
243
+    /**
244
+     * @param App[] $apps
245
+     */
246
+    public function delegateCapabilityRegistrations(array $apps): void {
247
+        foreach ($this->capabilities as $registration) {
248
+            try {
249
+                $apps[$registration['appId']]
250
+                    ->getContainer()
251
+                    ->registerCapability($registration['capability']);
252
+            } catch (Throwable $e) {
253
+                $appId = $registration['appId'];
254
+                $this->logger->logException($e, [
255
+                    'message' => "Error during capability registration of $appId: " . $e->getMessage(),
256
+                    'level' => ILogger::ERROR,
257
+                ]);
258
+            }
259
+        }
260
+    }
261
+
262
+    /**
263
+     * @param App[] $apps
264
+     */
265
+    public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
266
+        foreach ($this->crashReporters as $registration) {
267
+            try {
268
+                $registry->registerLazy($registration['class']);
269
+            } catch (Throwable $e) {
270
+                $appId = $registration['appId'];
271
+                $this->logger->logException($e, [
272
+                    'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(),
273
+                    'level' => ILogger::ERROR,
274
+                ]);
275
+            }
276
+        }
277
+    }
278
+
279
+    /**
280
+     * @param App[] $apps
281
+     */
282
+    public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
283
+        foreach ($this->dashboardPanels as $panel) {
284
+            try {
285
+                $dashboardManager->lazyRegisterPanel($panel['class']);
286
+            } catch (Throwable $e) {
287
+                $appId = $panel['appId'];
288
+                $this->logger->logException($e, [
289
+                    'message' => "Error during dashboard registration of $appId: " . $e->getMessage(),
290
+                    'level' => ILogger::ERROR,
291
+                ]);
292
+            }
293
+        }
294
+    }
295
+
296
+    public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
297
+        foreach ($this->eventListeners as $registration) {
298
+            try {
299
+                if (isset($registration['priority'])) {
300
+                    $eventDispatcher->addServiceListener(
301
+                        $registration['event'],
302
+                        $registration['listener'],
303
+                        $registration['priority']
304
+                    );
305
+                } else {
306
+                    $eventDispatcher->addServiceListener(
307
+                        $registration['event'],
308
+                        $registration['listener']
309
+                    );
310
+                }
311
+            } catch (Throwable $e) {
312
+                $appId = $registration['appId'];
313
+                $this->logger->logException($e, [
314
+                    'message' => "Error during event listener registration of $appId: " . $e->getMessage(),
315
+                    'level' => ILogger::ERROR,
316
+                ]);
317
+            }
318
+        }
319
+    }
320
+
321
+    /**
322
+     * @param App[] $apps
323
+     */
324
+    public function delegateContainerRegistrations(array $apps): void {
325
+        foreach ($this->services as $registration) {
326
+            try {
327
+                /**
328
+                 * Register the service and convert the callable into a \Closure if necessary
329
+                 */
330
+                $apps[$registration['appId']]
331
+                    ->getContainer()
332
+                    ->registerService(
333
+                        $registration['name'],
334
+                        Closure::fromCallable($registration['factory']),
335
+                        $registration['shared'] ?? true
336
+                    );
337
+            } catch (Throwable $e) {
338
+                $appId = $registration['appId'];
339
+                $this->logger->logException($e, [
340
+                    'message' => "Error during service registration of $appId: " . $e->getMessage(),
341
+                    'level' => ILogger::ERROR,
342
+                ]);
343
+            }
344
+        }
345
+
346
+        foreach ($this->aliases as $registration) {
347
+            try {
348
+                $apps[$registration['appId']]
349
+                    ->getContainer()
350
+                    ->registerAlias(
351
+                        $registration['alias'],
352
+                        $registration['target']
353
+                    );
354
+            } catch (Throwable $e) {
355
+                $appId = $registration['appId'];
356
+                $this->logger->logException($e, [
357
+                    'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
358
+                    'level' => ILogger::ERROR,
359
+                ]);
360
+            }
361
+        }
362
+
363
+        foreach ($this->parameters as $registration) {
364
+            try {
365
+                $apps[$registration['appId']]
366
+                    ->getContainer()
367
+                    ->registerParameter(
368
+                        $registration['name'],
369
+                        $registration['value']
370
+                    );
371
+            } catch (Throwable $e) {
372
+                $appId = $registration['appId'];
373
+                $this->logger->logException($e, [
374
+                    'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
375
+                    'level' => ILogger::ERROR,
376
+                ]);
377
+            }
378
+        }
379
+    }
380
+
381
+    /**
382
+     * @param App[] $apps
383
+     */
384
+    public function delegateMiddlewareRegistrations(array $apps): void {
385
+        foreach ($this->middlewares as $middleware) {
386
+            try {
387
+                $apps[$middleware['appId']]
388
+                    ->getContainer()
389
+                    ->registerMiddleWare($middleware['class']);
390
+            } catch (Throwable $e) {
391
+                $appId = $middleware['appId'];
392
+                $this->logger->logException($e, [
393
+                    'message' => "Error during capability registration of $appId: " . $e->getMessage(),
394
+                    'level' => ILogger::ERROR,
395
+                ]);
396
+            }
397
+        }
398
+    }
399
+
400
+    /**
401
+     * @return array[]
402
+     */
403
+    public function getSearchProviders(): array {
404
+        return $this->searchProviders;
405
+    }
406
+
407
+    /**
408
+     * @return array[]
409
+     */
410
+    public function getAlternativeLogins(): array {
411
+        return $this->alternativeLogins;
412
+    }
413 413
 }
Please login to merge, or discard this patch.