TYPO3 API  SVNRelease
DateHeader.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 
00013 
00014 /**
00015  * A Date MIME Header for Swift Mailer.
00016  * @package Swift
00017  * @subpackage Mime
00018  * @author Chris Corbyn
00019  */
00020 class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
00021 {
00022 
00023   /**
00024    * The UNIX timestamp value of this Header.
00025    * @var int
00026    * @access private
00027    */
00028   private $_timestamp;
00029 
00030   /**
00031    * Creates a new DateHeader with $name and $timestamp.
00032    * Example:
00033    * <code>
00034    * <?php
00035    * $header = new Swift_Mime_Headers_DateHeader('Date', time());
00036    * ?>
00037    * </code>
00038    * @param string $name of Header
00039    */
00040   public function __construct($name)
00041   {
00042     $this->setFieldName($name);
00043   }
00044 
00045   /**
00046    * Get the type of Header that this instance represents.
00047    * @return int
00048    * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
00049    * @see TYPE_DATE, TYPE_ID, TYPE_PATH
00050    */
00051   public function getFieldType()
00052   {
00053     return self::TYPE_DATE;
00054   }
00055 
00056   /**
00057    * Set the model for the field body.
00058    * This method takes a UNIX timestamp.
00059    * @param int $model
00060    */
00061   public function setFieldBodyModel($model)
00062   {
00063     $this->setTimestamp($model);
00064   }
00065 
00066   /**
00067    * Get the model for the field body.
00068    * This method returns a UNIX timestamp.
00069    * @return mixed
00070    */
00071   public function getFieldBodyModel()
00072   {
00073     return $this->getTimestamp();
00074   }
00075 
00076   /**
00077    * Get the UNIX timestamp of the Date in this Header.
00078    * @return int
00079    */
00080   public function getTimestamp()
00081   {
00082     return $this->_timestamp;
00083   }
00084 
00085   /**
00086    * Set the UNIX timestamp of the Date in this Header.
00087    * @param int $timestamp
00088    */
00089   public function setTimestamp($timestamp)
00090   {
00091     if (!is_null($timestamp))
00092     {
00093       $timestamp = (int) $timestamp;
00094     }
00095     $this->clearCachedValueIf($this->_timestamp != $timestamp);
00096     $this->_timestamp = $timestamp;
00097   }
00098 
00099   /**
00100    * Get the string value of the body in this Header.
00101    * This is not necessarily RFC 2822 compliant since folding white space will
00102    * not be added at this stage (see {@link toString()} for that).
00103    * @return string
00104    * @see toString()
00105    */
00106   public function getFieldBody()
00107   {
00108     if (!$this->getCachedValue())
00109     {
00110       if (isset($this->_timestamp))
00111       {
00112         $this->setCachedValue(date('r', $this->_timestamp));
00113       }
00114     }
00115     return $this->getCachedValue();
00116   }
00117 
00118 }