-
Notifications
You must be signed in to change notification settings - Fork 1
PSR 7: Response Example
Terry L edited this page Jun 20, 2020
·
4 revisions
Namespace
Shieldon\Psr7\Response
-
param
int
status= 200
Response HTTP status code. -
param
array
headers= []
Response headers. -
param
StreamInterface|string
body= ""
Response body. -
param
string
version= "1.1"
Response protocol version. -
param
string
reason= "OK"
Reasponse HTTP reason phrase.
Example:
$response = new \Shieldon\Psr7\Response();
-
return
int
Example:
$statusCode = $response->getStatusCode();
echo $statusCode
// Outputs: 200
-
param
string
code*
The 3-digit integer result code to set. -
param
string
reasonPhrase= ""
The reason phrase to use with the provided status code -
return
static
Example:
$response = $response->withStatus(599, 'Something went wrong.');
echo $response->getStatusCode();
// Outputs: 599
echo $response->getReasonPhrase();
// Outputs: Something went wrong.
-
return
string
Example:
$reasonPhrase = $response->getReasonPhrase();
echo $reasonPhrase
// Outputs: OK
composer require shieldon/psr-http
Shieldon PSR HTTP implementation written by Terry L. from Taiwan.