composer package updates
[openemr.git] / vendor / zendframework / zend-mail / src / Header / Subject.php
blobdf962c299efd324a6119c8afa4d5429fe659dfed
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-mail for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Mail\Header;
10 use Zend\Mime\Mime;
12 /**
13 * Subject header class methods.
15 * @see https://tools.ietf.org/html/rfc2822 RFC 2822
16 * @see https://tools.ietf.org/html/rfc2047 RFC 2047
18 class Subject implements UnstructuredInterface
20 /**
21 * @var string
23 protected $subject = '';
25 /**
26 * Header encoding
28 * @var null|string
30 protected $encoding;
32 public static function fromString($headerLine)
34 list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
35 $value = HeaderWrap::mimeDecodeValue($value);
37 // check to ensure proper header type for this factory
38 if (strtolower($name) !== 'subject') {
39 throw new Exception\InvalidArgumentException('Invalid header line for Subject string');
42 $header = new static();
43 $header->setSubject($value);
45 return $header;
48 public function getFieldName()
50 return 'Subject';
53 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
55 if (HeaderInterface::FORMAT_ENCODED === $format) {
56 return HeaderWrap::wrap($this->subject, $this);
59 return $this->subject;
62 public function setEncoding($encoding)
64 $this->encoding = $encoding;
65 return $this;
68 public function getEncoding()
70 if (! $this->encoding) {
71 $this->encoding = Mime::isPrintable($this->subject) ? 'ASCII' : 'UTF-8';
74 return $this->encoding;
77 public function setSubject($subject)
79 $subject = (string) $subject;
81 if (! HeaderWrap::canBeEncoded($subject)) {
82 throw new Exception\InvalidArgumentException(
83 'Subject value must be composed of printable US-ASCII or UTF-8 characters.'
87 $this->subject = $subject;
88 $this->encoding = null;
90 return $this;
93 public function toString()
95 return 'Subject: ' . $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);