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