# Class HttpSoft\Request\ServerRequestFactory
Factory for creating HttpSoft\Request\ServerRequest and implements Psr\Http\Message\ServerRequestFactoryInterface.
use HttpSoft\Request\ServerRequestFactory;
// Instance of `HttpSoft\Request\ServerRequest` with empty data:
$factory = new ServerRequestFactory();
$request = $factory->createServerRequest('GET', '');
// Or
$request = ServerRequestFactory::createFromGlobals([], [], [], [], []);
// Instance of `HttpSoft\Request\ServerRequest` with data taken from superglobal arrays:
$request = ServerRequestFactory::createFromGlobals($_SERVER, $_FILES, $_COOKIE, $_GET, $_POST);
// equivalently to:
$request = ServerRequestFactory::createFromGlobals(null, null, null, null, null);
// equivalently to:
$request = ServerRequestFactory::createFromGlobals();
// equivalently to:
$request = ServerRequestFactory::create(); # Public methods
See the original detailed description of the methods in the Psr\Http\Message\ServerRequestFactoryInterface.
# create
Create a new HttpSoft\Request\ServerRequest instance from superglobals (static method).
public static function create(ServerNormalizerInterface $normalizer = null): ServerRequestInterface; See the createFromGlobals() method, since this method is a wrapper over it.
# createFromGlobals
Create a new HttpSoft\Request\ServerRequest instance from superglobals (static method).
public static function createFromGlobals(
array $server = null,
array $files = null,
array $cookie = null,
array $get = null,
array $post = null,
ServerNormalizerInterface $normalizer = null
): ServerRequestInterface; If any of the arrays ($server, $files, $cookie, $get, $post) was not specified or is null, values from superglobals ($_SERVER, $_FILES, $_COOKIE, $_GET, $_POST) will be taken, but if an array was specified (even empty), it will be used.
$request = ServerRequestFactory::createFromGlobals([], null, [], null, []);
$request->getServerParams(); // []
$request->getUploadedFiles(); // $_FILES
$request->getCookieParams(); // []
$request->getQueryParams(); // $_GET
$request->getParsedBody(); // [] The $normalizer is responsible for normalizing the data needed to create a HttpSoft\Request\ServerRequest.
$request = ServerRequestFactory::createFromGlobals();
$request->getMethod(); // 'GET'
$request->getProtocolVersion(); // '1.1'
$request->getBody()->getContents(); // 'Page content'
$request->getBody()->getMetadata('uri'); // 'php://input'
(string) $request->getUri(); // 'http://example.com/path'
$request->getHeaders(); // ['Host' => ['example.com'], 'Content-Type' => ['text/html']]
$request->getServerParams(); // $_SERVER
$request->getUploadedFiles(); // $_FILES
$request->getCookieParams(); // $_COOKIE
$request->getQueryParams(); // $_GET
$request->getParsedBody(); // $_POST
$request->getAttributes(); // [] If $normalizer was not specified or is null, HttpSoft\Request\SapiNormalizer will be used, which normalizes data from PHP SAPI. If HttpSoft\Request\SapiNormalizer is not suitable for you, then create your own by implementing HttpSoft\Request\ServerNormalizerInterface interface.
# createServerRequest
Create a new HttpSoft\Request\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\Request\ServerRequest with empty data for superglobals. Unlike methods create() and createFromGlobals(), it returns an HttpSoft\Request\ServerRequest instance with a php://temp stream.
$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(); // [] 