EmbeddedFile.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * @package Swift
  13. * @subpackage Mime
  14. * @author Chris Corbyn
  15. */
  16. class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
  17. {
  18. /**
  19. * Create a new EmbeddedFile.
  20. *
  21. * Details may be optionally provided to the constructor.
  22. *
  23. * @param string|Swift_OutputByteStream $data
  24. * @param string $filename
  25. * @param string $contentType
  26. */
  27. public function __construct($data = null, $filename = null, $contentType = null)
  28. {
  29. call_user_func_array(
  30. array($this, 'Swift_Mime_EmbeddedFile::__construct'),
  31. Swift_DependencyContainer::getInstance()
  32. ->createDependenciesFor('mime.embeddedfile')
  33. );
  34. $this->setBody($data);
  35. $this->setFilename($filename);
  36. if ($contentType) {
  37. $this->setContentType($contentType);
  38. }
  39. }
  40. /**
  41. * Create a new EmbeddedFile.
  42. *
  43. * @param string|Swift_OutputByteStream $data
  44. * @param string $filename
  45. * @param string $contentType
  46. *
  47. * @return Swift_Mime_EmbeddedFile
  48. */
  49. public static function newInstance($data = null, $filename = null, $contentType = null)
  50. {
  51. return new self($data, $filename, $contentType);
  52. }
  53. /**
  54. * Create a new EmbeddedFile from a filesystem path.
  55. *
  56. * @param string $path
  57. *
  58. * @return Swift_Mime_EmbeddedFile
  59. */
  60. public static function fromPath($path)
  61. {
  62. return self::newInstance()->setFile(
  63. new Swift_ByteStream_FileByteStream($path)
  64. );
  65. }
  66. }