EmbeddedFile.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * An embedded file, in a multipart message.
  11. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
  15. {
  16. /**
  17. * Create a new EmbeddedFile.
  18. *
  19. * Details may be optionally provided to the constructor.
  20. *
  21. * @param string|Swift_OutputByteStream $data
  22. * @param string $filename
  23. * @param string $contentType
  24. */
  25. public function __construct($data = null, $filename = null, $contentType = null)
  26. {
  27. \call_user_func_array(
  28. [$this, 'Swift_Mime_EmbeddedFile::__construct'],
  29. Swift_DependencyContainer::getInstance()
  30. ->createDependenciesFor('mime.embeddedfile')
  31. );
  32. $this->setBody($data);
  33. $this->setFilename($filename);
  34. if ($contentType) {
  35. $this->setContentType($contentType);
  36. }
  37. }
  38. /**
  39. * Create a new EmbeddedFile from a filesystem path.
  40. *
  41. * @param string $path
  42. *
  43. * @return Swift_Mime_EmbeddedFile
  44. */
  45. public static function fromPath($path)
  46. {
  47. return (new self())->setFile(new Swift_ByteStream_FileByteStream($path));
  48. }
  49. }