AbstractPart.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Mime\Part;
  11. use Symfony\Component\Mime\Header\Headers;
  12. /**
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. */
  15. abstract class AbstractPart
  16. {
  17. private $headers;
  18. public function __construct()
  19. {
  20. $this->headers = new Headers();
  21. }
  22. public function getHeaders(): Headers
  23. {
  24. return $this->headers;
  25. }
  26. public function getPreparedHeaders(): Headers
  27. {
  28. $headers = clone $this->headers;
  29. $headers->setHeaderBody('Parameterized', 'Content-Type', $this->getMediaType().'/'.$this->getMediaSubtype());
  30. return $headers;
  31. }
  32. public function toString(): string
  33. {
  34. return $this->getPreparedHeaders()->toString()."\r\n".$this->bodyToString();
  35. }
  36. public function toIterable(): iterable
  37. {
  38. yield $this->getPreparedHeaders()->toString();
  39. yield "\r\n";
  40. yield from $this->bodyToIterable();
  41. }
  42. public function asDebugString(): string
  43. {
  44. return $this->getMediaType().'/'.$this->getMediaSubtype();
  45. }
  46. abstract public function bodyToString(): string;
  47. abstract public function bodyToIterable(): iterable;
  48. abstract public function getMediaType(): string;
  49. abstract public function getMediaSubtype(): string;
  50. }