1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Commands_Command_ShowDate} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Commands |
7
|
|
|
* @see Mailcode_Commands_Command_ShowDate |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Mailcode command: show a date variable value. |
16
|
|
|
* |
17
|
|
|
* @package Mailcode |
18
|
|
|
* @subpackage Commands |
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Mailcode_Commands_Command_ShowDate extends Mailcode_Commands_ShowBase |
22
|
|
|
{ |
23
|
|
|
const VALIDATION_NOT_A_FORMAT_STRING = 55401; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The date format string. |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $formatString; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Mailcode_Date_FormatInfo |
33
|
|
|
*/ |
34
|
|
|
private $formatInfo; |
35
|
|
|
|
36
|
|
|
public function getName() : string |
37
|
|
|
{ |
38
|
|
|
return 'showdate'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getLabel() : string |
42
|
|
|
{ |
43
|
|
|
return t('Show date variable'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function getValidations() : array |
47
|
|
|
{ |
48
|
|
|
return array( |
49
|
|
|
'variable', |
50
|
|
|
'check_format', |
51
|
|
|
'urlencode' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function init() : void |
56
|
|
|
{ |
57
|
|
|
$this->formatInfo = Mailcode_Factory::createDateInfo(); |
58
|
|
|
$this->formatString = $this->formatInfo->getDefaultFormat(); |
59
|
|
|
|
60
|
|
|
parent::init(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function validateSyntax_check_format() : void |
64
|
|
|
{ |
65
|
|
|
$tokens = $this->params->getInfo()->getStringLiterals(); |
66
|
|
|
|
67
|
|
|
// no format specified? Use the default one. |
68
|
|
|
if(empty($tokens)) |
69
|
|
|
{ |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$token = array_pop($tokens); |
74
|
|
|
$this->parseFormatString($token->getText()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function parseFormatString(string $format) : void |
78
|
|
|
{ |
79
|
|
|
$result = $this->formatInfo->validateFormat($format); |
80
|
|
|
|
81
|
|
|
if($result->isValid()) |
82
|
|
|
{ |
83
|
|
|
$this->formatString = $format; |
84
|
|
|
return; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->validationResult->makeError( |
88
|
|
|
$result->getErrorMessage(), |
89
|
|
|
$result->getCode() |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Retrieves the format string used to format the date. |
95
|
|
|
* |
96
|
|
|
* @return string A PHP compatible date format string. |
97
|
|
|
*/ |
98
|
|
|
public function getFormatString() : string |
99
|
|
|
{ |
100
|
|
|
return $this->formatString; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|