-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.php
More file actions
79 lines (65 loc) · 2.21 KB
/
Application.php
File metadata and controls
79 lines (65 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
namespace OCA\ProfileFields\AppInfo;
use OCA\ProfileFields\Listener\BeforeTemplateRenderedListener;
use OCA\ProfileFields\Listener\UserDeletedCleanupListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IRequest;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;
/**
* @codeCoverageIgnore
*/
class Application extends App implements IBootstrap {
public const APP_ID = 'profile_fields';
private static bool $userManagementAssetsLoaded = false;
public function __construct() {
parent::__construct(self::APP_ID);
}
#[\Override]
public function register(IRegistrationContext $context): void {
$context->registerEventListener('\\OCA\\Settings\\Events\\BeforeTemplateRenderedEvent', BeforeTemplateRenderedListener::class);
$context->registerEventListener(UserDeletedEvent::class, UserDeletedCleanupListener::class);
}
#[\Override]
public function boot(IBootContext $context): void {
try {
$context->injectFn($this->bootWithRequest(...));
} catch (\Throwable) {
return;
}
}
private function bootWithRequest(IRequest $request): void {
$path = $this->readRequestString(static fn (): string|false => $request->getPathInfo());
$requestUri = $this->readRequestString(static fn (): string => $request->getRequestUri());
if (
($path !== null && str_contains($path, '/settings/users'))
|| ($requestUri !== null && str_contains($requestUri, '/settings/users'))
) {
self::loadUserManagementAssets();
}
}
private function readRequestString(callable $reader): ?string {
try {
$value = $reader();
} catch (\Throwable) {
return null;
}
return is_string($value) && $value !== '' ? $value : null;
}
public static function loadUserManagementAssets(): void {
if (self::$userManagementAssetsLoaded) {
return;
}
Util::addStyle(self::APP_ID, 'profile_fields-user-management-action');
Util::addScript(self::APP_ID, 'profile_fields-user-management-action');
self::$userManagementAssetsLoaded = true;
}
}