1 <?php
2 /* --------------------------------------------------------------
3 EmailSubject.inc.php 2015-06-25 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('EmailSubjectInterface');
13
14 /**
15 * Class EmailSubject
16 *
17 * Subject assigned to an email.
18 *
19 * @category System
20 * @package Email
21 * @subpackage ValueObjects
22 */
23 class EmailSubject implements EmailSubjectInterface
24 {
25 /**
26 * Defines the maximum db field length.
27 * @var int
28 */
29 const MAX_LENGTH = 256;
30
31 /**
32 * Email subject.
33 * @var string
34 */
35 protected $subject;
36
37
38 /**
39 * Constructor
40 *
41 * Executes the validation checks of the email subject.
42 *
43 * @throws InvalidArgumentException If the provided argument is not valid.
44 *
45 * @param string $p_subject E-Mail subject.
46 */
47 public function __construct($p_subject)
48 {
49 if(!is_string($p_subject))
50 {
51 throw new InvalidArgumentException('Invalid argument provided (expected string subject) $p_subject: '
52 . print_r($p_subject, true));
53 }
54
55 if(strlen(trim($p_subject)) > self::MAX_LENGTH)
56 {
57 throw new InvalidArgumentException('Argument exceeded the maximum database field length ('
58 . self::MAX_LENGTH . '):' . $p_subject);
59 }
60
61 $this->subject = $p_subject;
62 }
63
64
65 /**
66 * Returns the email subject value.
67 *
68 * @return string Equivalent string.
69 */
70 public function __toString()
71 {
72 return $this->subject;
73 }
74
75 }