ParagonIE\CSPBuilder\CSPBuilder::addDirective PHP Method

addDirective() public method

If it already exists, do nothing
public addDirective ( string $key, mixed $value = null ) : self
$key string
$value mixed
return self
    public function addDirective(string $key, $value = null) : self
    {
        if ($value === null) {
            if (!isset($this->policies[$key])) {
                $this->policies[$key] = true;
            }
        } elseif (empty($this->policies[$key])) {
            $this->policies[$key] = $value;
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Add a directive if it doesn't already exist
  * If it already exists, do nothing.
  * 
  * @param string $directive
  * @param mixed  $value
  * 
  * @return self
  */
 public function addDirective($directive, $value)
 {
     $this->csp->addDirective($directive, $value);
     return $this;
 }