EmbeddedFile.php 1.8KB

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