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

Commit

Permalink
Merge pull request #13 from n3o77/master
Browse files Browse the repository at this point in the history
Allow to set base path for the image lookup
  • Loading branch information
nclsHart authored Dec 15, 2017
2 parents 5cc8938 + aea4f18 commit f6e2bd0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
14 changes: 13 additions & 1 deletion src/ImageEmbedPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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])
);
Expand Down

0 comments on commit f6e2bd0

Please sign in to comment.