public function listen() { $app = $this->getApp(); $this->collectGarbage($app); $server = Server::createServer($this->getMiddleware($app), $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server->listen(); }
/** * "Listen" to an incoming request * * If provided a $finalHandler, that callable will be used for * incomplete requests. * * Output buffering is enabled prior to invoking the attached * callback; any output buffered will be sent prior to any * response body content. * * @param null|callable $finalHandler */ private function traverse_middleware_pipeline($finalHandler = NULL) { $pipeline = $this->kernel->middleware(); $emitter = new SapiEmitter(); $this->server->setEmitter($emitter); ob_start(); $bufferLevel = ob_get_level(); # the work is done here $response = $pipeline($this->server->{'request'}, $this->server->{'response'}, $finalHandler); if (!$response instanceof ResponseInterface) { $response = $this->server->{'response'}; } $emitter->emit($response, $bufferLevel); }
<?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();
<?php /** * Part of Windwalker project. * * @copyright Copyright (C) 2016 LYRASOFT. All rights reserved. * @license GNU General Public License version 2 or later. */ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; include_once __DIR__ . '/../../../../vendor/autoload.php'; $request = Zend\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server = \Zend\Diactoros\Server::createServerFromRequest(function (RequestInterface $request, ResponseInterface $response, $done) { $response->getBody()->write("Hello world!"); show($request->getUri()); }, $request); $server->listen();
/** * @return \Closure */ protected function getServer() { return function (ContainerInterface $container) { return \Zend\Diactoros\Server::createServerfromRequest($container->get(Runner::class), $container->get(ServerRequestInterface::class)); }; }