1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
18: {
19:
20: private $_mimeTypes = array();
21:
22: 23: 24: 25: 26: 27: 28: 29:
30: public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $mimeTypes = array())
31: {
32: parent::__construct($headers, $encoder, $cache, $grammar);
33: $this->setDisposition('attachment');
34: $this->setContentType('application/octet-stream');
35: $this->_mimeTypes = $mimeTypes;
36: }
37:
38: 39: 40: 41: 42:
43: public function getNestingLevel()
44: {
45: return self::LEVEL_MIXED;
46: }
47:
48: 49: 50: 51: 52:
53: public function getDisposition()
54: {
55: return $this->_getHeaderFieldModel('Content-Disposition');
56: }
57:
58: 59: 60: 61: 62:
63: public function setDisposition($disposition)
64: {
65: if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition)) {
66: $this->getHeaders()->addParameterizedHeader(
67: 'Content-Disposition', $disposition
68: );
69: }
70:
71: return $this;
72: }
73:
74: 75: 76: 77:
78: public function getFilename()
79: {
80: return $this->_getHeaderParameter('Content-Disposition', 'filename');
81: }
82:
83: 84: 85: 86: 87:
88: public function setFilename($filename)
89: {
90: $this->_setHeaderParameter('Content-Disposition', 'filename', $filename);
91: $this->_setHeaderParameter('Content-Type', 'name', $filename);
92:
93: return $this;
94: }
95:
96: 97: 98: 99:
100: public function getSize()
101: {
102: return $this->_getHeaderParameter('Content-Disposition', 'size');
103: }
104:
105: 106: 107: 108: 109:
110: public function setSize($size)
111: {
112: $this->_setHeaderParameter('Content-Disposition', 'size', $size);
113:
114: return $this;
115: }
116:
117: 118: 119: 120: 121: 122:
123: public function setFile(Swift_FileStream $file, $contentType = null)
124: {
125: $this->setFilename(basename($file->getPath()));
126: $this->setBody($file, $contentType);
127: if (!isset($contentType)) {
128: $extension = strtolower(substr(
129: $file->getPath(), strrpos($file->getPath(), '.') + 1
130: ));
131:
132: if (array_key_exists($extension, $this->_mimeTypes)) {
133: $this->setContentType($this->_mimeTypes[$extension]);
134: }
135: }
136:
137: return $this;
138: }
139: }
140: