|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Directive; |
|
8
|
|
|
|
|
9
|
|
|
class UpdateIndexListDataDirective extends Directive implements \JsonSerializable |
|
10
|
|
|
{ |
|
11
|
|
|
public const TYPE = 'Alexa.Presentation.APL.UpdateIndexListData'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @param string $token The presentation token specified in the RenderDocument directive |
|
15
|
|
|
* @param string $listId The identifier for the list to update with this response |
|
16
|
|
|
* @param int $listVersion The new version of the list following the update |
|
17
|
|
|
* @param array $operations Individual operations to apply to the list, in array order |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct( |
|
20
|
|
|
public string $token, |
|
21
|
|
|
public string $listId, |
|
22
|
|
|
public int $listVersion, |
|
23
|
|
|
public array $operations = [], |
|
24
|
|
|
) { |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function addOperation(array $operation): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->operations[] = $operation; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function addInsertItemOperation(int $index, array $item): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->operations[] = [ |
|
35
|
|
|
'type' => UpdateIndexListDataOperationType::INSERT_ITEM->value, |
|
36
|
|
|
'index' => $index, |
|
37
|
|
|
'item' => $item, |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function addInsertMultipleItemsOperation(int $index, array $items): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->operations[] = [ |
|
44
|
|
|
'type' => UpdateIndexListDataOperationType::INSERT_MULTIPLE_ITEMS->value, |
|
45
|
|
|
'index' => $index, |
|
46
|
|
|
'items' => $items, |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function addSetItemOperation(int $index, array $item): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->operations[] = [ |
|
53
|
|
|
'type' => UpdateIndexListDataOperationType::SET_ITEM->value, |
|
54
|
|
|
'index' => $index, |
|
55
|
|
|
'item' => $item, |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function addDeleteItemOperation(int $index): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->operations[] = [ |
|
62
|
|
|
'type' => UpdateIndexListDataOperationType::DELETE_ITEM->value, |
|
63
|
|
|
'index' => $index, |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function addDeleteMultipleItemsOperation(int $index, int $count): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->operations[] = [ |
|
70
|
|
|
'type' => UpdateIndexListDataOperationType::DELETE_MULTIPLE_ITEMS->value, |
|
71
|
|
|
'index' => $index, |
|
72
|
|
|
'count' => $count, |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function jsonSerialize(): array |
|
77
|
|
|
{ |
|
78
|
|
|
return [ |
|
79
|
|
|
'type' => self::TYPE, |
|
80
|
|
|
'token' => $this->token, |
|
81
|
|
|
'listId' => $this->listId, |
|
82
|
|
|
'listVersion' => $this->listVersion, |
|
83
|
|
|
'operations' => $this->operations, |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|