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 use Zend\Mail\Headers
;
15 * @todo Allow setting date from DateTime, Zend\Date, or string
17 class Received
implements HeaderInterface
, MultipleHeadersInterface
24 public static function fromString($headerLine)
26 list($name, $value) = GenericHeader
::splitHeaderLine($headerLine);
28 // check to ensure proper header type for this factory
29 if (strtolower($name) !== 'received') {
30 throw new Exception\
InvalidArgumentException('Invalid header line for Received string');
33 $header = new static($value);
38 public function __construct($value = '')
40 $this->value
= $value;
43 public function getFieldName()
48 public function getFieldValue($format = HeaderInterface
::FORMAT_RAW
)
53 public function setEncoding($encoding)
55 // This header must be always in US-ASCII
59 public function getEncoding()
64 public function toString()
66 return 'Received: ' . $this->getFieldValue();
70 * Serialize collection of Received headers to string
72 * @param array $headers
73 * @throws Exception\RuntimeException
76 public function toStringMultipleHeaders(array $headers)
78 $strings = array($this->toString());
79 foreach ($headers as $header) {
80 if (!$header instanceof Received
) {
81 throw new Exception\
RuntimeException(
82 'The Received multiple header implementation can only accept an array of Received headers'
85 $strings[] = $header->toString();
87 return implode(Headers
::EOL
, $strings);