Creates a server instance from the callback and the following
PHP environmental values:
- server; typically this will be the $_SERVER superglobal
- query; typically this will be the $_GET superglobal
- body; typically this will be the $_POST superglobal
- cookies; typically this will be the $_COOKIE superglobal
- files; typically this will be the $_FILES superglobal
public function listen() { $app = $this->getApp(); $this->collectGarbage($app); $server = Server::createServer($this->getMiddleware($app), $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server->listen(); }
<?php /** * This makes our life easier when dealing with paths. Everything is relative * to the application root now. */ chdir(dirname(__DIR__)); //we activate full error reporting for our sample, to ease support error_reporting(E_ALL); ini_set('display_errors', 1); // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { return false; } // Setup autoloading require 'vendor/autoload.php'; $container = (require 'config/container.php'); $app = new \Zend\Stratigility\MiddlewarePipe(); //CargoUI route $app->pipe('/', function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, callable $next = null) use($container) { if ($request->getUri()->getPath() === "/") { /** @var $cargoUi \Codeliner\CargoUI\Main::class */ $cargoUi = $container->get(\Codeliner\CargoUI\Main::class); return $cargoUi($request, $response, $next); } return $next($request, $response); }); $cargoBackend = $container->get('Codeliner\\CargoBackend'); $app->pipe('/api', $cargoBackend); $server = \Zend\Diactoros\Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server->listen();
<?php use Zend\Stratigility\MiddlewarePipe; use Zend\Diactoros\Server; use Middleware\RouteManager; require_once __DIR__ . '/../vendor/autoload.php'; $app = new MiddlewarePipe(); $app->pipe(new RouteManager(require_once __DIR__ . '/../config/routes.php')); $server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server->listen();
public function listen() { Server::createServer($this, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES)->listen(); }
<?php use Zend\Stratigility\MiddlewarePipe; use Zend\Diactoros\Server; // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { return false; } chdir(__DIR__ . '/../'); $loader = (require_once 'vendor/autoload.php'); $loader->add('Application\\', 'src'); Server::createServer(include 'app.php', $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES)->listen();
/** * initialize the server/request/response and register with the service container. */ private function initialize_server() { # create and register the server, request and response $this->server = $server = Server::createServer($this->kernel->middleware(), $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); # register the server $this->kernel->forge()->singleton(['server', Server::class], $server); # register request $this->kernel->forge()->add(['request', ServerRequestInterface::class], function () use($server) { # return the active request return new Request($server->{'request'}); }); # register the response $this->kernel->forge()->add(['response', ResponseInterface::class], function () use($server) { # return the active response return new Response($server->{'response'}); }); }