From bb91d4320af79411fb480f1e9b95faddf41c0839 Mon Sep 17 00:00:00 2001 From: Steffen Persch Date: Wed, 13 Dec 2017 22:47:06 +0100 Subject: [PATCH 1/2] allow to set basepath to look for images --- src/ImageEmbedPlugin.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ImageEmbedPlugin.php b/src/ImageEmbedPlugin.php index 38bf75d..3562e3f 100644 --- a/src/ImageEmbedPlugin.php +++ b/src/ImageEmbedPlugin.php @@ -11,6 +11,18 @@ class ImageEmbedPlugin implements Swift_Events_SendListener { + private $basePath = ''; + + /** + * ImageEmbedPlugin constructor. + * + * @param string $basePath + */ + public function __construct($basePath = '') + { + $this->basePath = $basePath; + } + /** * @param Swift_Events_SendEvent $event */ @@ -60,7 +72,7 @@ protected function embedImages(Swift_Mime_SimpleMessage $message, Swift_Mime_Sim */ if (strpos($src, 'cid:') === false) { - $entity = Swift_Image::fromPath($src); + $entity = \Swift_Image::fromPath($this->basePath . $src); $message->setChildren( array_merge($message->getChildren(), [$entity]) ); From aea4f186d20dbfe59f38f9efc6ef04e0db1e8218 Mon Sep 17 00:00:00 2001 From: Steffen Persch Date: Wed, 13 Dec 2017 22:49:34 +0100 Subject: [PATCH 2/2] updated readme for symfony usage --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 9d58a79..ed54ad6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,17 @@ $mailer = new Swift_Mailer($yourTransport); $mailer->registerPlugin(new ImageEmbedPlugin()); ``` +or for symfony in your services.yml: +```yml + hexanet.swiftmailer.image_embed_plugin: + class: Hexanet\Swiftmailer\ImageEmbedPlugin + tags: + - { name: swiftmailer.default.plugin } + arguments: ['%kernel.root_dir%/../web/'] +``` + +The arguments are optional. + ## Credits Developed by the [Dev Team](http://teamdev.hexanet.fr) of [Hexanet](http://www.hexanet.fr/).