Web
extends WebBase
in package
Uses
CSP
A class that handles various web related things.
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
- $csp : array<, mixed>
- $nocsp : array<, mixed>
- acceptgzip() : bool
- Check to see if the client accepts gzip encoding
- addCache() : void
- Add an item for use in a Cache-Control header
- addCSP() : void
- Add an item for use in a CSP header - could be 'unsafe-inline', a domain or other stuff
- addHeader() : void
- Add a header to the header list.
- bad() : void
- Generate a 400 Bad Request error return
- created() : void
- Send a 201 response - Created
- getinstance() : object
- Checks, instantiates and returns the only instance of the using class.
- hasRange() : array<, mixed>
- Check for a range request and check it
- internal() : void
- Generate a 500 Internal Error error return
- isPost() : bool
- Is this a POST?
- method() : string
- What kind of request was this?
- noAccess() : void
- Generate a 403 Access Denied error return
- noContent() : void
- Send a 204 response - OK but no content
- notFound() : void
- Generate a 404 Not Found error return
- recaptcha() : bool
- Check a recaptcha value
- relocate() : void
- Generate a Location header
- removeCSP() : void
- Remove an item from a CSP header - could be 'unsafe-inline', a domain or other stuff
- saveCSP() : string
- compute, save and return a hash for use in a CSP header
- send304() : void
- Send a 304 response - this assumes that the Etag etc. have been set up using the set304Cache function in the \Support\SiteAction class
- 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.
- setCSP() : void
- Set up default CSP headers for a page
- 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
$csp
private
array<, mixed>
$csp
= []
Holds values that need to be added to CSP headers.
$nocsp
private
array<, mixed>
$nocsp
= []
Holds values that need to be removed from CSP headers.
Methods
acceptgzip()
Check to see if the client accepts gzip encoding
public
acceptgzip() : bool
Return values
bool —addCache()
Add an item for use in a Cache-Control header
public
addCache(array<, string> $items) : void
Parameters
- $items : array<, string>
-
An array of items
Return values
void —addCSP()
Add an item for use in a CSP header - could be 'unsafe-inline', a domain or other stuff
public
addCSP( $type[, string $host = '' ]) : void
Parameters
- $type :
-
What the item is for (script-src, style-src etc.)
- $host : string = ''
-
The host to add
Return values
void —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
Return values
void —bad()
Generate a 400 Bad Request error return
public
bad([string $msg = '' ]) : void
Parameters
- $msg : string = ''
-
A message to be sent
Tags
Return values
void —created()
Send a 201 response - Created
public
created(string $value[, string $mime = 'text/plain; charset=UTF-8' ]) : void
Parameters
- $value : string
-
a string to return
- $mime : string = 'text/plain; charset=UTF-8'
-
the mimetype
Return values
void —getinstance()
Checks, instantiates and returns the only instance of the using class.
public
static getinstance() : object
Tags
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
Return values
array<, mixed> —internal()
Generate a 500 Internal Error error return
public
internal([string $msg = '' ]) : void
Parameters
- $msg : string = ''
-
A message to be sent
Tags
Return values
void —isPost()
Is this a POST?
public
isPost() : bool
Tags
Return values
bool —method()
What kind of request was this?
public
method() : string
Return values
string —noAccess()
Generate a 403 Access Denied error return
public
noAccess([string $msg = '' ]) : void
Parameters
- $msg : string = ''
-
A message to be sent
Tags
Return values
void —noContent()
Send a 204 response - OK but no content
public
noContent() : void
Return values
void —notFound()
Generate a 404 Not Found error return
public
notFound([string $msg = '' ]) : void
Parameters
- $msg : string = ''
-
A message to be sent
Tags
Return values
void —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
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
Return values
void —removeCSP()
Remove an item from a CSP header - could be 'unsafe-inline', a domain or other stuff
public
removeCSP( $type[, string $host = '' ]) : void
Parameters
- $type :
-
What the item is for (script-src, style-src etc.)
- $host : string = ''
-
The item to remove
Tags
Return values
void —saveCSP()
compute, save and return a hash for use in a CSP header
public
saveCSP(string $type, string $data) : string
Parameters
- $type : string
-
What the hash is for (script-src, css-src etc.)
- $data : string
-
The data to be hashed
Tags
Return values
string —Returns the hash
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
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 —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
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
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