/framework/vendor/swift/lib/classes/Swift/Mime/Headers/DateHeader.php
PHP | 118 lines | 45 code | 13 blank | 60 comment | 4 complexity | 0547d0e371b2dc1d33bfd5d3f227398d MD5 | raw file
1<?php 2 3/* 4 * This file is part of SwiftMailer. 5 * (c) 2004-2009 Chris Corbyn 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11//@require 'Swift/Mime/Headers/AbstractHeader.php'; 12 13 14/** 15 * A Date MIME Header for Swift Mailer. 16 * @package Swift 17 * @subpackage Mime 18 * @author Chris Corbyn 19 */ 20class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader 21{ 22 23 /** 24 * The UNIX timestamp value of this Header. 25 * @var int 26 * @access private 27 */ 28 private $_timestamp; 29 30 /** 31 * Creates a new DateHeader with $name and $timestamp. 32 * Example: 33 * <code> 34 * <?php 35 * $header = new Swift_Mime_Headers_DateHeader('Date', time()); 36 * ?> 37 * </code> 38 * @param string $name of Header 39 */ 40 public function __construct($name) 41 { 42 $this->setFieldName($name); 43 } 44 45 /** 46 * Get the type of Header that this instance represents. 47 * @return int 48 * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX 49 * @see TYPE_DATE, TYPE_ID, TYPE_PATH 50 */ 51 public function getFieldType() 52 { 53 return self::TYPE_DATE; 54 } 55 56 /** 57 * Set the model for the field body. 58 * This method takes a UNIX timestamp. 59 * @param int $model 60 */ 61 public function setFieldBodyModel($model) 62 { 63 $this->setTimestamp($model); 64 } 65 66 /** 67 * Get the model for the field body. 68 * This method returns a UNIX timestamp. 69 * @return mixed 70 */ 71 public function getFieldBodyModel() 72 { 73 return $this->getTimestamp(); 74 } 75 76 /** 77 * Get the UNIX timestamp of the Date in this Header. 78 * @return int 79 */ 80 public function getTimestamp() 81 { 82 return $this->_timestamp; 83 } 84 85 /** 86 * Set the UNIX timestamp of the Date in this Header. 87 * @param int $timestamp 88 */ 89 public function setTimestamp($timestamp) 90 { 91 if (!is_null($timestamp)) 92 { 93 $timestamp = (int) $timestamp; 94 } 95 $this->clearCachedValueIf($this->_timestamp != $timestamp); 96 $this->_timestamp = $timestamp; 97 } 98 99 /** 100 * Get the string value of the body in this Header. 101 * This is not necessarily RFC 2822 compliant since folding white space will 102 * not be added at this stage (see {@link toString()} for that). 103 * @return string 104 * @see toString() 105 */ 106 public function getFieldBody() 107 { 108 if (!$this->getCachedValue()) 109 { 110 if (isset($this->_timestamp)) 111 { 112 $this->setCachedValue(date('r', $this->_timestamp)); 113 } 114 } 115 return $this->getCachedValue(); 116 } 117 118}