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