|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Renderer} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Utilities |
|
7
|
|
|
* @see Mailcode_Renderer |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Used to easily create commands and convert them to strings, |
|
16
|
|
|
* either in plain text or highlighted. |
|
17
|
|
|
* |
|
18
|
|
|
* @package Mailcode |
|
19
|
|
|
* @subpackage Utilities |
|
20
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Mailcode_Renderer |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var boolean |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $highlighted = false; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Sets whether to output highlighted commands instead of the default plain text. |
|
31
|
|
|
* |
|
32
|
|
|
* @param bool $highlighted |
|
33
|
|
|
* @return Mailcode_Renderer |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setOutputHighlighted(bool $highlighted=true) : Mailcode_Renderer |
|
36
|
|
|
{ |
|
37
|
|
|
$this->highlighted = $highlighted; |
|
38
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Converts a show variable command to string. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $variableName The variable name, with or without $ sign. |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function showVar(string $variableName) : string |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->command2string(Mailcode_Factory::showVar($variableName)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setVar(string $variableName, string $value, bool $quoteValue) : string |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->command2string(Mailcode_Factory::setVar($variableName, $value, $quoteValue)); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setVarString(string $variableName, string $value) : string |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->command2string(Mailcode_Factory::setVarString($variableName, $value)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function if(string $condition, string $type='') : string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->command2string(Mailcode_Factory::if($condition, $type)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function ifVar(string $variable, string $operand, string $value, bool $quoteValue) : string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->command2string(Mailcode_Factory::ifVar($variable, $operand, $value, $quoteValue)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function ifVarString(string $variable, string $operand, string $value) : string |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->command2string(Mailcode_Factory::ifVarString($variable, $operand, $value)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function ifVarEquals(string $variable, string $value, bool $quoteValue) : string |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->command2string(Mailcode_Factory::ifVarEquals($variable, $value, $quoteValue)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function ifVarEqualsString(string $variable, string $value) : string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->command2string(Mailcode_Factory::ifVarEqualsString($variable, $value)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function ifVarNotEquals(string $variable, string $value, bool $quoteValue) : string |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->command2string(Mailcode_Factory::ifVarNotEquals($variable, $value, $quoteValue)); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function ifVarNotEqualsString(string $variable, string $value) : string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->command2string(Mailcode_Factory::ifVarNotEqualsString($variable, $value)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function elseIf(string $condition, string $type='') : string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->command2string(Mailcode_Factory::elseIf($condition, $type)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function elseIfVar(string $variable, string $operand, string $value, bool $quoteValue) : string |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->command2string(Mailcode_Factory::elseIfVar($variable, $operand, $value, $quoteValue)); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function elseIfVarString(string $variable, string $operand, string $value) : string |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->command2string(Mailcode_Factory::elseIfVarString($variable, $operand, $value)); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function elseIfVarEquals(string $variable, string $value, bool $quoteValue) : string |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->command2string(Mailcode_Factory::elseIfVarEquals($variable, $value, $quoteValue)); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function elseIfVarEqualsString(string $variable, string $value) : string |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->command2string(Mailcode_Factory::elseIfVarEqualsString($variable, $value)); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function elseIfVarNotEquals(string $variable, string $value, bool $quoteValue) : string |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->command2string(Mailcode_Factory::elseIfVarNotEquals($variable, $value, $quoteValue)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function elseIfVarNotEqualsString(string $variable, string $value) : string |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->command2string(Mailcode_Factory::elseIfVarNotEqualsString($variable, $value)); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function else() : string |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->command2string(Mailcode_Factory::else()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function end() : string |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->command2string(Mailcode_Factory::end()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function comment(string $comment) : string |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->command2string(Mailcode_Factory::comment($comment)); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
protected function command2string(Mailcode_Commands_Command $command) : string |
|
149
|
|
|
{ |
|
150
|
|
|
if($this->highlighted) |
|
151
|
|
|
{ |
|
152
|
|
|
return $command->getHighlighted(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
return $command->getNormalized(); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|