composer package updates
[openemr.git] / vendor / zendframework / zend-mail / src / Header / Received.php
blob706158c73c3e2989eb201b431b52d3ee950b5c1a
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\Mail\Headers;
12 /**
13 * @todo Allow setting date from DateTime, Zend\Date, or string
15 class Received implements HeaderInterface, MultipleHeadersInterface
17 /**
18 * @var string
20 protected $value;
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);
34 return $header;
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()
47 return 'Received';
50 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
52 return $this->value;
55 public function setEncoding($encoding)
57 // This header must be always in US-ASCII
58 return $this;
61 public function getEncoding()
63 return 'ASCII';
66 public function toString()
68 return 'Received: ' . $this->getFieldValue();
71 /**
72 * Serialize collection of Received headers to string
74 * @param array $headers
75 * @throws Exception\RuntimeException
76 * @return string
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);