本文整理汇总了PHP中Symfony\Component\Process\Process::mustRun方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::mustRun方法的具体用法?PHP Process::mustRun怎么用?PHP Process::mustRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::mustRun方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Runs a process and returns the output.
*
* @param Process $process
* @return string
*/
public function run(Process $process, $returnOutput = true)
{
$process->mustRun();
if ($returnOutput) {
return $this->getProcessOutput($process);
}
}
示例2: runProcess
/**
* @param Process $process
* @param bool $mustRun
* @param bool $quiet
*
* @return int|string
* @throws \Exception
*/
protected function runProcess(Process $process, $mustRun = false, $quiet = true)
{
$this->output->writeln("Running command: <info>" . $process->getCommandLine() . "</info>", OutputInterface::VERBOSITY_VERBOSE);
try {
$process->mustRun($quiet ? null : function ($type, $buffer) {
$this->output->write(preg_replace('/^/m', ' ', $buffer));
});
} catch (ProcessFailedException $e) {
if (!$mustRun) {
return $process->getExitCode();
}
// The default for ProcessFailedException is to print the entire
// STDOUT and STDERR. But if $quiet is disabled, then the user will
// have already seen the command's output. So we need to re-throw
// the exception with a much shorter message.
$message = "The command failed with the exit code: " . $process->getExitCode();
$message .= "\n\nFull command: " . $process->getCommandLine();
if ($quiet) {
$message .= "\n\nError output:\n" . $process->getErrorOutput();
}
throw new \Exception($message);
}
$output = $process->getOutput();
return $output ? rtrim($output) : true;
}
示例3: runCommand
/**
* Runs the given string as a command and returns the resulting output.
* The CWD is set to the root project directory to simplify command paths.
*
* @param string $command
*
* @return string
*
* @throws ProcessFailedException in case the command execution is not successful
*/
private function runCommand($command, $workingDirectory = null)
{
$process = new Process($command);
$process->setWorkingDirectory($workingDirectory ?: $this->rootDir);
$process->mustRun();
return $process->getOutput();
}
示例4: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->config->load($this->argument('conversion'));
$command = $this->commandStringBuilder->build($this->config);
$outputPath = $this->config->outputPath();
if (file_exists($outputPath)) {
@unlink($outputPath);
}
if ($this->config->debug()) {
$this->output->block('[DEBUG] Running command: ' . $command);
}
if (empty(shell_exec("which mysqldump"))) {
throw new MissingDependency('mysqldump is not available');
}
if (is_executable($this->config->converterExecutable()) === false) {
$process = new Process('chmod +x ' . $this->config->converterExecutable());
$process->run();
}
$process = new Process($command);
$outputFilter = $this->outputFilter;
$process->mustRun(function ($type, $output) use($outputFilter) {
// some things are expected, so we'll hide that
// to avoid misleading warnings/errors
$output = $outputFilter->filter($output);
if ($output != null) {
if (Process::ERR === $type) {
echo 'ERR > ' . $output;
} else {
echo 'OUT > ' . $output;
}
}
});
$this->output->success('Dump created at ' . $outputPath);
}
示例5: __callStatic
/**
* @param string $name
* @param array $arguments
*
* @throws GulpBadTaskConfigurationException
* @throws GulpUndefinedTaskException
*/
public static function __callStatic($name, $arguments)
{
$taskName = Inflector::camelCaseToDaseCase($name);
/** @var Event $event */
list($event) = $arguments;
$gulpTasks = self::getOption('gulp-tasks', $event);
if (!isset($gulpTasks[$taskName])) {
throw new GulpUndefinedTaskException(sprintf('Gulp %s task is not defined.', $taskName));
}
// get gulp options
$gulpBin = self::getOption('gulp-bin', $event);
$logPrepend = self::getOption('gulp-log-prepend', $event);
// get task options
$taskOptions = $gulpTasks[$taskName];
if (empty($taskOptions['command'])) {
throw new GulpBadTaskConfigurationException(sprintf('Gulp %s task command option must be defined.', $taskName));
}
$command = [$gulpBin, $taskOptions['command'], isset($taskOptions['params']) ? $taskOptions['params'] : ''];
$failOnError = empty($taskOptions['fail-on-error']) ? false : $taskOptions['fail-on-error'];
if (!$failOnError) {
$command[] = '|| true';
}
// execute process
$process = new Process(implode(' ', $command), null, null, null, null, []);
$process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
});
}
示例6: mustRun
public function mustRun(array $commands, $timeout = 60)
{
$command_format = <<<SHELL
echo {{ESCAPED_COMMAND}}
{{COMMAND}}
SHELL;
$formatted_commands = $this->formatCommands($commands, $command_format);
$shell = <<<SHELL
set -e
set -u
{$formatted_commands}
SHELL;
$log_service = $this->log_service;
$process = new Process($shell);
$process->setTimeout($timeout);
$process->setIdleTimeout($timeout);
$process->mustRun(function ($type, $buffer) use($log_service) {
if (Process::ERR === $type) {
$this->log_service->error($buffer);
} else {
$this->log_service->info($buffer);
}
});
}
示例7: report
/**
* @param Event $event
*/
public static function report(Event $event)
{
$bin = self::getOption('phpcpd-bin', $event);
$include = self::getOption('phpcpd-include', $event);
$exclude = self::getOption('phpcpd-exclude', $event);
$xmlReportFile = self::getOption('phpcpd-xml-report-file', $event);
$minLines = self::getOption('phpcpd-min-lines', $event);
$minTokens = self::getOption('phpcpd-min-tokens', $event);
$failOnError = self::getOption('phpcpd-fail-on-error', $event);
$logPrepend = self::getOption('phpcpd-log-prepend', $event);
$command = array($bin, '--no-interaction', '--min-lines ' . $minLines, '--min-tokens ' . $minTokens);
if ($xmlReportFile) {
$command[] = '--log-pmd ' . self::getReportResultsPath($event) . '/' . $xmlReportFile;
}
if ($exclude) {
$command[] = '--exclude ' . implode(' ', $exclude);
}
$command[] = implode(' ', $include);
if (!$failOnError) {
$command[] = '|| true';
}
$process = new Process(implode(' ', $command), null, null, null, null, []);
$process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
});
}
示例8: mustRun
public function mustRun($callback = null)
{
parent::mustRun($callback);
// Check for problems with output.
$this->checkOutputForProblems();
return $this;
}
示例9: runFix
/**
* @param string $path
* @param Event $event
*/
protected static function runFix($path, Event $event)
{
$bin = self::getOption('phpcsfixer-bin', $event);
$failOnError = self::getOption('phpcsfixer-fail-on-error', $event);
$logPrepend = self::getOption('phpcsfixer-log-prepend', $event);
$level = self::getOption('phpcsfixer-level', $event);
$fixers = self::getOption('phpcsfixer-fixers', $event);
$config = self::getOption('phpcsfixer-config', $event);
$dryRun = self::getOption('phpcsfixer-dry-run', $event);
$command = array($bin, 'fix', $path);
if ($level) {
$command[] = '--level=' . $level;
}
if (!empty($fixers) && is_array($fixers)) {
$command[] = '--fixers=' . implode(',', $fixers);
}
if ($config) {
$command[] = '--config=' . $config;
}
if ($dryRun === true) {
$command[] = '--dry-run';
}
if (!$failOnError) {
$command[] = '|| true';
}
$process = new Process(implode(' ', $command), null, null, null, null, []);
$process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
});
}
示例10: report
/**
* @param Event $event
*/
public static function report(Event $event)
{
$bin = self::getOption('phpcs-bin', $event);
$include = self::getOption('phpcs-include', $event);
$exclude = self::getOption('phpcs-exclude', $event);
$report = self::getOption('phpcs-report', $event);
$xmlReportFile = self::getOption('phpcs-xml-report-file', $event);
$standard = self::getOption('phpcs-standard', $event);
$failOnError = self::getOption('phpcs-fail-on-error', $event);
$logPrepend = self::getOption('phpcs-log-prepend', $event);
$command = array($bin, '--report=' . $report, '--standard=' . $standard);
if ($xmlReportFile) {
$command[] = '--report-file=' . self::getReportResultsPath($event) . '/' . $xmlReportFile;
}
if ($exclude) {
$command[] = implode(' ', array_map(function ($element) {
return '--ignore=' . $element;
}, $exclude));
}
$command[] = implode(' ', $include);
if (!$failOnError) {
$command[] = '|| true';
}
$process = new Process(implode(' ', $command), null, null, null, null, []);
$process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
});
}
示例11: deploy
/**
*
* @param Project $project
* @return string
* @throws DeployException
*/
public function deploy(Project $project)
{
$path = sys_get_temp_dir() . '/AwesomeDeployer';
$this->filesystem->mkdir($path);
chdir($path);
$process = new Process('git clone ' . $project->getRepo() . ' project');
$process->mustRun();
$out = $process->getOutput();
$pathProject = $path . '/project';
chdir($pathProject);
$script = $project->getScript();
if ($script !== null) {
$script = new Process($script);
$script->mustRun();
$out .= $script->getOutput();
}
switch ($project->getStrategy()) {
case Project::STRATEGY_FABRIC:
$command = $project->getCommand();
break;
default:
throw new DeployException('Strategy not supported');
}
$deployment = new Process($command);
$deployment->mustRun();
$this->filesystem->remove($path);
$out .= $deployment->getOutput();
return $out;
}
示例12: execute
/**
* {@inheritdoc}
*
* @see PlatformCommand::getCurrentEnvironment()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \Symfony\Component\Console\Helper\ProcessHelper $process */
$process = $this->getHelper('process');
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
if (!is_dir(Platform::rootDir() . '/docker/fg')) {
$process->mustRun($output, ['git', 'clone', 'https://github.com/brendangregg/FlameGraph.git', Platform::rootDir() . '/docker/fg']);
}
if (!is_dir(Platform::rootDir() . '/docker/xhpfg')) {
$process->mustRun($output, ['git', 'clone', 'https://github.com/msonnabaum/xhprof-flamegraphs.git', Platform::rootDir() . '/docker/xhpfg']);
}
$stack = StacksFactory::getStack(Platform::webDir());
switch ($stack->type()) {
case Stacks\Drupal::TYPE:
$this->stdOut->writeln("<comment>Patching Drupal for xhprof</comment>");
$patchProcess = new Process('patch -p1 < ' . CLI_ROOT . '/resources/drupal-enable-profiling.patch', Platform::webDir());
break;
case Stacks\WordPress::TYPE:
$this->stdOut->writeln("<comment>Patching WordPress for xhprof</comment>");
$patchProcess = new Process('patch -p0 < ' . CLI_ROOT . '/resources/wordpress-enable-profiling.patch', Platform::webDir());
break;
default:
throw new \Exception('Stack type not supported yet.');
}
$patchProcess->mustRun();
}
示例13: check
/**
* @param Event $event
*/
public static function check(Event $event)
{
$logPrepend = self::getOption('security-checker-log-prepend', $event);
$process = new Process(self::getOption('security-checker-bin', $event) . ' security:check composer.lock --ansi');
$process->mustRun(function ($type, $buffer) use($event, $logPrepend) {
self::writeProcessBuffer($type, $buffer, $event, $logPrepend);
});
}
示例14: zip
/**
* @return string
*/
public function zip($file = 'archive.zip')
{
$temporaryDir = $this->createTmpDirectory();
$this->write($temporaryDir);
$command = sprintf('zip -r "%s" "%s"', $file, $temporaryDir);
$process = new Process($command);
$process->mustRun();
}
示例15: do
public function do()
{
$commands = $this->commands();
if (!empty($commands)) {
$process = new Process(implode("\n", $commands));
$process->mustRun();
$this->io->writeln($process->getOutput());
}
}