Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
OlzApps | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
342 | |
0.00% |
0 / 1 |
getApp | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getAppPaths | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
getApps | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
getAppsForUser | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
registerAllEndpoints | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace Olz\Apps; |
4 | |
5 | use Olz\Entity\Users\User; |
6 | use PhpTypeScriptApi\Api; |
7 | |
8 | class OlzApps { |
9 | public static function getApp(string $basename): ?BaseAppMetadata { |
10 | $metadata_class_name = "\\Olz\\Apps\\{$basename}\\Metadata"; |
11 | if (class_exists($metadata_class_name)) { |
12 | $instance = new $metadata_class_name(); |
13 | if ($instance instanceof BaseAppMetadata) { |
14 | return $instance; |
15 | } |
16 | } |
17 | return null; |
18 | } |
19 | |
20 | /** @return array<string> */ |
21 | public static function getAppPaths(): array { |
22 | $entries = scandir(__DIR__) ?: []; |
23 | $app_paths = []; |
24 | foreach ($entries as $entry) { |
25 | $path = __DIR__."/{$entry}"; |
26 | if (is_dir($path) && is_file("{$path}/Metadata.php")) { |
27 | $app_paths[] = $path; |
28 | } |
29 | } |
30 | return $app_paths; |
31 | } |
32 | |
33 | /** @return array<BaseAppMetadata> */ |
34 | public static function getApps(): array { |
35 | $app_paths = self::getAppPaths(); |
36 | $apps = []; |
37 | foreach ($app_paths as $app_path) { |
38 | $app_basename = basename($app_path); |
39 | $app = self::getApp($app_basename); |
40 | if ($app !== null) { |
41 | $apps[] = $app; |
42 | } |
43 | } |
44 | return $apps; |
45 | } |
46 | |
47 | /** @return array<BaseAppMetadata> */ |
48 | public static function getAppsForUser(?User $user): array { |
49 | $apps = self::getApps(); |
50 | $apps_for_user = []; |
51 | foreach ($apps as $app) { |
52 | if ($app->isAccessibleToUser($user)) { |
53 | $apps_for_user[] = $app; |
54 | } |
55 | } |
56 | return $apps_for_user; |
57 | } |
58 | |
59 | public static function registerAllEndpoints(Api $api): void { |
60 | $app_paths = self::getAppPaths(); |
61 | foreach ($app_paths as $app_path) { |
62 | $app_basename = basename($app_path); |
63 | $endpoints_class_name = "\\Olz\\Apps\\{$app_basename}\\{$app_basename}Endpoints"; |
64 | if (class_exists($endpoints_class_name)) { |
65 | $endpoints = new $endpoints_class_name(); |
66 | if ($endpoints instanceof BaseAppEndpoints) { |
67 | $endpoints->register($api); |
68 | } |
69 | } |
70 | } |
71 | } |
72 | } |