diff --git a/src/Renderer/BinaryRenderer.php b/src/Renderer/BinaryRenderer.php index d572d78..1494068 100644 --- a/src/Renderer/BinaryRenderer.php +++ b/src/Renderer/BinaryRenderer.php @@ -22,15 +22,26 @@ class BinaryRenderer implements RendererInterface */ private $command; + /** + * @var string + */ + private $mjmlFilePath; + /** * BinaryRenderer constructor. * * @param string $bin + * @param string $mjmlFilePath if set, reads this mjml file and creates a mjml.html file which will be read and return on render */ - public function __construct(string $bin) + public function __construct(string $bin, string $mjmlFilePath = "") { $this->bin = $bin; - $this->command = "{$this->bin} -i -s --config.validationLevel --config.minify"; + $this->mjmlFilePath = $mjmlFilePath; + if ($mjmlFilePath !== "") { + $this->command = "{$this->bin} --config.validationLevel 'skip' --config.minify true {$mjmlFilePath} -o {$mjmlFilePath}.html"; + } else { + $this->command = "{$this->bin} -i -s --config.validationLevel --config.minify"; + } } /** @@ -38,9 +49,17 @@ public function __construct(string $bin) */ public function render(string $content): string { - $process = new Process($this->command, $content); - $process->run(); + $returnValue = ""; + + if ($this->mjmlFilePath !== "") { + passthru($this->command); + $returnValue = file_get_contents("{$this->mjmlFilePath}.html"); + } else { + $process = new Process($this->command, $content); + $process->run(); + $returnValue = $process->getOutput(); + } - return $process->getOutput(); + return $returnValue; } }