|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Mailcode |
|
4
|
|
|
* @subpackage Translator |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace Mailcode\Translator\Syntax\HubL; |
|
10
|
|
|
|
|
11
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf; |
|
12
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_BeginsWith; |
|
13
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_BiggerThan; |
|
14
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_Command; |
|
15
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_Contains; |
|
16
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_Empty; |
|
17
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_EndsWith; |
|
18
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_EqualsNumber; |
|
19
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_ListBeginsWith; |
|
20
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_ListContains; |
|
21
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_ListEndsWith; |
|
22
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_ListEquals; |
|
23
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_ListNotContains; |
|
24
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_NotContains; |
|
25
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_NotEmpty; |
|
26
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_SmallerThan; |
|
27
|
|
|
use Mailcode\Mailcode_Commands_Command_ElseIf_Variable; |
|
28
|
|
|
use Mailcode\Mailcode_Translator_Command_ElseIf; |
|
29
|
|
|
use Mailcode\Translator\Syntax\HubL; |
|
30
|
|
|
use Mailcode\Translator\Syntax\HubL\Base\AbstractIfBase; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Translates the {@see Mailcode_Commands_Command_ElseIf} command to HubL. |
|
34
|
|
|
* |
|
35
|
|
|
* @package Mailcode |
|
36
|
|
|
* @subpackage Translator |
|
37
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
38
|
|
|
*/ |
|
39
|
|
|
class ElseIfTranslation extends AbstractIfBase implements Mailcode_Translator_Command_ElseIf |
|
40
|
|
|
{ |
|
41
|
|
|
protected function getCommandTemplate() : string |
|
42
|
|
|
{ |
|
43
|
|
|
return '{%% elif %s %%}'; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function translate(Mailcode_Commands_Command_ElseIf $command): string |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->_translate($command); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function translateBeginsWith(Mailcode_Commands_Command_ElseIf_BeginsWith $command) : string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->_translateSearch( |
|
54
|
|
|
'starts', |
|
55
|
|
|
$command->getVariable(), |
|
56
|
|
|
$command->isCaseInsensitive(), |
|
57
|
|
|
$command->getSearchTerm() |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function translateEndsWith(Mailcode_Commands_Command_ElseIf_EndsWith $command) : string |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->_translateSearch( |
|
64
|
|
|
'ends', |
|
65
|
|
|
$command->getVariable(), |
|
66
|
|
|
$command->isCaseInsensitive(), |
|
67
|
|
|
$command->getSearchTerm() |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function translateBiggerThan(Mailcode_Commands_Command_ElseIf_BiggerThan $command) : string |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->_translateNumberComparison( |
|
74
|
|
|
$command->getVariable(), |
|
75
|
|
|
$command->getNumber(), |
|
76
|
|
|
'>' |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function translateSmallerThan(Mailcode_Commands_Command_ElseIf_SmallerThan $command) : string |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->_translateNumberComparison( |
|
83
|
|
|
$command->getVariable(), |
|
84
|
|
|
$command->getNumber(), |
|
85
|
|
|
'<' |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function translateEqualsNumber(Mailcode_Commands_Command_ElseIf_EqualsNumber $command) : string |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->_translateNumberComparison( |
|
92
|
|
|
$command->getVariable(), |
|
93
|
|
|
$command->getNumber(), |
|
94
|
|
|
'==' |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
protected function translateCommand(Mailcode_Commands_Command_ElseIf_Command $command) : string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->_translateGeneric($command); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
protected function translateVariable(Mailcode_Commands_Command_ElseIf_Variable $command) : string |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->_translateVariable( |
|
106
|
|
|
$command->getVariable(), |
|
107
|
|
|
$command->getSign(), |
|
108
|
|
|
$command->getValue(), |
|
109
|
|
|
$command->isCaseInsensitive() |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function translateContains(Mailcode_Commands_Command_ElseIf_Contains $command) : string |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->_translateContains( |
|
116
|
|
|
$command->getVariable(), |
|
117
|
|
|
$command->isCaseInsensitive(), |
|
118
|
|
|
false, |
|
119
|
|
|
$command->getSearchTerms(), |
|
120
|
|
|
$command->getType() |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
protected function translateNotContains(Mailcode_Commands_Command_ElseIf_NotContains $command) : string |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->_translateContains( |
|
127
|
|
|
$command->getVariable(), |
|
128
|
|
|
$command->isCaseInsensitive(), |
|
129
|
|
|
false, |
|
130
|
|
|
$command->getSearchTerms(), |
|
131
|
|
|
$command->getType() |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
protected function translateListContains(Mailcode_Commands_Command_ElseIf_ListContains $command) : string |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->_translateContains( |
|
138
|
|
|
$command->getVariable(), |
|
139
|
|
|
$command->isCaseInsensitive(), |
|
140
|
|
|
$command->isRegexEnabled(), |
|
141
|
|
|
$command->getSearchTerms(), |
|
142
|
|
|
$command->getType() |
|
143
|
|
|
); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
protected function translateListEquals(Mailcode_Commands_Command_ElseIf_ListEquals $command) : string |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->_translateContains( |
|
149
|
|
|
$command->getVariable(), |
|
150
|
|
|
$command->isCaseInsensitive(), |
|
151
|
|
|
false, |
|
152
|
|
|
$command->getSearchTerms(), |
|
153
|
|
|
$command->getType() |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
protected function translateListNotContains(Mailcode_Commands_Command_ElseIf_ListNotContains $command) : string |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->_translateContains( |
|
160
|
|
|
$command->getVariable(), |
|
161
|
|
|
$command->isCaseInsensitive(), |
|
162
|
|
|
$command->isRegexEnabled(), |
|
163
|
|
|
$command->getSearchTerms(), |
|
164
|
|
|
$command->getType() |
|
165
|
|
|
); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
protected function translateListBeginsWith(Mailcode_Commands_Command_ElseIf_ListBeginsWith $command) : string |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->_translateContains( |
|
171
|
|
|
$command->getVariable(), |
|
172
|
|
|
$command->isCaseInsensitive(), |
|
173
|
|
|
$command->isRegexEnabled(), |
|
174
|
|
|
$command->getSearchTerms(), |
|
175
|
|
|
$command->getType() |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
protected function translateListEndsWith(Mailcode_Commands_Command_ElseIf_ListEndsWith $command) : string |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->_translateContains( |
|
182
|
|
|
$command->getVariable(), |
|
183
|
|
|
$command->isCaseInsensitive(), |
|
184
|
|
|
$command->isRegexEnabled(), |
|
185
|
|
|
$command->getSearchTerms(), |
|
186
|
|
|
$command->getType() |
|
187
|
|
|
); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
protected function translateEmpty(Mailcode_Commands_Command_ElseIf_Empty $command) : string |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->_translateEmpty($command->getVariable(), false); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
protected function translateNotEmpty(Mailcode_Commands_Command_ElseIf_NotEmpty $command) : string |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->_translateEmpty($command->getVariable(), true); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|