Skip to content

PSR 17: ServerRequestFactory Example

Terry L edited this page Jun 18, 2020 · 2 revisions
Clone this wiki locally

PSR 17 Factories

ServerRequestFactory

__construct

None

Example:

use Shieldon\Psr17\ServerRequestFactory;

$serverRequestFactory = new ServerRequestFactory();

createServerRequest($method, $uri, $serverParams)

  • param string method *The HTTP method associated with the request.
  • param UriInterface|string uri *The URI associated with the request.
  • param array serverParams = [] An array of Server API (SAPI) parameters with which to seed the generated request instance.
  • return ServerRequestInterface

Examples:

$serverRequestFactory = new ServerRequestFactory();

$method = 'GET';
$url = 'https://www.yourwebsite.com/current-page/';

$serverRequest = $serverRequestFactory->createServerRequest($method, $uri);

::fromGlobal()

(Non-PSR)

  • return ServerRequestInterface

Examples:

$serverRequest = ServerRequestFactory::fromGlobal();