1 <?php
2 /* --------------------------------------------------------------
3 CustomerSuburb.inc.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 MainFactory::load_class('CustomerSuburbInterface');
12
13 /**
14 * Class CustomerSuburb
15 *
16 * Represents a customer suburb
17 *
18 * @category System
19 * @package Customer
20 * @subpackage ValueObjects
21 */
22 class CustomerSuburb implements CustomerSuburbInterface
23 {
24 /**
25 * Customer's suburb.
26 * @var string
27 */
28 protected $suburb;
29
30
31 /**
32 * Constructor of the class CustomerSuburb
33 *
34 * Validates the length and the data type of the customer suburb.
35 *
36 * @param string $p_suburb Customer's suburb.
37 *
38 * @throws InvalidArgumentException If $p_suburb is not a string.
39 * @throws LengthException If $p_suburb contains more characters than 32.
40 */
41 public function __construct($p_suburb)
42 {
43 if(!is_string($p_suburb))
44 {
45 throw new InvalidArgumentException('$p_suburb is not a string');
46 }
47
48 $dbFieldLength = 32;
49 $suburb = trim($p_suburb);
50
51 if(strlen_wrapper($suburb) > $dbFieldLength)
52 {
53 throw new LengthException('$suburb is longer than ' . $dbFieldLength . ' characters VARCHAR(32)');
54 }
55
56 $this->suburb = $suburb;
57 }
58
59
60 /**
61 * Returns the equivalent string value.
62 * @return string Equivalent string value.
63 */
64 public function __toString()
65 {
66 return $this->suburb;
67 }
68 }