2023-03-11 12:04:29 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Zend Framework (http://framework.zend.com/)
|
|
|
|
*
|
|
|
|
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
2023-04-01 09:03:34 +03:00
|
|
|
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
2023-03-11 12:04:29 +03:00
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Zend\Mail\Header;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic class for Headers with multiple occurs in the same message
|
|
|
|
*/
|
|
|
|
class GenericMultiHeader extends GenericHeader implements MultipleHeadersInterface
|
|
|
|
{
|
|
|
|
public static function fromString($headerLine)
|
|
|
|
{
|
2023-04-01 09:03:34 +03:00
|
|
|
list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
|
|
|
|
$fieldValue = HeaderWrap::mimeDecodeValue($fieldValue);
|
2023-03-11 12:04:29 +03:00
|
|
|
|
|
|
|
if (strpos($fieldValue, ',')) {
|
|
|
|
$headers = array();
|
|
|
|
foreach (explode(',', $fieldValue) as $multiValue) {
|
2023-04-01 09:03:34 +03:00
|
|
|
$headers[] = new static($fieldName, $multiValue);
|
2023-03-11 12:04:29 +03:00
|
|
|
}
|
|
|
|
return $headers;
|
|
|
|
}
|
2023-04-01 09:03:34 +03:00
|
|
|
|
|
|
|
return new static($fieldName, $fieldValue);
|
2023-03-11 12:04:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cast multiple header objects to a single string header
|
|
|
|
*
|
|
|
|
* @param array $headers
|
|
|
|
* @throws Exception\InvalidArgumentException
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function toStringMultipleHeaders(array $headers)
|
|
|
|
{
|
2023-04-01 09:03:34 +03:00
|
|
|
$name = $this->getFieldName();
|
2023-03-11 12:04:29 +03:00
|
|
|
$values = array($this->getFieldValue(HeaderInterface::FORMAT_ENCODED));
|
2023-04-01 09:03:34 +03:00
|
|
|
|
2023-03-11 12:04:29 +03:00
|
|
|
foreach ($headers as $header) {
|
2023-04-01 09:03:34 +03:00
|
|
|
if (! $header instanceof static) {
|
2023-03-11 12:04:29 +03:00
|
|
|
throw new Exception\InvalidArgumentException(
|
|
|
|
'This method toStringMultipleHeaders was expecting an array of headers of the same type'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$values[] = $header->getFieldValue(HeaderInterface::FORMAT_ENCODED);
|
|
|
|
}
|
2023-04-01 09:03:34 +03:00
|
|
|
|
2023-03-11 12:04:29 +03:00
|
|
|
return $name . ': ' . implode(',', $values);
|
|
|
|
}
|
|
|
|
}
|