Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $docroot = $this->getContainer()->getParameter('sculpin.output_dir');
     $kernel = $this->getContainer()->get('kernel');
     $httpServer = new HttpServer($output, $docroot, $kernel->getEnvironment(), $kernel->isDebug(), $input->getOption('port'));
     $httpServer->run();
 }
Esempio n. 2
0
 /**
  * Constructor
  *
  * @param OutputInterface $output  Output
  * @param string          $docroot Docroot
  * @param string          $env     Environment
  * @param bool            $debug   Debug
  * @param int             $port    Port
  */
 public function __construct(OutputInterface $output, $docroot, $env, $debug, $port = null)
 {
     $repository = new PhpRepository();
     if (!$port) {
         $port = 8000;
     }
     $this->output = $output;
     $this->env = $env;
     $this->debug = $debug;
     $this->port = $port;
     $this->loop = new StreamSelectLoop();
     $socketServer = new ReactSocketServer($this->loop);
     $httpServer = new ReactHttpServer($socketServer);
     $httpServer->on("request", function ($request, $response) use($repository, $docroot, $output) {
         $path = $docroot . '/' . ltrim(rawurldecode($request->getPath()), '/');
         if (is_dir($path)) {
             $path .= '/index.html';
         }
         if (!file_exists($path)) {
             HttpServer::logRequest($output, 404, $request);
             $response->writeHead(404, ['Content-Type' => 'text/html']);
             return $response->end(implode('', ['<h1>404</h1>', '<h2>Not Found</h2>', '<p>', 'The embedded <a href="https://sculpin.io">Sculpin</a> web server could not find the requested resource.', '</p>']));
         }
         $type = 'application/octet-stream';
         if ('' !== ($extension = pathinfo($path, PATHINFO_EXTENSION))) {
             if ($guessedType = $repository->findType($extension)) {
                 $type = $guessedType;
             }
         }
         HttpServer::logRequest($output, 200, $request);
         $response->writeHead(200, array("Content-Type" => $type));
         $response->end(file_get_contents($path));
     });
     $socketServer->listen($port, '0.0.0.0');
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     foreach ($this->getApplication()->getMissingSculpinBundlesMessages() as $message) {
         $output->writeln($message);
     }
     $docroot = $this->getContainer()->getParameter('sculpin.output_dir');
     if ($input->getOption('clean')) {
         $this->clean($input, $output, $docroot);
     }
     $watch = $input->getOption('watch') ?: false;
     $sculpin = $this->getContainer()->get('sculpin');
     $dataSource = $this->getContainer()->get('sculpin.data_source');
     $sourceSet = new SourceSet();
     $config = $this->getContainer()->get('sculpin.site_configuration');
     if ($url = $input->getOption('url')) {
         $config->set('url', $url);
     }
     $consoleIo = new ConsoleIo($input, $output, $this->getApplication()->getHelperSet());
     if ($input->getOption('server')) {
         $sculpin->run($dataSource, $sourceSet, $consoleIo);
         $kernel = $this->getContainer()->get('kernel');
         $httpServer = new HttpServer($output, $docroot, $kernel->getEnvironment(), $kernel->isDebug(), $input->getOption('port'));
         if ($watch) {
             $httpServer->addPeriodicTimer(1, function () use($sculpin, $dataSource, $sourceSet, $consoleIo) {
                 clearstatcache();
                 $sourceSet->reset();
                 $sculpin->run($dataSource, $sourceSet, $consoleIo);
             });
         }
         $httpServer->run();
     } else {
         do {
             $sculpin->run($dataSource, $sourceSet, $consoleIo);
             if ($watch) {
                 sleep(2);
                 clearstatcache();
                 $sourceSet->reset();
             }
         } while ($watch);
     }
 }