/framework/vendor/swift/lib/classes/Swift/Mime/Headers/DateHeader.php

http://zoop.googlecode.com/ · PHP · 118 lines · 45 code · 13 blank · 60 comment · 4 complexity · 0547d0e371b2dc1d33bfd5d3f227398d MD5 · raw file

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