src/Zicht/Bundle/UrlBundle/Validator/Constraints/ContainsValidUrlsValidator.php
public function validate($value, Constraint $constraint)
    {
        // collect urls
        $matches = [];

        // matches all urls withing a href's
        preg_match_all('#<a\s+(?:[^>]*?\s+)?href="((https*:)*//[^"]*)">.*</a>#U', $value, $matches);

        if (count($matches) === 0 || !isset($matches[1])) {
            return;
        }

        $externalUrls = $matches[1];

        // validate urls
        foreach ($externalUrls as $externalUrl) {
            if ($this->urlValidator->validate($externalUrl) === false) {
                $this->context
                    ->addViolation($constraint->message, ['%string%' => $externalUrl]);
            }
        }
    }
public function validate($value, Constraint $constraint)
    {
        // collect urls
        $matches = [];

        // matches all urls withing a href's
        preg_match_all('#<a\s+(?:[^>]*?\s+)?href="((https*:)*//[^"]*)">.*</a>#U', $value, $matches);

        if (count($matches) === 0 || !isset($matches[1])) {
            return;
        }

        $externalUrls = $matches[1];

        // validate urls
        foreach ($externalUrls as $externalUrl) {
            if ($this->urlValidator->validate($externalUrl) === false) {
                $this->context
                    ->addViolation($constraint->message, ['%string%' => $externalUrl]);
            }
        }
    }
public function validate ( $ value , Constraint $ constraint ) { // collect urls $ matches = [ ] ; // matches all urls withing a href's preg_match_all ( '#<a\s+(?:[^>]*?\s+)?href="((https*:)*//[^"]*)">.*</a>#U' , $ value , $ matches ) ; if ( count ( $ matches ) === 0 || ! isset ( $ matches [ 1 ] ) ) { return ; } $ externalUrls = $ matches [ 1 ] ; // validate urls foreach ( $ externalUrls as $ externalUrl ) { if ( $ this -> urlValidator -> validate ( $ externalUrl ) === false ) { $ this -> context -> addViolation ( $ constraint -> message , [ '%string%' => $ externalUrl ] ) ; } } }
Checks if the passed value is valid.
Validates only urls within a href's

@param mixed $value The value that should be validated
@param Constraint $constraint The constraint for the validation
Checks if the passed value is valid . Validates only urls within a href s