|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLDocument; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Directive; |
|
9
|
|
|
|
|
10
|
|
|
class RenderDocumentDirective extends Directive implements \JsonSerializable |
|
11
|
|
|
{ |
|
12
|
|
|
public const TYPE = 'Alexa.Presentation.APL.RenderDocument'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param APLDocument $document The APL document to render |
|
16
|
|
|
* @param string $token Unique token for this directive |
|
17
|
|
|
* @param array<string,array>|null $sources Map of additional documents or references to documents |
|
18
|
|
|
* @param array<string,array>|null $datasources Map of data source objects for data binding |
|
19
|
|
|
*/ |
|
20
|
8 |
|
public function __construct( |
|
21
|
|
|
public APLDocument $document, |
|
22
|
|
|
public string $token, |
|
23
|
|
|
public array $sources = [], |
|
24
|
|
|
public array $datasources = [], |
|
25
|
|
|
) { |
|
26
|
8 |
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
public function setSource(string $name, array $data): void |
|
29
|
|
|
{ |
|
30
|
1 |
|
$this->sources[$name] = $data; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public function setDatasource(string $name, array $data): void |
|
34
|
|
|
{ |
|
35
|
1 |
|
$this->datasources[$name] = $data; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
4 |
|
public function jsonSerialize(): array |
|
39
|
|
|
{ |
|
40
|
4 |
|
$data = [ |
|
41
|
4 |
|
'type' => self::TYPE, |
|
42
|
4 |
|
'token' => $this->token, |
|
43
|
4 |
|
'document' => $this->document, |
|
44
|
4 |
|
]; |
|
45
|
|
|
|
|
46
|
4 |
|
if ($this->sources !== null && $this->sources !== []) { |
|
47
|
2 |
|
$data['sources'] = $this->sources; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
if ($this->datasources !== null && $this->datasources !== []) { |
|
51
|
2 |
|
$data['datasources'] = $this->datasources; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
4 |
|
return $data; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|