TemplatedEmail.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Bridge\Twig\Mime;
  11. use Symfony\Component\Mime\Email;
  12. /**
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. */
  15. class TemplatedEmail extends Email
  16. {
  17. private $htmlTemplate;
  18. private $textTemplate;
  19. private $context = [];
  20. /**
  21. * @return $this
  22. */
  23. public function textTemplate(?string $template)
  24. {
  25. $this->textTemplate = $template;
  26. return $this;
  27. }
  28. /**
  29. * @return $this
  30. */
  31. public function htmlTemplate(?string $template)
  32. {
  33. $this->htmlTemplate = $template;
  34. return $this;
  35. }
  36. public function getTextTemplate(): ?string
  37. {
  38. return $this->textTemplate;
  39. }
  40. public function getHtmlTemplate(): ?string
  41. {
  42. return $this->htmlTemplate;
  43. }
  44. /**
  45. * @return $this
  46. */
  47. public function context(array $context)
  48. {
  49. $this->context = $context;
  50. return $this;
  51. }
  52. public function getContext(): array
  53. {
  54. return $this->context;
  55. }
  56. /**
  57. * @internal
  58. */
  59. public function __serialize(): array
  60. {
  61. return [$this->htmlTemplate, $this->textTemplate, $this->context, parent::__serialize()];
  62. }
  63. /**
  64. * @internal
  65. */
  66. public function __unserialize(array $data): void
  67. {
  68. [$this->htmlTemplate, $this->textTemplate, $this->context, $parentData] = $data;
  69. parent::__unserialize($parentData);
  70. }
  71. }