# Class HttpSoft\Message\ServerRequestFactory

Factory for creating HttpSoft\Message\ServerRequest and implements Psr\Http\Message\ServerRequestFactoryInterface.

Source code on GitHub.

use HttpSoft\Message\ServerRequestFactory;

$factory = new ServerRequestFactory();
$request = $factory->createServerRequest('POST', 'http://example.com', $_SERVER);

$request->getMethod(); // 'POST'
$request->getProtocolVersion(); // '1.1'
$request->getBody()->getMetadata('uri'); // 'php://temp'
(string) $request->getUri(); // 'http://example.com'
$request->getHeaders(); // ['Host' => ['example.com'], 'Content-Type' => ['text/html']]

$request->getServerParams(); // $_SERVER
$request->getUploadedFiles(); // []
$request->getCookieParams(); // []
$request->getQueryParams(); // []
$request->getParsedBody(); // `null`
$request->getAttributes(); // []

# Public methods

See the original detailed description of the methods in the Psr\Http\Message\ServerRequestFactoryInterface.

# createServerRequest

Create a new HttpSoft\Message\ServerRequest instance.

/**
 * @param string $method
 * @param UriInterface|string $uri
 * @param array $serverParams
 * @return ServerRequestInterface
 */
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface;

Creates an instance of HttpSoft\Message\ServerRequest with empty data for superglobals.

use HttpSoft\Message\ServerRequestFactory;

$factory = new ServerRequestFactory();
$request = $factory->createServerRequest('GET', '', []);

$request->getMethod(); // 'GET'
$request->getProtocolVersion(); // '1.1'
$request->getBody()->getContents(); // ''
$request->getBody()->getMetadata('uri'); // 'php://temp'
(string) $request->getUri(); // ''
$request->getHeaders(); // []

$request->getServerParams(); // []
$request->getUploadedFiles(); // []
$request->getCookieParams(); // []
$request->getQueryParams(); // []
$request->getParsedBody(); // null
$request->getAttributes(); // []