|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Company\Domain\Model\VO; |
|
15
|
|
|
|
|
16
|
|
|
final class Currency |
|
17
|
|
|
{ |
|
18
|
|
|
public const CURRENCY = ['euro']; |
|
19
|
|
|
public const SYMBOL = ['€']; |
|
20
|
|
|
|
|
21
|
|
|
private string $currency; |
|
22
|
|
|
private string $symbol; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(string $currency) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->currency = self::isCurrency($currency); |
|
27
|
|
|
$this->symbol = self::isSymbol($this->currency); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public static function fromString(string $currency): self |
|
31
|
|
|
{ |
|
32
|
|
|
return new self($currency); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function fromCurrency(self $currency): string |
|
36
|
|
|
{ |
|
37
|
|
|
return $currency->toString(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getValue(): string |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->currency; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function currency(): string |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->currency; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function symbol(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->symbol; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private static function isCurrency(string $currency): string |
|
56
|
|
|
{ |
|
57
|
|
|
if (!\in_array(\strtolower($currency), self::CURRENCY, true)) { |
|
58
|
|
|
throw new InvalidCurrency(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return \strtolower($currency); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private static function isSymbol(string $currency): string |
|
65
|
|
|
{ |
|
66
|
|
|
return self::SYMBOL[\array_search($currency, self::CURRENCY, true)]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
private function toString(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->currency; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|