1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Translator_Syntax_ApacheVelocity_ElseIf} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Translator |
7
|
|
|
* @see Mailcode_Translator_Syntax_ApacheVelocity_ElseIf |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Translates the "ElseIf" command to Apache Velocity. |
16
|
|
|
* |
17
|
|
|
* @package Mailcode |
18
|
|
|
* @subpackage Translator |
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Mailcode_Translator_Syntax_ApacheVelocity_ElseIf extends Mailcode_Translator_Syntax_ApacheVelocity_Base_AbstractIf implements Mailcode_Translator_Command_ElseIf |
22
|
|
|
{ |
23
|
|
|
protected function getCommandTemplate() : string |
24
|
|
|
{ |
25
|
|
|
return '#elseif(%s)'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function translate(Mailcode_Commands_Command_ElseIf $command): string |
29
|
|
|
{ |
30
|
|
|
return $this->_translate($command); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function translateBody(Mailcode_Commands_IfBase $command) : string |
34
|
|
|
{ |
35
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_Command) |
36
|
|
|
{ |
37
|
|
|
return $this->translateCommand($command); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_Variable) |
41
|
|
|
{ |
42
|
|
|
return $this->translateVariable($command); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_Contains) |
46
|
|
|
{ |
47
|
|
|
return $this->translateContains($command); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_Empty) |
51
|
|
|
{ |
52
|
|
|
return $this->translateEmpty($command); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_NotEmpty) |
56
|
|
|
{ |
57
|
|
|
return $this->translateNotEmpty($command); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_BeginsWith) |
61
|
|
|
{ |
62
|
|
|
return $this->translateBeginsWith($command); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if($command instanceof Mailcode_Commands_Command_ElseIf_EndsWith) |
66
|
|
|
{ |
67
|
|
|
return $this->translateEndsWith($command); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return ''; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function translateBeginsWith(Mailcode_Commands_Command_ElseIf_BeginsWith $command) : string |
74
|
|
|
{ |
75
|
|
|
return $this->_translateSearch( |
76
|
|
|
'starts', |
77
|
|
|
$command->getVariable(), |
78
|
|
|
$command->isCaseInsensitive(), |
79
|
|
|
$command->getSearchTerm() |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function translateEndsWith(Mailcode_Commands_Command_ElseIf_EndsWith $command) : string |
84
|
|
|
{ |
85
|
|
|
return $this->_translateSearch( |
86
|
|
|
'ends', |
87
|
|
|
$command->getVariable(), |
88
|
|
|
$command->isCaseInsensitive(), |
89
|
|
|
$command->getSearchTerm() |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
protected function translateCommand(Mailcode_Commands_Command_ElseIf_Command $command) : string |
94
|
|
|
{ |
95
|
|
|
return $this->_translateGeneric($command); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function translateVariable(Mailcode_Commands_Command_ElseIf_Variable $command) : string |
99
|
|
|
{ |
100
|
|
|
return $this->_translateVariable( |
101
|
|
|
$command->getVariable(), |
102
|
|
|
$command->getSign(), |
103
|
|
|
$command->getValue() |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function translateContains(Mailcode_Commands_Command_ElseIf_Contains $command) : string |
108
|
|
|
{ |
109
|
|
|
return $this->_translateContains( |
110
|
|
|
$command->getVariable(), |
111
|
|
|
$command->isCaseInsensitive(), |
112
|
|
|
$command->getSearchTerm() |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function translateEmpty(Mailcode_Commands_Command_ElseIf_Empty $command) : string |
117
|
|
|
{ |
118
|
|
|
return $this->_translateEmpty($command->getVariable(), false); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
protected function translateNotEmpty(Mailcode_Commands_Command_ElseIf_NotEmpty $command) : string |
122
|
|
|
{ |
123
|
|
|
return $this->_translateEmpty($command->getVariable(), true); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|