dolibarr/htdocs/includes/swiftmailer/lib/classes/Swift/Attachment.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2016-04-16 18:15:03 +02:00
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
2018-01-21 15:55:56 +01:00
* Attachment class for attaching files to a {@link Swift_Mime_SimpleMessage}.
2016-04-16 18:15:03 +02:00
*
* @author Chris Corbyn
*/
class Swift_Attachment extends Swift_Mime_Attachment
{
/**
* Create a new Attachment.
*
* Details may be optionally provided to the constructor.
*
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null, $contentType = null)
{
2021-12-07 17:11:34 +01:00
\call_user_func_array(
[$this, 'Swift_Mime_Attachment::__construct'],
2016-04-16 18:15:03 +02:00
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.attachment')
);
2021-12-07 17:11:34 +01:00
$this->setBody($data, $contentType);
2016-04-16 18:15:03 +02:00
$this->setFilename($filename);
}
/**
* Create a new Attachment from a filesystem path.
*
* @param string $path
* @param string $contentType optional
*
2021-12-07 17:11:34 +01:00
* @return self
2016-04-16 18:15:03 +02:00
*/
public static function fromPath($path, $contentType = null)
{
2018-01-21 15:55:56 +01:00
return (new self())->setFile(
2016-04-16 18:15:03 +02:00
new Swift_ByteStream_FileByteStream($path),
$contentType
2018-01-21 15:55:56 +01:00
);
2016-04-16 18:15:03 +02:00
}
}