EmbeddedFile.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. array($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.
  40. *
  41. * @param string|Swift_OutputByteStream $data
  42. * @param string $filename
  43. * @param string $contentType
  44. *
  45. * @return Swift_Mime_EmbeddedFile
  46. */
  47. public static function newInstance($data = null, $filename = null, $contentType = null)
  48. {
  49. return new self($data, $filename, $contentType);
  50. }
  51. /**
  52. * Create a new EmbeddedFile from a filesystem path.
  53. *
  54. * @param string $path
  55. *
  56. * @return Swift_Mime_EmbeddedFile
  57. */
  58. public static function fromPath($path)
  59. {
  60. return self::newInstance()->setFile(
  61. new Swift_ByteStream_FileByteStream($path)
  62. );
  63. }
  64. }