public function runScript($__source_code, $__bootstrap_file)
 {
     $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'melody-composer';
     // make sure the melody subprocess has a composer home,
     // which is not the case when running from webcontext
     $_ENV['COMPOSER_HOME'] = $tmpDir;
     $melody = new Melody();
     $configuration = new RunConfiguration();
     $executor = function (Process $process, $verbose) {
         $callback = function ($type, $text) {
             // we only have one output channel to the browser, just echo "all the things"
             echo $text;
         };
         $process->run($callback);
     };
     //TODO missing $__bootstrap_file support
     /*
     if ($__bootstrap_file) {
         require $__bootstrap_file;
     }
     */
     $tmpFile = tempnam($tmpDir, '_script');
     register_shutdown_function(function () use($tmpFile) {
         @unlink($tmpFile);
     });
     file_put_contents($tmpFile, $__source_code);
     $melody->run($tmpFile, array(), $configuration, $executor);
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $melody = new Melody();
     $processHelper = $this->getHelperSet()->get('process');
     $cliExecutor = function (Process $process, $verbose) use($output, $processHelper) {
         if ($verbose) {
             // print debugging output for the build process
             $processHelper->mustRun($output, $process);
         } else {
             $callback = function ($type, $text) use($output) {
                 if ($type == 'out' && $output instanceof ConsoleOutputInterface) {
                     $output = $output->getErrorOutput();
                 }
                 $output->write($text);
             };
             return $process->run($callback);
         }
     };
     $configuration = new RunConfiguration($input->getOption('no-cache'), $input->getOption('prefer-source'));
     $script = $input->getArgument('script');
     $arguments = $input->getArgument('arguments');
     return $melody->run($script, $arguments, $configuration, $cliExecutor);
 }
Exemple #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $melody = new Melody();
     $configRepository = new UserConfigurationRepository();
     $userConfig = $configRepository->load();
     $processHelper = $this->getHelperSet()->get('process');
     $cliExecutor = function (Process $process, $verbose) use($output, $processHelper) {
         if ($verbose) {
             // print debugging output for the build process
             $processHelper->mustRun($output, $process);
         } else {
             $callback = function ($type, $text) use($output) {
                 if ($type == 'out' && $output instanceof ConsoleOutputInterface) {
                     $output = $output->getErrorOutput();
                 }
                 $output->write($text);
             };
             return $process->run($callback);
         }
     };
     $runConfiguration = new RunConfiguration($input->getOption('no-cache'), $input->getOption('prefer-source'), $input->getOption('trust'));
     $script = $input->getArgument('script');
     $arguments = $input->getArgument('arguments');
     while (true) {
         try {
             $melody->run($script, $arguments, $runConfiguration, $userConfig, $cliExecutor);
             return 0;
         } catch (TrustException $e) {
             if (false === $this->confirmTrust($e->getResource(), $input, $output)) {
                 $output->writeln('<error>Operation aborted by the user.</error>');
                 return 1;
             }
             $userConfig->addTrustedSignature($e->getResource()->getSignature());
             $configRepository->save($userConfig);
         }
     }
 }
 private function melodyRun($filename, array $options = array())
 {
     $melody = new Melody();
     $options = array_replace(array('trust' => false, 'prefer_source' => false, 'no_cache' => false), $options);
     $runConfiguration = new RunConfiguration($options['no_cache'], $options['prefer_source'], $options['trust']);
     $userConfiguration = new UserConfiguration();
     $output = null;
     $cliExecutor = function (Process $process, $useProcessHelper) use(&$output) {
         $process->setTty(false);
         $process->mustRun(function ($type, $text) use(&$output) {
             $output .= $text;
         });
     };
     $melody->run($filename, array(), $runConfiguration, $userConfiguration, $cliExecutor);
     return $output;
 }