当前位置: 首页>>代码示例>>PHP>>正文


PHP Process\ProcessBuilder类代码示例

本文整理汇总了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());
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:7,代码来源:ProcessBuilderTest.php

示例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());
 }
开发者ID:sdieunidou,项目名称:php-git-hooks,代码行数:28,代码来源:CodeSnifferHandler.php

示例3: execute

 /**
  * @param string $file
  *
  * @return Process
  */
 private function execute($file)
 {
     $processBuilder = new ProcessBuilder(['php', '-l', $file]);
     $process = $processBuilder->getProcess();
     $process->run();
     return $process;
 }
开发者ID:bruli,项目名称:php-git-hooks,代码行数:12,代码来源:PhpLintToolProcessor.php

示例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);
 }
开发者ID:noisebleed,项目名称:markdown-resume,代码行数:30,代码来源:PngoutFilter.php

示例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);
 }
开发者ID:TYPO3,项目名称:Surf,代码行数:36,代码来源:DumpDatabaseTask.php

示例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";
 }
开发者ID:mangareader,项目名称:laravel-ansible,代码行数:32,代码来源:runAnsible.php

示例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>");
 }
开发者ID:engelju,项目名称:kexpgrabber,代码行数:25,代码来源:BuildCommand.php

示例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));
 }
开发者ID:durgeshs,项目名称:DrupalConsole,代码行数:33,代码来源:RestoreCommand.php

示例9: runCommand

 protected function runCommand($cmd)
 {
     $builder = new ProcessBuilder($cmd);
     $process = $builder->getProcess();
     $process->run();
     return $process->getOutput();
 }
开发者ID:pierredup,项目名称:gush-block,代码行数:7,代码来源:AbstractGushTask.php

示例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());
     }
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:32,代码来源:ServerCommand.php

示例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();
     }
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:10,代码来源:PngFileListener.php

示例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());
 }
开发者ID:dw250100785,项目名称:php-git-hooks,代码行数:25,代码来源:JsonLintHandler.php

示例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;
 }
开发者ID:aminin,项目名称:LiipImagineBundle,代码行数:36,代码来源:OptiPngPostProcessor.php

示例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());
     }
 }
开发者ID:kangkot,项目名称:bldr,代码行数:33,代码来源:BackgroundTask.php

示例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;
 }
开发者ID:bruli,项目名称:php-git-hooks,代码行数:13,代码来源:PhpCsToolProcessor.php


注:本文中的Symfony\Component\Process\ProcessBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。