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