Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
BaseAppMetadata | |
0.00% |
0 / 34 |
|
0.00% |
0 / 4 |
182 | |
0.00% |
0 / 1 |
getDisplayName | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getPath | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getHref | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
isAccessibleToUser | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getBasename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIconPath | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
getIcon | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
getJsCssImports | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Olz\Apps; |
4 | |
5 | use Olz\Entity\Users\User; |
6 | use Olz\Utils\WithUtilsTrait; |
7 | |
8 | abstract class BaseAppMetadata { |
9 | use WithUtilsTrait; |
10 | |
11 | abstract public function getDisplayName(): string; |
12 | |
13 | abstract public function getPath(): string; |
14 | |
15 | abstract public function getHref(): string; |
16 | |
17 | abstract public function isAccessibleToUser(?User $user): bool; |
18 | |
19 | public function getBasename(): string { |
20 | return basename($this->getPath()); |
21 | } |
22 | |
23 | public function getIconPath(): ?string { |
24 | $app_path = $this->getPath(); |
25 | $svg_path = "{$app_path}/icon.svg"; |
26 | if (is_file($svg_path)) { |
27 | return $svg_path; |
28 | } |
29 | $png_path = "{$app_path}/icon.png"; |
30 | if (is_file($png_path)) { |
31 | return $png_path; |
32 | } |
33 | return null; |
34 | } |
35 | |
36 | public function getIcon(): ?string { |
37 | $icon_path = $this->getIconPath(); |
38 | if (!$icon_path) { |
39 | $base64 = base64_encode(file_get_contents(__DIR__.'/default_icon.svg') ?: ''); |
40 | $mime_type = 'image/svg+xml'; |
41 | return "data:{$mime_type};base64,{$base64}"; |
42 | } |
43 | $base64 = base64_encode(file_get_contents($icon_path) ?: ''); |
44 | if (substr($icon_path, strlen($icon_path) - 4) == '.svg') { |
45 | $mime_type = 'image/svg+xml'; |
46 | return "data:{$mime_type};base64,{$base64}"; |
47 | } |
48 | if (substr($icon_path, strlen($icon_path) - 4) == '.png') { |
49 | $mime_type = 'image/png'; |
50 | return "data:{$mime_type};base64,{$base64}"; |
51 | } |
52 | return null; |
53 | } |
54 | |
55 | public function getJsCssImports(): string { |
56 | $data_path = $this->envUtils()->getDataPath(); |
57 | $basename = $this->getBasename(); |
58 | $css_path = "{$data_path}jsbuild/app-{$basename}/main.min.css"; |
59 | $js_path = "{$data_path}jsbuild/app-{$basename}/main.min.js"; |
60 | $css_modified = is_file($css_path) ? filemtime($css_path) : 0; |
61 | $js_modified = is_file($js_path) ? filemtime($js_path) : 0; |
62 | $css_href = "/jsbuild/app-{$basename}/main.min.css?modified={$css_modified}"; |
63 | $js_href = "/jsbuild/app-{$basename}/main.min.js?modified={$js_modified}"; |
64 | |
65 | $out = ''; |
66 | $out .= "<link rel='stylesheet' href='{$css_href}' />"; |
67 | $out .= "<script type='text/javascript' src='{$js_href}' onload='olz{$basename}.loaded()'></script>"; |
68 | return $out; |
69 | } |
70 | } |