/framework/vendor/swift/lib/classes/Swift/Attachment.php

http://zoop.googlecode.com/ · PHP · 75 lines · 31 code · 8 blank · 36 comment · 1 complexity · f7f3161cee2f7d9e79cdf295f25a0772 MD5 · raw file

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