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
8 namespace Zend\Mail\Header
;
10 use Zend\Mail\Headers
;
13 * @todo Allow setting date from DateTime, Zend\Date, or string
15 class Received
implements HeaderInterface
, MultipleHeadersInterface
22 public static function fromString($headerLine)
24 list($name, $value) = GenericHeader
::splitHeaderLine($headerLine);
25 $value = HeaderWrap
::mimeDecodeValue($value);
27 // check to ensure proper header type for this factory
28 if (strtolower($name) !== 'received') {
29 throw new Exception\
InvalidArgumentException('Invalid header line for Received string');
32 $header = new static($value);
37 public function __construct($value = '')
39 if (! HeaderValue
::isValid($value)) {
40 throw new Exception\
InvalidArgumentException('Invalid Received value provided');
42 $this->value
= $value;
45 public function getFieldName()
50 public function getFieldValue($format = HeaderInterface
::FORMAT_RAW
)
55 public function setEncoding($encoding)
57 // This header must be always in US-ASCII
61 public function getEncoding()
66 public function toString()
68 return 'Received: ' . $this->getFieldValue();
72 * Serialize collection of Received headers to string
74 * @param array $headers
75 * @throws Exception\RuntimeException
78 public function toStringMultipleHeaders(array $headers)
80 $strings = [$this->toString()];
81 foreach ($headers as $header) {
82 if (! $header instanceof Received
) {
83 throw new Exception\
RuntimeException(
84 'The Received multiple header implementation can only accept an array of Received headers'
87 $strings[] = $header->toString();
89 return implode(Headers
::EOL
, $strings);