-
Notifications
You must be signed in to change notification settings - Fork 28
/
Intent.php
88 lines (72 loc) · 1.88 KB
/
Intent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace MaxBeckers\AmazonAlexa\Intent;
/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Intent implements \JsonSerializable
{
const STATUS_NONE = 'NONE';
const STATUS_CONFIRMED = 'CONFIRMED';
const STATUS_DENIED = 'DENIED';
/**
* @var string|null
*/
public $name;
/**
* @var string|null
*/
public $confirmationStatus;
/**
* @var Slot[]
*/
public $slots = [];
/**
* @param array $amazonRequest
*
* @return Intent
*/
public static function fromAmazonRequest(array $amazonRequest): self
{
$intent = new self();
$intent->name = isset($amazonRequest['name']) ? $amazonRequest['name'] : null;
$intent->confirmationStatus = isset($amazonRequest['confirmationStatus']) ? $amazonRequest['confirmationStatus'] : null;
if (isset($amazonRequest['slots'])) {
foreach ($amazonRequest['slots'] as $name => $slot) {
$intent->slots[] = Slot::fromAmazonRequest($name, $slot);
}
}
return $intent;
}
/**
* @inheritdoc
*/
public function jsonSerialize()
{
$data = [];
$data['name'] = $this->name;
if (null !== $this->confirmationStatus) {
$data['confirmationStatus'] = $this->confirmationStatus;
}
if (!empty($this->slots)) {
$data['slots'] = [];
foreach ($this->slots as $slot) {
$data['slots'][$slot->name] = $slot->jsonSerialize();
}
}
return $data;
}
/**
* @param $name
*
* @return null|Slot
*/
public function getSlotByName($name)
{
foreach ($this->slots as $slot) {
if ($slot->name === $name) {
return $slot;
}
}
return null;
}
}