XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
Attachment.php
Go to the documentation of this file.
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 //@require 'Swift/Mime/SimpleMimeEntity.php';
12 //@require 'Swift/Mime/ContentEncoder.php';
13 //@require 'Swift/Mime/HeaderSet.php';
14 //@require 'Swift/FileStream.php';
15 //@require 'Swift/KeyCache.php';
16 
24 {
25 
27  private $_mimeTypes = array();
28 
36  public function __construct(Swift_Mime_HeaderSet $headers,
38  $mimeTypes = array())
39  {
40  parent::__construct($headers, $encoder, $cache);
41  $this->setDisposition('attachment');
42  $this->setContentType('application/octet-stream');
43  $this->_mimeTypes = $mimeTypes;
44  }
45 
51  public function getNestingLevel()
52  {
53  return self::LEVEL_MIXED;
54  }
55 
61  public function getDisposition()
62  {
63  return $this->_getHeaderFieldModel('Content-Disposition');
64  }
65 
70  public function setDisposition($disposition)
71  {
72  if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition))
73  {
74  $this->getHeaders()->addParameterizedHeader(
75  'Content-Disposition', $disposition
76  );
77  }
78  return $this;
79  }
80 
85  public function getFilename()
86  {
87  return $this->_getHeaderParameter('Content-Disposition', 'filename');
88  }
89 
94  public function setFilename($filename)
95  {
96  $this->_setHeaderParameter('Content-Disposition', 'filename', $filename);
97  $this->_setHeaderParameter('Content-Type', 'name', $filename);
98  return $this;
99  }
100 
105  public function getSize()
106  {
107  return $this->_getHeaderParameter('Content-Disposition', 'size');
108  }
109 
114  public function setSize($size)
115  {
116  $this->_setHeaderParameter('Content-Disposition', 'size', $size);
117  return $this;
118  }
119 
125  public function setFile(Swift_FileStream $file, $contentType = null)
126  {
127  $this->setFilename(basename($file->getPath()));
128  $this->setBody($file, $contentType);
129  if (!isset($contentType))
130  {
131  $extension = strtolower(substr(
132  $file->getPath(), strrpos($file->getPath(), '.') + 1
133  ));
134 
135  if (array_key_exists($extension, $this->_mimeTypes))
136  {
137  $this->setContentType($this->_mimeTypes[$extension]);
138  }
139  }
140  return $this;
141  }
142 
143 }