|
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\Objects; |
|
13
|
|
|
|
|
14
|
|
|
use Fusonic\WebApp\Members\PlatformInterface; |
|
15
|
|
|
use Fusonic\WebApp\Members\PlatformTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Represents an <b>image object</b>. |
|
19
|
|
|
* |
|
20
|
|
|
* @package Fusonic\WebApp |
|
21
|
|
|
* |
|
22
|
|
|
* @see https://www.w3.org/TR/appmanifest/#image-object-and-its-members |
|
23
|
|
|
*/ |
|
24
|
|
|
final class Image implements PlatformInterface |
|
25
|
|
|
{ |
|
26
|
|
|
use PlatformTrait; |
|
27
|
|
|
|
|
28
|
|
|
const PURPOSE_BADGE = "badge"; |
|
29
|
|
|
const PURPOSE_ANY = "any"; |
|
30
|
|
|
|
|
31
|
|
|
private $purpose = [ ]; |
|
32
|
|
|
private $sizes = [ ]; |
|
33
|
|
|
private $src; |
|
34
|
|
|
private $type; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns the image's intended purpose. |
|
38
|
|
|
* |
|
39
|
|
|
* @return string[] |
|
40
|
|
|
*/ |
|
41
|
2 |
|
public function getPurpose() |
|
42
|
|
|
{ |
|
43
|
2 |
|
return array_values($this->purpose); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Adds a purpose for this image. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $purpose One of of Image::PURPOSE_* constants. |
|
50
|
|
|
* |
|
51
|
|
|
* @return Image |
|
52
|
|
|
* |
|
53
|
|
|
* @see https://www.w3.org/TR/appmanifest/#purpose-member |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function addPurpose($purpose) |
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->purpose[$purpose] = $purpose; |
|
58
|
1 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns an array of sizes contained in this file. |
|
63
|
|
|
* |
|
64
|
|
|
* @return array[] |
|
65
|
|
|
*/ |
|
66
|
3 |
|
public function getSizes() |
|
67
|
|
|
{ |
|
68
|
3 |
|
return $this->sizes; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Adds an additional size contained in this file. |
|
73
|
|
|
* |
|
74
|
|
|
* @param int $width |
|
75
|
|
|
* @param int $height |
|
76
|
|
|
* |
|
77
|
|
|
* @return Image |
|
78
|
|
|
* |
|
79
|
|
|
* @see https://www.w3.org/TR/appmanifest/#sizes-member |
|
80
|
|
|
*/ |
|
81
|
2 |
|
public function addSize($width, $height) |
|
82
|
|
|
{ |
|
83
|
2 |
|
$this->sizes[] = [ (int)$width, (int)$height ]; |
|
84
|
2 |
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the source path of this file. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string|null |
|
91
|
|
|
*/ |
|
92
|
3 |
|
public function getSrc() |
|
93
|
|
|
{ |
|
94
|
3 |
|
return $this->src; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Sets the source path of this file. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $src |
|
101
|
|
|
* |
|
102
|
|
|
* @return Image |
|
103
|
|
|
* |
|
104
|
|
|
* @see https://www.w3.org/TR/appmanifest/#src-member |
|
105
|
|
|
*/ |
|
106
|
2 |
|
public function setSrc($src) |
|
107
|
|
|
{ |
|
108
|
2 |
|
$this->src = $src; |
|
109
|
2 |
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns the MIME type of this file. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string|null |
|
116
|
|
|
*/ |
|
117
|
3 |
|
public function getType() |
|
118
|
|
|
{ |
|
119
|
3 |
|
return $this->type; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Sets the MIME type of this file. |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $type |
|
126
|
|
|
* |
|
127
|
|
|
* @return Image |
|
128
|
|
|
* |
|
129
|
|
|
* @see https://www.w3.org/TR/appmanifest/#type-member |
|
130
|
|
|
*/ |
|
131
|
2 |
|
public function setType($type) |
|
132
|
|
|
{ |
|
133
|
2 |
|
$this->type = $type; |
|
134
|
2 |
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|