|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the fusonic/webapp package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Fusonic GmbH <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Fusonic\WebApp\Generators; |
|
13
|
|
|
|
|
14
|
|
|
use Fusonic\WebApp\AppConfiguration; |
|
15
|
|
|
use Fusonic\WebApp\Objects\Image; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Generates an app manifest according to the W3C specification "Web App Manifest". |
|
19
|
|
|
* |
|
20
|
|
|
* @package Fusonic\WebApp |
|
21
|
|
|
* |
|
22
|
|
|
* @see https://www.w3.org/TR/appmanifest/ |
|
23
|
|
|
*/ |
|
24
|
|
|
final class ManifestGenerator |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Returns the manifest data as an array. |
|
28
|
|
|
* |
|
29
|
|
|
* @param AppConfiguration $configuration The configuration to create the manifest from. |
|
30
|
|
|
* |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
public function get(AppConfiguration $configuration) |
|
34
|
|
|
{ |
|
35
|
|
|
$manifest = [ ]; |
|
36
|
|
|
|
|
37
|
|
|
if (($backgroundColor = $configuration->getBackgroundColor()) !== null) { |
|
38
|
|
|
$manifest["background_color"] = $backgroundColor; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (($description = $configuration->getDescription()) !== null) { |
|
42
|
|
|
$manifest["description"] = $description; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (($direction = $configuration->getDirection()) !== null) { |
|
46
|
|
|
$manifest["dir"] = $direction; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (($display = $configuration->getDisplay()) !== null) { |
|
50
|
|
|
$manifest["display"] = $display; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (count($icons = $configuration->getIcons()) > 0) { |
|
54
|
|
|
$manifest["icons"] = [ ]; |
|
55
|
|
|
|
|
56
|
|
|
foreach ($icons as $icon) { |
|
57
|
|
|
$manifest["icons"][] = $this->getImageData($icon); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (($language = $configuration->getLanguage()) !== null) { |
|
62
|
|
|
$manifest["lang"] = $language; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (($name = $configuration->getName()) !== null) { |
|
66
|
|
|
$manifest["name"] = $name; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (($orientation = $configuration->getOrientation()) !== null) { |
|
70
|
|
|
$manifest["orientation"] = $orientation; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (($scope = $configuration->getScope()) !== null) { |
|
74
|
|
|
$manifest["scope"] = $scope; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (($shortName = $configuration->getShortName()) !== null) { |
|
78
|
|
|
$manifest["short_name"] = $shortName; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if (($startUrl = $configuration->getStartUrl()) !== null) { |
|
82
|
|
|
$manifest["start_url"] = $startUrl; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (($themeColor = $configuration->getThemeColor()) !== null) { |
|
86
|
|
|
$manifest["theme_color"] = $themeColor; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if (count($splashScreens = $configuration->getSplashScreens()) > 0) { |
|
90
|
|
|
$manifest["splash_screens"] = [ ]; |
|
91
|
|
|
|
|
92
|
|
|
foreach ($splashScreens as $splashScreen) { |
|
93
|
|
|
$manifest["splash_screens"][] = $this->getImageData($splashScreen); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $manifest; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private function getImageData(Image $image) |
|
101
|
|
|
{ |
|
102
|
|
|
$data = [ |
|
103
|
|
|
"src" => $image->getSrc(), |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
if (count($purpose = $image->getPurpose()) > 0) { |
|
107
|
|
|
$data["purpose"] = implode(" ", $purpose); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if (($type = $image->getType()) !== null) { |
|
111
|
|
|
$data["type"] = $type; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if (count($sizes = $image->getSizes()) > 0) { |
|
115
|
|
|
$data["sizes"] = implode( |
|
116
|
|
|
" ", |
|
117
|
|
|
array_map( |
|
118
|
|
|
function (array $size) { |
|
119
|
|
|
return "{$size[0]}x{$size[1]}"; |
|
120
|
|
|
}, |
|
121
|
|
|
$sizes |
|
122
|
|
|
) |
|
123
|
|
|
); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $data; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|