Checks if the passed value is valid.

@param FieldDefinitionData $value The value that should be validated
@param Constraint $constraint The constraint for the validation

@api
14996
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof FieldDefinitionData) {
            return;
        }

        $fieldType = $this->fieldTypeService->getFieldType($value->getFieldTypeIdentifier());
        $this->processValidationErrors($fieldType->validateValidatorConfiguration($value->validatorConfiguration));
    }
1011169
protected function validateMaxHeight($height, Constraint $constraint)
    {
        if ($constraint->maxHeight) {
            if (!ctype_digit((string) $constraint->maxHeight)) {
                throw new ConstraintDefinitionException(
                    sprintf(
                        '"%s" is not a valid maximum height',
                        $constraint->maxHeight
                    )
                );
            }

            if ($height > $constraint->maxHeight) {
                $this->context->addViolation(
                    $constraint->maxHeightMessage,
                    array(
                        '{{ height }}' => $height,
                        '{{ max_height }}' => $constraint->maxHeight
                    )
                );

                return true;
            }
        }
    }
1328159
public function isValid($value, Constraint $constraint)
    {
        $document = $this->parseDocument($value);
        $fields = $this->parseFields($constraint->fields);
        $caseInsensitive = $this->parseCaseInsensitive($constraint->caseInsensitive);

        $query = $this->createQuery($document, $fields, $caseInsensitive);
        $numberResults = $query->count();

        if (0 === $numberResults) {
            return true;
        }

        if (1 === $numberResults) {
            $result = $query->one();
            if ($result === $document) {
                return true;
            }
        }

        if ($this->context) {
            $this->addFieldViolation($fields[0], $constraint->message);
        }

        return false;
    }
283950
public function validate($value, Constraint $constraint)
    {

        $bitlyProvider = new BitlyProvider(new GenericAccessTokenAuthenticator($value));
        $urlShortener = new UrlShortenerService($bitlyProvider);
        $link = new Link();
        $link->setLongUrl('http://www.campaignchain.com');

        try {
            $urlShortener->shorten($link);
        } catch (ExternalApiException $e) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('%string%', $value)
                ->addViolation();
        } catch (\Exception $e) {
            // rethrow it
            throw $e;
        }


    }
1286141
public function validate($value, Constraint $constraint)
    {
        if (! $value instanceof MethodDescriptor
            && ! $value instanceof FunctionDescriptor
        ) {
            throw new ConstraintDefinitionException(
                'The Functions\AreAllArgumentsValid validator may only be used on function or method objects'
            );
        }

        $this->constraint = $constraint;

        $this->initValueObject($value);

        $violation = $this->processArgumentValidation();
        if ($violation) {
            return $violation;
        }

        $this->checkParamsExists();
    }
90546
public function validate($value, Constraint $constraint)
    {
        $url = $this->helper->getUrl($value);
        if($this->browser->get($url)->getStatusCode() >= 400) {
            $this->context->addViolation($constraint->message, array('%string%' => $url));
        }
    }
735956
protected function hasEntity($value, Constraint $constraint)
    {
        $repo = $this->em->getRepository($constraint->className);
        /** @var Entity $formEntity */
        $formEntity = $this->context->getRoot()->getData();
        $query = $repo->createQueryBuilder()
            ->setParameter('value', $value)
        ;
        foreach ((array) $constraint->fieldNames as $fieldName) {
            $query->orWhere($fieldName . ' = :value');
        }

        $entity = $repo->findOneWith($query);
        if ($entity === false) {
            return false;
        }
        if ($entity->getId() === $formEntity->getId()) {
            return false;
        }

        return true;
    }
174498
public function validate($value, Constraint $constraint)
    {
        if (null === $value || '' === $value) {
            return;
        }

        if (!is_numeric($value)) {
            $this->context->addViolation($constraint->message);
        }

        $schemes = array_flip($constraint->schemes);
        $schemeRegexes = array_intersect_key($this->schemes, $schemes);

        $valid = false;
        foreach ($schemeRegexes as $regexes) {
            foreach ($regexes as $regex) {
                $valid |= preg_match($regex, $value);
            }
        }

        if (!$valid) {
            $this->context->addViolation($constraint->message);
        }
    }
1318332
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof HasGuessableExtension) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\HasGuessableExtension');
        }

        if (!$value instanceof UploadedFile) {
            return;
        }

        $contentType = $this->mimeTypeGuesser->guess($value->getPathname());
        $pathInfo = pathinfo($value->getClientOriginalName());
        if (!array_key_exists('extension', $pathInfo)) {
            $pathInfo['extension'] = $this->extensionGuesser->guess($contentType);
        }

        if ($pathInfo['extension'] === null) {
            $this->context->buildViolation($constraint->notGuessableErrorMessage)
                ->setCode(HasGuessableExtension::NOT_GUESSABLE_ERROR)
                ->addViolation();
        }
    }
162104
protected function validateDelimiter(Constraint $constraint)
    {
        if (strlen($constraint->delimiter) > 2) {
            throw new ConstraintDefinitionException(sprintf('"%s" is not a valid delimiter', $constraint->delimiter));
        }
    }
1236332
public function validate($value, Constraint $constraint)
    {
        if (is_array($value)) {
            $value = json_encode($value);
        }

        if (!json_decode($value, true)) {
            $this->context->addViolation(
                $constraint->message,
                array()
            );
        }
    }
1056013
public function validate($value, Constraint $constraint)
    {
        /** @var Constraints\Disabled $constraint */
        Assert::isInstanceOf($constraint, Constraints\Disabled::class);

        if (null === $value) {
            return;
        }

        $this->ensureValueImplementsToggleableInterface($value);

        if ($value->isEnabled()) {
            $this->context->addViolation($constraint->message);
        }
    }
485936
public function validate($value, Constraint $constraint)
    {
        $mainAliases = $value->getAliases()->filter(function(SiteAliasInterface $alias) {
            return $alias->isMain();
        });
        if ($mainAliases->count() > 1) {
            foreach ($mainAliases as $name => $siteAlias) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('aliases[' . $name . '].main')
                    ->addViolation();
            }
        }
    }
666898
public function validate($value, Constraint $constraint)
    {
        /** @var EntityExists $constraint */
        if ($constraint->validate($value)) {
            $this->context->addViolation(
                $constraint->message,
                [
                    '{{ type }}' => $constraint->entityClass,
                    '{{ value }}' => $value,
                ]
            );
        }
    }
1053514
public function validate($value, Constraint $constraint)
    {
        $parameters = array(
            'initial_state' => 0,
            'translation_state' => 0,
            'published_state' => 0,
            'auto_publish_from_state' => 0,
            'auto_unpublish_to_state' => 0,
        );

        foreach ($value as $status) {
            if ($status->isInitialState()) {
                $parameters['initial_state']++;
            }
            if ($status->isTranslationState()) {
                $parameters['translation_state']++;
            }
            if ($status->isPublishedState()) {
                $parameters['published_state']++;
            }
            if ($status->isAutoPublishFromState()) {
                $parameters['auto_publish_from_state']++;
            }
            if ($status->isAutoUnpublishToState()) {
                $parameters['auto_unpublish_to_state']++;
            }
        }

        foreach ($parameters as $parameter => $setCount) {
            if (0 === $setCount) {
                $label = $this->translator
                    ->trans('open_orchestra_workflow_admin.status.' . $parameter, array(), 'interface');
                $this->context
                    ->buildViolation($constraint->requiredParameterMessage)
                    ->setParameter('%parameter%', $label)
                    ->addViolation();
            } elseif ($setCount > 1) {
                $label = $this->translator
                    ->trans('open_orchestra_workflow_admin.status.' . $parameter, array(), 'interface');
                $this->context
                    ->buildViolation($constraint->uniqueParameterMessage)
                    ->setParameter('%parameter%', $label)
                    ->addViolation();
            }
        }
    }
998077
protected function validateEnclosure(Constraint $constraint)
    {
        if (strlen($constraint->enclosure) > 2) {
            throw new ConstraintDefinitionException(sprintf('"%s" is not a valid enclosure', $constraint->enclosure));
        }
    }
1139007
public function validate($value, Constraint $constraint)
    {
        if (null === $value || '' === $value) {
            return;
        }

        if (!is_numeric($value)) {
            $this->context->addViolation($constraint->message);
        }

        $length = strlen($value);
        $oddLength = $length % 2;
        for ($sum = 0, $i = $length - 1; $i >= 0; --$i) {
            $digit = (int) $value[$i];
            $sum += (($i % 2) === $oddLength) ? array_sum(str_split($digit * 2)) : $digit;
        }

        if (($sum % 10) !== 0) {
            $this->context->addViolation($constraint->message);
        }
    }