Docs

Response Class


Definition

Namespace: DafCore
Phar: DafCore.phar
Implements: IResponse

Constructor

new Response(int $statusCode = 200, string $reasonPhrase = null)
  • int $statusCode - http status code, default 200 (ok).
  • string $reasonPhrase - status code reason msg.

Methods

function Reset() : void
Reset the response obj to clean new response.
function Status(int $statusCode, string $reasonPhrase) : void
Write status header to the response.
function Send(string $text, array $headers = null) : self
Write message and status headers ( if not empty ) to the response.
function Json(mixed $data, array $headers = null) : void
Write JSON message and status headers ( if not empty ) to the response.
function Redirect(string $location) : void
Redirect the request to new location.
function RedirectBack() : void
Reset the response obj to clean new response.
function Ok(mixed $obj, array $headers = null) : void
Write status code 200 ( Ok ) and message to the response.
if obj is string it will trigger Send with the headers.
else it will trigger Json with the headers.
function Created(mixed $obj, array $headers = null) : void
Write status code 201 ( Created ) and message to the response.
if obj is string it will trigger Send with the headers.
else it will trigger Json with the headers.
function InternalError(string $msg) : void
Write status code 500 ( InternalError ) and message to the response.
if msg not empty it will trigger Send with msg.
function NoContent() : void
Write status code 204 ( NoContent ) and message to the response.
function BadRequest(string $msg) : void
Write status code 400 ( BadRequest ) and message to the response.
if msg not empty it will trigger Send with msg.
function NotFound(string $msg) : void
Write status code 404 ( NotFound ) and message to the response.
if msg not empty it will trigger Send with msg.
function Forbidden(string $msg) : void
Write status code 403 ( Forbidden ) and message to the response.
if msg not empty it will trigger Send with msg.
function Unauthorized(string $msg) : void
Write status code 401 ( Unauthorized ) and message to the response.
if msg not empty it will trigger Send with msg.