rareloop / psr7-server-request-extension
Installs: 161 311
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/rareloop/psr7-server-request-extension
Requires
- php: >=8.1
- psr/http-message: ^2
Requires (Dev)
- brain/monkey: ^2.6.2
- laminas/laminas-diactoros: ^3.6
- mockery/mockery: ^1.6
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7.2
This package is auto-updated.
Last update: 2025-10-13 15:51:03 UTC
README
Provides traits that add utility functions to a PSR7 ServerResponse
subclass that make it easier to interact with the URI and input. Inspired by the API of Laravel.
Install
composer install rareloop/psr7-server-request-extension
Create a ServerRequest
Create a subclass of a PSR7 compatible ServerRequest
object (e.g. Diactoros) and add the InteractsWithInput
and InteractsWithUri
traits.
<?php namespace App; use Rareloop\Psr7ServerRequestExtension\InteractsWithInput; use Rareloop\Psr7ServerRequestExtension\InteractsWithUri; use Zend\Diactoros\ServerRequest; class MyServerRequest extends ServerRequest { use InteractsWithInput, InteractsWithUri; }
Usage
Get the path
$request->path();
Get the URL
$request->url(); // e.g. http://test.com/path $request->fullUrl(); // e.g. http://test.com/path?foo=bar
Get all query params
$request->query();
Get a specific query param
$request->query('name'); $request->query('name', 'Jane'); // Defaults to "Jane" if not set
Get all post params
$request->post();
Get a specific post param
$request->post('name'); $request->post('name', 'Jane'); // Defaults to "Jane" if not set
Get all input params
$request->input();
Get a specific input param
$request->input('name'); $request->input('name', 'Jane'); // Defaults to "Jane" if not set
Does the request have a specific input key?
if ($request->has('name')) { // do something } if ($request->has(['name', 'age'])) { // do something if both 'name' and 'age' are present }