예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $kernel = new AppKernel($environment = $input->getOption("environment"), $environment !== "prod");
     $kernel->boot();
     $loop = Factory::create();
     /** @var Container $container */
     $container = $kernel->getContainer();
     $container->set("react.loop", $loop);
     $socket = new Socket($loop);
     $http = new Server($socket);
     $http->on("request", function (Request $request, Response $response) use($kernel, $loop) {
         $headers = $request->getHeaders();
         $cookies = [];
         if (isset($headers["Cookie"])) {
             foreach ((array) $headers["Cookie"] as $cookieHeader) {
                 foreach (explode(";", $cookieHeader) as $cookie) {
                     list($name, $value) = explode("=", trim($cookie), 2);
                     $cookies[$name] = urldecode($value);
                 }
             }
         }
         $symfonyRequest = new SymfonyRequest($request->getQuery(), [], [], $cookies, [], ["REQUEST_URI" => $request->getPath(), "SERVER_NAME" => explode(":", $headers["Host"])[0], "REMOTE_ADDR" => $request->remoteAddress, "QUERY_STRING" => http_build_query($request->getQuery())], null);
         $symfonyRequest->headers->replace($headers);
         $symfonyResponse = $kernel->handle($symfonyRequest);
         if ($kernel instanceof TerminableInterface) {
             $kernel->terminate($symfonyRequest, $symfonyResponse);
         }
         if ($symfonyResponse instanceof PromiseInterface) {
             $symfonyResponse->then(function (SymfonyResponse $symfonyResponse) use($response) {
                 $this->send($response, $symfonyResponse);
             }, function ($error) use($loop, $response) {
                 echo "Exception: ", (string) $error, "\n";
                 $response->writeHead(500, ["Content-Type" => "text/plain"]);
                 $response->end("500 Internal Server Error");
                 $loop->stop();
             });
         } elseif ($symfonyResponse instanceof SymfonyResponse) {
             $this->send($response, $symfonyResponse);
         } else {
             echo "Unsupported response type: ", get_class($symfonyResponse), "\n";
             $response->writeHead(500, ["Content-Type" => "text/plain"]);
             $response->end("500 Internal Server Error");
             $loop->stop();
         }
     });
     $socket->listen($port = $input->getOption("port"), $host = $input->getOption("host"));
     echo "Listening to {$host}:{$port}\n";
     $loop->run();
 }
예제 #2
0
파일: index.php 프로젝트: skrz/stack
<?php

namespace App;

use Symfony\Component\HttpFoundation\Request;
use Tracy\Debugger;
require_once __DIR__ . "/../vendor/autoload.php";
$env = isset($_SERVER["APP_ENV"]) ? $_SERVER["APP_ENV"] : "prod";
Debugger::enable($env !== "dev", __DIR__ . "/../log");
$request = Request::createFromGlobals();
$kernel = new AppKernel($env, $env === "dev");
$response = $kernel->handle($request);
if ($env === "dev") {
    // ->send() calls fastcgi_finish_request(), so no other content would get rendered (e.g. Tracy debug bar)
    $response->sendHeaders();
    $response->sendContent();
} else {
    $response->send();
}
$kernel->terminate($request, $response);
예제 #3
0
파일: index.php 프로젝트: slince/webapp
<?php

use App\AppKernel;
include __DIR__ . '/../config/bootstrap.php';
$kernel = new AppKernel(true);
$kernel->run();