TYPO3 API  SVNRelease
Attachment.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This file is part of SwiftMailer.
00005  * (c) 2004-2009 Chris Corbyn
00006  *
00007  * For the full copyright and license information, please view the LICENSE
00008  * file that was distributed with this source code.
00009  */
00010 
00011 //@require 'Swift/Mime/Attachment.php';
00012 //@require 'Swift/ByteStream/FileByteStream.php';
00013 //@require 'Swift/DependencyContainer.php';
00014 
00015 /**
00016  * Attachment class for attaching files to a {@link Swift_Mime_Message}.
00017  * @package Swift
00018  * @subpackage Mime
00019  * @author Chris Corbyn
00020  */
00021 class Swift_Attachment extends Swift_Mime_Attachment
00022 {
00023 
00024   /**
00025    * Create a new Attachment.
00026    * Details may be optionally provided to the constructor.
00027    * @param string|Swift_OutputByteStream $data
00028    * @param string $filename
00029    * @param string $contentType
00030    */
00031   public function __construct($data = null, $filename = null,
00032     $contentType = null)
00033   {
00034     call_user_func_array(
00035       array($this, 'Swift_Mime_Attachment::__construct'),
00036       Swift_DependencyContainer::getInstance()
00037         ->createDependenciesFor('mime.attachment')
00038       );
00039 
00040     $this->setBody($data);
00041     $this->setFilename($filename);
00042     if ($contentType)
00043     {
00044       $this->setContentType($contentType);
00045     }
00046   }
00047 
00048   /**
00049    * Create a new Attachment.
00050    * @param string|Swift_OutputByteStream $data
00051    * @param string $filename
00052    * @param string $contentType
00053    * @return Swift_Mime_Attachment
00054    */
00055   public static function newInstance($data = null, $filename = null,
00056     $contentType = null)
00057   {
00058     return new self($data, $filename, $contentType);
00059   }
00060 
00061   /**
00062    * Create a new Attachment from a filesystem path.
00063    * @param string $path
00064    * @param string $contentType optional
00065    * @return Swift_Mime_Attachment
00066    */
00067   public static function fromPath($path, $contentType = null)
00068   {
00069     return self::newInstance()->setFile(
00070       new Swift_ByteStream_FileByteStream($path),
00071       $contentType
00072       );
00073   }
00074 
00075 }