Skip to content

PSR 7: Response Example

Terry L edited this page Jun 20, 2020 · 4 revisions

PSR-7 HTTP Message Interfaces

Namespace

Shieldon\Psr7\Response

Response

__construct

  • 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();

getStatusCode()

  • return int

Example:

$statusCode = $response->getStatusCode();

echo $statusCode
// Outputs: 200

withStatus($code, $reasonPhrase)

  • 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.

getReasonPhrase()

  • return string

Example:

$reasonPhrase = $response->getReasonPhrase();

echo $reasonPhrase
// Outputs: OK
Clone this wiki locally