PHP Class Phly\Http\Server

Given a callback, takes an incoming request, dispatches it to the callback, and then sends a response.
Datei anzeigen Open project: phly/http Class Usage Examples

Public Methods

Method Description
__construct ( callable $callback, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response ) Constructor
__get ( string $name ) : mixed Allow retrieving the request, response and callback as properties
createServer ( callable $callback, array $server, array $query, array $body, array $cookies, array $files ) : static Create a Server instance
createServerFromRequest ( callable $callback, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response = null ) : static Create a Server instance from an existing request object
listen ( callable $finalHandler = null ) "Listen" to an incoming request
setEmitter ( Phly\Http\Response\EmitterInterface $emitter ) Set alternate response emitter to use.

Private Methods

Method Description
getEmitter ( ) : Phly\Http\Response\EmitterInterface Retrieve the current response emitter.

Method Details

__construct() public method

Given a callback, a request, and a response, we can create a server.
public __construct ( callable $callback, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response )
$callback callable
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface

__get() public method

Allow retrieving the request, response and callback as properties
public __get ( string $name ) : mixed
$name string
return mixed

createServer() public static method

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 static createServer ( callable $callback, array $server, array $query, array $body, array $cookies, array $files ) : static
$callback callable
$server array
$query array
$body array
$cookies array
$files array
return static

createServerFromRequest() public static method

Provided a callback, an existing request object, and optionally an existing response object, create and return the Server instance. If no Response object is provided, one will be created.
public static createServerFromRequest ( callable $callback, Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response = null ) : static
$callback callable
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
return static

listen() public method

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.
public listen ( callable $finalHandler = null )
$finalHandler callable

setEmitter() public method

Set alternate response emitter to use.
public setEmitter ( Phly\Http\Response\EmitterInterface $emitter )
$emitter Phly\Http\Response\EmitterInterface