1 <?php
2 /* --------------------------------------------------------------
3 ContactType.inc.php 2015-02-03 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('ContactTypeInterface');
13
14 /**
15 * Class ContactType
16 *
17 * @category System
18 * @package Email
19 * @subpackage ValueObjects
20 */
21 class ContactType implements ContactTypeInterface
22 {
23 /**
24 * Contact type.
25 * @var string
26 */
27 protected $type;
28
29 /**
30 * Type Constants
31 */
32 const SENDER = 'sender';
33 const RECIPIENT = 'recipient';
34 const REPLY_TO = 'reply_to';
35 const BCC = 'bcc';
36 const CC = 'cc';
37
38
39 /**
40 * Class Constructor
41 *
42 * @param string $p_type Value has to be one of the declared constants, e.g. self::SENDER which value is 'sender'.
43 * @throws InvalidArgumentException On empty or invalid argument.
44 */
45 public function __construct($p_type)
46 {
47 if(!is_string($p_type) || empty($p_type)
48 || ($p_type != self::SENDER && $p_type != self::RECIPIENT && $p_type != self::BCC
49 && $p_type != self::CC
50 && $p_type != self::REPLY_TO)
51 )
52 {
53 throw new InvalidArgumentException('Invalid contact type provided (string constant expected): '
54 . print_r($p_type, true));
55 }
56 $this->type = $p_type;
57 }
58
59
60 /**
61 * Returns the contact type as a string.
62 *
63 * @return string Equivalent string.
64 */
65 public function __toString()
66 {
67 return $this->type;
68 }
69 }