Documentation

Web Uses Singleton

A class that handles various web related things.

Table of Contents

HTMLMIME 'text/html; charset="utf-8"'
$headers array
$csp array
$nocsp array
$cache array
$context object
$instance The only instance of using class object
relocate() Generate a Location header void
sendHead() output a header and msg - this never returns void
hasRange() Check for a range request and check it array
sendHeaders() Make a header sequence for a particular return code and add some other useful headers void
send304() Send a 304 response - this assumes that the Etag etc. have been set up using the set304Cache function in the \Support\SiteAction class void
bad() Generate a 400 Bad Request error return void
noAccess() Generate a 403 Access Denied error return void
notFound() Generate a 404 Not Found error return void
internal() Generate a 500 Internal Error error return void
sendFile() Deliver a file as a response. void
sendString() Deliver a string as a response. void
sendJSON() Deliver JSON response. void
addHeader() Add a header to the header list. void
putHeaders() Output the headers void
acceptgzip() Check to see if the client accepts gzip encoding bool
method() What kind of request was this? string
isPost() Is this a POST? bool
debuffer() Debuffer - sometimes when we need to do output we are inside buffering. This seems to be a problem with some LAMP stack systems. void
saveCSP() compute, save and return a hash for use in a CSP header string
addCSP() Add an item for use in a CSP header - could be 'unsafe-inline', a domain or other stuff void
removeCSP() Remove an item from a CSP header - could be 'unsafe-inline', a domain or other stuff void
setCSP() Set up default CSP headers for a page void
addCache() Add an item for use in a Cache-Control header void
recaptcha() Check a recaptcha value bool
makeNonce() Make a nonce value for including inline CSS string
getinstance() Checks, instantiates and returns the only instance of the using class. object

Constants

HTMLMIME

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

Properties

$headers

private array $headers = []

$csp

private array $csp = []

$nocsp

private array $nocsp = []

$cache

private array $cache = []

$context

private object $context

$instance

The only instance of using class

protected static object $instance = NULL

Methods

relocate()

Generate a Location header

public relocate( $where : string [, $temporary : bool = TRUE ] [, $msg : string = '' ] [, $nochange : bool = FALSE ] [, $use303 : bool = 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

sendHead()

output a header and msg - this never returns

private sendHead( $code : int , $msg : string ) : void
Parameters
$code : int

The return code

$msg : string

The message (or '')

Tags
psalm-return

never-return

hasRange()

Check for a range request and check it

public hasRange( $size : int [, $code : string|int = StatusCodes::HTTP_OK ] ) : array

Media players ask for the file in chunks.

Parameters
$size : int

The size of the output data

$code : string|int = StatusCodes::HTTP_OK

The HTTP return code or ''

Tags
psalm-suppress

InvalidOperand

psalm-suppress

PossiblyInvalidOperand

psalm-suppress

InvalidNullableReturnType

Return values
array

sendHeaders()

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

public sendHeaders( $code : int [, $mtype : string = '' ] [, $length : int|null = NULL ] [, $name : string = '' ] ) : 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

send304()

Send a 304 response - this assumes that the Etag etc. have been set up using the set304Cache function in the \Support\SiteAction class

public send304( ) : void
Tags
see

bad()

Generate a 400 Bad Request error return

public bad( [ $msg : string = '' ] ) : void
Parameters
$msg : string = ''

A message to be sent

Tags
psalm-return

never-return

noAccess()

Generate a 403 Access Denied error return

public noAccess( [ $msg : string = '' ] ) : void
Parameters
$msg : string = ''

A message to be sent

Tags
psalm-return

never-return

notFound()

Generate a 404 Not Found error return

public notFound( [ $msg : string = '' ] ) : void
Parameters
$msg : string = ''

A message to be sent

Tags
psalm-return

never-return

internal()

Generate a 500 Internal Error error return

public internal( [ $msg : string = '' ] ) : void
Parameters
$msg : string = ''

A message to be sent

Tags
psalm-return

never-return

sendFile()

Deliver a file as a response.

public sendFile( $path : string [, $name : string = '' ] [, $mime : string = '' ] ) : 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

sendString()

Deliver a string as a response.

public sendString( $value : string [, $mime : string = '' ] [, $code : int = 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

sendJSON()

Deliver JSON response.

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

addHeader()

Add a header to the header list.

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

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

Parameters
$key : string|string[]

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

putHeaders()

Output the headers

private putHeaders( ) : void

acceptgzip()

Check to see if the client accepts gzip encoding

public acceptgzip( ) : bool
Return values
bool

method()

What kind of request was this?

public method( ) : string
Return values
string

isPost()

Is this a POST?

public isPost( ) : bool
Tags
psalm-suppress

PossiblyUnusedMethod

Return values
bool

debuffer()

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

public debuffer( ) : void

saveCSP()

compute, save and return a hash for use in a CSP header

public saveCSP( $type : string , $string : string ) : string
Parameters
$type : string

What the hash is for (script-src, css-src etc.)

$string : string

The data to be hashed

Tags
psalm-suppress

PossiblyUnusedMethod

Return values
string

Returns the hash

addCSP()

Add an item for use in a CSP header - could be 'unsafe-inline', a domain or other stuff

public addCSP( $type : string|string[] [, $host : string = '' ] ) : void
Parameters
$type : string|string[]

What the item is for (script-src, style-src etc.)

$host : string = ''

The host to add

removeCSP()

Remove an item from a CSP header - could be 'unsafe-inline', a domain or other stuff

public removeCSP( $type : string|array [, $host : string = '' ] ) : void
Parameters
$type : string|array

What the item is for (script-src, style-src etc.)

$host : string = ''

The item to remove

Tags
psalm-suppress

PossiblyUnusedMethod

setCSP()

Set up default CSP headers for a page

public setCSP( ) : void

There will be a basic set of default CSP permissions for the site to function, but individual pages may wish to extend or restrict these.

Tags
psalm-suppress

PossiblyUnusedMethod

addCache()

Add an item for use in a Cache-Control header

public addCache( $items : string[] ) : void
Parameters
$items : string[]

An array of items

recaptcha()

Check a recaptcha value

public recaptcha( $secret : string ) : bool

This assumes that file_get_contetns

Parameters
$secret : string

The recaptcha secret for this site

Tags
psalm-suppress

PossiblyUnusedMethod

Return values
bool

makeNonce()

Make a nonce value for including inline CSS

public makeNonce( ) : string
Return values
string

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

Search results