This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/lib/vendor/lime/shell/LimeShellCommand.php
2010-01-04 15:26:20 +01:00

67 lines
1.3 KiB
PHP

<?php
class LimeShellCommand
{
protected
$command = null,
$status = null,
$output = '',
$errors = '',
$errorFile = '';
public function __construct($file, array $arguments = array())
{
foreach ($arguments as $argument => $value)
{
$arguments[$argument] = '--'.$argument;
if ($value !== true)
{
if (!is_string($value))
{
$value = var_export($value, true);
}
$arguments[$argument] .= '='.escapeshellarg($value);
}
}
$this->errorFile = tempnam(sys_get_temp_dir(), 'lime');
// see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing
$this->command = sprintf(
'cd & %s %s %s 2>%s',
escapeshellarg(LimeShell::getExecutable()),
escapeshellarg($file),
implode(' ', $arguments),
$this->errorFile
);
}
public function execute()
{
// clear old errors
$this->errors = '';
file_put_contents($this->errorFile, '');
ob_start();
passthru($this->command, $this->status);
$this->output = ob_get_clean();
$this->errors = file_get_contents($this->errorFile);
}
public function getStatus()
{
return $this->status;
}
public function getOutput()
{
return $this->output;
}
public function getErrors()
{
return $this->errors;
}
}