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: * @package Swift
14: * @subpackage Mime
15: * @author Chris Corbyn
16: */
17: class Swift_Attachment extends Swift_Mime_Attachment
18: {
19: /**
20: * Create a new Attachment.
21: * Details may be optionally provided to the constructor.
22: * @param string|Swift_OutputByteStream $data
23: * @param string $filename
24: * @param string $contentType
25: */
26: public function __construct($data = null, $filename = null, $contentType = null)
27: {
28: call_user_func_array(
29: array($this, 'Swift_Mime_Attachment::__construct'),
30: Swift_DependencyContainer::getInstance()
31: ->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: * @param string|Swift_OutputByteStream $data
44: * @param string $filename
45: * @param string $contentType
46: * @return Swift_Mime_Attachment
47: */
48: public static function newInstance($data = null, $filename = null, $contentType = null)
49: {
50: return new self($data, $filename, $contentType);
51: }
52:
53: /**
54: * Create a new Attachment from a filesystem path.
55: * @param string $path
56: * @param string $contentType optional
57: * @return Swift_Mime_Attachment
58: */
59: public static function fromPath($path, $contentType = null)
60: {
61: return self::newInstance()->setFile(
62: new Swift_ByteStream_FileByteStream($path),
63: $contentType
64: );
65: }
66: }
67: