Leaf PHP

Response
in package

Leaf HTTP Response ----------- This is a simple abstraction over top an HTTP response. This provides methods to set the HTTP status, the HTTP headers, and the HTTP body.

Tags
author

Michael Darko

since
1.0.0
version
2.0

Table of Contents

Properties

$cookies  : array<string|int, mixed>
$headers  : array<string|int, mixed>
$content  : string
$status  : int
$version  : string

Methods

closeOutputBuffers()  : void
Cleans or flushes output buffers up to target level.
custom()  : mixed
Output any text
die()  : mixed
Output some data and break the application
download()  : mixed
Output plain text
echo()  : mixed
Alias of custom
exit()  : mixed
Output some data and break the application
getMessageForCode()  : string|null
Get message for HTTP status code
httpVersion()  : mixed
Get/Set Http Version
inertia()  : mixed
Render an inertia view file if inertia is installed
js()  : mixed
Output js script
json()  : mixed
Output json encoded data with an HTTP code/message
markup()  : mixed
Output some html/PHP
next()  : mixed
Pass data to the route handler
noContent()  : mixed
The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page.
page()  : mixed
Output data from an HTML or PHP file
plain()  : mixed
Output plain text
redirect()  : mixed
Redirect
render()  : mixed
Render a view file if a view engine is available
send()  : $this
Send the Http headers and content
sendContent()  : $this
Sends content for the current web response.
sendCookies()  : Response
Send cookies
sendHeaders()  : $this
Sends HTTP headers.
status()  : Response
Force set HTTP status code
view()  : mixed
Render a view file if a view engine is available
withCookie()  : Response
Shorthand method of setting a cookie + value + expire time
withFlash()  : Response
Flash a piece of data to the session.
withHeader()  : Response
set header
withoutCookie()  : Response
Delete cookie
xml()  : mixed
Output xml text

Properties

$cookies

public array<string|int, mixed> $cookies = []

$headers

public array<string|int, mixed> $headers = []

$status

protected int $status = 200

HTTP status code

$version

protected string $version

HTTP Version

Methods

closeOutputBuffers()

Cleans or flushes output buffers up to target level.

public static closeOutputBuffers(int $targetLevel, bool $flush) : void

Resulting level can be greater than target level if a non-removable buffer has been encountered.

Parameters
$targetLevel : int
$flush : bool
Tags
final

custom()

Output any text

public custom(string $data[, int $code = 200 ]) : mixed
Parameters
$data : string

The data to output

$code : int = 200

The response status code

die()

Output some data and break the application

public die(mixed $data[, int $code = 500 ]) : mixed
Parameters
$data : mixed

The data to output

$code : int = 500

The Http status code

download()

Output plain text

public download(string $file[, string|null $name = null ][, int $code = 200 ]) : mixed
Parameters
$file : string

Path to the file to download

$name : string|null = null

The of the file as shown to user

$code : int = 200

The response status code

echo()

Alias of custom

public echo(string $data[, int $code = 200 ]) : mixed
Parameters
$data : string

The data to output

$code : int = 200

The response status code

exit()

Output some data and break the application

public exit(mixed $data[, int $code = 500 ]) : mixed
Parameters
$data : mixed

The data to output

$code : int = 500

The Http status code

getMessageForCode()

Get message for HTTP status code

public static getMessageForCode(int $status) : string|null
Parameters
$status : int
Return values
string|null

httpVersion()

Get/Set Http Version

public httpVersion([string|null $version = null ]) : mixed
Parameters
$version : string|null = null

inertia()

Render an inertia view file if inertia is installed

public inertia(string $view[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$view : string

The view file to render

$data : array<string|int, mixed> = []

The data to pass to the view

js()

Output js script

public js(string $data[, int $code = 200 ]) : mixed
Parameters
$data : string

The data to output

$code : int = 200

The response status code

json()

Output json encoded data with an HTTP code/message

public json(mixed $data[, int $code = 200 ][, bool $showCode = false ]) : mixed
Parameters
$data : mixed

The data to output

$code : int = 200

The response status code

$showCode : bool = false

Show response code in body?

markup()

Output some html/PHP

public markup(string $markup[, int $code = 200 ]) : mixed
Parameters
$markup : string

The data to output

$code : int = 200

The http status code

next()

Pass data to the route handler

public next(mixed $data) : mixed
Parameters
$data : mixed

The data to pass

noContent()

The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page.

public noContent() : mixed

page()

Output data from an HTML or PHP file

public page(string $file[, int $code = 200 ]) : mixed
Parameters
$file : string

The file to output

$code : int = 200

The http status code

plain()

Output plain text

public plain(mixed $data[, int $code = 200 ]) : mixed
Parameters
$data : mixed

The data to output

$code : int = 200

The response status code

redirect()

Redirect

public redirect(string|array<string|int, mixed> $url[, int $status = 302 ][, bool $exit = true ]) : mixed

This method prepares this response to return an HTTP Redirect response to the HTTP client.

Parameters
$url : string|array<string|int, mixed>

The redirect destination

$status : int = 302

The redirect HTTP status code

$exit : bool = true

render()

Render a view file if a view engine is available

public render(string $view[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$view : string

The view file to render

$data : array<string|int, mixed> = []

The data to pass to the view

send()

Send the Http headers and content

public send() : $this
Return values
$this

sendContent()

Sends content for the current web response.

public sendContent() : $this
Return values
$this

sendHeaders()

Sends HTTP headers.

public sendHeaders() : $this
Return values
$this

status()

Force set HTTP status code

public status([int|null $code = null ]) : Response
Parameters
$code : int|null = null
Return values
Response

view()

Render a view file if a view engine is available

public view(string $view[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$view : string

The view file to render

$data : array<string|int, mixed> = []

The data to pass to the view

withCookie()

Shorthand method of setting a cookie + value + expire time

public withCookie(string $name, string $value[, int|null $expire = null ]) : Response
Parameters
$name : string

The name of the cookie

$value : string

The value of cookie

$expire : int|null = null

When the cookie expires. Default: 7 days

Return values
Response

withFlash()

Flash a piece of data to the session.

public withFlash(mixed $key[, mixed $value = null ]) : Response
Parameters
$key : mixed
$value : mixed = null

The value of flash item

Return values
Response

withHeader()

set header

public withHeader(string|array<string|int, mixed> $name[, string|null $value = '' ][, bool $replace = true ][, int $httpCode = 200 ]) : Response
Parameters
$name : string|array<string|int, mixed>

Header name

$value : string|null = ''

Header value

$replace : bool = true

Replace existing header

$httpCode : int = 200

The HTTP status code

Return values
Response

withoutCookie()

Delete cookie

public withoutCookie(mixed $name) : Response
Parameters
$name : mixed

The name of the cookie

Return values
Response

xml()

Output xml text

public xml(string $data[, int $code = 200 ]) : mixed
Parameters
$data : string

The data to output

$code : int = 200

The response status code


        
On this page

Search results