/**
  * tests find() with the env var PHP_PATH
  */
 public function testFindArguments()
 {
     $f = new PhpExecutableFinder();
     if (defined('HHVM_VERSION')) {
         $this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
     } else {
         $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
     }
 }
示例#2
0
 public function getProcess(Script $script, $dir)
 {
     if ($script->getResource() instanceof LocalResource) {
         $bootstrap = $this->getLocalBootstrap($script->getResource());
     } else {
         $bootstrap = $this->getRemoteBootstrap($script->getResource());
     }
     $file = sprintf('%s/%s', $dir, self::BOOTSTRAP_FILENAME);
     file_put_contents($file, $bootstrap);
     $phpFinder = new PhpExecutableFinder();
     $process = ProcessBuilder::create(array_merge(array($phpFinder->find(false)), $script->getConfiguration()->getPhpOptions(), $phpFinder->findArguments(), array($file), $script->getArguments()))->setEnv('PATH', $_SERVER['PATH'])->getProcess();
     if (!defined('PHP_WINDOWS_VERSION_BUILD') && php_sapi_name() === 'cli') {
         $process->setTty(true);
     }
     return $process;
 }
示例#3
0
 /**
  * Guess and build the command to call composer.
  *
  * Search:
  *  - a executable composer (or composer.phar)
  *  - a file composer (or composer.phar) prefixed by php
  */
 private function guessComposerCommand()
 {
     $candidateNames = array('composer', 'composer.phar');
     $executableFinder = new ExecutableFinder();
     foreach ($candidateNames as $candidateName) {
         if ($composerPath = $executableFinder->find($candidateName, null, array(getcwd()))) {
             return array(realpath($composerPath));
         }
     }
     foreach ($candidateNames as $candidateName) {
         $composerPath = sprintf('%s/%s', getcwd(), $candidateName);
         if (file_exists($composerPath)) {
             $phpFinder = new PhpExecutableFinder();
             return array_merge(array($phpFinder->find(false), $composerPath), $phpFinder->findArguments());
         }
     }
     return null;
 }
示例#4
0
 private function iRunTheCommand($command, $siteaccess = null)
 {
     $phpFinder = new PhpExecutableFinder();
     if (!($phpPath = $phpFinder->find(false))) {
         throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
     }
     $arguments = $phpFinder->findArguments();
     if (false !== ($ini = php_ini_loaded_file())) {
         $arguments[] = '--php-ini=' . $ini;
     }
     $php = escapeshellarg($phpPath);
     $phpArgs = implode(' ', array_map('escapeshellarg', $arguments));
     $console = escapeshellarg('app/console');
     $cmd = escapeshellarg($command);
     $console .= ' --env=' . escapeshellarg('behat');
     if ($siteaccess !== null) {
         $console .= ' --siteaccess=' . escapeshellarg($siteaccess);
     }
     $commandLine = $php . ($phpArgs ? ' ' . $phpArgs : '') . ' ' . $console . ' ' . $cmd;
     $process = new Process($commandLine);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', escapeshellarg($cmd)));
     }
     $this->scriptOutput = $process->getOutput();
 }
 /**
  * Executes a Symfony command in separate process.
  *
  * Typically usefull when configuration has changed, our you are outside of Symfony context (Composer commands).
  *
  * Based on {@see \Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeCommand}.
  *
  * @param OutputInterface $output
  * @param string $cmd eZ Platform command to execute, like 'ezplatform:solr_create_index'
  *               Escape any user provided arguments, like: 'assets:install '.escapeshellarg($webDir)
  * @param int $timeout
  */
 private function executeCommand(OutputInterface $output, $cmd, $timeout = 300)
 {
     $phpFinder = new PhpExecutableFinder();
     if (!($phpPath = $phpFinder->find(false))) {
         throw new \RuntimeException('The php executable could not be found, add it to your PATH environment variable and try again');
     }
     // We don't know which php arguments where used so we gather some to be on the safe side
     $arguments = $phpFinder->findArguments();
     if (false !== ($ini = php_ini_loaded_file())) {
         $arguments[] = '--php-ini=' . $ini;
     }
     // Pass memory_limit in case this was specified as php argument, if not it will most likely be same as $ini.
     if ($memoryLimit = ini_get('memory_limit')) {
         $arguments[] = '-d memory_limit=' . $memoryLimit;
     }
     $phpArgs = implode(' ', array_map('escapeshellarg', $arguments));
     $php = escapeshellarg($phpPath) . ($phpArgs ? ' ' . $phpArgs : '');
     // Make sure to pass along relevant global Symfony options to console command
     $console = escapeshellarg('app/console');
     if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
         $console .= ' -' . str_repeat('v', $output->getVerbosity() - 1);
     }
     if ($output->isDecorated()) {
         $console .= ' --ansi';
     }
     $console .= ' --env=' . escapeshellarg($this->environment);
     $process = new Process($php . ' ' . $console . ' ' . $cmd, null, null, null, $timeout);
     $process->run(function ($type, $buffer) use($output) {
         $output->write($buffer, false);
     });
     if (!$process->isSuccessful()) {
         throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', escapeshellarg($cmd)));
     }
 }
示例#6
0
 /**
  * @param string|null $phpExecutablePath
  * @param array|null  $phpArguments
  *
  * @return $this
  */
 public function getOrFindPhpExecutablePathAndArguments(&$phpExecutablePath, &$phpArguments)
 {
     $phpExecutablePath = $this->phpExecutablePath;
     $phpArguments = $this->phpArguments;
     if ($phpExecutablePath === null || $phpArguments === null) {
         $executableFinder = new PhpExecutableFinder();
         if ($phpExecutablePath === null) {
             $phpExecutablePath = $executableFinder->find(false);
             if ($phpExecutablePath === false) {
                 throw new Exception\RuntimeException('Unable to find the PHP executable.');
             }
         }
         if ($phpArguments === null) {
             $phpArguments = $executableFinder->findArguments();
         }
     }
     return $this;
 }