vendor/sulu/sulu/src/Sulu/Bundle/MarkupBundle/Listener/SwiftMailerListener.php line 36

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\MarkupBundle\Listener;
  11. use Sulu\Bundle\MarkupBundle\Markup\MarkupParserInterface;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. class SwiftMailerListener implements \Swift_Events_SendListener
  14. {
  15.     /**
  16.      * @var MarkupParserInterface[]
  17.      */
  18.     private $markupParser;
  19.     /**
  20.      * @var RequestStack
  21.      */
  22.     private $requestStack;
  23.     /**
  24.      * @var string
  25.      */
  26.     private $defaultLocale;
  27.     public function __construct(\Traversable $markupParserRequestStack $requestStackstring $defaultLocale)
  28.     {
  29.         $this->markupParser \iterator_to_array($markupParser);
  30.         $this->requestStack $requestStack;
  31.         $this->defaultLocale $defaultLocale;
  32.     }
  33.     public function beforeSendPerformed(\Swift_Events_SendEvent $event)
  34.     {
  35.         $message $event->getMessage();
  36.         $body $message->getBody();
  37.         $format $message->getBodyContentType();
  38.         if (\count($explodedFormat \explode('/'$format)) > 1) {
  39.             $format $explodedFormat[1];
  40.         }
  41.         $currentRequest $this->requestStack->getCurrentRequest();
  42.         if (null !== $currentRequest) {
  43.             $locale $currentRequest->getLocale();
  44.         } else {
  45.             $locale $this->defaultLocale;
  46.         }
  47.         if (!$body || !\array_key_exists($format$this->markupParser)) {
  48.             return;
  49.         }
  50.         $message->setbody(
  51.             $this->markupParser[$format]->parse($body$locale)
  52.         );
  53.     }
  54.     public function sendPerformed(\Swift_Events_SendEvent $evt)
  55.     {
  56.     }
  57. }