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
|
|
|
use Mailcode\Interfaces\Commands\Validation\AbsoluteKeywordInterface; |
15
|
|
|
use Mailcode\Traits\Commands\Validation\AbsoluteKeywordTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Mailcode command: Display a variable containing a price with currency. |
19
|
|
|
* |
20
|
|
|
* @package Mailcode |
21
|
|
|
* @subpackage Commands |
22
|
|
|
* @author Olaf Böcker <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Mailcode_Commands_Command_ShowPrice extends Mailcode_Commands_ShowBase |
25
|
|
|
implements |
26
|
|
|
RegionInterface, |
27
|
|
|
CurrencyInterface, |
28
|
|
|
CurrencyNameInterface, |
29
|
|
|
AbsoluteKeywordInterface |
30
|
|
|
{ |
31
|
|
|
use RegionTrait; |
32
|
|
|
use CurrencyTrait; |
33
|
|
|
use CurrencyNameTrait; |
34
|
|
|
use AbsoluteKeywordTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Mailcode_Number_LocalCurrency |
38
|
|
|
*/ |
39
|
|
|
private Mailcode_Number_LocalCurrency $localCurrency; |
40
|
|
|
|
41
|
|
|
public function getName(): string |
42
|
|
|
{ |
43
|
|
|
return 'showprice'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getLabel(): string |
47
|
|
|
{ |
48
|
|
|
return t('Show price variable'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getValidations(): array |
52
|
|
|
{ |
53
|
|
|
return array( |
54
|
|
|
Mailcode_Interfaces_Commands_Validation_Variable::VALIDATION_NAME_VARIABLE, |
55
|
|
|
AbsoluteKeywordInterface::VALIDATION_NAME, |
56
|
|
|
'check_currency_exclusive', |
57
|
|
|
'check_currency', |
58
|
|
|
'check_region' |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function validateSyntax_check_currency_exclusive(): void |
63
|
|
|
{ |
64
|
|
|
$hasCurrencyNameKeyword = $this |
65
|
|
|
->requireParams() |
66
|
|
|
->getInfo() |
67
|
|
|
->hasKeyword(Mailcode_Commands_Keywords::TYPE_CURRENCY_NAME); |
68
|
|
|
|
69
|
|
|
$hasCurrencyParameter = $this |
70
|
|
|
->requireParams() |
71
|
|
|
->getInfo() |
72
|
|
|
->getTokenByParamName(CurrencyInterface::CURRENCY_PARAMETER_NAME); |
73
|
|
|
|
74
|
|
|
if ($hasCurrencyParameter && $hasCurrencyNameKeyword) { |
75
|
|
|
$this->validationResult->makeError( |
76
|
|
|
t("Can not use both 'currency-name' and 'currency'"), |
77
|
|
|
CurrencyInterface::VALIDATION_CURRENCY_EXCLUSIVE |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getLocalCurrency(): Mailcode_Number_LocalCurrency |
83
|
|
|
{ |
84
|
|
|
if (!isset($this->localCurrency)) { |
85
|
|
|
$this->localCurrency = Mailcode_Number_LocalCurrency::defaultInstance(); |
86
|
|
|
} |
87
|
|
|
return $this->localCurrency; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function setLocalCurrency(Mailcode_Number_LocalCurrency $localCurrency): Mailcode_Commands_Command_ShowPrice |
91
|
|
|
{ |
92
|
|
|
$this->localCurrency = $localCurrency; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|