3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mail\Header
;
12 class Subject
implements UnstructuredInterface
17 protected $subject = '';
24 protected $encoding = 'ASCII';
26 public static function fromString($headerLine)
28 $decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR
, 'UTF-8');
29 list($name, $value) = GenericHeader
::splitHeaderLine($decodedLine);
31 // check to ensure proper header type for this factory
32 if (strtolower($name) !== 'subject') {
33 throw new Exception\
InvalidArgumentException('Invalid header line for Subject string');
36 $header = new static();
37 if ($decodedLine != $headerLine) {
38 $header->setEncoding('UTF-8');
40 $header->setSubject($value);
45 public function getFieldName()
50 public function getFieldValue($format = HeaderInterface
::FORMAT_RAW
)
52 if (HeaderInterface
::FORMAT_ENCODED
=== $format) {
53 return HeaderWrap
::wrap($this->subject
, $this);
56 return $this->subject
;
59 public function setEncoding($encoding)
61 $this->encoding
= $encoding;
65 public function getEncoding()
67 return $this->encoding
;
70 public function setSubject($subject)
72 $this->subject
= (string) $subject;
76 public function toString()
78 return 'Subject: ' . $this->getFieldValue(HeaderInterface
::FORMAT_ENCODED
);