[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/ -> Attachment.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   * An attachment, in a multipart message.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
  17  {
  18      /** Recognized MIME types */
  19      private $mimeTypes = [];
  20  
  21      /**
  22       * Create a new Attachment with $headers, $encoder and $cache.
  23       *
  24       * @param array $mimeTypes
  25       */
  26      public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = [])
  27      {
  28          parent::__construct($headers, $encoder, $cache, $idGenerator);
  29          $this->setDisposition('attachment');
  30          $this->setContentType('application/octet-stream');
  31          $this->mimeTypes = $mimeTypes;
  32      }
  33  
  34      /**
  35       * Get the nesting level used for this attachment.
  36       *
  37       * Always returns {@link LEVEL_MIXED}.
  38       *
  39       * @return int
  40       */
  41      public function getNestingLevel()
  42      {
  43          return self::LEVEL_MIXED;
  44      }
  45  
  46      /**
  47       * Get the Content-Disposition of this attachment.
  48       *
  49       * By default attachments have a disposition of "attachment".
  50       *
  51       * @return string
  52       */
  53      public function getDisposition()
  54      {
  55          return $this->getHeaderFieldModel('Content-Disposition');
  56      }
  57  
  58      /**
  59       * Set the Content-Disposition of this attachment.
  60       *
  61       * @param string $disposition
  62       *
  63       * @return $this
  64       */
  65      public function setDisposition($disposition)
  66      {
  67          if (!$this->setHeaderFieldModel('Content-Disposition', $disposition)) {
  68              $this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition);
  69          }
  70  
  71          return $this;
  72      }
  73  
  74      /**
  75       * Get the filename of this attachment when downloaded.
  76       *
  77       * @return string
  78       */
  79      public function getFilename()
  80      {
  81          return $this->getHeaderParameter('Content-Disposition', 'filename');
  82      }
  83  
  84      /**
  85       * Set the filename of this attachment.
  86       *
  87       * @param string $filename
  88       *
  89       * @return $this
  90       */
  91      public function setFilename($filename)
  92      {
  93          $this->setHeaderParameter('Content-Disposition', 'filename', $filename);
  94          $this->setHeaderParameter('Content-Type', 'name', $filename);
  95  
  96          return $this;
  97      }
  98  
  99      /**
 100       * Get the file size of this attachment.
 101       *
 102       * @return int
 103       */
 104      public function getSize()
 105      {
 106          return $this->getHeaderParameter('Content-Disposition', 'size');
 107      }
 108  
 109      /**
 110       * Set the file size of this attachment.
 111       *
 112       * @param int $size
 113       *
 114       * @return $this
 115       */
 116      public function setSize($size)
 117      {
 118          $this->setHeaderParameter('Content-Disposition', 'size', $size);
 119  
 120          return $this;
 121      }
 122  
 123      /**
 124       * Set the file that this attachment is for.
 125       *
 126       * @param string $contentType optional
 127       *
 128       * @return $this
 129       */
 130      public function setFile(Swift_FileStream $file, $contentType = null)
 131      {
 132          $this->setFilename(basename($file->getPath()));
 133          $this->setBody($file, $contentType);
 134          if (!isset($contentType)) {
 135              $extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
 136  
 137              if (array_key_exists($extension, $this->mimeTypes)) {
 138                  $this->setContentType($this->mimeTypes[$extension]);
 139              }
 140          }
 141  
 142          return $this;
 143      }
 144  }


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