1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace iamsaint\yml\components; |
4
|
|
|
|
5
|
|
|
use iamsaint\yml\BaseObject; |
6
|
|
|
use XMLWriter; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Currency |
10
|
|
|
* @package iamsaint\yml\components |
11
|
|
|
* |
12
|
|
|
* @property int $id |
13
|
|
|
* @property float $rate |
14
|
|
|
* @property Tag[] $customTags |
15
|
|
|
*/ |
16
|
|
|
class Currency extends BaseObject |
17
|
|
|
{ |
18
|
|
|
public const CBRF = 'CBRF'; |
19
|
|
|
public const NBU = 'NBU'; |
20
|
|
|
public const NBK = 'NBK'; |
21
|
|
|
public const CB = 'CB'; |
22
|
|
|
public const DEFAULT_RATE = '1'; |
23
|
|
|
public const RUR = 'RUR'; |
24
|
|
|
public const BYN = 'BYN'; |
25
|
|
|
public const UAH = 'UAH'; |
26
|
|
|
public const KZT = 'KZT'; |
27
|
|
|
public $id; |
28
|
|
|
public $rate; |
29
|
|
|
public $customTags = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param XMLWriter $writer |
33
|
|
|
*/ |
34
|
|
|
public function write($writer): void |
35
|
|
|
{ |
36
|
|
|
$writer->startElement('currency'); |
37
|
|
|
|
38
|
|
|
$writer->writeAttribute('id', $this->id); |
39
|
|
|
$writer->writeAttribute('rate', $this->rate); |
40
|
|
|
|
41
|
|
|
$this->writeCustomTags($writer); |
42
|
|
|
|
43
|
|
|
$writer->endElement(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param XMLWriter $writer |
48
|
|
|
*/ |
49
|
|
|
public function writeCustomTags($writer): void |
50
|
|
|
{ |
51
|
|
|
foreach ($this->customTags as $tag) { |
52
|
|
|
$tag->write($writer); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function rules(): array |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
|
|
[['id', 'rate'], 'required'], |
63
|
|
|
['id', 'one_of', static::getSignList()], |
64
|
|
|
['rate', 'one_of', static::getRateList()] |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public static function getSignList(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
static::RUR, |
75
|
|
|
static::BYN, |
76
|
|
|
static::UAH, |
77
|
|
|
static::KZT |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public static function getRateList(): array |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
static::CBRF, |
88
|
|
|
static::NBU, |
89
|
|
|
static::NBK, |
90
|
|
|
static::CB, |
91
|
|
|
static::DEFAULT_RATE |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param $id |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function setId($id): self |
100
|
|
|
{ |
101
|
|
|
$this->id = $id; |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param $rate |
107
|
|
|
* @return $this |
108
|
|
|
*/ |
109
|
|
|
public function setRate($rate): self |
110
|
|
|
{ |
111
|
|
|
$this->rate = $rate; |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|