use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
-use Symfony\Component\Process\ProcessBuilder;
/**
* The ProcessHelper class provides helpers to run external processes.
*
* @return Process The process that ran
*/
- public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
+ public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
{
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
$formatter = $this->getHelperSet()->get('debug_formatter');
- if (is_array($cmd)) {
- $process = ProcessBuilder::create($cmd)->getProcess();
- } elseif ($cmd instanceof Process) {
+ if ($cmd instanceof Process) {
$process = $cmd;
} else {
$process = new Process($cmd);
*
* @see run()
*/
- public function mustRun(OutputInterface $output, $cmd, $error = null, $callback = null)
+ public function mustRun(OutputInterface $output, $cmd, $error = null, callable $callback = null)
{
$process = $this->run($output, $cmd, $error, $callback);
*
* @return callable
*/
- public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
+ public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null)
{
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
$formatter = $this->getHelperSet()->get('debug_formatter');
- $that = $this;
-
- return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) {
- $output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type));
+ return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
+ $output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));
if (null !== $callback) {
- call_user_func($callback, $type, $buffer);
+ \call_user_func($callback, $type, $buffer);
}
};
}
- /**
- * This method is public for PHP 5.3 compatibility, it should be private.
- *
- * @internal
- */
- public function escapeString($str)
+ private function escapeString($str)
{
return str_replace('<', '\\<', $str);
}