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