fyre / response
A HTTP response library.
Installs: 288
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/fyre/response
Requires
- fyre/message: ^4.0
- psr/http-message: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
README
FyreResponse is a free, open-source immutable HTTP response library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/response
In PHP:
use Fyre\Http\Response;
Basic Usage
$optionsis an array containing the message options.bodyis a string or StreamInterface representing the message body, and will default to "".headersis an array containing headers to set, and will default to [].protocolVersionis a string representing the protocol version, and will default to "1.1".statusCodeis a number representing the status code, and will default to 200.reasonPhraseis a string representing the reason phrase, and will default to "".
$response = new Response($options);
If a reasonPhrase is not provided, the default reason for the status code will be used instead.
Methods
This class extends the Message class.
Get Reason Phrase
Get the response reason phrase.
$reason = $response->getReasonPhrase();
Get Status Code
Get the status code.
$code = $response->getStatusCode();
With Status
Set the status code.
$codeis a number representing the status code.$reasonPhraseis a string representing the reason phrase, and will default to "".
$newResponse = $response->withStatus($code, $reasonPhrase);
If a $reasonPhrase is not provided, the default reason for the status code will be used instead.