[ Index ]

MailPress 544

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

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/Mime/Headers/ -> PathHeader.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 Path Header in Swift Mailer, such a Return-Path.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
  17  {
  18      /**
  19       * The address in this Header (if specified).
  20       *
  21       * @var string
  22       */
  23      private $_address;
  24  
  25      /**
  26       * Creates a new PathHeader with the given $name.
  27       *
  28       * @param string             $name
  29       * @param Swift_Mime_Grammar $grammar
  30       */
  31      public function __construct($name, Swift_Mime_Grammar $grammar)
  32      {
  33          $this->setFieldName($name);
  34          parent::__construct($grammar);
  35      }
  36  
  37      /**
  38       * Get the type of Header that this instance represents.
  39       *
  40       * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
  41       * @see TYPE_DATE, TYPE_ID, TYPE_PATH
  42       *
  43       * @return int
  44       */
  45      public function getFieldType()
  46      {
  47          return self::TYPE_PATH;
  48      }
  49  
  50      /**
  51       * Set the model for the field body.
  52       * This method takes a string for an address.
  53       *
  54       * @param string $model
  55       *
  56       * @throws Swift_RfcComplianceException
  57       */
  58      public function setFieldBodyModel($model)
  59      {
  60          $this->setAddress($model);
  61      }
  62  
  63      /**
  64       * Get the model for the field body.
  65       * This method returns a string email address.
  66       *
  67       * @return mixed
  68       */
  69      public function getFieldBodyModel()
  70      {
  71          return $this->getAddress();
  72      }
  73  
  74      /**
  75       * Set the Address which should appear in this Header.
  76       *
  77       * @param string $address
  78       *
  79       * @throws Swift_RfcComplianceException
  80       */
  81      public function setAddress($address)
  82      {
  83          if (is_null($address)) {
  84              $this->_address = null;
  85          } elseif ('' == $address) {
  86              $this->_address = '';
  87          } else {
  88              $this->_assertValidAddress($address);
  89              $this->_address = $address;
  90          }
  91          $this->setCachedValue(null);
  92      }
  93  
  94      /**
  95       * Get the address which is used in this Header (if any).
  96       *
  97       * Null is returned if no address is set.
  98       *
  99       * @return string
 100       */
 101      public function getAddress()
 102      {
 103          return $this->_address;
 104      }
 105  
 106      /**
 107       * Get the string value of the body in this Header.
 108       *
 109       * This is not necessarily RFC 2822 compliant since folding white space will
 110       * not be added at this stage (see {@link toString()} for that).
 111       *
 112       * @see toString()
 113       *
 114       * @return string
 115       */
 116      public function getFieldBody()
 117      {
 118          if (!$this->getCachedValue()) {
 119              if (isset($this->_address)) {
 120                  $this->setCachedValue('<'.$this->_address.'>');
 121              }
 122          }
 123  
 124          return $this->getCachedValue();
 125      }
 126  
 127      /**
 128       * Throws an Exception if the address passed does not comply with RFC 2822.
 129       *
 130       * @param string $address
 131       *
 132       * @throws Swift_RfcComplianceException If address is invalid
 133       */
 134      private function _assertValidAddress($address)
 135      {
 136          if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
 137              $address)) {
 138              throw new Swift_RfcComplianceException(
 139                  'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
 140                  );
 141          }
 142      }
 143  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1