Example #1
0
 public function testProjectNew()
 {
     $projectDir = sprintf('%s/my_test_project', sys_get_temp_dir());
     $this->fs->remove($projectDir);
     $output = $this->runCommand(sprintf('php crush.phar project new %s', ProcessUtils::escapeArgument($projectDir)));
     $this->assertContains('Projects process exited.', $output);
 }
Example #2
0
 /**
  * @param Process $process
  *
  * @return string
  */
 public function formatSuggestion(Process $process)
 {
     $pattern = '%s ';
     $dryrun = sprintf($pattern, ProcessUtils::escapeArgument('--dry-run'));
     $formatJson = sprintf($pattern, ProcessUtils::escapeArgument('--format=json'));
     return str_replace([$dryrun, $formatJson], '', $process->getCommandLine());
 }
 /**
  * Create process that lint PHP file.
  *
  * @param string $path path to file
  *
  * @return Process
  */
 public function createProcessForFile($path)
 {
     $process = new Process('php -l ' . ProcessUtils::escapeArgument($path));
     $process->setTimeout(null);
     $process->run();
     return $process;
 }
 /**
  * Escape the provided value, unless it contains only alphanumeric
  * plus a few other basic characters.
  *
  * @param string $value
  * @return string
  */
 public static function escape($value)
 {
     if (preg_match('/^[a-zA-Z0-9\\/.@~_-]*$/', $value)) {
         return $value;
     }
     return ProcessUtils::escapeArgument($value);
 }
Example #5
0
 /**
  * @param $path
  * @return Process
  */
 protected function lintFile($path)
 {
     $lintProcess = new Process('php -l ' . ProcessUtils::escapeArgument($path));
     $lintProcess->setTimeout(null);
     $lintProcess->run();
     return strpos($lintProcess->getOutput(), 'No syntax errors detected in') === 0;
 }
Example #6
0
 /**
  * @param array $targets
  * @param array $ports
  *
  * @return Host[]
  */
 public function scan(array $targets, array $ports = array())
 {
     $targets = implode(' ', array_map(function ($target) {
         return ProcessUtils::escapeArgument($target);
     }, $targets));
     $options = array();
     if (true === $this->enableOsDetection) {
         $options[] = '-O';
     }
     if (true === $this->enableServiceInfo) {
         $options[] = '-sV';
     }
     if (true === $this->enableVerbose) {
         $options[] = '-v';
     }
     if (true === $this->disablePortScan) {
         $options[] = '-sn';
     } elseif (!empty($ports)) {
         $options[] = '-p ' . implode(',', $ports);
     }
     if (true === $this->disableReverseDNS) {
         $options[] = '-n';
     }
     if (true == $this->treatHostsAsOnline) {
         $options[] = '-Pn';
     }
     $options[] = '-oX';
     $command = sprintf('%s %s %s %s', $this->executable, implode(' ', $options), ProcessUtils::escapeArgument($this->outputFile), $targets);
     $this->executor->execute($command);
     if (!file_exists($this->outputFile)) {
         throw new \RuntimeException(sprintf('Output file not found ("%s")', $this->outputFile));
     }
     return $this->parseOutputFile($this->outputFile);
 }
Example #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $port = $input->getOption('port');
     $daux = $this->prepareDaux($input);
     // Daux can only serve HTML
     $daux->getParams()->setFormat('html');
     chdir(__DIR__ . '/../../');
     putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory());
     putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath());
     putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile());
     putenv('DAUX_EXTENSION=' . DAUX_EXTENSION);
     $base = ProcessUtils::escapeArgument(__DIR__ . '/../../');
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     echo "Daux development server started on http://{$host}:{$port}/\n";
     if (defined('HHVM_VERSION')) {
         if (version_compare(HHVM_VERSION, '3.8.0') >= 0) {
             passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php");
         } else {
             throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0.");
         }
     } else {
         passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
     }
 }
Example #8
0
 public function prepare(BehatWrapper $behat, BehatCommand $command, $cwd = null)
 {
     // Build the command line options, flags, and arguments.
     $binary = ProcessUtils::escapeArgument($behat->getBehatBinary());
     $commandLine = rtrim($binary . ' ' . $command->getCommandLine());
     parent::__construct($commandLine, $cwd, null, null, $behat->getTimeout(), array());
 }
Example #9
0
 /**
  * Get the composer command for the environment.
  *
  * @return string
  */
 protected function findComposer()
 {
     if (!$this->files->exists($this->workingPath . '/composer.phar')) {
         return 'composer';
     }
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     return "{$binary} composer.phar";
 }
Example #10
0
 private function checkoutReference(Source $source, $path)
 {
     $process = new Process(sprintf('git checkout -f %s -- && git reset --hard %1$s --', ProcessUtils::escapeArgument($source->getReference())), realpath($path));
     $process->run();
     if (preg_match('/fatal: reference is not a tree: (.+)/', $process->getErrorOutput(), $matches)) {
         throw new RuntimeException('Failed to checkout ' . $source->getReference());
     }
 }
Example #11
0
 function it_outputs_the_command_when_run_very_very_verbose(GrumPHP $config, ExternalCommand $externalCommandLocator, IOInterface $io)
 {
     $io->isVeryVerbose()->willReturn(true);
     $command = '/usr/bin/grumphp';
     $io->write(PHP_EOL . 'Command: ' . ProcessUtils::escapeArgument($command), true)->shouldBeCalled();
     $arguments = new ProcessArgumentsCollection([$command]);
     $process = $this->buildProcess($arguments);
 }
Example #12
0
 private function extractShell()
 {
     $command = 'tar -jxvf  ' . ProcessUtils::escapeArgument($this->file) . ' -C ' . ProcessUtils::escapeArgument($this->path) . ' && chmod -R u+w ' . ProcessUtils::escapeArgument($this->path);
     $process = new Process($command);
     $process->run();
     echo $process->getErrorOutput();
     return $process->isSuccessful();
 }
Example #13
0
 /**
  * Executes command to start a development server.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $port = $input->getOption('port');
     $base = ProcessUtils::escapeArgument(realpath(__DIR__ . '/../../../../public'));
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     $output->writeln("<info>PHP development server started on http://{$host}:{$port}</info>");
     passthru("{$binary} -S {$host}:{$port} -t {$base}");
 }
Example #14
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $port = $input->getOption('port');
     $this->info('Blog-Tree development server started on http://' . $host . ':' . $port . '/');
     $base = ProcessUtils::escapeArgument($this->app->basePath());
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     passthru("{$binary} -S {$host}:{$port} {$base}/server.php");
 }
Example #15
0
 /**
  * Ejecuta el comando
  * 
  * @param InputInterface  $input  Instancia
  * @param OutputInterface $output Instancia
  * 
  * @return [type]                  [description]
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $port = $input->getOption('port');
     $target = $input->getOption('target');
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     $output->writeln("Resty development server started on http://{$host}:{$port}/ -t {$target}");
     $cmd = "{$binary} -S {$host}:{$port} -t {$target}";
     passthru($cmd);
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function getCompressionCommand($archivePath, $basePath)
 {
     $tarParams = array();
     $zipParams = array();
     if (isset($this->options['compression_ratio']) && $this->options['compression_ratio'] >= 0) {
         $compression_ratio = max(min($this->options['compression_ratio'], 9), 0);
         $zipParams[] = '-' . $compression_ratio;
     }
     return sprintf('tar %s c -C %s . | gzip %s > %s', implode(' ', $tarParams), ProcessUtils::escapeArgument($basePath), implode(' ', $zipParams), ProcessUtils::escapeArgument($archivePath));
 }
Example #17
0
 public function createProcessForFile($path)
 {
     if (!is_file($path)) {
         return $this->createProcessForSource(file_get_contents($path));
     }
     $process = new Process('php -l ' . ProcessUtils::escapeArgument($path));
     $process->setTimeout(null);
     $process->run();
     return $process;
 }
Example #18
0
 /**
  * Appends an input to the write buffer.
  *
  * @param resource|scalar|\Traversable|null The input to append as stream resource, scalar or \Traversable
  */
 public function write($input)
 {
     if (null === $input) {
         return;
     }
     if ($this->isClosed()) {
         throw new RuntimeException(sprintf('%s is closed', static::class));
     }
     $this->input[] = ProcessUtils::validateInput(__METHOD__, $input);
 }
Example #19
0
 /**
  * Execute the console command.
  *
  * @return void
  *
  * @throws \Exception
  */
 public function fire()
 {
     chdir($this->laravel->publicPath());
     $host = $this->input->getOption('host');
     $port = $this->input->getOption('port');
     $base = ProcessUtils::escapeArgument($this->laravel->basePath());
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     $this->info("Laravel development server started on http://{$host}:{$port}/");
     passthru("{$binary} -S {$host}:{$port} {$base}/server.php");
 }
 /**
  * @dataProvider provideSymfonyInstallationData
  */
 public function testSymfonyInstallation($commandArguments, $messageRegexp, $versionRegexp)
 {
     $projectDir = sprintf('%s/my_test_project', sys_get_temp_dir());
     $this->fs->remove($projectDir);
     $output = $this->runCommand(sprintf('php symfony.phar new %s %s', ProcessUtils::escapeArgument($projectDir), $commandArguments));
     $this->assertContains('Downloading Symfony...', $output);
     $this->assertRegExp($messageRegexp, $output);
     $output = $this->runCommand('php app/console --version', $projectDir);
     $this->assertRegExp($versionRegexp, $output);
 }
Example #21
0
 /**
  * Execute the console command.
  *
  * @throws \Exception
  */
 public function fire()
 {
     $base = $this->app['path.base'];
     chdir($base);
     $host = $this->input->getOption('host');
     $port = $this->input->getOption('port');
     $base = ProcessUtils::escapeArgument($base);
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     $this->info("Speedwork development server started on http://{$host}:{$port}/");
     passthru("{$binary} -S {$host}:{$port} {$base}/server.php");
 }
Example #22
0
 protected function runDumpAutoload($composerFile)
 {
     $basePath = dirname($composerFile);
     if (file_exists($basePath . '/composer.phar')) {
         $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
         $composer = "{$binary} composer.phar";
     } else {
         $composer = 'composer';
     }
     (new Process("{$composer} dump-autoload", $basePath))->run();
 }
Example #23
0
 /**
  * @param GitWrapper $gitWrapper
  * @param GitCommand $gitCommand
  */
 public function __construct(GitWrapper $gitWrapper, GitCommand $gitCommand)
 {
     $commandLine = ProcessUtils::escapeArgument($gitWrapper->getGitBinary()) . ' ' . $gitCommand->getCommandLine();
     $directory = realpath($gitCommand->getDirectory());
     $envVars = null;
     $wrapperEnvVars = $gitWrapper->getEnvVars();
     if (!empty($wrapperEnvVars)) {
         $envVars = array_merge($_ENV, $_SERVER, $wrapperEnvVars);
     }
     parent::__construct($commandLine, $directory, $envVars, null, $gitCommand->getTimeout());
 }
Example #24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $base = ProcessUtils::escapeArgument($this->getApplication()->getProjectFolder());
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     if (($scriptName = $this->findApplication()) !== false) {
         $host = $input->getOption('host');
         $port = $input->getOption('port');
         $output->writeln("<warn>Running the application on {$host}:{$port} using {$scriptName}</warn>");
         passthru("{$binary} -S {$host}:{$port} {$base}/web/{$scriptName}");
     }
 }
Example #25
0
 /**
  * Find composer.
  * @return string
  */
 protected function find()
 {
     if (!File::exists($this->workingPath . '/composer.phar')) {
         return 'composer';
     }
     $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder())->find(false));
     if (defined('HHVM_VERSION')) {
         $binary .= ' --php';
     }
     return "{$binary} composer.phar";
 }
Example #26
0
 private function extractShell()
 {
     $command = 'unzip ' . ProcessUtils::escapeArgument($this->file) . ' -d ' . ProcessUtils::escapeArgument($this->path) . ' && chmod -R u+w ' . ProcessUtils::escapeArgument($this->path);
     $process = new Process($command);
     $process->setTimeout(null);
     $process->run();
     if ($this->output) {
         $this->output->writeln($process->getErrorOutput());
     }
     return $process->isSuccessful();
 }
 /**
  * Fix escaping character.
  *
  * Escape character may be different on various environments.
  * This method change used escape character into character that is default
  * for environment.
  *
  * @param string $value          value to be fixed
  * @param string $usedEscapeChar used escape char, may be only ' or "
  *
  * @return string
  */
 private function fixEscape($value, $usedEscapeChar = '"')
 {
     static $escapeChar = null;
     if (null === $escapeChar) {
         $escapeChar = substr(ProcessUtils::escapeArgument('x'), 0, 1);
     }
     if ($usedEscapeChar === $escapeChar) {
         return $value;
     }
     return str_replace($usedEscapeChar, $escapeChar, $value);
 }
Example #28
0
 public function run()
 {
     $openCommand = $this->getOpenCommand();
     if (empty($openCommand)) {
         return Result::error($this, 'no suitable browser opening command found');
     }
     foreach ($this->urls as $url) {
         passthru(sprintf($openCommand, ProcessUtils::escapeArgument($url)));
         $this->printTaskInfo("Opened <info>{$url}</info>");
     }
     return Result::success($this);
 }
 /**
  * @test
  */
 public function arePhantomjsOptionsHandled()
 {
     $url = $this->configHelper->getOutputFileUrl('e4e5k2');
     $this->configHelper->setConfig(array_merge_recursive($this->config, array('phantomjs' => array('options' => array('--ignore-ssl-errors' => true)))));
     $process = $this->configHelper->buildProcess($url, 'e4e5k2');
     $this->assertContains(ProcessUtils::escapeArgument(sprintf('%s=%s', '--ignore-ssl-errors', 'true')), $process->getCommandLine());
     $this->configHelper->setConfig(array_merge_recursive($this->config, array('phantomjs' => array('options' => array('--ignore-ssl-errors=true')))));
     $process = $this->configHelper->buildProcess($url, 'e4e5k2');
     $command = $process->getCommandLine();
     $this->assertContains(ProcessUtils::escapeArgument('--ignore-ssl-errors=true'), $process->getCommandLine());
     $this->assertNotContains('0', $command);
 }
Example #30
0
 /**
  * Compile parameters for a command.
  *
  * @param  array  $parameters
  * @return string
  */
 protected function compileParameters(array $parameters)
 {
     return collect($parameters)->map(function ($value, $key) {
         if (is_array($value)) {
             $value = collect($value)->map(function ($value) {
                 return ProcessUtils::escapeArgument($value);
             })->implode(' ');
         } elseif (!is_numeric($value) && !preg_match('/^(-.$|--.*)/i', $value)) {
             $value = ProcessUtils::escapeArgument($value);
         }
         return is_numeric($key) ? $value : "{$key}={$value}";
     })->implode(' ');
 }