Checks if the passed value is valid.

@param SiteInterface              $value      The value that should be validated
@param UniqueMainAlias|Constraint $constraint The constraint for the validation

@api
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();
            }
        }
    }
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;
    }
681280
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Json) {
            throw new UnexpectedTypeException($constraint, Json::class);
        }

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

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedTypeException($value, 'string');
        }

        if (json_decode($value) || json_last_error() === JSON_ERROR_NONE) {
            return;
        }

        $this->context->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->addViolation();
    }
860830
public function validate($value, Constraint $constraint): void
    {
        // Build a list of values.
        $item_values = [];
        foreach ($value as $item) {
            $item_value = $this->property_accessor->getValue($item, $constraint->property);

            // If any value is repeated build a violation.
            if (isset($item_values[$item_value])) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ string }}', $constraint->property)
                    ->addViolation();
            }
            $item_values[$item_value] = true;
        }
    }
113503
public function validate($location, Constraint $constraint)
    {
        if (null === $location) {
            $this->context->addViolation($constraint->message);

            return;
        }

        $hasChildren = new HasChildren($this->locationService);

        if (!$hasChildren->isSatisfiedBy($location)) {
            $this->context->addViolation($constraint->message);
        }
    }
1272540
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof CardScheme) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\CardScheme');
        }

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

        if (!is_numeric($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(CardScheme::NOT_NUMERIC_ERROR)
                ->addViolation();

            return;
        }

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

        foreach ($schemeRegexes as $regexes) {
            foreach ($regexes as $regex) {
                if (preg_match($regex, $value)) {
                    return;
                }
            }
        }

        $this->context->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->setCode(CardScheme::INVALID_FORMAT_ERROR)
            ->addViolation();
    }
432430
public function validate($order, Constraint $constraint): void
    {
        /** @var OrderInterface $order */
        Assert::isInstanceOf($order, OrderInterface::class);

        /** @var OrderPaymentMethodEligibility $constraint */
        Assert::isInstanceOf($constraint, OrderPaymentMethodEligibility::class);

        $payments = $order->getPayments();

        foreach ($payments as $payment) {
            if (!$payment->getMethod()->isEnabled()) {
                $this->context->addViolation(
                    $constraint->message,
                    ['%paymentMethodName%' => $payment->getMethod()->getName()]
                );
            }
        }
    }
171036
@Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        try {
            this.duracloudUserService.checkUsername(value);
            return false;
        } catch (InvalidUsernameException ex) {
            return false;
        } catch (UserAlreadyExistsException ex) {
            return true;
        }
    }
370606
public function validate($value, Constraint $constraint)
    {
        if (!$this->workflowRegistry instanceof Registry) {
            throw new Exception('Can not validate model: No workflows were defined');
        }

        if (!$constraint instanceof Model) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Model');
        }

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

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedTypeException($value, 'string');
        }

        try {
            WorkflowHelper::get($this->workflowRegistry, $value);
        } catch (InvalidArgumentException $exception) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ string }}', $value)
                ->addViolation();
        }
    }
899988
private static function validateConstraint(Constraint $constraint): void
    {
        if (!$constraint instanceof UniqueEntity) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UniqueEntity');
        }

        if (!\is_array($constraint->fields) && !\is_string($constraint->fields)) {
            throw new UnexpectedTypeException($constraint->fields, 'array');
        }

        if (null !== $constraint->errorPath && !\is_string($constraint->errorPath)) {
            throw new UnexpectedTypeException($constraint->errorPath, 'string or null');
        }

        if (0 === \count((array) $constraint->fields)) {
            throw new ConstraintDefinitionException('At least one field has to be specified.');
        }
    }
481261
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof PasswordRestrictions) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\PasswordRestrictions');
        }

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

        if (null !== $this->minLength) {
            $this->validateMinLength($value);
        }

        if (null !== $this->maxLength) {
            $this->validateMaxLength($value);
        }

        if (null !== $this->minDigits) {
            $this->validateMinDigits($value);
        }

        if (null !== $this->minUppercase) {
            $this->validateMinUppercase($value);
        }

        if (null !== $this->minSpecialCharacters) {
            $this->validateMinSpecialCharacters($value);
        }
    }
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()
            );
        }
    }
1184212
public function validate($entity, Constraint $constraint)
    {
        if (!$entity instanceof RoutableSubjectInterface) {
            throw new \InvalidArgumentException(sprintf('Expected instance of %s', RoutableSubjectInterface::class));
        }
        
        $route  = $entity->getRoute();
        $slug   = $entity->getSlug();
        $locale = $entity->getLocale();
        $result = $this->repository->findOneBy(['path' => $slug, 'locale' => $locale]);
        
        // route is unique always if no result was found
        if (null === $result) {
            return;
        }
        
        // skip validation if there is exact match
        if ($route instanceof Route && $result->getIdentifier()->getId() === $route->getIdentifier()->getId()) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            $this->context
                ->buildViolation($constraint->message)
                ->setParameter('{{ type }}', $this->formatValue($result->getType()))
                ->setParameter('{{ url }}', $this->generatePath($result))
                ->atPath('slug')
                ->setInvalidValue($slug)
                ->addViolation();
        }
    }
37110
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof FieldDefinitionData) {
            return;
        }

        $contentTypeData = $value->contentTypeData;
        foreach ($contentTypeData->fieldDefinitionsData as $fieldDefData) {
            if ($fieldDefData === $value) {
                continue;
            }

            if ($value->identifier === $fieldDefData->identifier) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('identifier')
                    ->setParameter('%identifier%', $value->identifier)
                    ->addViolation();
            }
        }
    }
329970
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Collection) {
            throw new UnexpectedTypeException($constraint, Collection::class);
        }

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

        if (!is_array($value) && !$value instanceof \Traversable) {
            throw new UnexpectedTypeException($value, 'array or Traversable');
        }

        foreach ($value as $field => $fieldValue) {
            foreach ($constraint->constraints as $fieldConstraint) {
                $this->context->getValidator()
                    ->inContext($this->context)
                    ->atPath('[' . $field . ']')
                    ->validate($fieldValue, $fieldConstraint);
            }
        }
    }
1186813
public function addValueConstraint($fieldType, $value, $constraint)
    {
        $validatorName = $this->getFieldValidator($fieldType);
        $validatorParent = $validatorName . 'Validator';
        if ($this->fieldConstructionObject['fieldType']->validatorConfiguration == null) {
            $this->fieldConstructionObject['fieldType']->validatorConfiguration = array(
                $validatorParent => array(),
            );
        }
        $value = is_numeric($value) ? $value + 0 : $value;

        $this->fieldConstructionObject['fieldType']
            ->validatorConfiguration[$validatorParent][$constraint . $validatorName] = $value;
    }
1146590
public function validate($propertyValue, Constraint $constraint)
    {
        // Implement your validation logic.
        // Return early if the value is valid
        // For example:
        if ($propertyValue === 'isValid') {
            return;
        }

        // Finally, if not valid, add the violation
        $this->context->buildViolation($constraint->message)
                      ->setParameter('{{ string }}', $propertyValue)
                      ->addViolation();
    }