Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/zendframework/zend-mail/src/Header/Sender.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;

use 
ZendMail;

class 
Sender implements HeaderInterface
{
    
/**
     * @var ZendMailAddressAddressInterface
     */
    
protected $address;

    
/**
     * 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);

        
// check to ensure proper header type for this factory
        
if (strtolower($name) !== 'sender') {
            throw new 
ExceptionInvalidArgumentException('Invalid header line for Sender string');
        }

        
$header = new static();
        if (
$decodedLine != $headerLine) {
            
$header->setEncoding('UTF-8');
        }

        
// Check for address, and set if found
        
if (preg_match('/^(?P<name>.*?)<(?P<email>[^>]+)>$/'$value$matches)) {
            
$name $matches['name'];
            if (empty(
$name)) {
                
$name null;
            } else {
                
$name iconv_mime_decode($nameICONV_MIME_DECODE_CONTINUE_ON_ERROR'UTF-8');
            }
            
$header->setAddress($matches['email'], $name);
        }

        return 
$header;
    }

    public function 
getFieldName()
    {
        return 
'Sender';
    }

    public function 
getFieldValue($format HeaderInterface::FORMAT_RAW)
    {
        if (!
$this->address instanceof MailAddressAddressInterface) {
            return 
'';
        }

        
$email sprintf('<%s>'$this->address->getEmail());
        
$name  $this->address->getName();
        if (!empty(
$name)) {
            
$encoding $this->getEncoding();
            if (
$format == HeaderInterface::FORMAT_ENCODED
                
&& 'ASCII' !== $encoding
            
) {
                
$name  HeaderWrap::mimeEncodeValue($name$encoding);
            }
            
$email sprintf('%s %s'$name$email);
        }
        return 
$email;
    }

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

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

    public function 
toString()
    {
        return 
'Sender: ' $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);
    }

    
/**
     * Set the address used in this header
     *
     * @param  string|ZendMailAddressAddressInterface $emailOrAddress
     * @param  null|string $name
     * @throws ExceptionInvalidArgumentException
     * @return Sender
     */
    
public function setAddress($emailOrAddress$name null)
    {
        if (
is_string($emailOrAddress)) {
            
$emailOrAddress = new MailAddress($emailOrAddress$name);
        } elseif (!
$emailOrAddress instanceof MailAddressAddressInterface) {
            throw new 
ExceptionInvalidArgumentException(sprintf(
                
'%s expects a string or AddressInterface object; received "%s"',
                
__METHOD__,
                (
is_object($emailOrAddress) ? get_class($emailOrAddress) : gettype($emailOrAddress))
            ));
        }
        
$this->address $emailOrAddress;
        return 
$this;
    }

    
/**
     * Retrieve the internal address from this header
     *
     * @return ZendMailAddressAddressInterface|null
     */
    
public function getAddress()
    {
        return 
$this->address;
    }
}
Онлайн: 0
Реклама