1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Grandstream-XMLApp |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model; |
17
|
|
|
|
18
|
|
|
use mrcnpdlk\Grandstream\XMLApp\Application\ModelInterface; |
19
|
|
|
use mrcnpdlk\Grandstream\XMLApp\MyXML; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Event |
23
|
|
|
* |
24
|
|
|
* In one XML document, multiple <Event> elements could be used. However, the state for each event must |
25
|
|
|
* be different so that the action is unique for that state. |
26
|
|
|
* |
27
|
|
|
* @package mrcnpdlk\Grandstream\XMLApp\Application\Model |
28
|
|
|
*/ |
29
|
|
|
class Event implements ModelInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
const ACTION_DIAL = 'Dial'; |
34
|
|
|
const ACTION_USE_URL = 'UseURL'; |
35
|
|
|
const ACTION_APPEND_INPUT_URL = 'AppendInputURL'; |
36
|
|
|
const ACTION_QUIT_APP = 'QuitApp'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $sState; |
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $sAction; |
46
|
|
|
/** |
47
|
|
|
* @var string|null |
48
|
|
|
*/ |
49
|
|
|
private $sCommandArgs; |
50
|
|
|
|
51
|
|
|
public function __construct(string $sState, string $sAction, string $sCommandArgs = null) |
52
|
|
|
{ |
53
|
|
|
$this->sState = $sState; |
54
|
|
|
$this->sAction = $sAction; |
55
|
|
|
$this->sCommandArgs = $sCommandArgs; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return MyXML |
60
|
|
|
*/ |
61
|
|
|
public function getXml(): MyXML |
62
|
|
|
{ |
63
|
|
|
$oXml = new MyXML('Event'); |
64
|
|
|
$oXml->asObject()->addAttribute('state', $this->sState); |
65
|
|
|
$oAction = new MyXML('Action'); |
66
|
|
|
$oAction->asObject()->addAttribute('action', $this->sAction); |
67
|
|
|
$oAction->asObject()->addAttribute('commandArgs', $this->sCommandArgs); |
68
|
|
|
$oXml->insertChild($oAction->asObject()); |
69
|
|
|
|
70
|
|
|
return $oXml; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|