|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Component; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ImageAlign; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Scale; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
|
11
|
|
|
|
|
12
|
|
|
class ImageComponent extends APLBaseComponent implements \JsonSerializable |
|
13
|
|
|
{ |
|
14
|
|
|
public const TYPE = APLComponentType::IMAGE; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param ImageAlign|null $align Alignment of the image within the containing box |
|
18
|
|
|
* @param string $borderRadius Clipping radius for the image |
|
19
|
|
|
* @param array|null $filter Single filter to apply to the image |
|
20
|
|
|
* @param array|null $filters Array of filters to apply to the image |
|
21
|
|
|
* @param AbstractStandardCommand[]|null $onFail Commands to run when any source fails to load |
|
22
|
|
|
* @param AbstractStandardCommand[]|null $onLoad Commands to run after all sources loaded successfully |
|
23
|
|
|
* @param string $overlayColor Theme-appropriate scrim overlaid on the image |
|
24
|
|
|
* @param array|null $overlayGradient Colored gradient that overlays the image |
|
25
|
|
|
* @param Scale|null $scale How to resize the image to fit in the bounding box |
|
26
|
|
|
* @param string|null $source Single URL to download the image from |
|
27
|
|
|
* @param string[]|null $sources Array of URLs to download the image from |
|
28
|
|
|
*/ |
|
29
|
10 |
|
public function __construct( |
|
30
|
|
|
public ?ImageAlign $align = null, |
|
31
|
|
|
public string $borderRadius = '0', |
|
32
|
|
|
public ?array $filter = null, |
|
33
|
|
|
public ?array $filters = null, |
|
34
|
|
|
public ?array $onFail = null, |
|
35
|
|
|
public ?array $onLoad = null, |
|
36
|
|
|
public string $overlayColor = 'none', |
|
37
|
|
|
public ?array $overlayGradient = null, |
|
38
|
|
|
public ?Scale $scale = null, |
|
39
|
|
|
public ?string $source = null, |
|
40
|
|
|
public ?array $sources = null, |
|
41
|
|
|
) { |
|
42
|
10 |
|
parent::__construct(self::TYPE); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
6 |
|
public function jsonSerialize(): array |
|
46
|
|
|
{ |
|
47
|
6 |
|
$data = parent::jsonSerialize(); |
|
48
|
|
|
|
|
49
|
6 |
|
if ($this->align !== null) { |
|
50
|
1 |
|
$data['align'] = $this->align->value; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
if ($this->borderRadius !== '0') { |
|
54
|
2 |
|
$data['borderRadius'] = $this->borderRadius; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
6 |
|
if ($this->filter !== null && !empty($this->filter)) { |
|
58
|
1 |
|
$data['filter'] = $this->filter; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
6 |
|
if ($this->filters !== null && !empty($this->filters)) { |
|
62
|
1 |
|
$data['filters'] = $this->filters; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
6 |
|
if ($this->onFail !== null && !empty($this->onFail)) { |
|
66
|
1 |
|
$data['onFail'] = $this->onFail; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
6 |
|
if ($this->onLoad !== null && !empty($this->onLoad)) { |
|
70
|
1 |
|
$data['onLoad'] = $this->onLoad; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
6 |
|
if ($this->overlayColor !== 'none') { |
|
74
|
2 |
|
$data['overlayColor'] = $this->overlayColor; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
6 |
|
if ($this->overlayGradient !== null && !empty($this->overlayGradient)) { |
|
78
|
1 |
|
$data['overlayGradient'] = $this->overlayGradient; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
6 |
|
if ($this->scale !== null) { |
|
82
|
1 |
|
$data['scale'] = $this->scale->value; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
6 |
|
if ($this->source !== null) { |
|
86
|
1 |
|
$data['source'] = $this->source; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
6 |
|
if ($this->sources !== null && !empty($this->sources)) { |
|
90
|
|
|
$data['sources'] = $this->sources; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
6 |
|
return $data; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|