public function transform($text)
{
$descriptorspec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'a']];
$process = proc_open($this->markdownExecutablePath, $descriptorspec, $pipes, null, $GLOBALS['_ENV']);
stream_set_blocking($pipes[0], 1);
stream_set_blocking($pipes[1], 1);
stream_set_blocking($pipes[2], 1);
fwrite($pipes[0], $text);
fclose($pipes[0]);
$transformed = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$errors = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$exitCode = proc_close($process);
if ('' !== trim($errors)) {
throw new Exception('There was an error while executing ' . $this->markdownExecutablePath . '. The return code was ' . $exitCode . ' and the message reads: ' . $errors, 1350514144);
}
return $transformed;
}