コード例 #1
0
 /**
  * @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
0
ファイル: StartServer.php プロジェクト: dmitrynaum/sam
 /**
  * Запустить сервер
  * @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
0
    /**
     * {@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
0
 /**
  * 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
0
 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
0
 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
0
 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
0
 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
0
 /**
  * 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
0
 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
0
ファイル: LessFilter.php プロジェクト: laubosslink/lab
    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
0
 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
0
 /**
  * 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
0
ファイル: CompassFilter.php プロジェクト: ravinderphp/skfood
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $loadPaths = $this->loadPaths;
     if ($root && $path) {
         $loadPaths[] = dirname($root . '/' . $path);
     }
     // compass does not seems to handle symlink, so we use realpath()
     $tempDir = realpath(sys_get_temp_dir());
     $compassProcessArgs = array($this->compassPath, 'compile', $tempDir);
     if (null !== $this->rubyPath) {
         array_unshift($compassProcessArgs, $this->rubyPath);
     }
     $pb = new ProcessBuilder($compassProcessArgs);
     $pb->inheritEnvironmentVariables();
     if ($this->force) {
         $pb->add('--force');
     }
     if ($this->style) {
         $pb->add('--output-style')->add($this->style);
     }
     if ($this->quiet) {
         $pb->add('--quiet');
     }
     if ($this->boring) {
         $pb->add('--boring');
     }
     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
0
 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();
 }
コード例 #16
0
ファイル: TutuContext.php プロジェクト: coduo/tutu
 /**
  * @Given TuTu is running on host :host at port :port
  */
 public function tutuIsRunningOnHostAtPort($host, $port)
 {
     $this->tutuPort = $port;
     $this->tutuHost = $host;
     $this->killEveryProcessRunningOnTuTuPort();
     $builder = new ProcessBuilder([PHP_BINARY, '-S', sprintf('%s:%s > /Users/norzechowicz/Workspace/PHP/coduo/TuTu/log.txt', $host, $port)]);
     if (file_exists($this->workDir . '/config/config.yml')) {
         $builder->setEnv('tutu_config', $this->workDir . '/config/config.yml');
     }
     $builder->setEnv('tutu_responses', $this->workDir . '/config/responses.yml');
     $builder->setEnv('tutu_resources', $this->workDir . '/resources');
     $builder->setWorkingDirectory($this->webPath);
     $builder->setTimeout(null);
     $this->tutuProcess = $builder->getProcess();
     $this->tutuProcess->start();
     sleep(1);
 }
コード例 #17
0
ファイル: Fop.php プロジェクト: loicmonney/apache-fop
 /**
  *
  *
  * @param  InputInterface                            $input Ony $input can use StringInput
  * @param  string                                    $destination  The place where save the result
  * @param  string                                    $outputFormat
  * @param  InputInterface                            $xsl
  * @param  array                                     $params
  * @return \Symfony\Component\Process\ProcessBuilder
  */
 protected function runProcess(InputInterface $input, $destination, $outputFormat, InputInterface $xsl = null, array $params = array())
 {
     $builder = new ProcessBuilder();
     $builder->add($this->fopExecutable);
     foreach ($this->env as $name => $v) {
         $builder->setEnv($name, $v);
     }
     $builder->add("-q");
     $builder->add("-r");
     if ($xsl instanceof InputInterface) {
         $builder->add("-xml");
         $input->buildParams($builder);
         $builder->add("-xsl");
         $xsl->buildParams($builder);
     } else {
         $builder->add("-fo");
         $input->buildParams($builder);
     }
     foreach ($params as $key => $value) {
         $builder->add("-param");
         $builder->add($key);
         $builder->add($value);
     }
     $builder->add("-out");
     $builder->add($outputFormat);
     $builder->add($destination);
     if ($this->configurationFile !== null) {
         $builder->add("-c");
         $builder->add($this->configurationFile);
     }
     $proc = $builder->getProcess();
     $input->setInput($proc);
     if ($xsl instanceof InputInterface) {
         $xsl->setInput($proc);
     }
     return $proc;
 }
コード例 #18
0
ファイル: UpdateJob.php プロジェクト: Bonscho/packages
 public function run($args)
 {
     $package = $this->getEntityManager()->find('Terramar\\Packages\\Entity\\Package', $args['id']);
     if (!$package) {
         throw new \RuntimeException('Invalid project');
     }
     $config = $this->getEntityManager()->getRepository('Terramar\\Packages\\Plugin\\Sami\\PackageConfiguration')->findOneBy(array('package' => $package));
     if (!$config) {
         throw new \RuntimeException('Invalid project configuration');
     }
     $cachePath = $this->getCacheDir($package);
     if (!is_dir($cachePath)) {
         mkdir($cachePath, 0777, true);
     }
     $configFilePath = $cachePath . '/config.php';
     $this->writeConfig($configFilePath, $package, $config);
     echo "Wrote config file to: {$configFilePath}\n";
     $finder = new PhpExecutableFinder();
     $builder = new ProcessBuilder(array('vendor/bin/sami.php', 'update', $configFilePath));
     $builder->setEnv('HOME', $this->getContainer()->getParameter('app.root_dir'));
     $builder->setPrefix($finder->find());
     $process = $builder->getProcess();
     $process->run(function ($type, $message) {
         echo $message;
     });
     if (!$process->isSuccessful()) {
         throw new \RuntimeException("Unable to generate sami documentation\n");
     }
     if ($config->getRemoteRepoPath()) {
         echo "Updating configured remote with doc changes...\n";
         $localRepoPath = $cachePath . '/remote';
         $this->emptyAndRemoveDirectory($localRepoPath);
         $buildPath = $cachePath . '/build';
         $builder = new ProcessBuilder(array('clone', $config->getRemoteRepoPath(), $localRepoPath));
         $builder->setPrefix('git');
         $process = $builder->getProcess();
         $process->run(function ($type, $message) {
             echo $message;
         });
         if (!$process->isSuccessful()) {
             throw new \RuntimeException("Unable to clone remote repository \"" . $config->getRemoteRepoPath() . "\"\n");
         }
         echo "Copying generated files into repository...\n";
         $builder = new ProcessBuilder(array('-R', $buildPath . '/', '.'));
         $builder->setPrefix('cp');
         $process = $builder->getProcess();
         $process->setWorkingDirectory($localRepoPath);
         $process->run(function ($type, $message) {
             echo $message;
         });
         echo "Adding all files...\n";
         $builder = new ProcessBuilder(array('add', '.'));
         $builder->setPrefix('git');
         $process = $builder->getProcess();
         $process->setWorkingDirectory($localRepoPath);
         $process->run(function ($type, $message) {
             echo $message;
         });
         echo "Committing...\n";
         $builder = new ProcessBuilder(array('commit', '-m', 'Automated commit'));
         $builder->setPrefix('git');
         $process = $builder->getProcess();
         $process->setWorkingDirectory($localRepoPath);
         $process->run(function ($type, $message) {
             echo $message;
         });
         echo "Pushing...\n";
         $builder = new ProcessBuilder(array('push', 'origin'));
         $builder->setPrefix('git');
         $process = $builder->getProcess();
         $process->setWorkingDirectory($localRepoPath);
         $process->run(function ($type, $message) {
             echo $message;
         });
     }
 }
コード例 #19
0
ファイル: UpdateHelper.php プロジェクト: heartshare/dotplant2
 /**
  * Returns ProcessBuilder instance with predefined process command for any composer command execution
  * (update, require, etc.)
  * @return \Symfony\Component\Process\ProcessBuilder
  */
 private function getComposerBuilder()
 {
     $builder = new ProcessBuilder();
     $builder->setEnv('COMPOSER_HOME', $this->composerHomeDirectory)->setWorkingDirectory(Yii::getAlias('@app'))->setPrefix($this->getPhpExecutable())->setArguments([realpath(Yii::getAlias('@app') . '/../') . '/composer.phar', '-v']);
     return $builder;
 }
コード例 #20
0
 /**
  * Ajax action to install defined package.
  *
  * @Route("/install-bundle-ajax", name="guiInstallBundleAjax")
  * @Template()
  */
 public function installBundleAjaxAction()
 {
     $request = Request::createFromGlobals();
     $bundlePath = $request->request->get('bundlePath');
     $bundleVersion = $request->request->get('bundleVersion');
     $bundleName = $request->request->get('bundleName');
     $bundleTitle = $request->request->get('bundleTitle');
     $bundleNamespace = $request->get('bundleNamespace');
     $rootPath = rtrim(dirname($this->get('kernel')->getRootDir()), '/');
     $routingEntry = $request->request->get('routingEntry');
     $configuration = $request->request->get('configuration');
     if (!$bundlePath) {
         die('Error: Bundle path not set.');
     }
     if (!$bundleVersion) {
         die('Error: Bundle version not set.');
     }
     // insert bundle to composer.json file
     $composerJsonFile = $rootPath . '/composer.json';
     // use symfony file system
     $fs = new FS();
     if ($fs->exists($composerJsonFile)) {
         // read entries from file
         $composerFile = file_get_contents($composerJsonFile);
         // decode json string into object
         $composerJson = json_decode($composerFile);
         // check object if it a valid object
         if ($composerJson && is_object($composerJson)) {
             // retrieve all requirements from composer json object
             $composerRequires = $composerJson->require;
             // check if we have allready set the new bundle
             if (!isset($composerRequires->{$bundlePath})) {
                 // set new bundle and their version
                 $composerRequires->{$bundlePath} = $bundleVersion;
                 // override composer requirements with new one
                 $composerJson->require = $composerRequires;
                 // encode the json object
                 $data = json_encode($composerJson, JSON_PRETTY_PRINT);
                 // prepare json to a pretty json
                 $data = BundleUtil::getPrettyJson($data);
                 // dump json string into file
                 // mode 0664 = read/write for user and group and read for all other
                 file_put_contents($composerJsonFile, $data);
                 //$fs->dumpFile($composerJsonFile, '', 0777);
                 //$fs->dumpFile($composerJsonFile, $data, 0777);
             }
             unset($composerRequires);
         }
         unset($composerJson);
     }
     unset($composerJsonFile, $fs);
     /**
      * Anonymous callback for process
      *
      * @param string    $type   The process type
      * @param mixed     $output The output of process
      */
     $callback = function ($type, $output) {
         if (Process::ERR === $type) {
             echo 'error on executing composer: \\n\\n' . $output;
             die;
         }
     };
     // execute composer self-update
     $processBuilder = new ProcessBuilder($this->getComposerArguments($rootPath, 'self-update'));
     $processBuilder->setEnv('PATH', $request->server->get('PATH'));
     $processBuilder->setEnv('COMPOSER_HOME', $rootPath . '/bin');
     $process = $processBuilder->getProcess();
     $process->setTimeout(90);
     $process->setIdleTimeout(NULL);
     $ret = $process->run($callback);
     if ($ret == 0) {
         echo 'Execute composer self-update finished.';
     }
     unset($processBuilder, $process);
     // execute composer update on specified bundle
     $processBuilder = new ProcessBuilder($this->getComposerArguments($rootPath, 'update', $bundlePath));
     $processBuilder->setEnv('PATH', $request->server->get('PATH'));
     $processBuilder->setEnv('COMPOSER_HOME', $rootPath . '/bin');
     $processBuilder->setWorkingDirectory($rootPath);
     // Generate output for AJAX call
     echo 'Running update on: ' . $bundleTitle;
     $process = $processBuilder->getProcess();
     $process->setTimeout(3600);
     $process->setIdleTimeout(60);
     $ret = $process->run($callback);
     if ($ret == 0) {
         // Register new bundle after it was installed
         $kernel = $this->get('kernel');
         if ($kernel instanceof Kernel) {
             // Check if bundle already installed
             $bundleInstalled = BundleUtil::bundleInstalled($this, $bundleTitle);
             if (!$bundleInstalled) {
                 // Register bundle
                 $km = new KernelManipulator($kernel);
                 try {
                     $km->addBundle(urldecode($bundleNamespace) . '\\' . $bundleName);
                 } catch (RuntimeException $ex) {
                     echo $ex->getMessage();
                     die;
                 }
                 unset($km);
             }
         }
         // Handle configuration at config.yml
         if (isset($configuration) && !empty($configuration)) {
             $this->_addConfiguration($bundleTitle, $rootPath, $configuration);
         }
         // Handle route installation
         if (isset($routingEntry) && !empty($routingEntry)) {
             $this->_addRouting($bundleTitle, $rootPath, $routingEntry);
         }
         // Clear cache
         BundleUtil::clearCache($kernel);
         // handle success
         echo 'Done';
     } else {
         // handle error
         echo 'Error on updating: ' . $bundleTitle . '\\n\\n' . Process::$exitCodes[$ret];
     }
     unset($processBuilder, $process);
     exit;
 }
コード例 #21
0
ファイル: Server.php プロジェクト: robballou/MinkZombieDriver
 /**
  * Starts the server process
  *
  * @param Process $process A process object
  *
  * @throws \RuntimeException
  */
 public function start(Process $process = null)
 {
     // Check if the server script exists at given path
     if (false === $this->serverPath || false === is_file($this->serverPath)) {
         throw new \RuntimeException(sprintf("Could not find server script at path '%s'", $this->serverPath));
     }
     // Create process object if neccessary
     if (null === $process) {
         $processBuilder = new ProcessBuilder(array($this->nodeBin, $this->serverPath));
         $processBuilder->setEnv('HOST', $this->host)->setEnv('PORT', $this->port);
         if (!empty($this->nodeModulesPath)) {
             $processBuilder->setEnv('NODE_PATH', $this->nodeModulesPath);
         }
         $process = $processBuilder->getProcess();
     }
     $this->process = $process;
     // Start server process
     $this->process->start();
     $this->connection = null;
     // Wait for the server to start up
     $time = 0;
     $successString = sprintf("server started on %s:%s", $this->host, $this->port);
     while ($this->process->isRunning() && $time < $this->threshold) {
         if ($successString == trim($this->process->getOutput())) {
             $this->connection = new Connection($this->host, $this->port);
             break;
         }
         usleep(1000);
         $time += 1000;
     }
     // Make sure the server is ready or throw an exception otherwise
     $this->checkAvailability();
 }
コード例 #22
0
ファイル: ProcessSetCreator.php プロジェクト: mhujer/steward
 /**
  * Build Process instance for each testcase file
  *
  * @param string $fileName
  * @param array $phpunitArgs
  * @return Process
  */
 protected function buildProcess($fileName, array $phpunitArgs = [])
 {
     $processBuilder = new ProcessBuilder();
     $dispatcher = $this->command->getDispatcher();
     $dispatcher->dispatch(CommandEvents::RUN_TESTS_PROCESS, $processEvent = new RunTestsProcessEvent($this->command, $this->input, $this->output, $processBuilder, $phpunitArgs));
     $process = $processBuilder->setEnv('BROWSER_NAME', $this->input->getArgument('browser'))->setEnv('ENV', strtolower($this->input->getArgument('environment')))->setEnv('SERVER_URL', $this->input->getOption('server-url'))->setEnv('PUBLISH_RESULTS', $this->input->getOption('publish-results') ? '1' : '0')->setEnv('FIXTURES_DIR', $this->input->getOption('fixtures-dir'))->setEnv('LOGS_DIR', $this->input->getOption('logs-dir'))->setEnv('DEBUG', $this->output->isDebug() ? '1' : '0')->setPrefix(STEWARD_BASE_DIR . '/vendor/bin/phpunit')->setArguments(array_merge($processEvent->getArgs(), [$fileName]))->setTimeout(3600)->getProcess();
     return $process;
 }
コード例 #23
0
ファイル: BaseProcessFilter.php プロジェクト: samj1912/repo
 protected function mergeEnv(ProcessBuilder $pb)
 {
     foreach (array_filter($_SERVER, 'is_scalar') as $key => $value) {
         $pb->setEnv($key, $value);
     }
 }