generated from Setono/SyliusPluginSkeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMailerPlugin\EventSubscriber; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Setono\Doctrine\ORMTrait; | ||
use Setono\SyliusMailerPlugin\Model\SentEmailInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class SwiftMailerLoggerSubscriber implements EventSubscriberInterface | ||
{ | ||
use ORMTrait; | ||
|
||
public function __construct( | ||
ManagerRegistry $managerRegistry, | ||
private readonly FactoryInterface $emailFactory, | ||
) { | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
'sendPerformed' => 'log', | ||
]; | ||
} | ||
|
||
public function log(\Swift_Events_SendEvent $event): void | ||
{ | ||
$message = $event->getMessage(); | ||
|
||
/** @var SentEmailInterface $sentEmail */ | ||
$sentEmail = $this->emailFactory->createNew(); | ||
|
||
$sentEmail->setSubject($message->getSubject()); | ||
$sentEmail->setHtmlBody($message->getBody()); | ||
|
||
/** @psalm-suppress MixedArgumentTypeCoercion */ | ||
$sentEmail->setTo(array_keys($message->getTo())); | ||
|
||
/** @psalm-suppress MixedArgumentTypeCoercion */ | ||
$sentEmail->setReplyTo(array_keys($message->getReplyTo())); | ||
Check failure on line 45 in src/EventSubscriber/SwiftMailerLoggerSubscriber.php GitHub Actions / Static Code Analysis (PHP8.1 | Deps: highest | SF~5.4.0)InvalidArgument
Check failure on line 45 in src/EventSubscriber/SwiftMailerLoggerSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: lowest | SF~5.4.0)InvalidArgument
Check failure on line 45 in src/EventSubscriber/SwiftMailerLoggerSubscriber.php GitHub Actions / Static Code Analysis (PHP8.2 | Deps: highest | SF~5.4.0)InvalidArgument
|
||
|
||
/** @psalm-suppress MixedArgumentTypeCoercion */ | ||
$sentEmail->setCc(array_keys($message->getCc())); | ||
|
||
/** @psalm-suppress MixedArgumentTypeCoercion */ | ||
$sentEmail->setBcc(array_keys($message->getBcc())); | ||
|
||
$manager = $this->getManager($sentEmail); | ||
$manager->persist($sentEmail); | ||
$manager->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="Setono\SyliusMailerPlugin\EventSubscriber\SwiftMailerLoggerSubscriber"> | ||
<argument type="service" id="doctrine"/> | ||
<argument type="service" id="setono_sylius_mailer.factory.sent_email"/> | ||
|
||
<tag name="kernel.event_subscriber"/> | ||
</service> | ||
</services> | ||
</container> |