本文整理汇总了PHP中Symfony\Component\Process\Process::setEnv方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::setEnv方法的具体用法?PHP Process::setEnv怎么用?PHP Process::setEnv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::setEnv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* {@inheritdoc}
*/
public function run()
{
$this->printAction();
$this->process = new Process($this->getCommand());
$this->process->setTimeout($this->timeout);
$this->process->setIdleTimeout($this->idleTimeout);
$this->process->setWorkingDirectory($this->workingDirectory);
if (isset($this->env)) {
$this->process->setEnv($this->env);
}
if (!$this->background and !$this->isPrinted) {
$this->startTimer();
$this->process->run();
$this->stopTimer();
return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
}
if (!$this->background and $this->isPrinted) {
$this->startTimer();
$this->process->run(function ($type, $buffer) {
$progressWasVisible = $this->hideTaskProgress();
print $buffer;
$this->showTaskProgress($progressWasVisible);
});
$this->stopTimer();
return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
}
try {
$this->process->start();
} catch (\Exception $e) {
return Result::fromException($this, $e);
}
return Result::success($this);
}
示例2: render
function render($context = null, $vars = array())
{
$options = $this->options;
$compress = @$options["compress"] ?: false;
$outputFile = tempnam(sys_get_temp_dir(), 'metatemplate_template_less_output');
$finder = new ExecutableFinder();
$bin = @$this->options["less_bin"] ?: self::DEFAULT_LESSC;
$cmd = $finder->find($bin);
if ($cmd === null) {
throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
}
if ($compress) {
$cmd .= ' -x';
}
if (array_key_exists('include_path', $this->options)) {
$cmd .= sprintf('--include-path %s', escapeshellarg(join(PATH_SEPARATOR, (array) $this->options['include_path'])));
}
$cmd .= " --no-color - {$outputFile}";
$process = new Process($cmd);
$process->setStdin($this->getData());
if ($this->isFile()) {
$process->setWorkingDirectory(dirname($this->source));
}
$process->setEnv(array('PATH' => getenv("PATH")));
$process->run();
$content = @file_get_contents($outputFile);
@unlink($outputFile);
if (!$process->isSuccessful()) {
throw new \RuntimeException("{$cmd} returned an error: " . $process->getErrorOutput());
}
return $content;
}
示例3: render
function render($context = null, $vars = array())
{
$finder = new ExecutableFinder();
$bin = @$this->options["tsc_bin"] ?: self::DEFAULT_TSC;
$cmd = $finder->find($bin);
if ($cmd === null) {
throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
}
$inputFile = sys_get_temp_dir() . '/pipe_typescript_input_' . uniqid() . '.ts';
file_put_contents($inputFile, $this->getData());
$outputFile = tempnam(sys_get_temp_dir(), 'pipe_typescript_output_') . '.js';
$cmd .= " --out " . escapeshellarg($outputFile) . ' ' . escapeshellarg($inputFile);
$process = new Process($cmd);
$process->setEnv(array('PATH' => @$_SERVER['PATH'] ?: join(PATH_SEPARATOR, array("/bin", "/sbin", "/usr/bin", "/usr/local/bin", "/usr/local/share/npm/bin"))));
if ($this->isFile()) {
$process->setWorkingDirectory(dirname($this->source));
}
$process->run();
unlink($inputFile);
if ($process->getErrorOutput()) {
throw new \RuntimeException("tsc({$this->source}) returned an error:\n {$process->getErrorOutput()}");
}
$data = file_get_contents($outputFile);
unlink($outputFile);
return $data;
}
示例4: run
public function run()
{
$command = $this->getCommand();
$dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
$this->printTaskInfo("Running <info>{$command}</info>{$dir}");
$this->process = new Process($command);
$this->process->setTimeout($this->timeout);
$this->process->setIdleTimeout($this->idleTimeout);
$this->process->setWorkingDirectory($this->workingDirectory);
if (isset($this->env)) {
$this->process->setEnv($this->env);
}
if (!$this->background and !$this->isPrinted) {
$this->startTimer();
$this->process->run();
$this->stopTimer();
return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
}
if (!$this->background and $this->isPrinted) {
$this->startTimer();
$this->process->run(function ($type, $buffer) {
print $buffer;
});
$this->stopTimer();
return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
}
try {
$this->process->start();
} catch (\Exception $e) {
return Result::error($this, $e->getMessage());
}
return Result::success($this);
}
示例5: shell
public static function shell($commands, array $opts = [])
{
//$cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array()
if (is_array($commands)) {
$procs = [];
foreach ($commands as $command) {
$procs[] = static::shell($command, $opts);
}
return $procs;
}
$process = new Process($commands);
$options = array_replace(['type' => 'sync', 'cwd' => null, 'env' => null, 'timeout' => 60, 'callback' => null, 'output' => true], $opts);
$options['cwd'] !== null && $process->setWorkingDirectory($options['cwd']);
$options['env'] !== null && $process->setEnv($options['env']);
is_int($options['timeout']) && $process->setTimeout($options['timeout']);
if ($options['output'] === true) {
$process->enableOutput();
} else {
$process->disableOutput();
}
$type = $options['type'];
if ($type === 'sync') {
$process->run($options['callback']);
} elseif ($type === 'async') {
$process->start();
}
return $process;
}
示例6: iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode
/**
* @When I run phpspec and answer :answer when asked if I want to generate the code
*/
public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer)
{
$command = sprintf('%s %s', $this->buildPhpSpecCmd(), 'run');
$env = array('SHELL_INTERACTIVE' => true, 'HOME' => $_SERVER['HOME']);
$this->process = $process = new Process($command);
$process->setEnv($env);
$process->setInput($answer);
$process->run();
}
示例7: exists
/**
* @Given :class exists
*/
public function exists($class)
{
$descCmd = $this->buildCmd(sprintf('desc %s', $class));
$runCmd = $this->buildCmd('run');
$cmd = sprintf('%s && %s', $descCmd, $runCmd);
$process = new Process($cmd);
$process->setEnv(['SHELL_INTERACTIVE' => true]);
$process->setInput('Y');
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
示例8: iRunTheSpecFor
/**
* @When I run the spec for :fqcn
*/
public function iRunTheSpecFor($fqcn)
{
$cmd = $this->buildCmd(sprintf('run %s', $fqcn));
$cmd .= ' --format pretty';
$process = new Process($cmd);
$process->setEnv(['SHELL_INTERACTIVE' => true]);
$process->setInput('Y');
$process->run();
$this->lastOutput = $process->getOutput();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
示例9: run
/**
* Run a command in the shell.
*
* @param $command
* @param int $timeoutInSeconds
* @param array $env
*
* @return bool|string
*/
public function run($command, $timeoutInSeconds = 60, array $env = null)
{
$process = new Process($command);
$process->setTimeout($timeoutInSeconds);
if ($env != null) {
$process->setEnv($env);
}
$process->run();
if ($process->isSuccessful()) {
return true;
} else {
return $process->getErrorOutput();
}
}
示例10: iRunBehat
/**
* Runs behat command with provided parameters
*
* @When /^I run "behat(?: ((?:\"|[^"])*))?"$/
*
* @param string $argumentsString
*/
public function iRunBehat($argumentsString = '')
{
$argumentsString = strtr($argumentsString, array('\'' => '"'));
$this->process->setWorkingDirectory($this->workingDir);
$this->process->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $argumentsString, strtr('--format-settings=\'{"timer": false}\'', array('\'' => '"', '"' => '\\"'))));
// Don't reset the LANG variable on HHVM, because it breaks HHVM itself
if (!defined('HHVM_VERSION')) {
$env = $this->process->getEnv();
$env['LANG'] = 'en';
// Ensures that the default language is en, whatever the OS locale is.
$this->process->setEnv($env);
}
$this->process->start();
$this->process->wait();
}
示例11: exec
/**
* @param string $command
* @param array $arguments
* @param array $env
* @param LoggerInterface $logger
*
* @return Process
*/
public static function exec($command, array $arguments, array $env = [], LoggerInterface $logger = null)
{
$process = new BaseProcess(strtr($command, $arguments));
if ($logger) {
$logger->debug('Executing ' . $process->getCommandLine());
}
try {
$process->setEnv($env)->setTimeout(null)->mustRun();
} catch (ProcessFailedException $exception) {
if ($logger) {
$logger->error($exception->getMessage());
}
throw $exception;
}
return $process;
}
示例12: execute
/**
* Executes an SVN command.
*
* @param array|string $command
* @param bool $ssh
*
* @return [bool, string]
*/
public function execute($command, $ssh = false)
{
if (is_array($command)) {
$command = implode(' ', $command);
}
$output = '';
with($process = new Process($this->binary() . ' ' . $command))->setWorkingDirectory($this->location)->setTimeout(null)->setIdleTimeout(null);
if ($ssh) {
$process->setEnv(['SVN_SSH' => env('SSH_KEY_PATH')]);
}
$process->run(function ($t, $buffer) use(&$output) {
$output .= $buffer;
});
$response = [$successful = $process->isSuccessful(), $output];
return $response;
}
示例13: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var string $webRoot */
$webRoot = $this->getContainer()->getParameter('oro_require_js.web_root');
/** @var array $config */
$config = $this->getContainer()->getParameter('oro_require_js');
/** @var RequireJSConfigProvider $configProvider */
$configProvider = $this->getContainer()->get('oro_requirejs_config_provider');
$output->writeln('Generating require.js main config');
$mainConfigContent = $configProvider->generateMainConfig();
// for some reason built application gets broken with configuration in "oneline-json"
$mainConfigContent = str_replace(',', ",\n", $mainConfigContent);
$mainConfigFilePath = $webRoot . DIRECTORY_SEPARATOR . self::MAIN_CONFIG_FILE_NAME;
if (false === @file_put_contents($mainConfigFilePath, $mainConfigContent)) {
throw new \RuntimeException('Unable to write file ' . $mainConfigFilePath);
}
$output->writeln('Generating require.js build config');
$buildConfigContent = $configProvider->generateBuildConfig(self::MAIN_CONFIG_FILE_NAME);
$buildConfigContent = '(' . json_encode($buildConfigContent) . ')';
$buildConfigFilePath = $webRoot . DIRECTORY_SEPARATOR . self::BUILD_CONFIG_FILE_NAME;
if (false === @file_put_contents($buildConfigFilePath, $buildConfigContent)) {
throw new \RuntimeException('Unable to write file ' . $buildConfigFilePath);
}
if (isset($config['js_engine']) && $config['js_engine']) {
$output->writeln('Running code optimizer');
$command = $config['js_engine'] . ' ' . self::OPTIMIZER_FILE_PATH . ' -o ' . basename($buildConfigFilePath) . ' 1>&2';
$process = new Process($command, $webRoot);
$process->setTimeout($config['building_timeout']);
// some workaround when this command is launched from web
if (isset($_SERVER['PATH'])) {
$env = $_SERVER;
if (isset($env['Path'])) {
unset($env['Path']);
}
$process->setEnv($env);
}
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
$output->writeln('Cleaning up');
if (false === @unlink($buildConfigFilePath)) {
throw new \RuntimeException('Unable to remove file ' . $buildConfigFilePath);
}
$output->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), realpath($webRoot . DIRECTORY_SEPARATOR . $config['build_path'])));
}
}
示例14: render
function render($context = null, $vars = array())
{
$finder = new ExecutableFinder();
$bin = @$this->options["coffee_bin"] ?: self::DEFAULT_COFFEE;
$cmd = $finder->find($bin);
if ($cmd === null) {
throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
}
$cmd .= " -sc";
$process = new Process($cmd);
$process->setEnv(array('PATH' => @$_SERVER['PATH'] ?: join(PATH_SEPARATOR, array("/bin", "/sbin", "/usr/bin", "/usr/local/bin"))));
$process->setStdin($this->data);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException("coffee({$this->source}) returned an error:\n {$process->getErrorOutput()}");
}
return $process->getOutput();
}
示例15: iRunInProjectAs
/**
* @Given /^I run in project "([^"]*)" as "([^"]*)":$/
*/
public function iRunInProjectAs($project, $username, PyStringNode $commands)
{
$commands = $commands->getLines();
$this->run(function ($kernel) use($project, $username, $commands) {
$em = $kernel->getContainer()->get('doctrine')->getManager();
$project = $em->getRepository('GitonomyCoreBundle:Project')->findOneByName($project);
$user = $em->getRepository('GitonomyCoreBundle:User')->findOneByUsername($username);
// create temp folders
do {
$dir = sys_get_temp_dir() . '/shell_' . md5(mt_rand());
} while (is_dir($dir));
mkdir($dir, 0777, true);
register_shutdown_function(function () use($dir) {
$iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS);
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $file) {
if (!is_link($file)) {
chmod($file, 0777);
}
if (is_dir($file)) {
rmdir($file);
} else {
unlink($file);
}
}
chmod($dir, 0777);
rmdir($dir);
});
$repo = Admin::cloneTo($dir, $project->getRepository()->getPath(), false);
foreach ($commands as $command) {
$process = new Process($command);
$process->setWorkingDirectory($dir);
$env = array('GITONOMY_USER' => $username, 'GITONOMY_PROJECT' => $project->getSlug());
$env = array_merge($_SERVER, $env);
$process->setEnv($env);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException(sprintf("Execution of command '%s' failed: \n%s\n%s", $command, $process->getOutput(), $process->getErrorOutput()));
}
}
});
}