diff --git a/src/Listeners/SwiftEmbedImages.php b/src/Listeners/SwiftEmbedImages.php index ee56869..ec3490b 100755 --- a/src/Listeners/SwiftEmbedImages.php +++ b/src/Listeners/SwiftEmbedImages.php @@ -14,6 +14,8 @@ use Swift_Events_SendEvent; use Swift_Events_SendListener; use Swift_Message; +use Swift_Mime_SimpleMessage; +use Symfony\Component\Mime\Email; class SwiftEmbedImages implements Swift_Events_SendListener { @@ -23,7 +25,7 @@ class SwiftEmbedImages implements Swift_Events_SendListener private $config; /** - * @var Swift_Message + * @var Email|Swift_Mime_SimpleMessage */ private $message; @@ -40,8 +42,16 @@ public function __construct($config) */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { - $this->message = $evt->getMessage(); + $this->handle($evt->getMessage()); + } + /** + * @param Swift_Mime_SimpleMessage $message + * @return void + */ + public function handle(Swift_Mime_SimpleMessage $message) + { + $this->message = $message; $this->attachImages(); } @@ -215,4 +225,4 @@ private function embed(Embedder $embedder, $src) return $src; } -} +} \ No newline at end of file diff --git a/src/Listeners/SymfonyEmbedImages.php b/src/Listeners/SymfonyEmbedImages.php index 38ba3a8..2fc4a7d 100644 --- a/src/Listeners/SymfonyEmbedImages.php +++ b/src/Listeners/SymfonyEmbedImages.php @@ -23,7 +23,7 @@ class SymfonyEmbedImages private $config; /** - * @var Email|Swift_Message + * @var Email */ private $message; @@ -38,10 +38,18 @@ public function __construct($config) /** * @param MessageSending $event */ - public function handle(MessageSending $event) + public function beforeSendPerformed(MessageSending $event) { - $this->message = $event->message; + $this->handle($event->message); + } + /** + * @param Email $message + * @return void + */ + public function handle(Email $message) + { + $this->message = $message; $this->attachImages(); } @@ -195,3 +203,4 @@ private function embed(Embedder $embedder, $src) return $src; } } + diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 5d74b97..e74170f 100755 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -24,7 +24,7 @@ public function boot() if (version_compare(app()->version(), '9.0.0', '>=')) { Event::listen(function (MessageSending $event) { (new SymfonyEmbedImages($this->app['config']->get('mail-auto-embed'))) - ->handle($event); + ->beforeSendPerformed($event); }); } else { foreach (Arr::get($this->app['config'], 'mail.mailers', []) as $driver => $mailer) { diff --git a/tests/Traits/InteractsWithMessage.php b/tests/Traits/InteractsWithMessage.php index 30c7775..2c7271a 100755 --- a/tests/Traits/InteractsWithMessage.php +++ b/tests/Traits/InteractsWithMessage.php @@ -63,7 +63,7 @@ protected function handleBeforeSendPerformedEvent($libraryFile, $options) if ($this->isLaravel9()) { $event = new MessageSending($message); (new SymfonyEmbedImages($options)) - ->handle($event); + ->beforeSendPerformed($event); $event->message->getBody(); return $event->message; }