1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Commands_Command_ShowPrice} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Commands |
7
|
|
|
* @see Mailcode_Commands_Command_ShowPrice |
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 Olaf Böcker <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Mailcode_Commands_Command_ShowPrice extends Mailcode_Commands_ShowBase |
22
|
|
|
implements |
23
|
|
|
RegionInterface, CurrencyInterface, CurrencyNameInterface |
24
|
|
|
{ |
25
|
|
|
use RegionTrait; |
26
|
|
|
use CurrencyTrait; |
27
|
|
|
use CurrencyNameTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Mailcode_Parser_Statement_Tokenizer_Token_Keyword|NULL |
31
|
|
|
*/ |
32
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword $absoluteKeyword = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Mailcode_Number_LocalCurrency |
36
|
|
|
*/ |
37
|
|
|
private Mailcode_Number_LocalCurrency $localCurrency; |
38
|
|
|
|
39
|
|
|
public function getName(): string |
40
|
|
|
{ |
41
|
|
|
return 'showprice'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getLabel(): string |
45
|
|
|
{ |
46
|
|
|
return t('Show price variable'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function getValidations(): array |
50
|
|
|
{ |
51
|
|
|
return array( |
52
|
|
|
Mailcode_Interfaces_Commands_Validation_Variable::VALIDATION_NAME_VARIABLE, |
53
|
|
|
'absolute', |
54
|
|
|
'check_currency_exclusive', |
55
|
|
|
'check_currency', |
56
|
|
|
'check_region' |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function validateSyntax_absolute(): void |
61
|
|
|
{ |
62
|
|
|
$keywords = $this->requireParams() |
63
|
|
|
->getInfo() |
64
|
|
|
->getKeywords(); |
65
|
|
|
|
66
|
|
|
foreach ($keywords as $keyword) { |
67
|
|
|
if ($keyword->getKeyword() === Mailcode_Commands_Keywords::TYPE_ABSOLUTE) { |
68
|
|
|
$this->absoluteKeyword = $keyword; |
69
|
|
|
break; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function validateSyntax_check_currency_exclusive(): void |
75
|
|
|
{ |
76
|
|
|
$hasCurrencyNameKeyword = $this |
77
|
|
|
->requireParams() |
78
|
|
|
->getInfo() |
79
|
|
|
->hasKeyword(Mailcode_Commands_Keywords::TYPE_CURRENCY_NAME); |
80
|
|
|
|
81
|
|
|
$hasCurrencyParameter = $this |
82
|
|
|
->requireParams() |
83
|
|
|
->getInfo() |
84
|
|
|
->getTokenByParamName(CurrencyInterface::CURRENCY_PARAMETER_NAME); |
85
|
|
|
|
86
|
|
|
if ($hasCurrencyParameter && $hasCurrencyNameKeyword) { |
87
|
|
|
$this->validationResult->makeError( |
88
|
|
|
t("Can not use both 'currency-name' and 'currency'"), |
89
|
|
|
CurrencyInterface::VALIDATION_CURRENCY_EXCLUSIVE |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function isAbsolute(): bool |
95
|
|
|
{ |
96
|
|
|
return isset($this->absoluteKeyword); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function setAbsolute(bool $absolute): Mailcode_Commands_Command_ShowPrice |
100
|
|
|
{ |
101
|
|
|
if ($absolute === false && isset($this->absoluteKeyword)) { |
102
|
|
|
$this->requireParams()->getInfo()->removeKeyword($this->absoluteKeyword->getKeyword()); |
|
|
|
|
103
|
|
|
$this->absoluteKeyword = null; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if ($absolute === true && !isset($this->absoluteKeyword)) { |
107
|
|
|
$this->requireParams() |
108
|
|
|
->getInfo() |
109
|
|
|
->addKeyword(Mailcode_Commands_Keywords::TYPE_ABSOLUTE); |
110
|
|
|
|
111
|
|
|
$this->validateSyntax_absolute(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getLocalCurrency(): Mailcode_Number_LocalCurrency |
118
|
|
|
{ |
119
|
|
|
if (!isset($this->localCurrency)) { |
120
|
|
|
$this->localCurrency = Mailcode_Number_LocalCurrency::defaultInstance(); |
121
|
|
|
} |
122
|
|
|
return $this->localCurrency; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function setLocalCurrency(Mailcode_Number_LocalCurrency $localCurrency): Mailcode_Commands_Command_ShowPrice |
126
|
|
|
{ |
127
|
|
|
$this->localCurrency = $localCurrency; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.