Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/zendframework/zend-mail/src/Header/GenericHeader.php
Строк: 164
<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendMailHeader;

class 
GenericHeader implements HeaderInterfaceUnstructuredInterface
{
    
/**
     * @var string
     */
    
protected $fieldName null;

    
/**
     * @var string
     */
    
protected $fieldValue null;

    
/**
     * Header encoding
     *
     * @var string
     */
    
protected $encoding 'ASCII';

    public static function 
fromString($headerLine)
    {
        
$decodedLine iconv_mime_decode($headerLineICONV_MIME_DECODE_CONTINUE_ON_ERROR'UTF-8');
        list(
$name$value) = GenericHeader::splitHeaderLine($decodedLine);
        
$header = new static($name$value);
        if (
$decodedLine != $headerLine) {
            
$header->setEncoding('UTF-8');
        }
        return 
$header;
    }

    
/**
     * Splits the header line in `name` and `value` parts.
     *
     * @param string $headerLine
     * @return string[] `name` in the first index and `value` in the second.
     * @throws ExceptionInvalidArgumentException If header does not match with the format ``name:value``
     */
    
public static function splitHeaderLine($headerLine)
    {
        
$parts explode(':'$headerLine2);
        if (
count($parts) !== 2) {
            throw new 
ExceptionInvalidArgumentException('Header must match with the format "name:value"');
        }

        
$parts[1] = ltrim($parts[1]);

        return 
$parts;
    }

    
/**
     * Constructor
     *
     * @param string $fieldName  Optional
     * @param string $fieldValue Optional
     */
    
public function __construct($fieldName null$fieldValue null)
    {
        if (
$fieldName) {
            
$this->setFieldName($fieldName);
        }

        if (
$fieldValue) {
            
$this->setFieldValue($fieldValue);
        }
    }

    
/**
     * Set header name
     *
     * @param  string $fieldName
     * @throws ExceptionInvalidArgumentException
     * @return GenericHeader
     */
    
public function setFieldName($fieldName)
    {
        if (!
is_string($fieldName) || empty($fieldName)) {
            throw new 
ExceptionInvalidArgumentException('Header name must be a string');
        }

        
// Pre-filter to normalize valid characters, change underscore to dash
        
$fieldName str_replace(' ''-'ucwords(str_replace(array('_''-'), ' '$fieldName)));

        
// Validate what we have
        
if (!preg_match('/^[x21-x39x3B-x7E]*$/'$fieldName)) {
            throw new 
ExceptionInvalidArgumentException(
                
'Header name must be composed of printable US-ASCII characters, except colon.'
            
);
        }

        
$this->fieldName $fieldName;
        return 
$this;
    }

    public function 
getFieldName()
    {
        return 
$this->fieldName;
    }

    
/**
     * Set header value
     *
     * @param  string $fieldValue
     * @return GenericHeader
     */
    
public function setFieldValue($fieldValue)
    {
        
$fieldValue = (string) $fieldValue;

        if (empty(
$fieldValue) || preg_match('/^s+$/'$fieldValue)) {
            
$fieldValue '';
        }

        
$this->fieldValue $fieldValue;
        return 
$this;
    }

    public function 
getFieldValue($format HeaderInterface::FORMAT_RAW)
    {
        if (
HeaderInterface::FORMAT_ENCODED === $format) {
            return 
HeaderWrap::wrap($this->fieldValue$this);
        }

        return 
$this->fieldValue;
    }

    public function 
setEncoding($encoding)
    {
        
$this->encoding $encoding;
        return 
$this;
    }

    public function 
getEncoding()
    {
        return 
$this->encoding;
    }

    public function 
toString()
    {
        
$name  $this->getFieldName();
        
$value $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);

        return 
$name ': ' $value;
    }
}
Онлайн: 2
Реклама