本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
示例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());
}
示例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)));
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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());
}