Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit f6e2bd0

Browse files
authored
Merge pull request #13 from n3o77/master
Allow to set base path for the image lookup
2 parents 5cc8938 + aea4f18 commit f6e2bd0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ $mailer = new Swift_Mailer($yourTransport);
2020
$mailer->registerPlugin(new ImageEmbedPlugin());
2121
```
2222

23+
or for symfony in your services.yml:
24+
```yml
25+
hexanet.swiftmailer.image_embed_plugin:
26+
class: Hexanet\Swiftmailer\ImageEmbedPlugin
27+
tags:
28+
- { name: swiftmailer.default.plugin }
29+
arguments: ['%kernel.root_dir%/../web/']
30+
```
31+
32+
The arguments are optional.
33+
2334
## Credits
2435
2536
Developed by the [Dev Team](http://teamdev.hexanet.fr) of [Hexanet](http://www.hexanet.fr/).

src/ImageEmbedPlugin.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
class ImageEmbedPlugin implements Swift_Events_SendListener
1212
{
1313

14+
private $basePath = '';
15+
16+
/**
17+
* ImageEmbedPlugin constructor.
18+
*
19+
* @param string $basePath
20+
*/
21+
public function __construct($basePath = '')
22+
{
23+
$this->basePath = $basePath;
24+
}
25+
1426
/**
1527
* @param Swift_Events_SendEvent $event
1628
*/
@@ -60,7 +72,7 @@ protected function embedImages(Swift_Mime_SimpleMessage $message, Swift_Mime_Sim
6072
*/
6173
if (strpos($src, 'cid:') === false) {
6274

63-
$entity = Swift_Image::fromPath($src);
75+
$entity = \Swift_Image::fromPath($this->basePath . $src);
6476
$message->setChildren(
6577
array_merge($message->getChildren(), [$entity])
6678
);

0 commit comments

Comments
 (0)