1 <?php
2 /* --------------------------------------------------------------
3 CustomerCountryIso3.php 2015-02-02 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('CustomerCountryIso3Interface');
13
14 /**
15 * Value Object
16 *
17 * Class CustomerCountryIso3
18 *
19 * Represents a customer country ISO3 code
20 *
21 * @category System
22 * @package Customer
23 * @subpackage ValueObjects
24 * @implements CustomerCountryIso3Interface
25 */
26 class CustomerCountryIso3 implements CustomerCountryIso3Interface
27 {
28 /**
29 * Customer's ISO-3 country code.
30 * @var string
31 */
32 protected $iso3;
33
34
35 /**
36 * Constructor of the class CustomerCountryIso3.
37 *
38 * Validates the length and data type of the customer country ISO-3 code.
39 *
40 * @param string $p_iso3 Customer's ISO-3 country code.
41 *
42 * @throws InvalidArgumentException If $p_iso3 is not a string.
43 * @throws LengthException If $p_iso3 contains more characters than 3.
44 */
45 public function __construct($p_iso3)
46 {
47 if(!is_string($p_iso3))
48 {
49 throw new InvalidArgumentException('$p_iso3 is not a string');
50 }
51
52 $dbFieldLengthIso3 = 3;
53 $iso3 = trim($p_iso3);
54
55 if(strlen_wrapper($iso3) > $dbFieldLengthIso3)
56 {
57 throw new LengthException('$iso3 is longer than ' . $dbFieldLengthIso3 . ' characters CHAR(3)');
58 }
59
60 $this->iso3 = $iso3;
61 }
62
63
64 /**
65 * Returns the equivalent string value.
66 * @return string Equivalent string value.
67 */
68 public function __toString()
69 {
70 return $this->iso3;
71 }
72 }