1 <?php
2 /* --------------------------------------------------------------
3 CustomerEmail.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('CustomerEmailInterface');
13
14 /**
15 * Value Object
16 *
17 * Class CustomerEmail
18 *
19 * Represents a customer email
20 *
21 * @category System
22 * @package Customer
23 * @subpackage ValueObjects
24 * @implements CustomerEmailInterface
25 */
26 class CustomerEmail implements CustomerEmailInterface
27 {
28 /**
29 * Customer's E-Mail address.
30 * @var string
31 */
32 protected $email;
33
34
35 /**
36 * Constructor of the class CustomerEmail.
37 *
38 * Validates the data type and format of the customer email.
39 *
40 * @param string $p_email Customer's E-Mail address.
41 *
42 * @throws InvalidArgumentException If $p_email is not a string.
43 * @throws UnexpectedValueException If $p_email is not a valid e-mail address.
44 */
45 public function __construct($p_email)
46 {
47 if(!is_string($p_email))
48 {
49 throw new InvalidArgumentException('$p_email is not a string');
50 }
51
52 if(!filter_var($p_email, FILTER_VALIDATE_EMAIL))
53 {
54 throw new UnexpectedValueException('$p_email is not a valid e-mail address');
55 }
56
57 $this->email = trim($p_email);
58 }
59
60
61 /**
62 * Returns the equivalent string value.
63 * @return string Equivalent string value.
64 */
65 public function __toString()
66 {
67 return $this->email;
68 }
69 }