[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/ -> DateHeader.php (source)

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


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1