|
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\Gesture\AbstractGesture; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
|
10
|
|
|
|
|
11
|
|
|
abstract class TouchableComponent extends ActionableComponent implements \JsonSerializable |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param APLComponentType $type The type of the component |
|
15
|
|
|
* @param AbstractGesture|null $gesture Single gesture handler |
|
16
|
|
|
* @param AbstractGesture[]|null $gestures Array of gesture handlers |
|
17
|
|
|
* @param AbstractStandardCommand[]|null $onCancel Commands to run when a gesture takes over the pointer |
|
18
|
|
|
* @param AbstractStandardCommand[]|null $onDown Commands to run when a pointer down event occurs |
|
19
|
|
|
* @param AbstractStandardCommand[]|null $onMove Commands to run as the pointer moves |
|
20
|
|
|
* @param AbstractStandardCommand[]|null $onPress Commands to run for a pointer down followed by a pointer up |
|
21
|
|
|
* @param AbstractStandardCommand[]|null $onUp Commands to run when releasing the pointer |
|
22
|
|
|
*/ |
|
23
|
19 |
|
public function __construct( |
|
24
|
|
|
APLComponentType $type, |
|
25
|
|
|
public ?AbstractGesture $gesture = null, |
|
26
|
|
|
public ?array $gestures = null, |
|
27
|
|
|
public ?array $onCancel = null, |
|
28
|
|
|
public ?array $onDown = null, |
|
29
|
|
|
public ?array $onMove = null, |
|
30
|
|
|
public ?array $onPress = null, |
|
31
|
|
|
public ?array $onUp = null, |
|
32
|
|
|
) { |
|
33
|
19 |
|
parent::__construct($type); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
11 |
|
public function jsonSerialize(): array |
|
37
|
|
|
{ |
|
38
|
11 |
|
$data = parent::jsonSerialize(); |
|
39
|
|
|
|
|
40
|
11 |
|
if ($this->gesture !== null) { |
|
41
|
|
|
$data['gesture'] = $this->gesture; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
11 |
|
if ($this->gestures !== null && !empty($this->gestures)) { |
|
45
|
|
|
$data['gestures'] = $this->gestures; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
11 |
|
if ($this->onCancel !== null && !empty($this->onCancel)) { |
|
49
|
|
|
$data['onCancel'] = $this->onCancel; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
11 |
|
if ($this->onDown !== null && !empty($this->onDown)) { |
|
53
|
|
|
$data['onDown'] = $this->onDown; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
11 |
|
if ($this->onMove !== null && !empty($this->onMove)) { |
|
57
|
|
|
$data['onMove'] = $this->onMove; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
11 |
|
if ($this->onPress !== null && !empty($this->onPress)) { |
|
61
|
|
|
$data['onPress'] = $this->onPress; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
11 |
|
if ($this->onUp !== null && !empty($this->onUp)) { |
|
65
|
|
|
$data['onUp'] = $this->onUp; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
11 |
|
return $data; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|