Passed
Push — master ( 77f2a3...0c35c3 )
by Sebastian
03:02
created

Mailcode_Factory::elseIfNotContainsAny()   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
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
    // region Show commands
32
33
    /**
34
     * Creates a ShowVariable command.
35
     *
36
     * @param string $variableName A variable name, with or without the $ sign prepended.
37
     * @return Mailcode_Commands_Command_ShowVariable
38
     * @throws Mailcode_Factory_Exception
39
     */
40
    public static function showVar(string $variableName) : Mailcode_Commands_Command_ShowVariable
41
    {
42
        return self::$commandSets->show()->showVar($variableName);
43
    }
44
45
    /**
46
     * Creates a ShowDate command, used to display date variables and
47
     * format the date using date format strings.
48
     *
49
     * @param string $variableName A variable name, with or without the $ sign prepended.
50
     * @param string $formatString A date format string, or empty string for default.
51
     * @return Mailcode_Commands_Command_ShowDate
52
     * @throws Mailcode_Factory_Exception
53
     */
54
    public static function showDate(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowDate
55
    {
56
        return self::$commandSets->show()->showDate($variableName, $formatString);
57
    }
58
59
    /**
60
     * Creates a ShowNumber command, used to display numeric variables
61
     * and format the numbers to a specific format.
62
     *
63
     * @param string $variableName A variable name, with or without the $ sign prepended.
64
     * @param string $formatString A number format string, or empty string for default.
65
     * @return Mailcode_Commands_Command_ShowNumber
66
     * @throws Mailcode_Factory_Exception
67
     */
68
    public static function showNumber(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowNumber
69
    {
70
        return self::$commandSets->show()->showNumber($variableName, $formatString);
71
    }
72
73
    /**
74
     * Creates a ShowSnippet command.
75
     *
76
     * @param string $snippetName A snippet name, with or without the $ sign prepended.
77
     * @return Mailcode_Commands_Command_ShowSnippet
78
     * @throws Mailcode_Factory_Exception
79
     */
80
    public static function showSnippet(string $snippetName) : Mailcode_Commands_Command_ShowSnippet
81
    {
82
        return self::$commandSets->show()->showSnippet($snippetName);
83
    }
84
85
    // endregion
86
87
    // region Miscellaneous
88
89
    /**
90
     * Creates a SetVariable command.
91
     *
92
     * @param string $variableName A variable name, with or without the $ sign prepended.
93
     * @param string $value
94
     * @param bool $quoteValue Whether to treat the value as a string literal, and add quotes to it.
95
     * @return Mailcode_Commands_Command_SetVariable
96
     * @throws Mailcode_Factory_Exception
97
     *
98
     * @see Mailcode_Factory::ERROR_INVALID_COMMAND_CREATED
99
     */
100
    public static function setVar(string $variableName, string $value, bool $quoteValue=true) : Mailcode_Commands_Command_SetVariable
101
    {
102
        return self::$commandSets->set()->setVar($variableName, $value, $quoteValue);
103
    }
104
105
    /**
106
     * Like setVar(), but treats the value as a string literal
107
     * and automatically adds quotes to it.
108
     *
109
     * @param string $variableName
110
     * @param string $value
111
     * @return Mailcode_Commands_Command_SetVariable
112
     * @throws Mailcode_Factory_Exception
113
     */
114
    public static function setVarString(string $variableName, string $value) : Mailcode_Commands_Command_SetVariable
115
    {
116
        return self::$commandSets->set()->setVar($variableName, $value, true);
117
    }
118
119
    /**
120
     * Creates a comment command for documenting things.
121
     *
122
     * @param string $comments
123
     * @return Mailcode_Commands_Command_Comment
124
     * @throws Mailcode_Factory_Exception
125
     */
126
    public static function comment(string $comments) : Mailcode_Commands_Command_Comment
127
    {
128
        return self::$commandSets->misc()->comment($comments);
129
    }
130
131
    /**
132
     * Creates a code command for inserting code blocks meant for
133
     * the backend system that will parse the templates.
134
     *
135
     * @param string $language
136
     * @return Mailcode_Commands_Command_Code
137
     * @throws Mailcode_Factory_Exception
138
     */
139
    public static function code(string $language) : Mailcode_Commands_Command_Code
140
    {
141
        return self::$commandSets->misc()->code($language);
142
    }
143
144
    /**
145
     * Ends commands like IF and FOR.
146
     *
147
     * @return Mailcode_Commands_Command_End
148
     * @throws Mailcode_Factory_Exception
149
     */
150
    public static function end() : Mailcode_Commands_Command_End
151
    {
152
        return self::$commandSets->if()->end();
153
    }
154
155
    /**
156
     * Creates a FOR loop command to iterate over collections.
157
     *
158
     * @param string $sourceVariable
159
     * @param string $loopVariable
160
     * @return Mailcode_Commands_Command_For
161
     * @throws Mailcode_Factory_Exception
162
     */
163
    public static function for(string $sourceVariable, string $loopVariable) : Mailcode_Commands_Command_For
164
    {
165
        return self::$commandSets->misc()->for($sourceVariable, $loopVariable);
166
    }
167
168
    /**
169
     * Used to break out of a FOR loop command.
170
     *
171
     * @return Mailcode_Commands_Command_Break
172
     * @throws Mailcode_Factory_Exception
173
     */
174
    public static function break() : Mailcode_Commands_Command_Break
175
    {
176
        return self::$commandSets->misc()->break();
177
    }
178
179
    // endregion
180
    
181
    public static function else() : Mailcode_Commands_Command_Else
182
    {
183
        return self::$commandSets->if()->else();
184
    }
185
    
186
    public static function if(string $condition, string $type='') : Mailcode_Commands_Command_If
187
    {
188
        return self::$commandSets->if()->if($condition, $type);
189
    }
190
    
191
192
    public static function elseIf(string $condition, string $type='') : Mailcode_Commands_Command_ElseIf
193
    {
194
        return self::$commandSets->elseIf()->elseIf($condition, $type);
195
    }
196
    
197
    public static function elseIfEmpty(string $variable) : Mailcode_Commands_Command_ElseIf_Empty
198
    {
199
        return self::$commandSets->elseIf()->elseIfEmpty($variable);
200
    }
201
    
202
    public static function elseIfNotEmpty(string $variable) : Mailcode_Commands_Command_ElseIf_NotEmpty
203
    {
204
        return self::$commandSets->elseIf()->elseIfNotEmpty($variable);
205
    }
206
207
    // region IF variable
208
209
    public static function ifVar(string $variable, string $operand, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_If_Variable
210
    {
211
        return self::$commandSets->if()->ifVar($variable, $operand, $value, $quoteValue);
212
    }
213
214
    public static function ifVarString(string $variable, string $operand, string $value) : Mailcode_Commands_Command_If_Variable
215
    {
216
        return self::$commandSets->if()->ifVarString($variable, $operand, $value);
217
    }
218
219
    public static function ifVarEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_If_Variable
220
    {
221
        return self::$commandSets->if()->ifVarEquals($variable, $value, $quoteValue);
222
    }
223
224
    public static function ifVarEqualsString(string $variable, string $value) : Mailcode_Commands_Command_If
225
    {
226
        return self::$commandSets->if()->ifVarEqualsString($variable, $value);
227
    }
228
229
    public static function ifVarNotEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_If_Variable
230
    {
231
        return self::$commandSets->if()->ifVarNotEquals($variable, $value, $quoteValue);
232
    }
233
234
    public static function ifVarNotEqualsString(string $variable, string $value) : Mailcode_Commands_Command_If_Variable
235
    {
236
        return self::$commandSets->if()->ifVarNotEqualsString($variable, $value);
237
    }
238
239
    public static function elseIfVar(string $variable, string $operand, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_ElseIf_Variable
240
    {
241
        return self::$commandSets->elseIf()->elseIfVar($variable, $operand, $value, $quoteValue);
242
    }
243
244
    public static function elseIfVarString(string $variable, string $operand, string $value) : Mailcode_Commands_Command_ElseIf_Variable
245
    {
246
        return self::$commandSets->elseIf()->elseIfVarString($variable, $operand, $value);
247
    }
248
    
249
    public static function elseIfVarEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_ElseIf_Variable
250
    {
251
        return self::$commandSets->elseIf()->elseIfVarEquals($variable, $value, $quoteValue);
252
    }
253
254
    public static function elseIfVarEqualsString(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_Variable
255
    {
256
        return self::$commandSets->elseIf()->elseIfVarEqualsString($variable, $value);
257
    }
258
    
259
    public static function elseIfVarNotEquals(string $variable, string $value, bool $quoteValue=false) : Mailcode_Commands_Command_ElseIf_Variable
260
    {
261
        return self::$commandSets->elseIf()->elseIfVarNotEquals($variable, $value, $quoteValue);
262
    }
263
264
    public static function elseIfVarNotEqualsString(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_Variable
265
    {
266
        return self::$commandSets->elseIf()->elseIfVarNotEqualsString($variable, $value);
267
    }
268
269
    public static function ifVarEqualsNumber(string $variable, string $number) : Mailcode_Commands_Command_If_EqualsNumber
270
    {
271
        return self::$commandSets->if()->ifVarEqualsNumber($variable, $number);
272
    }
273
274
    public static function elseIfVarEqualsNumber(string $variable, string $number) : Mailcode_Commands_Command_ElseIf_EqualsNumber
275
    {
276
        return self::$commandSets->elseIf()->elseIfVarEqualsNumber($variable, $number);
277
    }
278
279
    // endregion
280
281
    public static function ifBeginsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_BeginsWith
282
    {
283
        return self::$commandSets->if()->ifBeginsWith($variable, $search, $caseInsensitive);
284
    }
285
286
    public static function ifBiggerThan(string $variable, string $number) : Mailcode_Commands_Command_If_BiggerThan
287
    {
288
        return self::$commandSets->if()->ifBiggerThan($variable, $number);
289
    }
290
291
    public static function ifSmallerThan(string $variable, string $number) : Mailcode_Commands_Command_If_SmallerThan
292
    {
293
        return self::$commandSets->if()->ifSmallerThan($variable, $number);
294
    }
295
296
    public static function ifEndsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_EndsWith
297
    {
298
        return self::$commandSets->if()->ifEndsWith($variable, $search, $caseInsensitive);
299
    }
300
301
    public static function elseIfBeginsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_BeginsWith
302
    {
303
        return self::$commandSets->elseIf()->elseIfBeginsWith($variable, $search, $caseInsensitive);
304
    }
305
    
306
    public static function elseIfEndsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_EndsWith
307
    {
308
        return self::$commandSets->elseIf()->elseIfEndsWith($variable, $search, $caseInsensitive);
309
    }
310
    
311
    public static function elseIfBiggerThan(string $variable, string $number) : Mailcode_Commands_Command_ElseIf_BiggerThan
312
    {
313
        return self::$commandSets->elseIf()->elseIfBiggerThan($variable, $number);
314
    }
315
316
    public static function elseIfSmallerThan(string $variable, string $number) : Mailcode_Commands_Command_ElseIf_SmallerThan
317
    {
318
        return self::$commandSets->elseIf()->elseIfSmallerThan($variable, $number);
319
    }
320
321
    // region Contains
322
323
    public static function ifContains(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_Contains
324
    {
325
        return self::$commandSets->if()->ifContains($variable, array($search), $caseInsensitive);
326
    }
327
328
    /**
329
     * Creates if contains command, with several search terms.
330
     *
331
     * @param string $variable
332
     * @param string[] $searchTerms List of search terms. Do not add surrounding quotes.
333
     * @param bool $caseInsensitive
334
     * @return Mailcode_Commands_Command_If_Contains
335
     * @throws Mailcode_Factory_Exception
336
     */
337
    public static function ifContainsAny(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_Contains
338
    {
339
        return self::$commandSets->if()->ifContains($variable, $searchTerms, $caseInsensitive);
340
    }
341
    
342
    public static function elseIfContains(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_Contains
343
    {
344
        return self::$commandSets->elseIf()->elseIfContains($variable, array($search), $caseInsensitive);
345
    }
346
347
    /**
348
     * Creates else if contains command, with several search terms.
349
     *
350
     * @param string $variable
351
     * @param string[] $searchTerms List of search terms. Do not add surrounding quotes.
352
     * @param bool $caseInsensitive
353
     * @return Mailcode_Commands_Command_ElseIf_Contains
354
     * @throws Mailcode_Factory_Exception
355
     */
356
    public static function elseIfContainsAny(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_Contains
357
    {
358
        return self::$commandSets->elseIf()->elseIfContains($variable, $searchTerms, $caseInsensitive);
359
    }
360
361
    public static function ifNotContains(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_NotContains
362
    {
363
        return self::$commandSets->if()->ifNotContains($variable, array($search), $caseInsensitive);
364
    }
365
366
    /**
367
     * Creates if not contains command, with several search terms.
368
     *
369
     * @param string $variable
370
     * @param string[] $searchTerms List of search terms. Do not add surrounding quotes.
371
     * @param bool $caseInsensitive
372
     * @return Mailcode_Commands_Command_If_NotContains
373
     * @throws Mailcode_Factory_Exception
374
     */
375
    public static function ifNotContainsAny(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_NotContains
376
    {
377
        return self::$commandSets->if()->ifNotContains($variable, $searchTerms, $caseInsensitive);
378
    }
379
380
    public static function elseIfNotContains(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_NotContains
381
    {
382
        return self::$commandSets->elseIf()->elseIfNotContains($variable, array($search), $caseInsensitive);
383
    }
384
385
    /**
386
     * Creates else if not contains command, with several search terms.
387
     *
388
     * @param string $variable
389
     * @param string[] $searchTerms List of search terms. Do not add surrounding quotes.
390
     * @param bool $caseInsensitive
391
     * @return Mailcode_Commands_Command_ElseIf_NotContains
392
     * @throws Mailcode_Factory_Exception
393
     */
394
    public static function elseIfNotContainsAny(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_NotContains
395
    {
396
        return self::$commandSets->elseIf()->elseIfNotContains($variable, $searchTerms, $caseInsensitive);
397
    }
398
399
    //endregion
400
401
402
    public static function ifEmpty(string $variable) : Mailcode_Commands_Command_If_Empty
403
    {
404
        return self::$commandSets->if()->ifEmpty($variable);
405
    }
406
    
407
    public static function ifNotEmpty(string $variable) : Mailcode_Commands_Command_If_NotEmpty
408
    {
409
        return self::$commandSets->if()->ifNotEmpty($variable);
410
    }
411
    
412
   /**
413
    * Creates a renderer instance, which can be used to easily
414
    * create and convert commands to strings.
415
    * 
416
    * @return Mailcode_Renderer
417
    */
418
    public static function createRenderer() : Mailcode_Renderer
419
    {
420
        return new Mailcode_Renderer();
421
    }
422
    
423
   /**
424
    * Creates a printer instance, which works like the renderer,
425
    * but outputs the generated strings to standard output.
426
    * 
427
    * @return Mailcode_Printer
428
    */
429
    public static function createPrinter() : Mailcode_Printer
430
    {
431
        return new Mailcode_Printer();
432
    }
433
    
434
   /**
435
    * Gets/creates the global instance of the date format info
436
    * class, used to handle date formatting aspects.
437
    * 
438
    * @return Mailcode_Date_FormatInfo
439
    */
440
    public static function createDateInfo() : Mailcode_Date_FormatInfo
441
    {
442
        return Mailcode_Date_FormatInfo::getInstance();
443
    }
444
445
    public static function init() : void
446
    {
447
        if(!isset(self::$commandSets))
448
        {
449
            self::$commandSets = new Mailcode_Factory_CommandSets();
450
        }
451
    }
452
}
453
454
Mailcode_Factory::init();
455