EmbeddedFile.php 1.6KB

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