Esempio n. 1
0
 /**
  * @Command start-http
  */
 public function startHttpServer(Option $entryPoint, Option $host, Option $port, Output $output, ErrorOutput $errorOutput)
 {
     $host->setDefaultValue('localhost');
     $port->setDefaultValue(8000);
     $entryPoint->setDefaultValue('public/index.php');
     $listen = "{$host->getValue()}:{$port->getValue()}";
     $output->writeln("Running http server on {$listen}");
     $process = new Process("php -S {$listen} {$entryPoint->getValue()}");
     $process->setTimeout(null);
     $process->run(function ($type, $buffer) use($output, $errorOutput) {
         if (Process::ERR === $type) {
             $errorOutput->write($buffer);
         } else {
             $output->write($buffer);
         }
     });
 }
Esempio n. 2
0
 /**
  * @Command request
  */
 public function request(Parameter $method, Parameter $uri, Option $data, Option $baseUri, Output $output, ErrorOutput $errorOutput)
 {
     $baseUri->setDefaultValue('http://localhost:8000');
     $args = ['-siL', '-X', $method->getValue(), '-H', 'Content-Type: application/json', '-d', $data->getValue(), "{$baseUri->getValue()}{$uri->getValue()}"];
     $command = "curl";
     foreach ($args as $arg) {
         $command .= ' ' . escapeshellarg($arg);
     }
     $process = new Process($command);
     $process->run(function ($type, $buffer) use($output, $errorOutput) {
         if (Process::ERR === $type) {
             $errorOutput->write($buffer);
         } else {
             $output->write($buffer);
         }
     });
     $output->writeln('');
 }