1 <?php
2 /* --------------------------------------------------------------
3 ContactName.inc.php 2015-01-29 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('ContactNameInterface');
13
14 /**
15 * Class ContactName
16 *
17 * Contact name will be the display name for an EmailContact object.
18 *
19 * @category System
20 * @package Email
21 * @subpackage ValueObjects
22 */
23 class ContactName implements ContactNameInterface
24 {
25 /**
26 * Maximum name length constant.
27 * @var int
28 */
29 const MAX_LENGTH = 128;
30
31 /**
32 * Contact name.
33 *
34 * @var string
35 */
36 protected $contactName;
37
38
39 /**
40 * Constructor
41 *
42 * Executes the validation checks upon the contact name.
43 *
44 * @throws InvalidArgumentException If the provided argument is not a string.
45 *
46 * @param string $p_contactName Contact name.
47 */
48 public function __construct($p_contactName)
49 {
50 if(!is_string($p_contactName)) // contact name CAN be empty string
51 {
52 throw new InvalidArgumentException('Invalid argument provided (expected string name) $p_contactName: '
53 . print_r($p_contactName, true));
54 }
55
56 if(strlen(trim($p_contactName)) > self::MAX_LENGTH)
57 {
58 $p_contactName = substr($p_contactName, 0, self::MAX_LENGTH - 3) . '...';
59 }
60
61 $this->contactName = $p_contactName;
62 }
63
64
65 /**
66 * Returns the contact name as a string.
67 *
68 * @return string Equivalent string.
69 */
70 public function __toString()
71 {
72 return $this->contactName;
73 }
74 }