TYPO3 API  SVNRelease
PathHeader.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This file is part of SwiftMailer.
00005  * (c) 2004-2009 Chris Corbyn
00006  *
00007  * For the full copyright and license information, please view the LICENSE
00008  * file that was distributed with this source code.
00009  */
00010 
00011 //@require 'Swift/Mime/Headers/AbstractHeader.php';
00012 //@require 'Swift/RfcComplianceException.php';
00013 
00014 /**
00015  * A Path Header in Swift Mailer, such a Return-Path.
00016  * @package Swift
00017  * @subpackage Mime
00018  * @author Chris Corbyn
00019  */
00020 class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
00021 {
00022 
00023   /**
00024    * The address in this Header (if specified).
00025    * @var string
00026    * @access private
00027    */
00028   private $_address;
00029 
00030   /**
00031    * Creates a new PathHeader with the given $name.
00032    * @param string $name
00033    */
00034   public function __construct($name)
00035   {
00036     $this->setFieldName($name);
00037     $this->initializeGrammar();
00038   }
00039 
00040   /**
00041    * Get the type of Header that this instance represents.
00042    * @return int
00043    * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
00044    * @see TYPE_DATE, TYPE_ID, TYPE_PATH
00045    */
00046   public function getFieldType()
00047   {
00048     return self::TYPE_PATH;
00049   }
00050 
00051   /**
00052    * Set the model for the field body.
00053    * This method takes a string for an address.
00054    * @param string $model
00055    * @throws Swift_RfcComplianceException
00056    */
00057   public function setFieldBodyModel($model)
00058   {
00059     $this->setAddress($model);
00060   }
00061 
00062   /**
00063    * Get the model for the field body.
00064    * This method returns a string email address.
00065    * @return mixed
00066    */
00067   public function getFieldBodyModel()
00068   {
00069     return $this->getAddress();
00070   }
00071 
00072   /**
00073    * Set the Address which should appear in this Header.
00074    * @param string $address
00075    * @throws Swift_RfcComplianceException
00076    */
00077   public function setAddress($address)
00078   {
00079     if (is_null($address))
00080     {
00081       $this->_address = null;
00082     }
00083     elseif ('' == $address
00084       || preg_match('/^' . $this->getGrammar('addr-spec') . '$/D', $address))
00085     {
00086       $this->_address = $address;
00087     }
00088     else
00089     {
00090       throw new Swift_RfcComplianceException(
00091         'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
00092         );
00093     }
00094     $this->setCachedValue(null);
00095   }
00096 
00097   /**
00098    * Get the address which is used in this Header (if any).
00099    * Null is returned if no address is set.
00100    * @return string
00101    */
00102   public function getAddress()
00103   {
00104     return $this->_address;
00105   }
00106 
00107   /**
00108    * Get the string value of the body in this Header.
00109    * This is not necessarily RFC 2822 compliant since folding white space will
00110    * not be added at this stage (see {@link toString()} for that).
00111    * @return string
00112    * @see toString()
00113    */
00114   public function getFieldBody()
00115   {
00116     if (!$this->getCachedValue())
00117     {
00118       if (isset($this->_address))
00119       {
00120         $this->setCachedValue('<' . $this->_address . '>');
00121       }
00122     }
00123     return $this->getCachedValue();
00124   }
00125 
00126 }