Skip to content

Commit 1dc7574

Browse files
use symfony process to run shell command
1 parent 6d9b270 commit 1dc7574

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

Css/PreProcessor/Adapter/Less/Processor.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,21 @@ public function processContent(AssetFile $asset)
9393
*/
9494
protected function compileFile($filePath)
9595
{
96-
$nodeCmdArgs = $this->getNodeArgsAsArray();
97-
$lessCmdArgs = $this->getCompilerArgsAsArray();
98-
99-
$cmd = '%s ' . str_repeat(' %s', count($nodeCmdArgs)) . ' %s' . str_repeat(' %s', count($lessCmdArgs)) . ' %s';
100-
$arguments = [];
101-
$arguments[] = $this->getPathToNodeBinary();
102-
$arguments = array_merge($arguments, $nodeCmdArgs);
103-
$arguments[] = $this->getPathToLessCompiler();
104-
$arguments = array_merge($arguments, $lessCmdArgs);
105-
$arguments[] = $filePath;
106-
107-
// to log or not to log, that's the question
108-
// also, it would be better to use the logger in the Shell class,
109-
// since that one will contain the exact correct command, and not this sprintf version
110-
// $logArguments = array_map('escapeshellarg', $arguments);
111-
// $this->logger->debug('Less compilation command: `'
112-
// . sprintf($cmd, ...$logArguments)
113-
// . '`');
114-
115-
return $this->shell->execute(
116-
$cmd,
117-
$arguments
118-
);
96+
$process = new \Symfony\Component\Process\Process([
97+
$this->getPathToNodeBinary(),
98+
...$this->getNodeArgsAsArray(),
99+
$this->getPathToLessCompiler(),
100+
...$this->getCompilerArgsAsArray(),
101+
$filePath,
102+
]);
103+
104+
$process->run();
105+
106+
if (!$process->isSuccessful()) {
107+
throw new \Symfony\Component\Process\Exception\ProcessFailedException($process);
108+
}
109+
110+
return $process->getOutput();
119111
}
120112

121113
/**

0 commit comments

Comments
 (0)