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\Component\Traits\ActionableComponentTrait; |
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\MultiChildComponentTrait; |
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType; |
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Navigation; |
11
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\PageDirection; |
12
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
13
|
|
|
|
14
|
|
|
class PagerComponent extends APLBaseComponent implements \JsonSerializable |
15
|
|
|
{ |
16
|
|
|
use ActionableComponentTrait; |
17
|
|
|
use MultiChildComponentTrait; |
18
|
|
|
|
19
|
|
|
public const TYPE = APLComponentType::PAGER; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param array|null $handlePageMove Handlers to run when the Pager changes pages |
23
|
|
|
* @param int $initialPage The index of the starting page (0-based) |
24
|
|
|
* @param Navigation|null $navigation Specifies the allowed navigation direction |
25
|
|
|
* @param AbstractStandardCommand[]|null $onPageChanged Commands to run when the page changes |
26
|
|
|
* @param PageDirection|null $pageDirection The direction to move pages |
27
|
|
|
* @param string[]|null $preserve Properties to save when reinflating the document |
28
|
|
|
*/ |
29
|
13 |
|
public function __construct( |
30
|
|
|
public ?array $handlePageMove = null, |
31
|
|
|
public int $initialPage = 0, |
32
|
|
|
public ?Navigation $navigation = null, |
33
|
|
|
public ?array $onPageChanged = null, |
34
|
|
|
public ?PageDirection $pageDirection = null, |
35
|
|
|
?array $preserve = null, |
36
|
|
|
) { |
37
|
13 |
|
parent::__construct(type: self::TYPE, preserve: $preserve); |
38
|
|
|
} |
39
|
|
|
|
40
|
7 |
|
public function jsonSerialize(): array |
41
|
|
|
{ |
42
|
7 |
|
$data = array_merge( |
43
|
7 |
|
parent::jsonSerialize(), |
44
|
7 |
|
$this->serializeActionableProperties(), |
45
|
7 |
|
$this->serializeMultiChildProperties() |
46
|
7 |
|
); |
47
|
|
|
|
48
|
7 |
|
if ($this->handlePageMove !== null && !empty($this->handlePageMove)) { |
49
|
1 |
|
$data['handlePageMove'] = $this->handlePageMove; |
50
|
|
|
} |
51
|
|
|
|
52
|
7 |
|
if ($this->initialPage !== 0) { |
53
|
2 |
|
$data['initialPage'] = $this->initialPage; |
54
|
|
|
} |
55
|
|
|
|
56
|
7 |
|
if ($this->navigation !== null) { |
57
|
2 |
|
$data['navigation'] = $this->navigation->value; |
58
|
|
|
} |
59
|
|
|
|
60
|
7 |
|
if ($this->onPageChanged !== null && !empty($this->onPageChanged)) { |
61
|
1 |
|
$data['onPageChanged'] = $this->onPageChanged; |
62
|
|
|
} |
63
|
|
|
|
64
|
7 |
|
if ($this->pageDirection !== null) { |
65
|
2 |
|
$data['pageDirection'] = $this->pageDirection->value; |
66
|
|
|
} |
67
|
|
|
|
68
|
7 |
|
if ($this->preserve !== null && !empty($this->preserve)) { |
69
|
1 |
|
$data['preserve'] = $this->preserve; |
70
|
|
|
} |
71
|
|
|
|
72
|
7 |
|
return $data; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|