Documentation

SiteAction Uses SiteAction

A class that all provides a base class for any class that wants to implement a site action

Common functions used across the various sub-classes should go in here

Table of Contents

$maxage int
handle() Handle an action string|array
setCSP() Set up any CSP headers for a page void
ifmodcheck() Look to see if there are any IF... headers, and deal with them. Exit if a 304 or 412 is generated. void
makemod() Format a time suitable for Last-Modified header string
etagmatched() We have a matched etag - check request method and send the appropriate header. void
checkRest() Validate the number of fields in the rest of the URL string[]
setCache() Set any cache headers that are wanted for a normal page delivery void
set304Cache() Set any cache headers that are wanted on a 304 response void
makeetag() Make an etag for an item string
makemaxage() Make a max age value for an item int
exists() Returns true of the request would generate a page. bool
lastmodified() Get a last modified time for the page int
checkmodtime() Check a timestamp to see if we need to send the page again or not. bool
checketag() Check an etag to see if we need to send the page again or not. bool

Properties

Methods

handle()

Handle an action

public handle( $context : Context ) : string|array
Parameters
$context : Context

The context object for the site

Tags
psalm-suppress

InvalidReturnType

Return values
string|array

A template name or an array [template name, mimetype, HTTP code]

setCSP()

Set up any 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
phpcsSuppress

NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff

ifmodcheck()

Look to see if there are any IF... headers, and deal with them. Exit if a 304 or 412 is generated.

public ifmodcheck( $context : Context ) : void
Parameters
$context : Context
Tags
link

This should be used in page classes where there is some way of determining page freshness (ETags, last modified etc.), otherwise it need not be called.

The actual ways of determining page freshness will be page specific and you may need to override some of the other methods that this method calls in order to make things work!

The Data class provides (or will in the future...) an example of how to use this code when dealing with file data.

makemod()

Format a time suitable for Last-Modified header

public makemod( $time : int ) : string
Parameters
$time : int

The last modified time

Return values
string

etagmatched()

We have a matched etag - check request method and send the appropriate header.

private etagmatched( $context : Context ) : void

Does not return

Parameters
$context : Context
Tags
link
psalm-return

never-return

checkRest()

Validate the number of fields in the rest of the URL

public checkRest( $rest : string[] , $start : int , $num : int [, $format : string[] = [] ] ) : string[]
Parameters
$rest : string[]
$start : int

The element to start at

$num : int

The number of params required

$format : string[] = []

Currently not used

Tags
todo

This function could do a lot moreabout checking things....

throws
phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
string[]

setCache()

Set any cache headers that are wanted for a normal page delivery

public setCache( $context : Context ) : void
Parameters
$context : Context

The context object

Tags
psalm-suppress

PossiblyUnusedMethod

phpcsSuppress

NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff

set304Cache()

Set any cache headers that are wanted on a 304 response

public set304Cache( $context : Context ) : void
Parameters
$context : Context

The context object for the site

Tags
phpcsSuppress

NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff

makeetag()

Make an etag for an item

public makeetag( $context : Context ) : string

This needs to be overridden by pages that can generate etags

Parameters
$context : Context

The context object for the site

Tags
psalm-suppress

PossiblyUnusedParam

phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
string

makemaxage()

Make a max age value for an item

public makemaxage( $context : Context ) : int

This needs to be overridden by pages that want to use this

Parameters
$context : Context

The context object for the site

Tags
psalm-suppress

PossiblyUnusedParam

phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
int

exists()

Returns true of the request would generate a page.

public exists( $context : Context ) : bool

This needs to be overridden if it is to be used. Currently returns TRUE, thus assuming that pages always exist....

Parameters
$context : Context

The context object for the site

Tags
psalm-suppress

PossiblyUnusedParam

phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
bool

lastmodified()

Get a last modified time for the page

public lastmodified( $context : Context ) : int

By default this returns the current time. For pages that need to use this in anger, then this function may need to be overridden.

Parameters
$context : Context

The context object for the site

Tags
psalm-suppress

PossiblyUnusedParam

phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
int

checkmodtime()

Check a timestamp to see if we need to send the page again or not.

public checkmodtime( $context : Context , $time : string ) : bool

This always returns FALSE, indicating that we need to send the page again. The assumption is that pages that implement etags will override this function appropriately to do actual value checking.

Parameters
$context : Context

The context object for the site

$time : string

The time value to check

Tags
psalm-suppress

PossiblyUnusedParam

phpcsSuppress

SlevomatCodingStandard.Functions.UnusedParameter

Return values
bool

checketag()

Check an etag to see if we need to send the page again or not.

public checketag( $context : Context , $tag : string ) : bool
Parameters
$context : Context

The context object for the site

$tag : string

The etag value to check

Return values
bool

Search results