Documentation

WebBase
in package
Uses Singleton

A class that provides some basic Web operations and Constants.

Table of Contents

HTMLMIME  = 'text/html; charset="utf-8"'
$cache  : array<, mixed>
$context  : object
$headers  : array<, mixed>
$instance  : object
The only instance of using class
addHeader()  : void
Add a header to the header list.
getinstance()  : object
Checks, instantiates and returns the only instance of the using class.
hasRange()  : array<, mixed>
Check for a range request and check it
recaptcha()  : bool
Check a recaptcha value
relocate()  : void
Generate a Location header
sendFile()  : void
Deliver a file as a response.
sendHeaders()  : void
Make a header sequence for a particular return code and add some other useful headers
sendJSON()  : void
Deliver JSON response.
sendString()  : void
Deliver a string as a response.
sendHead()  : void
output a header and msg - this never returns
debuffer()  : void
Debuffer - sometimes when we need to do output we are inside buffering. This seems to be a problem with some LAMP stack systems.
putHeaders()  : void
Output the headers

Constants

HTMLMIME

public mixed HTMLMIME = 'text/html; charset="utf-8"'

Properties

$cache

protected array<, mixed> $cache = []

Holds values for Cache-Control headers

$context

protected object $context

The Context object

$headers

protected array<, mixed> $headers = []

Holds values for headers that are required. Keyed by the name of the header

$instance

The only instance of using class

protected static object $instance = NULL

Methods

addHeader()

Add a header to the header list.

public addHeader( $key[, string $value = '' ]) : void

This supports having more than one header with the same name.

Parameters
$key :

Either an array of key/value pairs or the key for the value that is in the second parameter

$value : string = ''
Tags
psalm-suppress

PossiblyUnusedMethod

Return values
void

getinstance()

Checks, instantiates and returns the only instance of the using class.

public static getinstance() : object
Tags
template

object

psalm-return

object

psalm-suppress

MismatchingDocblockReturnType

psalm-suppress

ReservedWord

Return values
object

hasRange()

Check for a range request and check it

public hasRange(int $size[,  $code = StatusCodes::HTTP_OK ]) : array<, mixed>

Media players ask for the file in chunks.

Parameters
$size : int

The size of the output data

$code : = StatusCodes::HTTP_OK

The HTTP return code or ''

Tags
psalm-suppress

InvalidOperand

psalm-suppress

PossiblyInvalidOperand

psalm-suppress

InvalidNullableReturnType

Return values
array<, mixed>

recaptcha()

Check a recaptcha value

public recaptcha(string $secret) : bool

This assumes that file_get_contents can access a URL

Parameters
$secret : string

The recaptcha secret for this site

Tags
psalm-suppress

PossiblyUnusedMethod

Return values
bool

relocate()

Generate a Location header

public relocate(string $where[, bool $temporary = TRUE ][, string $msg = '' ][, bool $nochange = FALSE ][, bool $use303 = FALSE ]) : void

These codes are a mess and are handled by brtowsers incorrectly....

Parameters
$where : string

The URL to divert to

$temporary : bool = TRUE

TRUE if this is a temporary redirect

$msg : string = ''

A message to send

$nochange : bool = FALSE

If TRUE then reply status codes 307 and 308 will be used rather than 301 and 302

$use303 : bool = FALSE

If TRUE then use 303 rather than 302

Tags
psalm-return

never-return

Return values
void

sendFile()

Deliver a file as a response.

public sendFile(string $path[, string $name = '' ][, string $mime = '' ]) : void
Parameters
$path : string

The path to the file

$name : string = ''

The name of the file as told to the downloader

$mime : string = ''

The mime type of the file

Return values
void

sendHeaders()

Make a header sequence for a particular return code and add some other useful headers

public sendHeaders(int $code[, string $mtype = '' ][, int|null $length = NULL ][, string $name = '' ]) : void
Parameters
$code : int

The HTTP return code

$mtype : string = ''

The mime-type of the file

$length : int|null = NULL

The length of the data or NULL

$name : string = ''

A file name

Return values
void

sendJSON()

Deliver JSON response.

public sendJSON(mixed $res[, int $code = StatusCodes::HTTP_OK ]) : void
Parameters
$res : mixed
$code : int = StatusCodes::HTTP_OK
Return values
void

sendString()

Deliver a string as a response.

public sendString(string $value[, string $mime = '' ][, int $code = StatusCodes::HTTP_OK ]) : void
Parameters
$value : string

The data to send

$mime : string = ''

The mime type of the file

$code : int = StatusCodes::HTTP_OK

The HTTP return code

Return values
void

sendHead()

output a header and msg - this never returns

protected sendHead(int $code[, string $msg = '' ]) : void
Parameters
$code : int

The return code

$msg : string = ''

The message (or '')

Tags
psalm-return

never-return

Return values
void

debuffer()

Debuffer - sometimes when we need to do output we are inside buffering. This seems to be a problem with some LAMP stack systems.

private debuffer() : void
Return values
void

putHeaders()

Output the headers

private putHeaders() : void
Return values
void

Search results