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.
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
__construct()
public
__construct(ResourceHashCollection $resourceHashCollection) : mixed
Parameters
- $resourceHashCollection : ResourceHashCollection
addGenericHashValue()
Stores an already-computed HashValue (e.g. parsed from an `integrity` attribute).
public
addGenericHashValue(Directive $directive, HashValue|string $hashValue) : void
Parameters
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
addResourceHash()
Lazily computes a hash from a local file identified by an EXT: path or absolute path.
public
addResourceHash(Directive $directive, string|UriInterface|StaticResourceInterface $resource) : void
No-op if the file cannot be read.
Parameters
- $directive : Directive
- $resource : string|UriInterface|StaticResourceInterface
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
intisEmpty()
public
isEmpty() : bool
Return values
booljsonSerialize()
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>