本文整理汇总了PHP中Symfony\Component\Process\ProcessBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP ProcessBuilder类的具体用法?PHP ProcessBuilder怎么用?PHP ProcessBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProcessBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testShouldSetArguments
public function testShouldSetArguments()
{
$pb = new ProcessBuilder(array('initial'));
$pb->setArguments(array('second'));
$proc = $pb->getProcess();
$this->assertContains("second", $proc->getCommandLine());
}
示例2: run
/**
* @throws InvalidCodingStandardException
*/
public function run()
{
$this->outputHandler->setTitle('Checking code style with PHPCS');
$this->output->write($this->outputHandler->getTitle());
foreach ($this->files as $file) {
if (!preg_match($this->neddle, $file)) {
continue;
}
$oldPath = getcwd();
$file = $oldPath . '/' . $file;
chdir(__DIR__ . '/../../../../../../../');
$processBuilder = new ProcessBuilder(array('php', 'bin/phpcs', '--standard=' . self::STANDARD . '', $file));
/** @var Process $phpCs */
$phpCs = $processBuilder->getProcess();
$phpCs->run();
if (false === $phpCs->isSuccessful()) {
$this->outputHandler->setError($phpCs->getOutput());
$this->output->writeln($this->outputHandler->getError());
$this->output->writeln(BadJobLogo::paint());
throw new InvalidCodingStandardException();
}
chdir($oldPath);
}
$this->output->writeln($this->outputHandler->getSuccessfulStepMessage());
}
示例3: execute
/**
* @param string $file
*
* @return Process
*/
private function execute($file)
{
$processBuilder = new ProcessBuilder(['php', '-l', $file]);
$process = $processBuilder->getProcess();
$process->run();
return $process;
}
示例4: filterDump
public function filterDump(AssetInterface $asset)
{
$pb = new ProcessBuilder(array($this->pngoutBin));
if (null !== $this->color) {
$pb->add('-c' . $this->color);
}
if (null !== $this->filter) {
$pb->add('-f' . $this->filter);
}
if (null !== $this->strategy) {
$pb->add('-s' . $this->strategy);
}
if (null !== $this->blockSplitThreshold) {
$pb->add('-b' . $this->blockSplitThreshold);
}
$pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_pngout'));
file_put_contents($input, $asset->getContent());
$output = tempnam(sys_get_temp_dir(), 'assetic_pngout');
unlink($output);
$pb->add($output .= '.png');
$proc = $pb->getProcess();
$code = $proc->run();
if (0 < $code) {
unlink($input);
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent(file_get_contents($output));
unlink($input);
unlink($output);
}
示例5: execute
/**
* Execute this task
*
* @param \TYPO3\Surf\Domain\Model\Node $node
* @param \TYPO3\Surf\Domain\Model\Application $application
* @param \TYPO3\Surf\Domain\Model\Deployment $deployment
* @param array $options
* @throws \TYPO3\Surf\Exception\InvalidConfigurationException
* @return void
*/
public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
{
$this->assertRequiredOptionsExist($options);
$dumpCommand = new ProcessBuilder();
$dumpCommand->setPrefix('mysqldump');
$dumpCommand->setArguments(array('-h', $options['sourceHost'], '-u', $options['sourceUser'], '-p' . $options['sourcePassword'], $options['sourceDatabase']));
$mysqlCommand = new ProcessBuilder();
$mysqlCommand->setPrefix('mysql');
$mysqlCommand->setArguments(array('-h', $options['targetHost'], '-u', $options['targetUser'], '-p' . $options['targetPassword'], $options['targetDatabase']));
$arguments = array();
$username = isset($options['username']) ? $options['username'] . '@' : '';
$hostname = $node->getHostname();
$arguments[] = $username . $hostname;
if ($node->hasOption('port')) {
$arguments[] = '-P';
$arguments[] = $node->getOption('port');
}
$arguments[] = $mysqlCommand->getProcess()->getCommandLine();
$sshCommand = new ProcessBuilder();
$sshCommand->setPrefix('ssh');
$sshCommand->setArguments($arguments);
$command = $dumpCommand->getProcess()->getCommandLine() . ' | ' . $sshCommand->getProcess()->getCommandLine();
$localhost = new Node('localhost');
$localhost->setHostname('localhost');
$this->shell->executeOrSimulate($command, $localhost, $deployment);
}
示例6: handle
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
echo "Run task: #" . $this->job_id, "\n";
$task = Tasks::find($this->job_id);
$task->status = Tasks::RUN;
$task->save();
$client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client('tcp://127.0.0.1:8889'));
$client->setHost('127.0.0.1');
$client->connect();
$client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::RUN])]));
$builder = new ProcessBuilder();
$builder->setPrefix('ansible-playbook');
$builder->setArguments(["-i", "inv" . $this->job_id, "yml" . $this->job_id]);
$builder->setWorkingDirectory(storage_path("roles"));
$process = $builder->getProcess();
$process->run();
//echo $process->getOutput() . "\n";
$client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::FINISH])]));
$client->close();
$task->status = Tasks::FINISH;
$task->content = file_get_contents(storage_path("tmp/log" . $this->job_id . ".txt"));
$task->save();
unlink(storage_path("roles/yml" . $this->job_id));
unlink(storage_path("roles/inv" . $this->job_id));
unlink(storage_path("tmp/log" . $this->job_id . ".txt"));
echo "End task: #" . $this->job_id, "\n";
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// Direct access to the Container.
/** @var Kengrabber $kg */
$kg = $this->getApplication()->getContainer();
$output->writeln("Build everything...");
$kg['monolog']->addDebug("Build everything...");
$commands = array("videolist:grab", "videolist:download", "cleanup", "verify", "render");
foreach ($commands as $command) {
$builder = new ProcessBuilder(array("php", $_SERVER["SCRIPT_FILENAME"], $command));
if ($kg['debug'] === true) {
$builder->add("--debug");
}
$process = $builder->getProcess();
$process->setTimeout(0);
$process->run(function ($type, $buffer) use($kg, $output) {
if (Process::ERR === $type) {
$output->write("<error>{$buffer}</error>");
} else {
$output->write($buffer);
}
});
}
$output->writeln("<info>Finished building...</info>");
}
示例8: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$database = $input->getArgument('database');
$file = $input->getOption('file');
$learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
$databaseConnection = $this->resolveConnection($io, $database);
if (!$file) {
$io->error($this->trans('commands.database.restore.messages.no-file'));
return;
}
if ($databaseConnection['driver'] == 'mysql') {
$command = sprintf('mysql --user=%s --password=%s --host=%s --port=%s %s < %s', $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], $databaseConnection['port'], $databaseConnection['database'], $file);
} elseif ($databaseConnection['driver'] == 'pgsql') {
$command = sprintf('PGPASSWORD="%s" psql -w -U %s -h %s -p %s -d %s -f %s', $databaseConnection['password'], $databaseConnection['username'], $databaseConnection['host'], $databaseConnection['port'], $databaseConnection['database'], $file);
}
if ($learning) {
$io->commentBlock($command);
}
$processBuilder = new ProcessBuilder(['-v']);
$process = $processBuilder->getProcess();
$process->setWorkingDirectory($this->getDrupalHelper()->getRoot());
$process->setTty('true');
$process->setCommandLine($command);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
$io->success(sprintf('%s %s', $this->trans('commands.database.restore.messages.success'), $file));
}
示例9: runCommand
protected function runCommand($cmd)
{
$builder = new ProcessBuilder($cmd);
$process = $builder->getProcess();
$process->run();
return $process->getOutput();
}
示例10: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$learning = $input->hasOption('learning') ? $input->getOption('learning') : false;
$address = $this->validatePort($input->getArgument('address'));
$finder = new PhpExecutableFinder();
if (false === ($binary = $finder->find())) {
$io->error($this->trans('commands.server.errors.binary'));
return;
}
$router = $this->getRouterPath();
$cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router);
if ($learning) {
$io->commentBlock($cli);
}
$io->success(sprintf($this->trans('commands.server.messages.executing'), $binary));
$processBuilder = new ProcessBuilder(explode(' ', $cli));
$process = $processBuilder->getProcess();
$process->setWorkingDirectory($this->appRoot);
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
$process->setTty('true');
} else {
$process->setTimeout(null);
}
$process->run();
if (!$process->isSuccessful()) {
$io->error($process->getErrorOutput());
}
}
示例11: onPngImageSaved
/**
* @param ImageSavedEvent $event
*/
public function onPngImageSaved(ImageSavedEvent $event)
{
if ($event->getImage()->mime() == "image/png" && $this->pngquantPath != "") {
$builder = new ProcessBuilder(array($this->pngquantPath, '-f', '--speed', '1', '-o', $event->getImageFile()->getPathname(), $event->getImageFile()->getPathname()));
$builder->getProcess()->run();
}
}
示例12: run
public function run()
{
$this->outputHandler->setTitle(sprintf('Checking json code with %s', strtoupper('jsonlint')));
$this->output->write($this->outputHandler->getTitle());
$errors = [];
foreach ($this->files as $file) {
if (!preg_match($this->needle, $file)) {
continue;
}
$processBuilder = new ProcessBuilder(array('php', 'bin/jsonlint', $file));
$process = $processBuilder->getProcess();
$process->run();
if (false === $process->isSuccessful()) {
$errors[] = $process->getOutput();
}
}
$errors = array_filter($errors, function ($var) {
return !is_null($var);
});
if ($errors) {
$this->output->writeln(BadJobLogo::paint());
throw new JsonLintViolationsException(implode('', $errors));
}
$this->output->writeln($this->outputHandler->getSuccessfulStepMessage());
}
示例13: process
/**
* @param BinaryInterface $binary
*
* @throws ProcessFailedException
*
* @return BinaryInterface
*
* @see Implementation taken from Assetic\Filter\optipngFilter
*/
public function process(BinaryInterface $binary)
{
$type = strtolower($binary->getMimeType());
if (!in_array($type, array('image/png'))) {
return $binary;
}
if (false === ($input = tempnam(sys_get_temp_dir(), 'imagine_optipng'))) {
throw new \RuntimeException(sprintf('Temp file can not be created in "%s".', sys_get_temp_dir()));
}
$pb = new ProcessBuilder(array($this->optipngBin));
$pb->add('--o7');
$pb->add($input);
if ($binary instanceof FileBinaryInterface) {
copy($binary->getPath(), $input);
} else {
file_put_contents($input, $binary->getContent());
}
$proc = $pb->getProcess();
$proc->run();
if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) {
unlink($input);
throw new ProcessFailedException($proc);
}
$result = new Binary(file_get_contents($input), $binary->getMimeType(), $binary->getFormat());
unlink($input);
return $result;
}
示例14: startProcess
/**
* Creates the given process
*
* @throws \Exception
*/
private function startProcess(OutputInterface $output)
{
$arguments = $this->resolveProcessArgs();
$name = sha1(serialize($arguments));
if ($this->background->hasProcess($name)) {
throw new \RuntimeException("Service is already running.");
}
$builder = new ProcessBuilder($arguments);
if ($this->hasParameter('cwd')) {
$builder->setWorkingDirectory($this->getParameter('cwd'));
}
$process = $builder->getProcess();
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($process->getCommandLine());
}
if ($this->hasParameter('output')) {
$append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
$stream = fopen($this->getParameter('output'), $append);
$output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
}
$process->start(function ($type, $buffer) use($output) {
$output->write($buffer);
});
$this->background->addProcess($name, $process);
if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
}
}
示例15: execute
/**
* @param string $file
* @param string $standard
*
* @return Process
*/
private function execute($file, $standard)
{
$processBuilder = new ProcessBuilder(['php', $this->toolPathFinder->find('phpcs'), '--standard=' . $standard, $file]);
$process = $processBuilder->getProcess();
$process->run();
return $process;
}