DirectiveHashCollection implements JsonSerializable

FinalYes

Per-request registry collecting CSP hash values for inline and static assets.

Hash values are preferred over nonce values as they allow response caching.

Internal
Attributes
#[Autoconfigure]
$public: true

Table of Contents

Interfaces

JsonSerializable

Methods

__construct()  : mixed
addGenericHashValue()  : void
Stores an already-computed HashValue (e.g. parsed from an `integrity` attribute).
addInlineHash()  : void
Computes a SHA-256 hash of the given inline content and stores it for the directive.
addResourceHash()  : void
Lazily computes a hash from a local file identified by an EXT: path or absolute path.
asMutationCollections()  : array<int, MutationCollection>
Converts all stored hashes into MutationCollection instances that can be applied to the CSP.
countInlineHashValues()  : int
isEmpty()  : bool
jsonSerialize()  : array<string|int, mixed>
updateFromJson()  : void
Restores hash values from a previously serialized (cached) state.

Methods

addGenericHashValue()

Stores an already-computed HashValue (e.g. parsed from an `integrity` attribute).

public addGenericHashValue(Directive $directive, HashValue|string $hashValue) : void
Parameters
$directive : Directive
$hashValue : HashValue|string

addInlineHash()

Computes a SHA-256 hash of the given inline content and stores it for the directive.

public addInlineHash(Directive $directive, string $content) : void
Parameters
$directive : Directive
$content : string

asMutationCollections()

Converts all stored hashes into MutationCollection instances that can be applied to the CSP.

public asMutationCollections() : array<int, MutationCollection>

Hash values from all types are merged per directive.

Return values
array<int, MutationCollection>

countInlineHashValues()

public countInlineHashValues([string|null $aspect = null ]) : int
Parameters
$aspect : string|null = null
Return values
int

isEmpty()

public isEmpty() : bool
Return values
bool

jsonSerialize()

public jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

updateFromJson()

Restores hash values from a previously serialized (cached) state.

public updateFromJson(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

        
On this page

Search results