PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/extensions/swiftmailer/lib/classes/Swift/Mime/Headers/DateHeader.php

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