1 <?php
2 /* --------------------------------------------------------------
3 CustomerGender.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
12 MainFactory::load_class('CustomerGenderInterface');
13
14 /**
15 * Value Object
16 *
17 * Class CustomerGender
18 *
19 * Represents a customer gender
20 *
21 * @category System
22 * @package Customer
23 * @subpackage ValueObjects
24 * @implements CustomerGenderInterface
25 */
26 class CustomerGender implements CustomerGenderInterface
27 {
28 /**
29 * Customer's gender.
30 * @var string
31 */
32 protected $gender;
33
34
35 /**
36 * Constructor of the class CustomerGender.
37 *
38 * Validates the data type and the entered values of the customer gender.
39 *
40 * @param string $p_gender Customer's gender.
41 *
42 * @throws InvalidArgumentException If $p_gender is not a string.
43 * @throws UnexpectedValueException If $p_gender is not expected string "m" or "f".
44 */
45 public function __construct($p_gender)
46 {
47 if(!is_string($p_gender))
48 {
49 throw new InvalidArgumentException('$p_gender is not a string');
50 }
51
52 if(!in_array($p_gender, array('m', 'f', '')))
53 {
54 throw new UnexpectedValueException('$p_gender is not expected string "m" or "f"');
55 }
56
57 $this->gender = $p_gender;
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->gender;
68 }
69 }