|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the {@see Mailcode_Factory_CommandSets_Set_Show} class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Utilities |
|
7
|
|
|
* @see Mailcode_Factory_CommandSets_Set_Show |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Command set used to create showxxx commands. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Mailcode |
|
18
|
|
|
* @subpackage Utilities |
|
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Mailcode_Factory_CommandSets_Set_Show extends Mailcode_Factory_CommandSets_Set |
|
22
|
|
|
{ |
|
23
|
|
|
public function showVar(string $variableName) : Mailcode_Commands_Command_ShowVariable |
|
24
|
|
|
{ |
|
25
|
|
|
$variableName = $this->instantiator->filterVariableName($variableName); |
|
26
|
|
|
|
|
27
|
|
|
$cmd = Mailcode::create()->getCommands()->createCommand( |
|
28
|
|
|
'ShowVariable', |
|
29
|
|
|
'', |
|
30
|
|
|
$variableName, |
|
31
|
|
|
'{showvar:'.$variableName.'}' |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$this->instantiator->checkCommand($cmd); |
|
35
|
|
|
|
|
36
|
|
|
if($cmd instanceof Mailcode_Commands_Command_ShowVariable) |
|
37
|
|
|
{ |
|
38
|
|
|
return $cmd; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
throw $this->instantiator->exceptionUnexpectedType('ShowVariable', $cmd); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function showDate(string $variableName, string $formatString="") : Mailcode_Commands_Command_ShowDate |
|
45
|
|
|
{ |
|
46
|
|
|
$variableName = $this->instantiator->filterVariableName($variableName); |
|
47
|
|
|
|
|
48
|
|
|
$format = ''; |
|
49
|
|
|
if(!empty($formatString)) |
|
50
|
|
|
{ |
|
51
|
|
|
$format = sprintf( |
|
52
|
|
|
' "%s"', |
|
53
|
|
|
$formatString |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$cmd = Mailcode::create()->getCommands()->createCommand( |
|
58
|
|
|
'ShowDate', |
|
59
|
|
|
'', |
|
60
|
|
|
$variableName.$format, |
|
61
|
|
|
sprintf( |
|
62
|
|
|
'{showdate: %s%s}', |
|
63
|
|
|
$variableName, |
|
64
|
|
|
$format |
|
65
|
|
|
) |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$this->instantiator->checkCommand($cmd); |
|
69
|
|
|
|
|
70
|
|
|
if($cmd instanceof Mailcode_Commands_Command_ShowDate) |
|
71
|
|
|
{ |
|
72
|
|
|
return $cmd; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
throw $this->instantiator->exceptionUnexpectedType('ShowDate', $cmd); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function showSnippet(string $snippetName) : Mailcode_Commands_Command_ShowSnippet |
|
79
|
|
|
{ |
|
80
|
|
|
$snippetName = $this->instantiator->filterVariableName($snippetName); |
|
81
|
|
|
|
|
82
|
|
|
$cmd = Mailcode::create()->getCommands()->createCommand( |
|
83
|
|
|
'ShowSnippet', |
|
84
|
|
|
'', |
|
85
|
|
|
$snippetName, |
|
86
|
|
|
'{showsnippet:'.$snippetName.'}' |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$this->instantiator->checkCommand($cmd); |
|
90
|
|
|
|
|
91
|
|
|
if($cmd instanceof Mailcode_Commands_Command_ShowSnippet) |
|
92
|
|
|
{ |
|
93
|
|
|
return $cmd; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
throw $this->instantiator->exceptionUnexpectedType('ShowSnippet', $cmd); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|