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
|
32 |
|
public function __construct($data = null, $filename = null, $contentType = null) |
28
|
|
|
{ |
29
|
32 |
|
call_user_func_array( |
30
|
32 |
|
array($this, 'Swift_Mime_Attachment::__construct'), |
31
|
32 |
|
Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.attachment') |
32
|
32 |
|
); |
33
|
|
|
|
34
|
32 |
|
$this->setBody($data); |
35
|
32 |
|
$this->setFilename($filename); |
36
|
32 |
|
if ($contentType) { |
|
|
|
|
37
|
1 |
|
$this->setContentType($contentType); |
38
|
1 |
|
} |
39
|
32 |
|
} |
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
|
|
|
public static function newInstance($data = null, $filename = null, $contentType = null) |
51
|
|
|
{ |
52
|
|
|
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
|
10 |
|
public static function fromPath($path, $contentType = null) |
64
|
|
|
{ |
65
|
10 |
|
$self = new self(); |
66
|
10 |
|
return $self->setFile( |
67
|
10 |
|
new Swift_ByteStream_FileByteStream($path), |
68
|
|
|
$contentType |
69
|
9 |
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.