|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Commands_Command_If} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Commands |
|
7
|
|
|
* @see Mailcode_Commands_Command_If |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Mailcode command: opening IF statement. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Mailcode |
|
18
|
|
|
* @subpackage Commands |
|
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Mailcode_Commands_Command_If extends Mailcode_Commands_Command_Type_Opening |
|
22
|
|
|
{ |
|
23
|
|
|
const VALIDATION_VARIABLE_COUNT_MISMATCH = 49201; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var Mailcode_Variables_Variable |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $variable; |
|
29
|
|
|
|
|
30
|
|
|
public function getName() : string |
|
31
|
|
|
{ |
|
32
|
|
|
return 'if'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getLabel() : string |
|
36
|
|
|
{ |
|
37
|
|
|
return t('IF condition'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function supportsType(): bool |
|
41
|
|
|
{ |
|
42
|
|
|
return true; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function requiresParameters(): bool |
|
46
|
|
|
{ |
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function isCommand() : bool |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->type === 'command' || empty($this->type); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function isVariable() : bool |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->type === 'variable'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Available only if the command is of type "variable". |
|
62
|
|
|
* |
|
63
|
|
|
* @return Mailcode_Variables_Variable|NULL |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getVariable() : ?Mailcode_Variables_Variable |
|
66
|
|
|
{ |
|
67
|
|
|
if(isset($this->variable)) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->variable; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function validateSyntax_require_variable() : void |
|
76
|
|
|
{ |
|
77
|
|
|
$amount = $this->getVariables()->countVariables(); |
|
78
|
|
|
|
|
79
|
|
|
if($amount >= 1) |
|
80
|
|
|
{ |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->validationResult->makeError( |
|
85
|
|
|
t('Command has %1$s variables, %2$s expected.', $amount, 1), |
|
86
|
|
|
self::VALIDATION_VARIABLE_COUNT_MISMATCH |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
protected function getValidations() : array |
|
91
|
|
|
{ |
|
92
|
|
|
$validations = array(); |
|
93
|
|
|
|
|
94
|
|
|
if($this->getType() === 'variable') |
|
95
|
|
|
{ |
|
96
|
|
|
$validations[] = 'require_variable'; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $validations; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function generatesContent() : bool |
|
103
|
|
|
{ |
|
104
|
|
|
return false; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getSupportedTypes() : array |
|
108
|
|
|
{ |
|
109
|
|
|
return array( |
|
110
|
|
|
'variable', |
|
111
|
|
|
'command' |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|