vendor/coreshop/pimcore-bundle/Mail/MailProcessor.php line 21

Open in your IDE?
  1. <?php
  2. /**
  3.  * CoreShop.
  4.  *
  5.  * This source file is subject to the GNU General Public License version 3 (GPLv3)
  6.  * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
  7.  * files that are distributed with this source code.
  8.  *
  9.  * @copyright  Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
  10.  * @license    https://www.coreshop.org/license     GNU General Public License version 3 (GPLv3)
  11.  */
  12. namespace CoreShop\Bundle\PimcoreBundle\Mail;
  13. use CoreShop\Bundle\PimcoreBundle\Event\MailEvent;
  14. use CoreShop\Bundle\PimcoreBundle\Events;
  15. use CoreShop\Component\Pimcore\Mail;
  16. use Pimcore\Model\Document\Email;
  17. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  18. final class MailProcessor implements MailProcessorInterface
  19. {
  20.     /**
  21.      * @var EventDispatcherInterface
  22.      */
  23.     private $eventDispatcher;
  24.     /**
  25.      * @param EventDispatcherInterface $eventDispatcher
  26.      */
  27.     public function __construct(EventDispatcherInterface $eventDispatcher)
  28.     {
  29.         $this->eventDispatcher $eventDispatcher;
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function sendMail(Email $emailDocument$subject null$recipients null$attachments = [], $params = [])
  35.     {
  36.         $mailHasBeenSent false;
  37.         $mail = new Mail();
  38.         foreach ($attachments as $attachment) {
  39.             if ($attachment instanceof \Swift_Mime_SimpleMimeEntity) {
  40.                 $mail->attach($attachment);
  41.             }
  42.         }
  43.         $mail->setDocument($emailDocument);
  44.         $mail->setParams($params);
  45.         $mail->addRecipients($recipients);
  46.         $mail->setEnableLayoutOnPlaceholderRendering(false);
  47.         $mailEvent = new MailEvent(
  48.             $subject,
  49.             $emailDocument,
  50.             $mail,
  51.             $params
  52.         );
  53.         $this->eventDispatcher->dispatch(Events::PRE_MAIL_SEND$mailEvent);
  54.         if ($mailEvent->getShouldSendMail()) {
  55.             $mail->send();
  56.             $mailHasBeenSent true;
  57.         }
  58.         $this->eventDispatcher->dispatch(Events::POST_MAIL_SEND$mailEvent);
  59.         return $mailHasBeenSent;
  60.     }
  61. }