guennichi / psr7-request-creator
Factory class to create request body from PSR-7 server requests
1.0.2
2022-09-12 13:59 UTC
Requires
- php: ^8.1
- php-http/multipart-stream-builder: ^1.2
- psr/http-message: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.9
- nyholm/psr7: ^1.5
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
README
Factory class to create simple request objects from PSR-7 server requests.
Installation
composer require guennichi/psr7-request-creator
Usage
Create request object
This library can be used with Nyholm/psr7
/ Nyholm/psr7-server
or any other PSR-7 implementation to transform server requests:
$psr17Factory = new Nyholm\Psr7\Factory\Psr17Factory(); $serverRequestCreator = new Nyholm\Psr7Server\ServerRequestCreator( $psr17Factory, // ServerRequestFactory $psr17Factory, // UriFactory $psr17Factory, // UploadedFileFactory $psr17Factory, // StreamFactory ); // Psr\Http\Message\ServerRequestInterface instance $serverRequest = $serverRequestCreator->fromGlobals(); $requestCreator = new Guennichi\Psr7RequestFactory\RequestCreator( $psr17Factory, // RequestFactory $psr17Factory, // StreamFactory new Http\Message\MultipartStream\MultipartStreamBuilder($psr17Factory), ); // Psr\Http\Message\RequestInterface instance $request = $requestCreator->fromServerRequest('/example', $serverRequest);