1 <?php
2 /* --------------------------------------------------------------
3 CustomerPostcode.inc.phpc.php 2015-01-30 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('CustomerPostcodeInterface');
13
14 /**
15 * Value Object
16 *
17 * Class CustomerPostcode
18 *
19 * Represents a customer postcode
20 *
21 * @category System
22 * @package Customer
23 * @subpackage ValueObjects
24 * @implements CustomerPostcodeInterface
25 */
26 class CustomerPostcode implements CustomerPostcodeInterface
27 {
28 /**
29 * Customer's post code.
30 * @var string
31 */
32 protected $postcode;
33
34
35 /**
36 * Constructor for the class CustomerPostcode.
37 *
38 * Validates the length and the data type of the postcode.
39 *
40 * @param string $p_postcode Customer's post code.
41 *
42 * @throws InvalidArgumentException If $p_postcode is not a string.
43 * @throws LengthException If $p_postcode contains more characters than 10.
44 */
45 public function __construct($p_postcode)
46 {
47 if(!is_string($p_postcode))
48 {
49 throw new InvalidArgumentException('$p_postcode is not a string');
50 }
51
52 $dbFieldLength = 10;
53 $postcode = trim($p_postcode);
54
55 if(strlen_wrapper($postcode) > $dbFieldLength)
56 {
57 throw new LengthException('$postcode is longer than ' . $dbFieldLength . ' characters VARCHAR(10)');
58 }
59
60 $this->postcode = $postcode;
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->postcode;
71 }
72 }