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