1 <?php
2
3 /* --------------------------------------------------------------
4 CurrencyCode.php 2015-11-05
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 /**
14 * CurrencyCode
15 *
16 * @category System
17 * @package Shared
18 */
19 class CurrencyCode
20 {
21 /**
22 * Holds the currency code as a string.
23 *
24 * @var string
25 */
26 protected $code;
27
28 /**
29 * Holds the currency value as a decimal type.
30 *
31 * @var float
32 */
33 protected $currencyValue;
34
35
36 /**
37 * Constructor
38 *
39 * Validates the parameter and saves it to the property in uppercase format.
40 *
41 * @throws InvalidArgumentException if Argument is not exactly 3 letters
42 *
43 * @param \StringType $code The currency Code (e.g. EUR)
44 * @param \DecimalType $currencyValue Value of the currency
45 */
46 public function __construct(StringType $code, DecimalType $currencyValue = null)
47 {
48 // Validate string length.
49 if(strlen($code->asString()) !== 3)
50 {
51 throw new InvalidArgumentException('Argument must have exactly 3 letters');
52 }
53
54 $this->code = strtoupper($code->asString());
55 $this->currencyValue = (null !== $currencyValue) ? $currencyValue->asDecimal() : 1.00;
56 }
57
58 /**
59 * Get Code
60 *
61 * Returns the currency code as a string.
62 *
63 * @return string
64 */
65 public function getCode()
66 {
67 return $this->code;
68 }
69
70
71 /**
72 * Get Currency Value
73 *
74 * Returns the currency value as a decimal type.
75 *
76 * @return DecimalType
77 */
78 public function getCurrencyValue()
79 {
80 return $this->currencyValue;
81 }
82 }