123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Bridge\Twig\Mime;
- use Symfony\Component\Mime\Address;
- use Twig\Environment;
- /**
- * @internal
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
- final class WrappedTemplatedEmail
- {
- private $twig;
- private $message;
- public function __construct(Environment $twig, TemplatedEmail $message)
- {
- $this->twig = $twig;
- $this->message = $message;
- }
- public function toName(): string
- {
- return $this->message->getTo()[0]->getName();
- }
- public function image(string $image, string $contentType = null): string
- {
- $file = $this->twig->getLoader()->getSourceContext($image);
- if ($path = $file->getPath()) {
- $this->message->embedFromPath($path, $image, $contentType);
- } else {
- $this->message->embed($file->getCode(), $image, $contentType);
- }
- return 'cid:'.$image;
- }
- public function attach(string $file, string $name = null, string $contentType = null): void
- {
- $file = $this->twig->getLoader()->getSourceContext($file);
- if ($path = $file->getPath()) {
- $this->message->attachFromPath($path, $name, $contentType);
- } else {
- $this->message->attach($file->getCode(), $name, $contentType);
- }
- }
- /**
- * @return $this
- */
- public function setSubject(string $subject): self
- {
- $this->message->subject($subject);
- return $this;
- }
- public function getSubject(): ?string
- {
- return $this->message->getSubject();
- }
- /**
- * @return $this
- */
- public function setReturnPath(string $address): self
- {
- $this->message->returnPath($address);
- return $this;
- }
- public function getReturnPath(): string
- {
- return $this->message->getReturnPath();
- }
- /**
- * @return $this
- */
- public function addFrom(string $address, string $name = ''): self
- {
- $this->message->addFrom(new Address($address, $name));
- return $this;
- }
- /**
- * @return Address[]
- */
- public function getFrom(): array
- {
- return $this->message->getFrom();
- }
- /**
- * @return $this
- */
- public function addReplyTo(string $address): self
- {
- $this->message->addReplyTo($address);
- return $this;
- }
- /**
- * @return Address[]
- */
- public function getReplyTo(): array
- {
- return $this->message->getReplyTo();
- }
- /**
- * @return $this
- */
- public function addTo(string $address, string $name = ''): self
- {
- $this->message->addTo(new Address($address, $name));
- return $this;
- }
- /**
- * @return Address[]
- */
- public function getTo(): array
- {
- return $this->message->getTo();
- }
- /**
- * @return $this
- */
- public function addCc(string $address, string $name = ''): self
- {
- $this->message->addCc(new Address($address, $name));
- return $this;
- }
- /**
- * @return Address[]
- */
- public function getCc(): array
- {
- return $this->message->getCc();
- }
- /**
- * @return $this
- */
- public function addBcc(string $address, string $name = ''): self
- {
- $this->message->addBcc(new Address($address, $name));
- return $this;
- }
- /**
- * @return Address[]
- */
- public function getBcc(): array
- {
- return $this->message->getBcc();
- }
- /**
- * @return $this
- */
- public function setPriority(int $priority): self
- {
- $this->message->setPriority($priority);
- return $this;
- }
- public function getPriority(): int
- {
- return $this->message->getPriority();
- }
- }
|