IResponse Interface
Definition
Namespace: DafCore
Phar: DafCore.phar
represents the HTTP response that an Daf app sends to the client when it gets an HTTP request.
Methods
function GetStatus(): int
Get the current status code.
function Status(int $statusCode, ?string $reasonPhrase = null): self
Write status header to the response.
function Header(string $name, string $value): self
Write header to the response.
function Headers(array $headers): self
Write array of headers to the response.
function Send(?string $text = null, ?array $headers = null): string
Write message and status headers ( if not empty ) to the response.
function Json(mixed $data, ?array $headers = null): string
Write JSON message and status headers ( if not empty ) to the response.
function Redirect(string $location = "", int $statusCode = 302): string
Redirect the request to new location. return empty string.
function RedirectBack(int $statusCode = 302): string
Redirect the request to the last location. return empty string.
function Ok(mixed $obj = null, ?array $headers = null): string
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 = null, ?array $headers = null): string
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 = null): string
Write status code 500 ( InternalError ) and message to the response.
if msg not empty it will trigger Send with msg.
function NoContent(): string
Write status code 204 ( NoContent ) and message to the response.
function BadRequest(?string $msg = null): string
Write status code 400 ( BadRequest ) and message to the response.
if msg not empty it will trigger Send with msg.
function NotFound(?string $msg = null): string
Write status code 404 ( NotFound ) and message to the response.
if msg not empty it will trigger Send with msg.
function Forbidden(?string $msg = null): string
Write status code 403 ( Forbidden ) and message to the response.
if msg not empty it will trigger Send with msg.
function Unauthorized(?string $msg = null): string
Write status code 401 ( Unauthorized ) and message to the response.
if msg not empty it will trigger Send with msg.