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