Passed
Push — master ( 1515ff...7c0b30 )
by Sebastian
04:21
created

Mailcode_Factory::ifEndsWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Factory} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Utilities
7
 * @see Mailcode_Factory
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Factory utility used to create commands.
16
 *
17
 * @package Mailcode
18
 * @subpackage Utilities
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
class Mailcode_Factory
22
{
23
    const ERROR_INVALID_COMMAND_CREATED = 50001;
24
    const ERROR_UNEXPECTED_COMMAND_TYPE = 50002;
25
26
   /**
27
    * @var Mailcode_Factory_CommandSets
28
    */
29
    private static $commandSets;
30
    
31
   /**
32
    * Creates a ShowVariable command.
33
    * 
34
    * @param string $variableName A variable name, with or without the $ sign prepended.
35
    * @return Mailcode_Commands_Command_ShowVariable
36
    */
37
    public static function showVar(string $variableName) : Mailcode_Commands_Command_ShowVariable
38
    {
39
        return self::$commandSets->show()->showVar($variableName);
40
    }
41
    
42
    /**
43
     * Creates a ShowDate command, used to display date variables and 
44
     * format the date using date format strings.
45
     *
46
     * @param string $variableName A variable name, with or without the $ sign prepended.
47
     * @param string $formatString A date format string, or empty string for default.
48
     * @return Mailcode_Commands_Command_ShowDate
49
     */
50
    public static function showDate(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowDate
51
    {
52
        return self::$commandSets->show()->showDate($variableName, $formatString);
53
    }
54
55
   /**
56
    * Creates a ShowSnippet command.
57
    *
58
    * @param string $snippetName A snippet name, with or without the $ sign prepended.
59
    * @return Mailcode_Commands_Command_ShowSnippet
60
    */
61
    public static function showSnippet(string $snippetName) : Mailcode_Commands_Command_ShowSnippet
62
    {
63
        return self::$commandSets->show()->showSnippet($snippetName);
64
    }
65
    
66
   /**
67
    * Creates a SetVariable command.
68
    * 
69
    * @param string $variableName A variable name, with or without the $ sign prepended.
70
    * @param string $value
71
    * @param bool $quoteValue Whether to treat the value as a string literal, and add quotes to it.
72
    * @return Mailcode_Commands_Command_SetVariable
73
    * @throws Mailcode_Factory_Exception
74
    * 
75
    * @see Mailcode_Factory::ERROR_INVALID_COMMAND_CREATED
76
    */
77
    public static function setVar(string $variableName, string $value, bool $quoteValue=true) : Mailcode_Commands_Command_SetVariable
78
    {
79
        return self::$commandSets->set()->setVar($variableName, $value, $quoteValue);
80
    }
81
    
82
   /**
83
    * Like setVar(), but treats the value as a string literal
84
    * and automatically adds quotes to it.
85
    * 
86
    * @param string $variableName
87
    * @param string $value
88
    * @return Mailcode_Commands_Command_SetVariable
89
    */
90
    public static function setVarString(string $variableName, string $value) : Mailcode_Commands_Command_SetVariable
91
    {
92
        return self::$commandSets->set()->setVar($variableName, $value, true);
93
    }
94
    
95
    public static function comment(string $comments) : Mailcode_Commands_Command_Comment
96
    {
97
        return self::$commandSets->misc()->comment($comments);
98
    }
99
    
100
    public static function else() : Mailcode_Commands_Command_Else
101
    {
102
        return self::$commandSets->if()->else();
103
    }
104
    
105
    public static function end() : Mailcode_Commands_Command_End
106
    {
107
        return self::$commandSets->if()->end();
108
    }
109
    
110
    public static function if(string $condition, string $type='') : Mailcode_Commands_Command_If
111
    {
112
        return self::$commandSets->if()->if($condition, $type);
113
    }
114
    
115
    public static function ifVar(string $variable, string $operand, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_If_Variable
116
    {
117
        return self::$commandSets->if()->ifVar($variable, $operand, $value, $quoteValue);
118
    }
119
120
    public static function ifVarString(string $variable, string $operand, string $value) : Mailcode_Commands_Command_If_Variable
121
    {
122
        return self::$commandSets->if()->ifVarString($variable, $operand, $value);
123
    }
124
    
125
    public static function ifVarEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_If_Variable
126
    {
127
        return self::$commandSets->if()->ifVarEquals($variable, $value, $quoteValue);
128
    }
129
130
    public static function ifVarEqualsString(string $variable, string $value) : Mailcode_Commands_Command_If
131
    {
132
        return self::$commandSets->if()->ifVarEqualsString($variable, $value);
133
    }
134
    
135
    public static function ifVarNotEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_If_Variable
136
    {
137
        return self::$commandSets->if()->ifVarNotEquals($variable, $value, $quoteValue);
138
    }
139
140
    public static function ifVarNotEqualsString(string $variable, string $value) : Mailcode_Commands_Command_If_Variable
141
    {
142
        return self::$commandSets->if()->ifVarNotEqualsString($variable, $value);
143
    }
144
    
145
    public static function elseIf(string $condition, string $type='') : Mailcode_Commands_Command_ElseIf
146
    {
147
        return self::$commandSets->elseIf()->elseIf($condition, $type);
148
    }
149
    
150
    public static function elseIfEmpty(string $variable) : Mailcode_Commands_Command_ElseIf_Empty
151
    {
152
        return self::$commandSets->elseIf()->elseIfEmpty($variable);
153
    }
154
    
155
    public static function elseIfNotEmpty(string $variable) : Mailcode_Commands_Command_ElseIf_NotEmpty
156
    {
157
        return self::$commandSets->elseIf()->elseIfNotEmpty($variable);
158
    }
159
    
160
    public static function elseIfVar(string $variable, string $operand, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_ElseIf_Variable
161
    {
162
        return self::$commandSets->elseIf()->elseIfVar($variable, $operand, $value, $quoteValue);
163
    }
164
165
    public static function elseIfVarString(string $variable, string $operand, string $value) : Mailcode_Commands_Command_ElseIf_Variable
166
    {
167
        return self::$commandSets->elseIf()->elseIfVarString($variable, $operand, $value);
168
    }
169
    
170
    public static function elseIfVarEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_ElseIf_Variable
171
    {
172
        return self::$commandSets->elseIf()->elseIfVarEquals($variable, $value, $quoteValue);
173
    }
174
175
    public static function elseIfVarEqualsString(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_Variable
176
    {
177
        return self::$commandSets->elseIf()->elseIfVarEqualsString($variable, $value);
178
    }
179
    
180
    public static function elseIfVarNotEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_ElseIf_Variable
181
    {
182
        return self::$commandSets->elseIf()->elseIfVarNotEquals($variable, $value, $quoteValue);
183
    }
184
185
    public static function elseIfVarNotEqualsString(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_Variable
186
    {
187
        return self::$commandSets->elseIf()->elseIfVarNotEqualsString($variable, $value);
188
    }
189
190
    public static function ifBeginsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_BeginsWith
191
    {
192
        return self::$commandSets->if()->ifBeginsWith($variable, $search, $caseInsensitive);
193
    }
194
195
    public static function ifEndsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_EndsWith
196
    {
197
        return self::$commandSets->if()->ifEndsWith($variable, $search, $caseInsensitive);
198
    }
199
200
    public static function elseIfBeginsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_BeginsWith
201
    {
202
        return self::$commandSets->elseIf()->elseIfBeginsWith($variable, $search, $caseInsensitive);
203
    }
204
    
205
    public static function elseIfEndsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_EndsWith
206
    {
207
        return self::$commandSets->elseIf()->elseIfEndsWith($variable, $search, $caseInsensitive);
208
    }
209
    
210
    public static function ifContains(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_Contains
211
    {
212
        return self::$commandSets->if()->ifContains($variable, $search, $caseInsensitive);
213
    }
214
    
215
    public static function elseIfContains(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_Contains
216
    {
217
        return self::$commandSets->elseIf()->elseIfContains($variable, $search, $caseInsensitive);
218
    }
219
    
220
    public static function ifEmpty(string $variable) : Mailcode_Commands_Command_If_Empty
221
    {
222
        return self::$commandSets->if()->ifEmpty($variable);
223
    }
224
    
225
    public static function ifNotEmpty(string $variable) : Mailcode_Commands_Command_If_NotEmpty
226
    {
227
        return self::$commandSets->if()->ifNotEmpty($variable);
228
    }
229
    
230
   /**
231
    * Creates a renderer instance, which can be used to easily
232
    * create and convert commands to strings.
233
    * 
234
    * @return Mailcode_Renderer
235
    */
236
    public static function createRenderer() : Mailcode_Renderer
237
    {
238
        return new Mailcode_Renderer();
239
    }
240
    
241
   /**
242
    * Creates a printer instance, which works like the renderer,
243
    * but outputs the generated strings to standard output.
244
    * 
245
    * @return Mailcode_Printer
246
    */
247
    public static function createPrinter() : Mailcode_Printer
248
    {
249
        return new Mailcode_Printer();
250
    }
251
    
252
   /**
253
    * Gets/creates the global instance of the date format info
254
    * class, used to handle date formatting aspects.
255
    * 
256
    * @return Mailcode_Date_FormatInfo
257
    */
258
    public static function createDateInfo() : Mailcode_Date_FormatInfo
259
    {
260
        return Mailcode_Date_FormatInfo::getInstance();
261
    }
262
    
263
    public static function init() : void
264
    {
265
        if(!isset(self::$commandSets))
266
        {
267
            self::$commandSets = new Mailcode_Factory_CommandSets();
268
        }
269
    }
270
}
271
272
Mailcode_Factory::init();
273