public function evaluate($values)
    {
        // Only validate if the source is set to 'list'
        $sourceElement = $this->getOption('sourceElement');
        $sourceElementValue = $sourceElement->getEvaluatedValue();
        if ($sourceElementValue !== 'list') {
            return true;
        }

        $this->invalidValues = [];
        $values = trim(str_replace("\r", '', $values));

        if (!$values) {
            $this->setMessage('Please add at least one domain or directive.');
            return false;
        }

        $sources = explode("\n", $values);

        foreach ($sources as $key => $source) {
            if ($source === '') {
                unset($sources[$key]);
            }

            if (in_array($source, self::DIRECTIVES, true)) {
                if ($this->isValidDirective($source) === false) {
                    $this->invalidValues['domain'][] = $source;
                }
                $sources[$key] = $this->getNormalizedDirective($source);

                continue;
            }

            if ($this->isValidDomain($source) === false) {
                $this->invalidValues['domain'][] = $source;
            }
        }

        $isValid = empty($this->invalidValues);
        if (!$isValid) {
            $this->setMessage($this->getErrorMessage());
        }

        return $isValid;
    }
public function evaluate($values)
    {
        // Only validate if the source is set to 'list'
        $sourceElement = $this->getOption('sourceElement');
        $sourceElementValue = $sourceElement->getEvaluatedValue();
        if ($sourceElementValue !== 'list') {
            return true;
        }

        $this->invalidValues = [];
        $values = trim(str_replace("\r", '', $values));

        if (!$values) {
            $this->setMessage('Please add at least one domain or directive.');
            return false;
        }

        $sources = explode("\n", $values);

        foreach ($sources as $key => $source) {
            if ($source === '') {
                unset($sources[$key]);
            }

            if (in_array($source, self::DIRECTIVES, true)) {
                if ($this->isValidDirective($source) === false) {
                    $this->invalidValues['domain'][] = $source;
                }
                $sources[$key] = $this->getNormalizedDirective($source);

                continue;
            }

            if ($this->isValidDomain($source) === false) {
                $this->invalidValues['domain'][] = $source;
            }
        }

        $isValid = empty($this->invalidValues);
        if (!$isValid) {
            $this->setMessage($this->getErrorMessage());
        }

        return $isValid;
    }
public function evaluate ( $ values ) { // Only validate if the source is set to 'list' $ sourceElement = $ this -> getOption ( 'sourceElement' ) ; $ sourceElementValue = $ sourceElement -> getEvaluatedValue ( ) ; if ( $ sourceElementValue !== 'list' ) { return true ; } $ this -> invalidValues = [ ] ; $ values = trim ( str_replace ( "\r" , '' , $ values ) ) ; if ( ! $ values ) { $ this -> setMessage ( 'Please add at least one domain or directive.' ) ; return false ; } $ sources = explode ( "\n" , $ values ) ; foreach ( $ sources as $ key => $ source ) { if ( $ source === '' ) { unset ( $ sources [ $ key ] ) ; } if ( in_array ( $ source , self :: DIRECTIVES , true ) ) { if ( $ this -> isValidDirective ( $ source ) === false ) { $ this -> invalidValues [ 'domain' ] [ ] = $ source ; } $ sources [ $ key ] = $ this -> getNormalizedDirective ( $ source ) ; continue ; } if ( $ this -> isValidDomain ( $ source ) === false ) { $ this -> invalidValues [ 'domain' ] [ ] = $ source ; } } $ isValid = empty ( $ this -> invalidValues ) ; if ( ! $ isValid ) { $ this -> setMessage ( $ this -> getErrorMessage ( ) ) ; } return $ isValid ; }
Validates the list of domains and directives for the CSP Header.

@param string $values
@return bool
Validates the list of domains and directives for the CSP Header .