You are here

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

Append values to an existing directive.

Parameters

string $name: The directive name.

array|string $value: The directive value.

2 calls to Csp::appendDirective()
Csp::fallbackAwareAppendIfEnabled in src/Csp.php
Append to a directive if it or a fallback directive is enabled.
Csp::setDirective in src/Csp.php
Add a new directive to the policy, or replace an existing directive.

File

src/Csp.php, line 295

Class

Csp
A CSP Header.

Namespace

Drupal\csp

Code

public function appendDirective($name, $value) {
  self::validateDirectiveName($name);
  if (empty($value)) {
    return;
  }
  if (gettype($value) === 'string') {
    $value = explode(' ', $value);
  }
  elseif (gettype($value) !== 'array') {
    throw new \InvalidArgumentException("Invalid directive value provided");
  }
  if (!isset($this->directives[$name])) {
    $this->directives[$name] = [];
  }
  $this->directives[$name] = array_merge($this->directives[$name], $value);
}