You are here

public function Csp::setDirective in Content-Security-Policy 8

Add a new directive to the policy, or replace an existing directive.

Parameters

string $name: The directive name.

array|bool|string $value: The directive value.

1 call to Csp::setDirective()
Csp::fallbackAwareAppendIfEnabled in src/Csp.php
Append to a directive if it or a fallback directive is enabled.

File

src/Csp.php, line 272

Class

Csp
A CSP Header.

Namespace

Drupal\csp

Code

public function setDirective($name, $value) {
  self::validateDirectiveName($name);
  if (self::DIRECTIVES[$name] === self::DIRECTIVE_SCHEMA_BOOLEAN) {
    $this->directives[$name] = (bool) $value;
    return;
  }
  $this->directives[$name] = [];
  if (empty($value)) {
    return;
  }
  $this
    ->appendDirective($name, $value);
}