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