torrentpier-lts/library/Zend/Mail/Header/GenericMultiHeader.php

57 lines
1.8 KiB
PHP
Raw Normal View History

<?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)
* @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);
if (strpos($fieldValue, ',')) {
$headers = array();
foreach (explode(',', $fieldValue) as $multiValue) {
2023-04-01 09:03:34 +03:00
$headers[] = new static($fieldName, $multiValue);
}
return $headers;
}
2023-04-01 09:03:34 +03:00
return new static($fieldName, $fieldValue);
}
/**
* 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();
$values = array($this->getFieldValue(HeaderInterface::FORMAT_ENCODED));
2023-04-01 09:03:34 +03:00
foreach ($headers as $header) {
2023-04-01 09:03:34 +03:00
if (! $header instanceof static) {
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
return $name . ': ' . implode(',', $values);
}
}