src/WellCommerce/Bundle/AppBundle/EventListener/SystemEventSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=0);
  3. /*
  4.  * WellCommerce Foundation
  5.  *
  6.  * This file is part of the WellCommerce package.
  7.  *
  8.  * (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
  9.  *
  10.  * For the full copyright and license information,
  11.  * please view the LICENSE file that was distributed with this source code.
  12.  */
  13. namespace WellCommerce\Bundle\AppBundle\EventListener;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use WellCommerce\Bundle\CoreBundle\DependencyInjection\AbstractServiceSubscriber;
  16. use WellCommerce\Bundle\CoreBundle\Event\SystemEvent;
  17. /**
  18.  * Class CurrencySubscriber
  19.  *
  20.  * @author  Adam Piotrowski <adam@wellcommerce.org>
  21.  */
  22. class SystemEventSubscriber extends AbstractServiceSubscriber implements EventSubscriberInterface
  23. {
  24.     public static function getSubscribedEvents()
  25.     {
  26.         return [
  27.             SystemEvent::class => 'onSystemEvent',
  28.         ];
  29.     }
  30.     public function onSystemEvent(SystemEvent $event)
  31.     {
  32.         $shop       $this->getShopStorage()->getCurrentShop();
  33.         $recipients explode(PHP_EOL$shop->getDevelopersEmails());
  34.         $sendTo     = [];
  35.         foreach ($recipients as $recipient) {
  36.             $recipient trim($recipient);
  37.             if ($this->getMailerHelper()->isEmailValid($recipient)) {
  38.                 $sendTo[] = $recipient;
  39.             }
  40.         }
  41.         foreach ($sendTo as $recipient) {
  42.             $this->getMailerHelper()->sendEmail([
  43.                 'recipient'           => $recipient,
  44.                 'bcc'                 => [],
  45.                 'subject'             => $event->getTitle(),
  46.                 'template'            => 'WellCommerceAppBundle:Admin/Email:system_event.html.twig',
  47.                 'parameters'          => [
  48.                     'event' => $event,
  49.                 ],
  50.                 'dynamic_attachments' => $event->getAttachments(),
  51.                 'configuration'       => $shop->getMailerConfiguration(),
  52.             ]);
  53.         }
  54.     }
  55. }