|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Commands_Command_ShowVariable} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Commands |
|
7
|
|
|
* @see Mailcode_Commands_Command_ShowVariable |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Mailcode command: show a variable value. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Mailcode |
|
18
|
|
|
* @subpackage Commands |
|
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Mailcode_Commands_Command_ShowVariable extends Mailcode_Commands_Command implements Mailcode_Commands_Command_Type_Standalone |
|
22
|
|
|
{ |
|
23
|
|
|
const ERROR_NO_VARIABLE_AVAILABLE = 49301; |
|
24
|
|
|
|
|
25
|
|
|
const VALIDATION_VARIABLE_MISSING = 48401; |
|
26
|
|
|
|
|
27
|
|
|
const VALIDATION_VARIABLE_COUNT_MISMATCH = 48402; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Mailcode_Variables_Variable|NULL |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $variable; |
|
33
|
|
|
|
|
34
|
|
|
public function getName() : string |
|
35
|
|
|
{ |
|
36
|
|
|
return 'showvar'; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getLabel() : string |
|
40
|
|
|
{ |
|
41
|
|
|
return t('Show variable'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function supportsType(): bool |
|
45
|
|
|
{ |
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getDefaultType() : string |
|
50
|
|
|
{ |
|
51
|
|
|
return ''; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function requiresParameters(): bool |
|
55
|
|
|
{ |
|
56
|
|
|
return true; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function supportsLogicKeywords() : bool |
|
60
|
|
|
{ |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Retrieves the variable to show. |
|
66
|
|
|
* |
|
67
|
|
|
* NOTE: Only available once the command has been |
|
68
|
|
|
* validated. Always use isValid() first. |
|
69
|
|
|
* |
|
70
|
|
|
* @throws Mailcode_Exception |
|
71
|
|
|
* @return Mailcode_Variables_Variable |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getVariable() : Mailcode_Variables_Variable |
|
74
|
|
|
{ |
|
75
|
|
|
$this->validate(); |
|
76
|
|
|
|
|
77
|
|
|
if($this->variable instanceof Mailcode_Variables_Variable) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->variable; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
throw new Mailcode_Exception( |
|
83
|
|
|
'No variable available.', |
|
84
|
|
|
'No variable is present at this time, or the validation failed.', |
|
85
|
|
|
self::ERROR_NO_VARIABLE_AVAILABLE |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Retrieves the full name of the variable to show. |
|
91
|
|
|
* |
|
92
|
|
|
* NOTE: Only available once the command has been |
|
93
|
|
|
* validated. Always use isValid() first. |
|
94
|
|
|
* |
|
95
|
|
|
* @throws Mailcode_Exception |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getVariableName() : string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getVariable()->getFullName(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
protected function validateSyntax_require_variable() : void |
|
104
|
|
|
{ |
|
105
|
|
|
$vars = $this->getVariables()->getGroupedByName(); |
|
106
|
|
|
$amount = count($vars); |
|
107
|
|
|
|
|
108
|
|
|
if($amount === 1) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->variable = array_pop($vars); |
|
111
|
|
|
return; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$this->validationResult->makeError( |
|
115
|
|
|
t('Command has %1$s variables, %2$s expected.', $amount, 1), |
|
116
|
|
|
self::VALIDATION_VARIABLE_COUNT_MISMATCH |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
protected function getValidations() : array |
|
121
|
|
|
{ |
|
122
|
|
|
return array('require_variable'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function generatesContent() : bool |
|
126
|
|
|
{ |
|
127
|
|
|
return true; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|