本文整理汇总了PHP中Symfony\Component\Process\ProcessBuilder::setEnv方法的典型用法代码示例。如果您正苦于以下问题:PHP ProcessBuilder::setEnv方法的具体用法?PHP ProcessBuilder::setEnv怎么用?PHP ProcessBuilder::setEnv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\ProcessBuilder
的用法示例。
在下文中一共展示了ProcessBuilder::setEnv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @throws \RuntimeException
*
* @return string
*/
public function run()
{
$lc_ctype = setlocale(LC_CTYPE, 0);
$this->processBuilder->add($this->filePath);
$this->processBuilder->setEnv('LANG', $lc_ctype);
$process = $this->processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
return $process->getOutput();
}
示例2: startWebServer
/**
* Запустить сервер
* @param InputInterface $input
* @param OutputInterface $output
* @param string $targetDirectory
* @return \Symfony\Component\Process\Process
*/
private function startWebServer(InputInterface $input, OutputInterface $output, $targetDirectory)
{
$manifestPath = getcwd() . '/' . $input->getArgument('manifest');
$manifest = new \Dmitrynaum\SAM\Component\Manifest($manifestPath);
$address = $manifest->getServerAddress();
$builder = new ProcessBuilder([PHP_BINARY, '-S', $address, 'server.php']);
$builder->setWorkingDirectory($targetDirectory);
$builder->setEnv('projectDir', getcwd());
$builder->setEnv('manifestPath', $manifestPath);
$builder->setTimeout(null);
$process = $builder->getProcess();
$process->start();
$output->writeln(sprintf('Server running on <comment>%s</comment>', $address));
return $process;
}
示例3: format
/**
* {@inheritDoc}
*/
public function format($string)
{
static $format = <<<EOF
var marked = require('marked'),
sys = require(process.binding('natives').util ? 'util' : 'sys');
marked.setOptions({
gfm: true,
highlight: function (code, lang, callback) {
require('pygmentize-bundled')({ lang: lang ? lang.toLowerCase() : null, format: 'html' }, code, function (err, result) {
if (err) return callback(err);
callback(null, result.toString());
});
},
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
langPrefix: 'lang-'
});
marked(%s, {}, function (error, content) {
if (error) {
throw error;
}
sys.print(content);
});
EOF;
$input = tempnam(sys_get_temp_dir(), 'fabricius_marked');
file_put_contents($input, sprintf($format, json_encode($string)));
$pb = new ProcessBuilder(array($this->nodeBin, $input));
if ($this->nodePaths) {
$pb->setEnv('NODE_PATH', implode(':', $this->nodePaths));
}
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 !== $code) {
$message = sprintf("An error occurred while running:\n%s", $proc->getCommandLine());
$errorOutput = $proc->getErrorOutput();
if (!empty($errorOutput)) {
$message .= "\n\nError Output:\n" . str_replace("\r", '', $errorOutput);
}
$output = $proc->getOutput();
if (!empty($output)) {
$message .= "\n\nOutput:\n" . str_replace("\r", '', $output);
}
throw new RuntimeException($message);
}
return $proc->getOutput();
}
示例4: __construct
/**
* Constructs the proccess
*
* @param string $cmd command to be executed
*/
public function __construct($cmd)
{
$this->builder = new ProcessBuilder();
// Inherit environment variables from Host operating system
$this->builder->inheritEnvironmentVariables();
$arguments = explode(' ', $cmd);
// Environment variables could be passed as per *nix command line (FLAG)=(VALUE) pairs
foreach ($arguments as $key => $argument) {
if (preg_match('/([A-Z][A-Z0-9_-]+)=(.*)/', $argument, $matches)) {
$this->builder->setEnv($matches[1], $matches[2]);
unset($arguments[$key]);
// Unset it from arguments list since we do not want it in proccess (otherwise command not found is given)
} else {
// Break if first non-environment argument is found, since after that everything is either command or option
break;
}
}
$this->builder->setArguments($arguments);
$this->symfonyProcess = $this->builder->getProcess();
}
示例5: run
public function run($args)
{
$finder = new PhpExecutableFinder();
$builder = new ProcessBuilder(array('bin/console', 'satis:update', '--build'));
$builder->setEnv('HOME', $this->getContainer()->getParameter('app.root_dir'));
$builder->setPrefix($finder->find());
$process = $builder->getProcess();
$process->run(function ($type, $message) {
echo $message;
});
}
示例6: checkNodeModule
protected function checkNodeModule($module, $bin = null)
{
if (!$bin && !($bin = $this->findExecutable('node', 'NODE_BIN'))) {
$this->markTestSkipped('Unable to find `node` executable.');
}
$pb = new ProcessBuilder(array($bin, '-e', 'require(\'' . $module . '\')'));
if (isset($_SERVER['NODE_PATH'])) {
$pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']);
}
return 0 === $pb->getProcess()->run();
}
示例7: checkRubyGem
protected function checkRubyGem($gem, $bin = null)
{
if (!$bin && !($bin = $this->findExecutable('ruby', 'RUBY_BIN'))) {
$this->markTestSkipped('Unable to find `ruby` executable.');
}
$pb = new ProcessBuilder(array($bin, '-e', 'require "' . $gem . '"'));
if (isset($_SERVER['RUBY_PATH'])) {
$pb->setEnv('RUBY_PATH', $_SERVER['RUBY_PATH']);
}
return 0 === $pb->getProcess()->run();
}
示例8: testNotReplaceExplicitlySetVars
public function testNotReplaceExplicitlySetVars()
{
$snapshot = $_ENV;
$_ENV = array('foo' => 'bar');
$expected = array('foo' => 'baz');
$pb = new ProcessBuilder();
$pb->setEnv('foo', 'baz')->inheritEnvironmentVariables()->add('foo');
$proc = $pb->getProcess();
$this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
$_ENV = $snapshot;
}
示例9: getProcess
/**
* Get a ready-to-run process instance.
*
* @param mixed[] $arguments
*
* @return \Symfony\Component\Process\Process
*/
protected function getProcess($arguments)
{
$prefix = [$this->platform->getPhpExecutable(), $this->platform->getPhpScript(), 'moodle'];
if ($this->moodleDir) {
$prefix = array_merge($prefix, ['--moodle-dir', $this->moodleDir]);
}
$arguments = array_merge($prefix, $arguments);
$builder = new ProcessBuilder($arguments);
$builder->setEnv('XDEBUG_CONFIG', '');
return $builder->getProcess();
}
示例10: run
public function run($args)
{
$configFile = $this->getConfigurationHelper()->generateConfiguration();
$finder = new PhpExecutableFinder();
$builder = new ProcessBuilder(array('vendor/bin/satis', 'build', $configFile));
$builder->setEnv('HOME', $this->getContainer()->getParameter('app.root_dir'));
$builder->setPrefix($finder->find());
$process = $builder->getProcess();
$process->run(function ($type, $message) {
echo $message;
});
}
示例11: filterLoad
public function filterLoad(AssetInterface $asset)
{
static $format = <<<'EOF'
var less = require('less');
var sys = require(process.binding('natives').util ? 'util' : 'sys');
new(less.Parser)(%s).parse(%s, function(e, tree) {
if (e) {
less.writeError(e);
process.exit(2);
}
try {
sys.print(tree.toCSS(%s));
} catch (e) {
less.writeError(e);
process.exit(3);
}
});
EOF;
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
// parser options
$parserOptions = array();
if ($root && $path) {
$parserOptions['paths'] = array(dirname($root . '/' . $path));
$parserOptions['filename'] = basename($path);
}
// tree options
$treeOptions = array();
if (null !== $this->compress) {
$treeOptions['compress'] = $this->compress;
}
$pb = new ProcessBuilder();
$pb->inheritEnvironmentVariables();
// node.js configuration
if (0 < count($this->nodePaths)) {
$pb->setEnv('NODE_PATH', implode(':', $this->nodePaths));
}
$pb->add($this->nodeBin)->add($input = tempnam(sys_get_temp_dir(), 'assetic_less'));
file_put_contents($input, sprintf($format, json_encode($parserOptions), json_encode($asset->getContent()), json_encode($treeOptions)));
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (0 < $code) {
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent($proc->getOutput());
}
示例12: setUp
protected function setUp()
{
$uglifyjsBin = $this->findExecutable('uglifyjs', 'UGLIFYJS2_BIN');
$nodeBin = $this->findExecutable('node', 'NODE_BIN');
if (!$uglifyjsBin) {
$this->markTestSkipped('Unable to find `uglifyjs` executable.');
}
// verify uglifyjs version
$pb = new ProcessBuilder($nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin));
$pb->add('--version');
if (isset($_SERVER['NODE_PATH'])) {
$pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']);
}
if (0 !== $pb->getProcess()->run()) {
$this->markTestSkipped('Incorrect version of UglifyJs');
}
$this->asset = new FileAsset(__DIR__ . '/fixtures/uglifyjs/script.js');
$this->asset->load();
$this->filter = new UglifyJs2Filter($uglifyjsBin, $nodeBin);
}
示例13: setEnv
/**
* Sets an environment variable.
*
* Setting a variable overrides its previous value. Use `null` to unset a
* defined environment variable.
*
* @param string $name The variable name
* @param null|string $value The variable value
*
* @return ProcessBuilderProxyInterface
*/
public function setEnv(string $name, string $value) : ProcessBuilderProxyInterface
{
$this->processBuilder->setEnv($name, $value);
return $this;
}
示例14: filterLoad
//.........这里部分代码省略.........
}
if ($this->noLineComments) {
$pb->add('--no-line-comments');
}
// these two options are not passed into the config file
// because like this, compass adapts this to be xxx_dir or xxx_path
// whether it's an absolute path or not
if ($this->imagesDir) {
$pb->add('--images-dir')->add($this->imagesDir);
}
if ($this->javascriptsDir) {
$pb->add('--javascripts-dir')->add($this->javascriptsDir);
}
// options in config file
$optionsConfig = array();
if (!empty($loadPaths)) {
$optionsConfig['additional_import_paths'] = $loadPaths;
}
if ($this->unixNewlines) {
$optionsConfig['sass_options']['unix_newlines'] = true;
}
if ($this->debugInfo) {
$optionsConfig['sass_options']['debug_info'] = true;
}
if ($this->cacheLocation) {
$optionsConfig['sass_options']['cache_location'] = $this->cacheLocation;
}
if ($this->noCache) {
$optionsConfig['sass_options']['no_cache'] = true;
}
if ($this->httpPath) {
$optionsConfig['http_path'] = $this->httpPath;
}
if ($this->httpImagesPath) {
$optionsConfig['http_images_path'] = $this->httpImagesPath;
}
if ($this->generatedImagesPath) {
$optionsConfig['generated_images_path'] = $this->generatedImagesPath;
}
if ($this->httpJavascriptsPath) {
$optionsConfig['http_javascripts_path'] = $this->httpJavascriptsPath;
}
// options in configuration file
if (count($optionsConfig)) {
$config = array();
foreach ($this->plugins as $plugin) {
$config[] = sprintf("require '%s'", addcslashes($plugin, '\\'));
}
foreach ($optionsConfig as $name => $value) {
if (!is_array($value)) {
$config[] = sprintf('%s = "%s"', $name, addcslashes($value, '\\'));
} elseif (!empty($value)) {
$config[] = sprintf('%s = %s', $name, $this->formatArrayToRuby($value));
}
}
$configFile = tempnam($tempDir, 'assetic_compass');
file_put_contents($configFile, implode("\n", $config) . "\n");
$pb->add('--config')->add($configFile);
}
$pb->add('--sass-dir')->add('')->add('--css-dir')->add('');
// compass choose the type (sass or scss from the filename)
if (null !== $this->scss) {
$type = $this->scss ? 'scss' : 'sass';
} elseif ($path) {
// FIXME: what if the extension is something else?
$type = pathinfo($path, PATHINFO_EXTENSION);
} else {
$type = 'scss';
}
$tempName = tempnam($tempDir, 'assetic_compass');
unlink($tempName);
// FIXME: don't use tempnam() here
// input
$input = $tempName . '.' . $type;
// work-around for https://github.com/chriseppstein/compass/issues/748
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
$input = str_replace('\\', '/', $input);
}
$pb->add($input);
file_put_contents($input, $asset->getContent());
// output
$output = $tempName . '.css';
// it's not really usefull but... https://github.com/chriseppstein/compass/issues/376
$pb->setEnv('HOME', sys_get_temp_dir());
$proc = $pb->getProcess();
$code = $proc->run();
if (0 < $code) {
unlink($input);
if (isset($configFile)) {
unlink($configFile);
}
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent(file_get_contents($output));
unlink($input);
unlink($output);
if (isset($configFile)) {
unlink($configFile);
}
}
示例15: parse
public function parse($parameters = [], $file = null)
{
$inputFile = $file !== null ? $file : $this->file;
$parameters = is_array($parameters) ? $parameters : [$parameters];
if ($inputFile === null || !file_exists($inputFile) || !is_readable($inputFile)) {
throw new InvalidArgumentException('File is null, not existent or not readable');
}
$finder = new ExecutableFinder();
$binary = $finder->find('java', null, $this->binDir);
if ($binary === null) {
throw new RuntimeException('Could not find java on your system');
}
// Jar binary, with additional java option (see https://github.com/tabulapdf/tabula-java/issues/26)
$arguments = ['-Xss2m', '-jar', $this->jarArchive, $inputFile];
$processBuilder = new ProcessBuilder();
if ($this->locale) {
$processBuilder->setEnv('LC_ALL', $this->locale);
}
$processBuilder->setPrefix($binary)->setArguments(array_merge($arguments, $parameters));
$process = $processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
throw new RuntimeException($process->getErrorOutput());
}
return $process->getOutput();
}