THIS IS WORK IN PROGRESS WITHOUT ANY RELEASE
This tiny library parses an HTTP request from its raw string representation to PHP superglobal like arrays. Typical PHP libraries such as the Symfony HttpFoundation provide ways to represent the current request as an object by using the PHP globals like so:
<?phpuseSymfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();However, if you have a string representation of a request, many of them do not support parsing these. This library parses the raw HTTP request and provides access to all the superglobals as PHP would create them. It's easiest to understand by using an example:
<?phpuseToflar\HttpRequestParser\Parser;
$raw = <<<REQUESTGET /foobar?test=foo%20bar HTTP/1.1Accept: application/jsonHost: example.comConnection: closeREQUEST;
$parser = newParser($raw);
var_dump($parser->getGet()); // would output the equivalent of $_GET (decoded as PHP would)You can use the results to create e.g. Symfony requests from these values then:
<?phpuseSymfony\Component\HttpFoundation\Request;
useToflar\HttpRequestParser\Parser;
$raw = <<<REQUESTGET /foobar?test=foo%20bar HTTP/1.1Accept: application/jsonHost: example.comConnection: closeREQUEST;
$parser = newParser($raw);
$request = newRequest(
$parser->getGet(),
$parser->getServer(),
[],
$parser->getCookie(),
$parser->getFiles(),
$parser->getServer(),
$parser->getBody()
);