src/CSPBuilder.php
public function hash(
        string $directive = 'script-src',
        string $script = '',
        string $algorithm = 'sha384'
    ): self {
        $ruleKeys = \array_keys($this->policies);
        if (\in_array($directive, $ruleKeys)) {
            $this->policies[$directive]['hashes'] []= [
                $algorithm => Base64::encode(
                    \hash($algorithm, $script, true)
                )
            ];
        }
        return $this;
    }
public function hash(
        string $directive = 'script-src',
        string $script = '',
        string $algorithm = 'sha384'
    ): self {
        $ruleKeys = \array_keys($this->policies);
        if (\in_array($directive, $ruleKeys)) {
            $this->policies[$directive]['hashes'] []= [
                $algorithm => Base64::encode(
                    \hash($algorithm, $script, true)
                )
            ];
        }
        return $this;
    }
public function hash ( string $ directive = 'script-src' , string $ script = '' , string $ algorithm = 'sha384' ) : self { $ ruleKeys = \ array_keys ( $ this -> policies ) ; if ( \ in_array ( $ directive , $ ruleKeys ) ) { $ this -> policies [ $ directive ] [ 'hashes' ] [ ] = [ $ algorithm => Base64 :: encode ( \ hash ( $ algorithm , $ script , true ) ) ] ; } return $ this ; }
Add a new hash to the existing CSP

@param string $directive
@param string $script
@param string $algorithm
@return self
Add a new hash to the existing CSP