123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
-
-
-
-
-
- class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
- {
-
-
- private $_mimeTypes = array();
-
-
-
- public function __construct(Swift_Mime_HeaderSet $headers,
- Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache,
- Swift_Mime_Grammar $grammar, $mimeTypes = array())
- {
- parent::__construct($headers, $encoder, $cache, $grammar);
- $this->setDisposition('attachment');
- $this->setContentType('application/octet-stream');
- $this->_mimeTypes = $mimeTypes;
- }
-
-
-
- public function getNestingLevel()
- {
- return self::LEVEL_MIXED;
- }
-
-
-
- public function getDisposition()
- {
- return $this->_getHeaderFieldModel('Content-Disposition');
- }
-
-
-
- public function setDisposition($disposition)
- {
- if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition))
- {
- $this->getHeaders()->addParameterizedHeader(
- 'Content-Disposition', $disposition
- );
- }
- return $this;
- }
-
-
-
- public function getFilename()
- {
- return $this->_getHeaderParameter('Content-Disposition', 'filename');
- }
-
-
-
- public function setFilename($filename)
- {
- $this->_setHeaderParameter('Content-Disposition', 'filename', $filename);
- $this->_setHeaderParameter('Content-Type', 'name', $filename);
- return $this;
- }
-
-
-
- public function getSize()
- {
- return $this->_getHeaderParameter('Content-Disposition', 'size');
- }
-
-
-
- public function setSize($size)
- {
- $this->_setHeaderParameter('Content-Disposition', 'size', $size);
- return $this;
- }
-
-
-
- public function setFile(Swift_FileStream $file, $contentType = null)
- {
- $this->setFilename(basename($file->getPath()));
- $this->setBody($file, $contentType);
- if (!isset($contentType))
- {
- $extension = strtolower(substr(
- $file->getPath(), strrpos($file->getPath(), '.') + 1
- ));
-
- if (array_key_exists($extension, $this->_mimeTypes))
- {
- $this->setContentType($this->_mimeTypes[$extension]);
- }
- }
- return $this;
- }
-
- }
|