本文整理汇总了PHP中Symfony\Component\Process\ProcessBuilder::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ProcessBuilder::create方法的具体用法?PHP ProcessBuilder::create怎么用?PHP ProcessBuilder::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\ProcessBuilder
的用法示例。
在下文中一共展示了ProcessBuilder::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config = $this->getContainer()->getParameter('chebur_sphinx_config');
$configFile = $config['config']['destination'];
//Проверяем на существование файла конфига
if (!file_exists($configFile)) {
$output->writeln('<error>Config file not found. Run "chebur:sphinx:generate" first.</error>');
return;
}
$pb = ProcessBuilder::create()->inheritEnvironmentVariables()->setPrefix($config['commands']['bin'] . DIRECTORY_SEPARATOR . 'searchd')->add('--config')->add($configFile)->add('--stop');
$process = $pb->getProcess();
$process->start();
$output->writeln('<info>executing</info> ' . $process->getCommandLine());
while ($process->isRunning()) {
if (!$process->getOutput()) {
continue;
}
$output->writeln($process->getOutput());
$process->clearOutput();
}
$output->writeln($process->getOutput());
if (!$process->isSuccessful()) {
$output->writeln('<error>' . $process->getExitCodeText() . '</error>');
return;
}
}
示例2: execute
/**
* {@inheritdoc}
*
* @see PlatformCommand::getCurrentEnvironment()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$now = new \DateTime();
// Hopefully this isn't too opinionated?
$workingDir = dirname($this->behatLocation);
if (!is_dir($workingDir . '/vendor')) {
$output->writeln("<error>Assumed behat directory doesn't have depednencies installed: {$workingDir}.");
exit(1);
}
// Try to find the Behat binary
$composerData = json_decode(file_get_contents($workingDir . '/composer.json'), true);
if (isset($composerData['config']['bin-dir'])) {
$binDir = $composerData['config']['bin-dir'];
} else {
$binDir = 'vendor/bin/';
}
$outPath = Platform::rootDir() . '/behat-run-' . $now->getTimestamp() . '.log';
$builder = ProcessBuilder::create([$binDir . 'behat', '--format=pretty', '--out=' . $outPath]);
$builder->setWorkingDirectory($workingDir);
$builder->setTimeout(null);
$process = $builder->getProcess();
// @todo: export environment variables (postponed.)
// @note there's also v2 v3 issues we'd have to sort out for exporting.
// just run the dang thing.
$output->writeln("<info>Running Behat, saving output to {$outPath}");
$this->startSeleniumContainer();
$process->run();
$this->stopSeleniumContainer();
if (!$process->isSuccessful()) {
$output->writeln($process->getErrorOutput());
}
}
示例3: create
/**
* @inheritdoc
*/
public function create()
{
if (null === $this->binary) {
throw new InvalidArgumentException('No binary set');
}
return ProcessBuilder::create(array($this->binary))->setTimeout(null);
}
示例4: extractArchive
/**
* @throws ReleaseException
*/
private function extractArchive()
{
$process = ProcessBuilder::create(["tar", "-xvf", $this->release->path("build.tar.gz")])->setWorkingDirectory($this->release->path())->getProcess();
if ($process->run() !== 0) {
throw new ReleaseException($this->release, "Release failed, export repo: " . $process->getErrorOutput());
}
}
示例5: runCommand
/**
* Run an arbitrary command
*
* To display errors/output make sure to run with -vvv
*
* @param OutputInterface $output
* @param string|array|Process $command An instance of Process or an array of arguments to escape and run
* or a command to run
* @param string|null $error An error message that must be displayed if something went wrong
* @param bool $exceptionOnError If an error occurs, this message is an exception rather than a notice
* @return bool|string Output, or false if error
* @throws Exception
*/
public function runCommand(OutputInterface $output, $command, $error = null, $exceptionOnError = true)
{
$helper = $this->getProcessHelper();
// Prepare unbound command
if (is_array($command)) {
$process = ProcessBuilder::create($command)->getProcess();
} elseif ($command instanceof Process) {
$process = $command;
} else {
$process = new Process($command);
}
// Run it
$process->setTimeout(null);
$result = $helper->run($output, $process, $error);
// And cleanup
if ($result->isSuccessful()) {
return $result->getOutput();
} else {
if ($exceptionOnError) {
$error = $error ?: "Command did not run successfully";
throw new Exception($error);
}
return false;
}
}
示例6: run
/**
* Runs an external process.
*
* @param OutputInterface $output An OutputInterface instance
* @param string|array|Process $cmd An instance of Process or an array of arguments to escape and run or a command to run
* @param string|null $error An error message that must be displayed if something went wrong
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
* @param int $verbosity The threshold for verbosity
*
* @return Process The process that ran
*/
public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
{
$formatter = $this->getHelperSet()->get('debug_formatter');
if (is_array($cmd)) {
$process = ProcessBuilder::create($cmd)->getProcess();
} elseif ($cmd instanceof Process) {
$process = $cmd;
} else {
$process = new Process($cmd);
}
if ($verbosity <= $output->getVerbosity()) {
$output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
}
if ($output->isDebug()) {
$callback = $this->wrapCallback($output, $process, $callback);
}
$process->run($callback);
if ($verbosity <= $output->getVerbosity()) {
$message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
$output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
}
if (!$process->isSuccessful() && null !== $error) {
$output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
}
return $process;
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$configHelper = $this->getHelper('configuration');
/* @var $configHelper GlobalConfigurationHelper */
$processHelper = $this->getHelper('process');
/* @var $processHelper ProcessHelper */
$appConfig = $configHelper->getConfiguration()->getApplication($input->getArgument('application'));
$applicationVhosts = $appConfig->getVhosts();
if ($input->getOption('remove-vhosts') && count($applicationVhosts) > 0) {
$this->getApplication()->find('vhost:remove')->run(new ArrayInput(['vhosts' => array_map(function (VhostConfiguration $vhostConfiguration) {
return $vhostConfiguration->getName();
}, $applicationVhosts)]), $output);
$applicationVhosts = $appConfig->getVhosts();
}
if (count($applicationVhosts) > 0) {
throw new \RuntimeException(sprintf('This application has active vhosts: %s', implode(', ', array_map(function (VhostConfiguration $vhostConfig) {
return $vhostConfig->getName();
}, $applicationVhosts))));
}
$output->write(sprintf('Remove application <info>%s</info>...', $appConfig->getName()));
if ($input->getOption('purge')) {
$output->writeln(sprintf('Purging <comment>%s</comment>', $appConfig->getPath()));
$processHelper->mustRun($output, ProcessBuilder::create(['rm', '-rf', $appConfig->getPath()])->getProcess());
}
$configHelper->getConfiguration()->removeApplication($appConfig->getName());
$output->writeln('<info>OK</info>');
$configHelper->getConfiguration()->write();
}
示例8: __construct
/**
* AbstractDiagnoser constructor.
*
* @param ProcessHelper $processHelper
*/
public function __construct(ProcessHelper $processHelper)
{
$this->processHelper = $processHelper;
$this->process = ProcessBuilder::create($this->getProcessDefinition())->getProcess();
$this->output = new NullOutput();
$this->transformer = $this->getTransformer();
}
示例9: run
/**
* Runs an external process.
*
* @param OutputInterface $output An OutputInterface instance
* @param string|array|Process $cmd An instance of Process or an array of arguments to escape and run or a command to run
* @param string|null $error An error message that must be displayed if something went wrong
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
* @param int $verbosity The threshold for verbosity
* @param int $lineVerbosity Threshold for verbosity to show all output of the process
*
* @return Process The process that ran
*/
public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE, $lineVerbosity = OutputInterface::VERBOSITY_DEBUG)
{
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}
$formatter = $this->getHelperSet()->get('debug_formatter');
/* @var $formatter DebugFormatterHelper */
if (is_array($cmd)) {
$process = ProcessBuilder::create($cmd)->getProcess();
} elseif ($cmd instanceof Process) {
$process = $cmd;
} else {
$process = new Process($cmd);
}
if ($verbosity <= $output->getVerbosity()) {
$output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
$output->write($formatter->progress(spl_object_hash($process), $this->escapeString($process->getWorkingDirectory()), false, 'DIR'));
$output->write($formatter->progress(spl_object_hash($process), PHP_EOL));
}
if ($lineVerbosity <= $output->getVerbosity()) {
$callback = $this->wrapCallback($output, $process, $callback);
}
$process->run($callback);
if ($verbosity <= $output->getVerbosity()) {
$message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
$output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
}
if (!$process->isSuccessful() && null !== $error) {
$output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
}
return $process;
}
示例10: __construct
/**
* @param ProcessBuilder $processBuilder
*/
public function __construct($processBuilder = null)
{
if ($processBuilder === null) {
$this->processBuilder = ProcessBuilder::create()->setPrefix(array($this->command, $this->arguments));
} else {
$this->processBuilder = $processBuilder;
}
}
示例11: createProcessBuilder
private function createProcessBuilder($command)
{
$git_bin = $this->config['staging']['bin']['git'];
$processBuilder = ProcessBuilder::create([$git_bin, $command]);
$processBuilder->setTimeout(60);
$processBuilder->setWorkingDirectory($this->config['staging']['repo']['work_dir']);
return $processBuilder;
}
示例12: buildProcess
/**
* @param ProcessArgumentsCollection $arguments
*
* @return Process
* @throws \GrumPHP\Exception\PlatformException
*/
public function buildProcess(ProcessArgumentsCollection $arguments)
{
$builder = SymfonyProcessBuilder::create($arguments->getValues());
$builder->setTimeout($this->config->getProcessTimeout());
$process = $builder->getProcess();
$this->logProcessInVerboseMode($process);
$this->guardWindowsCmdMaxInputStringLimitation($process);
return $process;
}
示例13: applyPatch
/**
* @param $patch
*
* @return string
*/
protected function applyPatch($patch)
{
$process = ProcessBuilder::create(['patch', '-N', '--input=' . $patch])->setWorkingDirectory($this->tmpFolder)->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new PatchException('Patch failed: ' . $process->getOutput());
}
return $process->getOutput();
}
示例14: addFile
public function addFile($file)
{
$args = array('zip', '-j', $this->path, $file);
$process = ProcessBuilder::create($args)->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new LibraryException('Error while running zip command: ' . $process->getErrorOutput());
}
}
示例15: fetch
/**
* {@inheritdoc}
*/
public function fetch($scratchDir, LoggerInterface $logger)
{
$logger->info(sprintf('Syncing files from: %s', $this->source));
$process = ProcessBuilder::create($this->options)->setTimeout($this->timeout)->setPrefix('rsync')->add($this->source)->add($scratchDir)->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}