PHP Класс ParagonIE\CSPBuilder\CSPBuilder

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$supportOldBrowsers boolean

Открытые методы

Метод Описание
__construct ( array $policy = [] )
addDirective ( string $key, mixed $value = null ) : self Add a directive if it doesn't already exist
addSource ( string $directive, string $path ) : self Add a source to our allow white-list
allowPluginType ( string $mime = 'text/plain' ) : self Add a plugin type to be added
compile ( ) : string Compile the current policies into a CSP header
disableOldBrowserSupport ( ) : self Disable old browser support (e.g. Safari)
enableOldBrowserSupport ( ) : self Enable old browser support (e.g. Safari)
fromData ( string $data = '' ) : self Factory method - create a new CSPBuilder object from a JSON data
fromFile ( string $filename = '' ) : self Factory method - create a new CSPBuilder object from a JSON file
getCompiledHeader ( ) : string Get the formatted CSP header
getHeaderArray ( boolean $legacy = true ) : array Get an associative array of headers to return.
hash ( string $directive = 'script-src', string $script = '', string $algorithm = 'sha384' ) : self Add a new hash to the existing CSP
injectCSPHeader ( Psr\Http\Message\MessageInterface $message, boolean $legacy = false ) : Psr\Http\Message\MessageInterface PSR-7 header injection
nonce ( string $directive = 'script-src', string $nonce = '' ) : string Add a new nonce to the existing CSP
preHash ( string $directive = 'script-src', string $hash = '', string $algorithm = 'sha384' ) : self Add a new (pre-calculated) base64-encoded hash to the existing CSP
saveSnippet ( string $outputFile, string $format = self::FORMAT_NGINX ) : boolean Save CSP to a snippet file
sendCSPHeader ( boolean $legacy = true ) : boolean Send the compiled CSP as a header()
setDirective ( string $key, mixed $value = null ) : self Set a directive

Защищенные методы

Метод Описание
compileSubgroup ( string $directive, mixed $policies = null ) : string Compile a subgroup into a policy string
getHeaderKeys ( boolean $legacy = true ) : array Get an array of header keys to return
isHTTPSConnection ( ) : boolean Is this user currently connected over HTTPS?

Описание методов

__construct() публичный Метод

public __construct ( array $policy = [] )
$policy array

addDirective() публичный Метод

If it already exists, do nothing
public addDirective ( string $key, mixed $value = null ) : self
$key string
$value mixed
Результат self

addSource() публичный Метод

Add a source to our allow white-list
public addSource ( string $directive, string $path ) : self
$directive string
$path string
Результат self

allowPluginType() публичный Метод

Add a plugin type to be added
public allowPluginType ( string $mime = 'text/plain' ) : self
$mime string
Результат self

compile() публичный Метод

Compile the current policies into a CSP header
public compile ( ) : string
Результат string

compileSubgroup() защищенный Метод

Compile a subgroup into a policy string
protected compileSubgroup ( string $directive, mixed $policies = null ) : string
$directive string
$policies mixed
Результат string

disableOldBrowserSupport() публичный Метод

Disable old browser support (e.g. Safari)
public disableOldBrowserSupport ( ) : self
Результат self

enableOldBrowserSupport() публичный Метод

This is enabled by default
public enableOldBrowserSupport ( ) : self
Результат self

fromData() публичный статический Метод

Factory method - create a new CSPBuilder object from a JSON data
public static fromData ( string $data = '' ) : self
$data string
Результат self

fromFile() публичный статический Метод

Factory method - create a new CSPBuilder object from a JSON file
public static fromFile ( string $filename = '' ) : self
$filename string
Результат self

getCompiledHeader() публичный Метод

Get the formatted CSP header
public getCompiledHeader ( ) : string
Результат string

getHeaderArray() публичный Метод

Get an associative array of headers to return.
public getHeaderArray ( boolean $legacy = true ) : array
$legacy boolean
Результат array

getHeaderKeys() защищенный Метод

Get an array of header keys to return
protected getHeaderKeys ( boolean $legacy = true ) : array
$legacy boolean
Результат array

hash() публичный Метод

Add a new hash to the existing CSP
public hash ( string $directive = 'script-src', string $script = '', string $algorithm = 'sha384' ) : self
$directive string
$script string
$algorithm string
Результат self

injectCSPHeader() публичный Метод

PSR-7 header injection
public injectCSPHeader ( Psr\Http\Message\MessageInterface $message, boolean $legacy = false ) : Psr\Http\Message\MessageInterface
$message Psr\Http\Message\MessageInterface
$legacy boolean
Результат Psr\Http\Message\MessageInterface

isHTTPSConnection() защищенный Метод

Is this user currently connected over HTTPS?
protected isHTTPSConnection ( ) : boolean
Результат boolean

nonce() публичный Метод

Add a new nonce to the existing CSP
public nonce ( string $directive = 'script-src', string $nonce = '' ) : string
$directive string
$nonce string (if empty, it will be generated)
Результат string

preHash() публичный Метод

Add a new (pre-calculated) base64-encoded hash to the existing CSP
public preHash ( string $directive = 'script-src', string $hash = '', string $algorithm = 'sha384' ) : self
$directive string
$hash string
$algorithm string
Результат self

saveSnippet() публичный Метод

Save CSP to a snippet file
public saveSnippet ( string $outputFile, string $format = self::FORMAT_NGINX ) : boolean
$outputFile string Output file name
$format string Which format are we saving in?
Результат boolean

sendCSPHeader() публичный Метод

Send the compiled CSP as a header()
public sendCSPHeader ( boolean $legacy = true ) : boolean
$legacy boolean Send legacy headers?
Результат boolean

setDirective() публичный Метод

Set a directive
public setDirective ( string $key, mixed $value = null ) : self
$key string
$value mixed
Результат self

Описание свойств

$supportOldBrowsers защищенное свойство

protected bool $supportOldBrowsers
Результат boolean