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


PHP ProcessBuilder::add方法代码示例

本文整理汇总了PHP中Symfony\Component\Process\ProcessBuilder::add方法的典型用法代码示例。如果您正苦于以下问题:PHP ProcessBuilder::add方法的具体用法?PHP ProcessBuilder::add怎么用?PHP ProcessBuilder::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Process\ProcessBuilder的用法示例。


在下文中一共展示了ProcessBuilder::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compress

 /**
  * Compresses a string.
  *
  * @param string $content The content to compress
  * @param string $type    The type of content, either "js" or "css"
  * @param array  $options An indexed array of additional options
  *
  * @return string The compressed content
  */
 protected function compress($content, $type, $options = array())
 {
     $pb = new ProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
     foreach ($options as $option) {
         $pb->add($option);
     }
     if (null !== $this->charset) {
         $pb->add('--charset')->add($this->charset);
     }
     if (null !== $this->lineBreak) {
         $pb->add('--line-break')->add($this->lineBreak);
     }
     // input and output files
     $tempDir = realpath(sys_get_temp_dir());
     $hash = substr(sha1(time() . rand(11111, 99999)), 0, 7);
     $input = $tempDir . DIRECTORY_SEPARATOR . $hash . '.' . $type;
     $output = $tempDir . DIRECTORY_SEPARATOR . $hash . '-min.' . $type;
     file_put_contents($input, $content);
     $pb->add('-o')->add($output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 < $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw FilterException::fromProcess($proc)->setInput($content);
     } elseif (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $retval = file_get_contents($output);
     unlink($output);
     return $retval;
 }
开发者ID:noisebleed,项目名称:markdown-resume,代码行数:43,代码来源:BaseCompressorFilter.php

示例2: compress

 /**
  * Compresses a string.
  *
  * @param string $content The content to compress
  * @param string $type    The type of content, either "js" or "css"
  * @param array  $options An indexed array of additional options
  *
  * @return string The compressed content
  */
 protected function compress($content, $type, $options = array())
 {
     $pb = new ProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
     foreach ($options as $option) {
         $pb->add($option);
     }
     if (null !== $this->charset) {
         $pb->add('--charset')->add($this->charset);
     }
     if (null !== $this->lineBreak) {
         $pb->add('--line-break')->add($this->lineBreak);
     }
     // input and output files
     $tempDir = realpath(sys_get_temp_dir());
     $input = tempnam($tempDir, 'YUI-IN-');
     $output = tempnam($tempDir, 'YUI-OUT-');
     file_put_contents($input, $content);
     $pb->add('-o')->add($output)->add('--type')->add($type)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 < $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw FilterException::fromProcess($proc)->setInput($content);
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $retval = file_get_contents($output);
     unlink($output);
     return $retval;
 }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:43,代码来源:BaseCompressorFilter.php

示例3: execute

 function execute($argv = array())
 {
     $builder = new ProcessBuilder();
     $builder->add($this->executable);
     if (@$argv[0] instanceof Response) {
         $builder->setInput(array_shift($argv)->getOutput());
     } else {
         if (is_array(@$argv[0])) {
             $flags = array_shift($argv);
             foreach ($flags as $flag => $value) {
                 $builder->add((strlen($flag) > 1 ? "--" : "-") . $flag);
                 $value === true or $builder->add($value);
             }
         }
     }
     foreach ($argv as $a) {
         $builder->add($a);
     }
     $process = $builder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         $status = $process->getExitCode();
         $commandLine = $process->getCommandLine();
         throw new ErrorException("Command [{$commandLine}] failed with status [{$status}].", $status, $process->getErrorOutput());
     }
     return new Response($process->getOutput(), $process->getErrorOutput());
 }
开发者ID:chh,项目名称:commander,代码行数:27,代码来源:Command.php

示例4: 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

示例5: filterDump

 public function filterDump(AssetInterface $asset)
 {
     $pb = new ProcessBuilder(array($this->jpegtranBin));
     if ($this->optimize) {
         $pb->add('-optimize');
     }
     if ($this->copy) {
         $pb->add('-copy')->add($this->copy);
     }
     if ($this->progressive) {
         $pb->add('-progressive');
     }
     if (null !== $this->restart) {
         $pb->add('-restart')->add($this->restart);
     }
     $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_jpegtran'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 < $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
开发者ID:noisebleed,项目名称:markdown-resume,代码行数:25,代码来源:JpegtranFilter.php

示例6: processWithConfiguration

 /**
  * @param BinaryInterface $binary
  * @param array           $options
  *
  * @throws ProcessFailedException
  *
  * @return BinaryInterface
  */
 public function processWithConfiguration(BinaryInterface $binary, array $options)
 {
     $type = strtolower($binary->getMimeType());
     if (!in_array($type, array('image/jpeg', 'image/jpg'))) {
         return $binary;
     }
     $pb = new ProcessBuilder(array($this->mozjpegBin));
     // Places emphasis on DC
     $pb->add('-quant-table');
     $pb->add(2);
     $transformQuality = array_key_exists('quality', $options) ? $options['quality'] : $this->quality;
     if ($transformQuality !== null) {
         $pb->add('-quality');
         $pb->add($transformQuality);
     }
     $pb->add('-optimise');
     // Favor stdin/stdout so we don't waste time creating a new file.
     $pb->setInput($binary->getContent());
     $proc = $pb->getProcess();
     $proc->run();
     if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) {
         throw new ProcessFailedException($proc);
     }
     $result = new Binary($proc->getOutput(), $binary->getMimeType(), $binary->getFormat());
     return $result;
 }
开发者ID:aminin,项目名称:LiipImagineBundle,代码行数:34,代码来源:MozJpegPostProcessor.php

示例7: 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

示例8: filterDump

 /**
  * Run the asset through UglifyJs
  *
  * @see Assetic\Filter\FilterInterface::filterDump()
  */
 public function filterDump(AssetInterface $asset)
 {
     $executables = array();
     if ($this->nodeJsPath !== null) {
         $executables[] = $this->nodeJsPath;
     }
     $executables[] = $this->uglifyCssPath;
     $pb = new ProcessBuilder($executables);
     if ($this->expandVars) {
         $pb->add('--expand-vars');
     }
     if ($this->uglyComments) {
         $pb->add('--ugly-comments');
     }
     if ($this->cuteComments) {
         $pb->add('--cute-comments');
     }
     // input and output files
     $input = tempnam(sys_get_temp_dir(), 'input');
     file_put_contents($input, $asset->getContent());
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (127 === $code) {
         throw new \RuntimeException('Path to node executable could not be resolved.');
     }
     if (0 < $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
开发者ID:Robert-Xie,项目名称:php-framework-benchmark,代码行数:37,代码来源:UglifyCssFilter.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process(array $files)
 {
     $tmpFile = Filename::temporaryFilename($this->filename);
     $processBuilder = new ProcessBuilder();
     $processBuilder->add('tar');
     if (!is_null($this->flags)) {
         $processBuilder->add($this->flags);
     }
     $processBuilder->add($tmpFile);
     /**
      * @var FileInterface $backup
      */
     foreach ($files as $backup) {
         $processBuilder->add($backup->getPath());
     }
     $process = $processBuilder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new ProcessorException(sprintf('Unable to create gzip archive, reason: "%s".', $process->getErrorOutput()));
     }
     $this->getEventDispatcher()->addListener(BackupEvents::TERMINATE, function () use($tmpFile) {
         unlink($tmpFile);
     });
     return array(File::fromLocal($tmpFile, dirname($tmpFile)));
 }
开发者ID:runopencode,项目名称:backup,代码行数:28,代码来源:GzipArchiveProcessor.php

示例10: __construct

 /**
  * Constructor.
  *
  * @param GitRepository $repository The git repository to work on.
  */
 public function __construct(GitRepository $repository)
 {
     $this->repository = $repository;
     $this->processBuilder = new ProcessBuilder();
     $this->processBuilder->setWorkingDirectory($repository->getRepositoryPath());
     $this->processBuilder->add($this->repository->getConfig()->getGitExecutablePath());
     $this->initializeProcessBuilder();
 }
开发者ID:bit3,项目名称:git-php,代码行数:13,代码来源:AbstractCommandBuilder.php

示例11: start

 /**
  * Asynchronously start mediainfo operation.
  * Make call to MediaInfoCommandRunner::wait() afterwards to receive output.
  */
 public function start()
 {
     $this->processBuilder->add($this->filePath);
     $this->processAsync = $this->processBuilder->getProcess();
     // just takes advantage of symfony's underlying Process framework
     // process runs in background
     $this->processAsync->start();
 }
开发者ID:petrofcz,项目名称:php-mediainfo,代码行数:12,代码来源:MediaInfoCommandRunner.php

示例12: configureProcess

 /**
  * {@inheritdoc}
  */
 protected function configureProcess(ProcessBuilder $processBuilder, Notification $notification)
 {
     $script = 'display notification "' . $notification->getBody() . '"';
     if ($notification->getTitle()) {
         $script .= ' with title "' . $notification->getTitle() . '"';
     }
     $processBuilder->add('-e');
     $processBuilder->add($script);
 }
开发者ID:kjmtrue,项目名称:JoliNotif,代码行数:12,代码来源:AppleScriptNotifier.php

示例13: run

 /**
  * @return string
  */
 public function run()
 {
     $this->processBuilder->add($this->filePath);
     $process = $this->processBuilder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     return $process->getOutput();
 }
开发者ID:yupmin,项目名称:php-chardet,代码行数:13,代码来源:ChardetCommandRunner.php

示例14: runCommand

 /**
  * Launches a command.
  * If '--process-isolation' parameter is specified the command will be launched as a separate process.
  * In this case you can parameter '--process-timeout' to set the process timeout
  * in seconds. Default timeout is 60 seconds.
  * If '--ignore-errors' parameter is specified any errors are ignored;
  * otherwise, an exception is raises if an error happened.
  *
  * @param string $command
  * @param array  $params
  * @return CommandExecutor
  * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified
  */
 public function runCommand($command, $params = array())
 {
     $params = array_merge(array('command' => $command, '--no-debug' => true), $params);
     if ($this->env && $this->env !== 'dev') {
         $params['--env'] = $this->env;
     }
     $ignoreErrors = false;
     if (array_key_exists('--ignore-errors', $params)) {
         $ignoreErrors = true;
         unset($params['--ignore-errors']);
     }
     if (array_key_exists('--process-isolation', $params)) {
         unset($params['--process-isolation']);
         $phpFinder = new PhpExecutableFinder();
         $php = $phpFinder->find();
         $pb = new ProcessBuilder();
         $pb->add($php)->add($_SERVER['argv'][0]);
         if (array_key_exists('--process-timeout', $params)) {
             $pb->setTimeout($params['--process-timeout']);
             unset($params['--process-timeout']);
         }
         foreach ($params as $param => $val) {
             if ($param && '-' === $param[0]) {
                 if ($val === true) {
                     $pb->add($param);
                 } elseif (is_array($val)) {
                     foreach ($val as $value) {
                         $pb->add($param . '=' . $value);
                     }
                 } else {
                     $pb->add($param . '=' . $val);
                 }
             } else {
                 $pb->add($val);
             }
         }
         $process = $pb->inheritEnvironmentVariables(true)->getProcess();
         $output = $this->output;
         $process->run(function ($type, $data) use($output) {
             $output->write($data);
         });
         $ret = $process->getExitCode();
     } else {
         $this->application->setAutoExit(false);
         $ret = $this->application->run(new ArrayInput($params), $this->output);
     }
     if (0 !== $ret) {
         if ($ignoreErrors) {
             $this->output->writeln(sprintf('<error>The command terminated with an error code: %u.</error>', $ret));
         } else {
             throw new \RuntimeException(sprintf('The command terminated with an error status: %u.', $ret));
         }
     }
     return $this;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:68,代码来源:CommandExecutor.php

示例15: configureProcess

 /**
  * {@inheritdoc}
  */
 protected function configureProcess(ProcessBuilder $processBuilder, Notification $notification)
 {
     if ($notification->getIcon()) {
         $processBuilder->add('--icon');
         $processBuilder->add($notification->getIcon());
     }
     if ($notification->getTitle()) {
         $processBuilder->add($notification->getTitle());
     }
     $processBuilder->add($notification->getBody());
 }
开发者ID:kjmtrue,项目名称:JoliNotif,代码行数:14,代码来源:NotifySendNotifier.php


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