mirror of
https://github.com/saccas/mjml-typo3.git
synced 2024-11-26 10:56:10 +01:00
Daniel Siepmann
eba401aa9f
Add all dependencies to run tests. Configure tests as composer task. Add tests to travis. Adjust code to make him exchangeable and testable.
45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
namespace Saccas\Mjml\Domain\Renderer;
|
|
|
|
use TYPO3\CMS\Core\Utility\CommandUtility;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
class Command implements RendererInterface
|
|
{
|
|
protected function getHtmlFromMjml($mjml)
|
|
{
|
|
$configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['mjml']);
|
|
|
|
$temporaryMjmlFileWithPath = GeneralUtility::tempnam('mjml_', '.mjml');
|
|
|
|
GeneralUtility::writeFileToTypo3tempDir($temporaryMjmlFileWithPath, $mjml);
|
|
|
|
// see https://mjml.io/download and https://www.npmjs.com/package/mjml-cli
|
|
$cmd = $configuration['nodeBinaryPath'] . ' ' . $configuration['mjmlBinaryPath'] . $configuration['mjmlBinary'];
|
|
$args = $configuration['mjmlParams'] . ' ' . $temporaryMjmlFileWithPath;
|
|
|
|
$result = [];
|
|
$returnValue = '';
|
|
CommandUtility::exec($this->getEscapedCommand($cmd, $args), $result, $returnValue);
|
|
|
|
GeneralUtility::unlink_tempfile($temporaryMjmlFileWithPath);
|
|
|
|
return implode('', $result);
|
|
}
|
|
|
|
/**
|
|
* @param string $cmd
|
|
* @param string $args
|
|
* @return string
|
|
*/
|
|
protected function getEscapedCommand(string $cmd, string $args)
|
|
{
|
|
$escapedCmd = escapeshellcmd($cmd);
|
|
|
|
$argsArray = explode(' ', $args);
|
|
$escapedArgsArray = CommandUtility::escapeShellArguments($argsArray);
|
|
$escapedArgs = implode(' ', $escapedArgsArray);
|
|
|
|
return $escapedCmd . ' ' . $escapedArgs;
|
|
}
|
|
}
|