Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Http Server Request Laravel Package

httpsoft/http-server-request

PSR-7/PSR-17 friendly ServerRequest implementation and helpers for building HTTP server requests in PHP. Lightweight, standards-based request object with convenient access to headers, cookies, query params, body, uploaded files, and server params.

View on GitHub
Deep Wiki
Context7

HTTP Server Request

License Latest Stable Version Total Downloads GitHub Build Status GitHub Static Analysis Status Scrutinizer Code Coverage Scrutinizer Code Quality

This package makes it easy and flexible to create PSR-7 components ServerRequest and UploadedFile.

Depends on the httpsoft/http-message package.

Documentation

Installation

This package requires PHP version 7.4 or later.

composer require httpsoft/http-server-request

Usage ServerRequestCreator

use HttpSoft\ServerRequest\ServerRequestCreator;

// All necessary data will be received automatically:
$request = ServerRequestCreator::createFromGlobals($_SERVER, $_FILES, $_COOKIE, $_GET, $_POST);
// equivalently to:
$request = ServerRequestCreator::createFromGlobals();
// equivalently to:
$request = ServerRequestCreator::create();

By default HttpSoft\ServerRequest\SapiNormalizer is used for normalization of server parameters. You can use your own server parameters normalizer, for this you need to implement an HttpSoft\ServerRequest\ServerNormalizerInterface interface.

$normalizer = new YouCustomServerNormalizer();

$request = ServerRequestCreator::create($normalizer);
// equivalently to:
$request = ServerRequestCreator::createFromGlobals($_SERVER, $_FILES, $_COOKIE, $_GET, $_POST, $normalizer);
// or with custom superglobals:
$request = ServerRequestCreator::createFromGlobals($server, $files, $cookie, $get, $post, $normalizer);

Usage UploadedFileCreator

use HttpSoft\ServerRequest\UploadedFileCreator;

/** @var StreamInterface|string|resource $streamOrFile */
$uploadedFile = UploadedFileCreator::create($streamOrFile, 1024, UPLOAD_ERR_OK, 'file.txt', 'text/plain');

// Create a new `HttpSoft\UploadedFile\UploadedFile` instance from array (the item `$_FILES`)
$uploadedFile = UploadedFileCreator::createFromArray([
    'name' => 'filename.jpg', // optional
    'type' => 'image/jpeg', // optional
    'tmp_name' => '/tmp/php/php6hst32',
    'error' => 0, // UPLOAD_ERR_OK
    'size' => 98174,
]);

// Normalizes the superglobal structure and converts each array
// value to an instance of `Psr\Http\Message\UploadedFileInterface`.
$uploadedFiles = UploadedFileCreator::createFromGlobals($_FILES);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport