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


PHP ProcessBuilder::setInput方法代码示例

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


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

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

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

示例3: generate

 /**
  * {@inheritdoc}
  */
 public function generate($uri, $alias = null)
 {
     $html = $this->htmlFetcher->fetch($uri);
     $builder = new ProcessBuilder();
     $builder->setPrefix($this->criticalBin);
     $builder->setArguments(['--base=' . realpath(__DIR__ . '/../.tmp'), '--width=' . $this->width, '--height=' . $this->height, '--minify']);
     foreach ($this->css as $css) {
         $builder->add('--css=' . $css);
     }
     foreach ($this->ignore as $ignore) {
         $builder->add('--ignore=' . $ignore);
     }
     $builder->setInput($html);
     $process = $builder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new CssGeneratorException(sprintf('Error processing URI [%s]. This is probably caused by ' . 'the Critical npm package. Checklist: 1) `critical_bin`' . ' is correct, 2) `css` paths are correct 3) run `npm ' . 'install` again.', $uri));
     }
     return $this->storage->writeCss(is_null($alias) ? $uri : $alias, $process->getOutput());
 }
开发者ID:krisawzm,项目名称:critical-css,代码行数:23,代码来源:CriticalGenerator.php

示例4: 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/png'))) {
         return $binary;
     }
     $pb = new ProcessBuilder(array($this->pngquantBin));
     // Specify quality.
     $tranformQuality = array_key_exists('quality', $options) ? $options['quality'] : $this->quality;
     $pb->add('--quality');
     $pb->add($tranformQuality);
     // Read to/from stdout to save resources.
     $pb->add('-');
     $pb->setInput($binary->getContent());
     $proc = $pb->getProcess();
     $proc->run();
     // 98 and 99 are "quality too low" to compress current current image which, while isn't ideal, is not a failure
     if (!in_array($proc->getExitCode(), array(0, 98, 99))) {
         throw new ProcessFailedException($proc);
     }
     $result = new Binary($proc->getOutput(), $binary->getMimeType(), $binary->getFormat());
     return $result;
 }
开发者ID:aminin,项目名称:LiipImagineBundle,代码行数:31,代码来源:PngquantPostProcessor.php

示例5: highlight

 public function highlight($block, $language)
 {
     // Build the options
     $builder = new ProcessBuilder();
     // Input the block to the bin
     $builder->setPrefix("{$this->bin}");
     $builder->setInput($block);
     // Set the language and desired output
     $builder->add("-l{$language}")->add("-f{$this->output}");
     // Set some other options
     foreach ($this->defaultOpts as $argument => $value) {
         $builder->add("-P{$argument}={$value}");
     }
     // Run the process
     $process = $builder->getProcess();
     $process->run();
     // Check the output
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     // Return the result
     return $process->getOutput();
 }
开发者ID:cammanderson,项目名称:mmb,代码行数:23,代码来源:PygmentsShell.php

示例6: getProcessBuilder

 protected function getProcessBuilder($cmd, array $extras = array(), $input = null)
 {
     $builder = new ProcessBuilder();
     $builder->add($cmd);
     $builder->setTimeout($this->options['process-timeout']);
     foreach ($this->arguments as $argument) {
         try {
             $builder->add($this->getFormattedParameter($argument, $this->getArgument($argument)));
         } catch (\InvalidArgumentException $ex) {
             //nothing here
         }
     }
     foreach ($extras as $key => $value) {
         try {
             $builder->add($this->getFormattedParameter($key, $value));
         } catch (\InvalidArgumentException $ex) {
             //nothing here
         }
     }
     if (!is_null($input)) {
         $builder->setInput($input);
     }
     return $builder;
 }
开发者ID:pmaselkowski,项目名称:php-dmtx,代码行数:24,代码来源:AbstractDmtx.php

示例7: setInput

 /**
  * Sets the input of the process.
  *
  * @param string $input The input as a string
  *
  * @return ProcessBuilderProxyInterface
  *
  * @throws InvalidArgumentException In case the argument is invalid
  *
  * Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
  */
 public function setInput(string $input) : ProcessBuilderProxyInterface
 {
     $this->processBuilder->setInput($input);
     return $this;
 }
开发者ID:gplanchat,项目名称:grenade,代码行数:16,代码来源:ProcessBuilderProxyTrait.php

示例8: getProcess

 /**
  * @return Process
  */
 private function getProcess()
 {
     $processBuilder = new ProcessBuilder([$this->executable, 'a', '-si', '-so', '-an', '-txz', '-m0=lzma2', '-mx=9', '-mfb=64', '-md=32m']);
     $processBuilder->setInput($this->data);
     return $processBuilder->getProcess();
 }
开发者ID:brainbits,项目名称:transcoder,代码行数:9,代码来源:SevenzEncoder.php

示例9: compileFile

 public function compileFile(AssetInfo $assetInfo)
 {
     $assetPath = $assetInfo->getPath();
     $localPath = $this->getAssetPath($assetPath);
     if (!file_exists($localPath)) {
         return null;
     }
     $publicPath = $this->getPublicAssetPath($assetPath);
     $targetPath = 'cache/scss/' . substr($publicPath, 0, strrpos($publicPath, '.'));
     if ('.css' !== substr($targetPath, -4)) {
         $targetPath .= '.css';
     }
     $needsCompilation = true;
     $sourceMTime = filemtime($localPath);
     $dir = dirname($localPath);
     if ($this->filesystem->has('web/' . $targetPath)) {
         $fh = $this->filesystem->handle('web/' . $targetPath);
         if ($fh) {
             $firstLine = fgets($fh);
             $info = substr($firstLine, strlen('/* compiled at '), -3);
             $spacePosition = strpos($info, ' ');
             $lastSourceMTime = 0;
             $dependencies = [];
             if ($spacePosition > 0) {
                 $lastSourceMTime = (int) substr($info, 0, $spacePosition);
                 $dependencies = trim(substr($info, $spacePosition + 1));
                 if ($dependencies) {
                     $dependencies = explode(',', trim(substr($info, $spacePosition + 1)));
                 } else {
                     $dependencies = [];
                 }
             } else {
                 //old format without dependencies
                 $lastSourceMTime = (int) $info;
             }
             $needsCompilation = $lastSourceMTime !== $sourceMTime;
             if (!$needsCompilation) {
                 //check dependencies
                 foreach ($dependencies as $dependency) {
                     list($path, $depLastMTime) = explode(':', $dependency);
                     $depLastMTime = (int) $depLastMTime;
                     if (!file_exists($dir . '/' . $path)) {
                         //depended file does not exist anymore, so we need to recompile
                         $needsCompilation = true;
                         break;
                     }
                     $depSourceMTime = filemtime($dir . '/' . $path);
                     if ($depLastMTime !== $depSourceMTime) {
                         $needsCompilation = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($needsCompilation) {
         //resolve all dependencies
         $dependencies = [];
         $this->resolveDependencies($localPath, $dependencies);
         $processBuilder = new ProcessBuilder();
         $processBuilder->setInput(file_get_contents($localPath))->add('sass')->add('--scss')->add('--no-cache')->add('--unix-newlines')->add('--load-path')->add(dirname($localPath))->add($localPath)->enableOutput();
         $process = $processBuilder->getProcess();
         $process->start();
         while ($process->isRunning()) {
         }
         if (127 === $process->getExitCode()) {
             throw new \RuntimeException('sass binary not found. Please install sass first and make its in $PATH. ' . $process->getExitCodeText());
         }
         if (0 !== $process->getExitCode()) {
             throw new \RuntimeException(sprintf("Error during scss compilation of %s:\n%s\n%s\n%s", $assetPath, $process->getExitCodeText(), $process->getErrorOutput(), $process->getOutput()));
         }
         $compiled = $process->getOutput();
         $compiled = $this->replaceRelativePaths($publicPath, $targetPath, $compiled);
         $dependencies = implode(',', $dependencies);
         $info = "{$sourceMTime} {$dependencies}";
         $compiled = "/* compiled at {$info} */\n" . $compiled;
         $this->filesystem->write('web/' . $targetPath, $compiled);
     }
     $assetInfo = new AssetInfo();
     $assetInfo->setPath($targetPath);
     $assetInfo->setContentType('text/css');
     return $assetInfo;
 }
开发者ID:jarves,项目名称:jarves,代码行数:83,代码来源:ScssHandler.php


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