CSPBackend
extends Requirements_Backend
in package
Uses
Configurable, CSPBackendTrait
Table of Contents
Constants
Properties
- $cssBuilder : CSSBuilder
- $cssSRI : bool
- CSS defaults to false.
- $headCSS : array<string|int, mixed>
- CSS to be inserted in to the head
- $headJS : array<string|int, mixed>
- JS to be inserted in to the head
- $jsBuilder : JSBuilder
- $jsSRI : bool
- $useNonce : bool
Methods
- __construct() : mixed
- customCSS() : void
- customScript() : void
- Specific method for JS insertion
- getCssBuilder() : CSSBuilder
- getHeadCSS() : array<string|int, mixed>
- getHeadJS() : array<string|int, mixed>
- getJsBuilder() : JSBuilder
- getTagType() : string|null
- Determine the type of the head tag if it's js or css
- includeInHTML() : string
- Copy-paste of the original backend code. There is no way to override this in a more clean way
- insertHeadTags() : void
- Add the following custom HTML code to the `<head>` section of the page
- isCssSRI() : bool
- isJsSRI() : bool
- isUsesNonce() : bool
- javascript() : void
- Register the given JavaScript file as required.
- setCssBuilder() : void
- setCssSRI() : void
- setHeadCSS() : void
- setHeadJS() : void
- setJsBuilder() : void
- setJsSRI() : void
- setUsesNonce() : void
- getCSSRequirements() : array<string|int, mixed>
- getHeadTags() : string
- getJSRequirements() : string
- getOptions() : array<string|int, mixed>
- insertContent() : string
- isAsync() : bool
- isDefer() : bool
- shouldContinue() : bool
Constants
SHA256
public
mixed
SHA256
= 'sha256'
SHA384
public
mixed
SHA384
= 'sha384'
Properties
$cssBuilder
protected
CSSBuilder
$cssBuilder
$cssSRI
CSS defaults to false.
protected
static bool
$cssSRI
It's causing a lot of trouble with CDN's usually
$headCSS
CSS to be inserted in to the head
protected
static array<string|int, mixed>
$headCSS
= []
$headJS
JS to be inserted in to the head
protected
static array<string|int, mixed>
$headJS
= []
$jsBuilder
protected
JSBuilder
$jsBuilder
$jsSRI
protected
static bool
$jsSRI
$useNonce
protected
static bool
$useNonce
= false
Methods
__construct()
public
__construct() : mixed
customCSS()
public
customCSS( $css[, null|string $uniquenessID = null ]) : void
Parameters
customScript()
Specific method for JS insertion
public
customScript( $js[, null|string $uniquenessID = null ]) : void
Parameters
getCssBuilder()
public
getCssBuilder() : CSSBuilder
Return values
CSSBuildergetHeadCSS()
public
static getHeadCSS() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeadJS()
public
static getHeadJS() : array<string|int, mixed>
Return values
array<string|int, mixed>getJsBuilder()
public
getJsBuilder() : JSBuilder
Return values
JSBuildergetTagType()
Determine the type of the head tag if it's js or css
public
getTagType(string $html) : string|null
Parameters
- $html : string
Return values
string|nullincludeInHTML()
Copy-paste of the original backend code. There is no way to override this in a more clean way
public
includeInHTML(string $content) : string
Update the given HTML content with the appropriate include tags for the registered requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, including a head and body tag.
We need to override the whole method to adjust for SRI in javascript
Parameters
Tags
Return values
string —HTML content augmented with the requirements tags
insertHeadTags()
Add the following custom HTML code to the `<head>` section of the page
public
insertHeadTags(string $html[, string|null $uniquenessID = null ]) : void
Parameters
- $html : string
-
Custom HTML code
- $uniquenessID : string|null = null
-
A unique ID that ensures a piece of code is only added once
isCssSRI()
public
static isCssSRI() : bool
Return values
boolisJsSRI()
public
static isJsSRI() : bool
Return values
boolisUsesNonce()
public
static isUsesNonce() : bool
Return values
booljavascript()
Register the given JavaScript file as required.
public
javascript(string $file[, array<string|int, mixed> $options = [] ]) : void
Parameters
- $file : string
-
Either relative to docroot or in the form "vendor/package:resource"
- $options : array<string|int, mixed> = []
-
List of options. Available options include:
- 'provides' : List of scripts files included in this file
- 'async' : Boolean value to set async attribute to script tag
- 'defer' : Boolean value to set defer attribute to script tag
- 'type' : Override script type= value.
setCssBuilder()
public
setCssBuilder(CSSBuilder $cssBuilder) : void
Parameters
- $cssBuilder : CSSBuilder
setCssSRI()
public
static setCssSRI(bool $cssSRI) : void
Parameters
- $cssSRI : bool
setHeadCSS()
public
static setHeadCSS(array<string|int, mixed> $headCSS) : void
Parameters
- $headCSS : array<string|int, mixed>
setHeadJS()
public
static setHeadJS(array<string|int, mixed> $headJS) : void
Parameters
- $headJS : array<string|int, mixed>
setJsBuilder()
public
setJsBuilder(JSBuilder $jsBuilder) : void
Parameters
- $jsBuilder : JSBuilder
setJsSRI()
public
static setJsSRI(bool $jsSRI) : void
Parameters
- $jsSRI : bool
setUsesNonce()
public
static setUsesNonce(bool $useNonce) : void
Parameters
- $useNonce : bool
-
static::isUseNonce()
getCSSRequirements()
protected
getCSSRequirements(array<string|int, mixed> $requirements) : array<string|int, mixed>
Parameters
- $requirements : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getHeadTags()
protected
getHeadTags([array<string|int, mixed> $requirements = [] ]) : string
Parameters
- $requirements : array<string|int, mixed> = []
Return values
stringgetJSRequirements()
protected
getJSRequirements(array<string|int, mixed> $jsRequirements) : string
Parameters
- $jsRequirements : array<string|int, mixed>
Tags
Return values
stringgetOptions()
protected
getOptions( $html) : array<string|int, mixed>
Parameters
Return values
array<string|int, mixed>insertContent()
protected
insertContent( $content, string $requirements, string $jsRequirements) : string
Parameters
Return values
stringisAsync()
protected
isAsync( $file, $options) : bool
Parameters
Return values
boolisDefer()
protected
isDefer( $file, $options) : bool
Parameters
Return values
boolshouldContinue()
protected
shouldContinue( $content) : bool