<?php
declare(strict_types=0);
/*
* WellCommerce Foundation
*
* This file is part of the WellCommerce package.
*
* (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/
namespace WellCommerce\Bundle\AppBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use WellCommerce\Bundle\CoreBundle\DependencyInjection\AbstractServiceSubscriber;
use WellCommerce\Bundle\CoreBundle\Event\SystemEvent;
/**
* Class CurrencySubscriber
*
* @author Adam Piotrowski <adam@wellcommerce.org>
*/
class SystemEventSubscriber extends AbstractServiceSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
SystemEvent::class => 'onSystemEvent',
];
}
public function onSystemEvent(SystemEvent $event)
{
$shop = $this->getShopStorage()->getCurrentShop();
$recipients = explode(PHP_EOL, $shop->getDevelopersEmails());
$sendTo = [];
foreach ($recipients as $recipient) {
$recipient = trim($recipient);
if ($this->getMailerHelper()->isEmailValid($recipient)) {
$sendTo[] = $recipient;
}
}
foreach ($sendTo as $recipient) {
$this->getMailerHelper()->sendEmail([
'recipient' => $recipient,
'bcc' => [],
'subject' => $event->getTitle(),
'template' => 'WellCommerceAppBundle:Admin/Email:system_event.html.twig',
'parameters' => [
'event' => $event,
],
'dynamic_attachments' => $event->getAttachments(),
'configuration' => $shop->getMailerConfiguration(),
]);
}
}
}