|
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
|
|
|
* Attachment class for attaching files to a {@link Swift_Mime_Message}. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Chris Corbyn |
|
15
|
|
|
*/ |
|
16
|
|
|
class Swift_Attachment extends Swift_Mime_Attachment |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Create a new Attachment. |
|
20
|
|
|
* |
|
21
|
|
|
* Details may be optionally provided to the constructor. |
|
22
|
|
|
* |
|
23
|
|
|
* @param string|Swift_OutputByteStream $data |
|
24
|
|
|
* @param string $filename |
|
25
|
|
|
* @param string $contentType |
|
26
|
|
|
*/ |
|
27
|
6 |
|
public function __construct($data = null, $filename = null, $contentType = null) |
|
28
|
|
|
{ |
|
29
|
|
|
call_user_func_array( |
|
30
|
6 |
|
array($this, 'Swift_Mime_Attachment::__construct'), |
|
31
|
6 |
|
Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.attachment') |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$this->setBody($data); |
|
35
|
|
|
$this->setFilename($filename); |
|
36
|
|
|
if ($contentType) { |
|
|
|
|
|
|
37
|
|
|
$this->setContentType($contentType); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Create a new Attachment. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string|Swift_OutputByteStream $data |
|
45
|
|
|
* @param string $filename |
|
46
|
|
|
* @param string $contentType |
|
47
|
|
|
* |
|
48
|
|
|
* @return Swift_Mime_Attachment |
|
49
|
|
|
*/ |
|
50
|
6 |
|
public static function newInstance($data = null, $filename = null, $contentType = null) |
|
51
|
|
|
{ |
|
52
|
6 |
|
return new self($data, $filename, $contentType); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Create a new Attachment from a filesystem path. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $path |
|
59
|
|
|
* @param string $contentType optional |
|
60
|
|
|
* |
|
61
|
|
|
* @return Swift_Mime_Attachment |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function fromPath($path, $contentType = null) |
|
64
|
|
|
{ |
|
65
|
|
|
return self::newInstance()->setFile( |
|
66
|
|
|
new Swift_ByteStream_FileByteStream($path), |
|
67
|
|
|
$contentType |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.