Attachment.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * Attachment class for attaching files to a {@link Swift_Mime_SimpleMessage}.
  11. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_Attachment extends Swift_Mime_Attachment
  15. {
  16. /**
  17. * Create a new Attachment.
  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_Attachment::__construct'],
  29. Swift_DependencyContainer::getInstance()
  30. ->createDependenciesFor('mime.attachment')
  31. );
  32. $this->setBody($data, $contentType);
  33. $this->setFilename($filename);
  34. }
  35. /**
  36. * Create a new Attachment from a filesystem path.
  37. *
  38. * @param string $path
  39. * @param string $contentType optional
  40. *
  41. * @return self
  42. */
  43. public static function fromPath($path, $contentType = null)
  44. {
  45. return (new self())->setFile(
  46. new Swift_ByteStream_FileByteStream($path),
  47. $contentType
  48. );
  49. }
  50. }