本文整理汇总了PHP中Symfony\Component\Process\Process::enableOutput方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::enableOutput方法的具体用法?PHP Process::enableOutput怎么用?PHP Process::enableOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::enableOutput方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shell
public static function shell($commands, array $opts = [])
{
//$cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array()
if (is_array($commands)) {
$procs = [];
foreach ($commands as $command) {
$procs[] = static::shell($command, $opts);
}
return $procs;
}
$process = new Process($commands);
$options = array_replace(['type' => 'sync', 'cwd' => null, 'env' => null, 'timeout' => 60, 'callback' => null, 'output' => true], $opts);
$options['cwd'] !== null && $process->setWorkingDirectory($options['cwd']);
$options['env'] !== null && $process->setEnv($options['env']);
is_int($options['timeout']) && $process->setTimeout($options['timeout']);
if ($options['output'] === true) {
$process->enableOutput();
} else {
$process->disableOutput();
}
$type = $options['type'];
if ($type === 'sync') {
$process->run($options['callback']);
} elseif ($type === 'async') {
$process->start();
}
return $process;
}
示例2: execute
/**
* @param $command
*/
public function execute($command)
{
$cwd = getcwd();
chdir($this->currentWorkingDirectory);
$process = new Process($command);
$process->enableOutput();
$process->run();
if (!$process->isSuccessful()) {
chdir($cwd);
throw new ProcessException($process->getErrorOutput());
}
chdir($cwd);
}
示例3: getCurrentGitUser
/**
* Get the current git user information. We need this to extract
* the user name and email to put into the generated files
* @return mixed
*/
private function getCurrentGitUser()
{
$p = new Process('git config --list');
$p->enableOutput();
$result = [];
try {
$p->mustRun();
$lines = explode("\n", trim($p->getOutput()));
foreach ($lines as $line) {
$ar = explode('=', trim($line));
if (count($ar) === 2) {
$result[$ar[0]] = $ar[1];
}
}
return $result;
} catch (\Exception $e) {
$user = get_current_user();
return array('user.name' => $user, 'user.email' => $user);
}
}