Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Rareloop/psr7-server-request-extension
https://github.com/Rareloop/psr7-server-request-extension
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/Rareloop/psr7-server-request-extension
- Owner: Rareloop
- License: mit
- Created: 2018-07-12T19:41:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-28T16:43:15.000Z (about 4 years ago)
- Last Synced: 2024-10-20T09:18:48.108Z (23 days ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PSR7 ServerRequest Extension
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](https://laravel.com/docs/5.6/requests).
## Install
`composer install rareloop/psr7-server-request-extension`
## Create a ServerRequest
Create a subclass of a PSR7 compatible `ServerRequest` object (e.g. [Diactoros](https://github.com/zendframework/zend-diactoros)) and add the `InteractsWithInput` and `InteractsWithUri` traits.
```php
path();
```### Get the URL
```php
$request->url(); // e.g. http://test.com/path
$request->fullUrl(); // e.g. http://test.com/path?foo=bar
```### Get all query params
```php
$request->query();
```### Get a specific query param
```php
$request->query('name');
$request->query('name', 'Jane'); // Defaults to "Jane" if not set
```### Get all post params
```php
$request->post();
```### Get a specific post param
```php
$request->post('name');
$request->post('name', 'Jane'); // Defaults to "Jane" if not set
```### Get all input params
```php
$request->input();
```### Get a specific input param
```php
$request->input('name');
$request->input('name', 'Jane'); // Defaults to "Jane" if not set
```### Does the request have a specific input key?
```php
if ($request->has('name')) {
// do something
}if ($request->has(['name', 'age'])) {
// do something if both 'name' and 'age' are present
}
```