1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Commands_Command_ShowNumber} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Commands |
7
|
|
|
* @see Mailcode_Commands_Command_ShowNumber |
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_ShowNumber extends Mailcode_Commands_ShowBase |
22
|
|
|
{ |
23
|
|
|
const VALIDATION_NOT_A_FORMAT_STRING = 72201; |
24
|
|
|
const VALIDATION_PADDING_SEPARATOR_OVERFLOW = 72202; |
25
|
|
|
const VALIDATION_INVALID_FORMAT_NUMBER = 72203; |
26
|
|
|
const VALIDATION_INVALID_THOUSANDS_SEPARATOR = 72204; |
27
|
|
|
const VALIDATION_INVALID_DECIMALS_NO_DECIMALS = 72205; |
28
|
|
|
const VALIDATION_INVALID_CHARACTERS = 72206; |
29
|
|
|
const VALIDATION_PADDING_INVALID_CHARS = 72207; |
30
|
|
|
const VALIDATION_INVALID_DECIMALS_CHARS = 72208; |
31
|
|
|
const VALIDATION_INVALID_DECIMAL_SEPARATOR = 72209; |
32
|
|
|
const VALIDATION_SEPARATORS_SAME_CHARACTER = 72210; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The default number format string. |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $formatString = Mailcode_Number_Info::DEFAULT_FORMAT; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Mailcode_Date_FormatInfo |
42
|
|
|
*/ |
43
|
|
|
private $formatInfo; |
|
|
|
|
44
|
|
|
|
45
|
|
|
public function getName() : string |
46
|
|
|
{ |
47
|
|
|
return 'shownumber'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getLabel() : string |
51
|
|
|
{ |
52
|
|
|
return t('Show number variable'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function getValidations() : array |
56
|
|
|
{ |
57
|
|
|
return array( |
58
|
|
|
'variable', |
59
|
|
|
'check_format', |
60
|
|
|
'urlencode' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function validateSyntax_check_format() : void |
65
|
|
|
{ |
66
|
|
|
$tokens = $this->params->getInfo()->getStringLiterals(); |
67
|
|
|
|
68
|
|
|
// no format specified? Use the default one. |
69
|
|
|
if(empty($tokens)) |
70
|
|
|
{ |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$token = array_pop($tokens); |
75
|
|
|
$this->parseFormatString($token->getText()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function parseFormatString(string $format) : void |
79
|
|
|
{ |
80
|
|
|
$result = new Mailcode_Number_Info($format); |
81
|
|
|
|
82
|
|
|
if($result->isValid()) |
83
|
|
|
{ |
84
|
|
|
$this->formatString = $format; |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->validationResult->makeError( |
89
|
|
|
$result->getErrorMessage(), |
90
|
|
|
$result->getCode() |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Retrieves the format string used to format the number. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getFormatString() : string |
100
|
|
|
{ |
101
|
|
|
return $this->formatString; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Retrieves information on how the number should be formatted. |
106
|
|
|
* |
107
|
|
|
* @return Mailcode_Number_Info |
108
|
|
|
*/ |
109
|
|
|
public function getFormatInfo() : Mailcode_Number_Info |
110
|
|
|
{ |
111
|
|
|
return new Mailcode_Number_Info($this->getFormatString()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|