|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Commands_Command_SetVariable} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Commands |
|
7
|
|
|
* @see Mailcode_Commands_Command_SetVariable |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Mailcode command: set a variable value. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Mailcode |
|
18
|
|
|
* @subpackage Commands |
|
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Mailcode_Commands_Command_SetVariable extends Mailcode_Commands_Command implements Mailcode_Commands_Command_Type_Standalone |
|
22
|
|
|
{ |
|
23
|
|
|
const ERROR_NO_VARIABLE_AVAILABLE = 49401; |
|
24
|
|
|
const ERROR_NO_VARIABLE_IN_ASSIGNMENT = 49403; |
|
25
|
|
|
|
|
26
|
|
|
const VALIDATION_NOT_ASSIGNMENT_STATEMENT = 48501; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Mailcode_Parser_Statement_Tokenizer_Type_Value |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $value; |
|
32
|
|
|
|
|
33
|
|
|
public function getName() : string |
|
34
|
|
|
{ |
|
35
|
|
|
return 'setvar'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getLabel() : string |
|
39
|
|
|
{ |
|
40
|
|
|
return t('Set variable value'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function supportsType(): bool |
|
44
|
|
|
{ |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDefaultType() : string |
|
49
|
|
|
{ |
|
50
|
|
|
return ''; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function requiresParameters(): bool |
|
54
|
|
|
{ |
|
55
|
|
|
return true; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function supportsLogicKeywords() : bool |
|
59
|
|
|
{ |
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Retrieves the variable to show. |
|
65
|
|
|
* |
|
66
|
|
|
* NOTE: Only available once the command has been |
|
67
|
|
|
* validated. Always use isValid() first. |
|
68
|
|
|
* |
|
69
|
|
|
* @throws Mailcode_Exception |
|
70
|
|
|
* @return Mailcode_Variables_Variable |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getVariable() : Mailcode_Variables_Variable |
|
73
|
|
|
{ |
|
74
|
|
|
$variable = $this->params->getInfo()->getVariableByIndex(0); |
|
75
|
|
|
|
|
76
|
|
|
if($variable) |
|
77
|
|
|
{ |
|
78
|
|
|
return $variable->getVariable(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
throw new Mailcode_Exception( |
|
82
|
|
|
'No variable at position #0 in statement.', |
|
83
|
|
|
'This signifies an error in the statement handling: a variable assignment should have a variable in the first token.', |
|
84
|
|
|
self::ERROR_NO_VARIABLE_IN_ASSIGNMENT |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Retrieves the full name of the variable to show. |
|
90
|
|
|
* |
|
91
|
|
|
* NOTE: Only available once the command has been |
|
92
|
|
|
* validated. Always use isValid() first. |
|
93
|
|
|
* |
|
94
|
|
|
* @throws Mailcode_Exception |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getVariableName() : string |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->getVariable()->getFullName(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
protected function validateSyntax_assignment() : void |
|
103
|
|
|
{ |
|
104
|
|
|
if($this->params->getInfo()->isVariableAssignment()) |
|
105
|
|
|
{ |
|
106
|
|
|
return; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$this->validationResult->makeError( |
|
110
|
|
|
t('Not a variable assignment.').' '.t('Is the equality sign (=) present?'), |
|
111
|
|
|
self::VALIDATION_NOT_ASSIGNMENT_STATEMENT |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
protected function validateSyntax_value() : void |
|
116
|
|
|
{ |
|
117
|
|
|
$info = $this->params->getInfo(); |
|
118
|
|
|
|
|
119
|
|
|
$value = $info->getTokenByIndex(2); |
|
120
|
|
|
|
|
121
|
|
|
if($value instanceof Mailcode_Parser_Statement_Tokenizer_Type_Value) |
|
122
|
|
|
{ |
|
123
|
|
|
$this->value = $value; |
|
124
|
|
|
return; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
protected function getValidations() : array |
|
129
|
|
|
{ |
|
130
|
|
|
return array( |
|
131
|
|
|
'assignment', |
|
132
|
|
|
'value' |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function getValue() : Mailcode_Parser_Statement_Tokenizer_Type_Value |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->value; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function generatesContent() : bool |
|
142
|
|
|
{ |
|
143
|
|
|
return false; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|