Checks if the value is valid.

@param mixed $value
@param \Symfony\Component\Validator\Constraint $constraint

@throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
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);
            }
        }
    }
1109121
public function validate($order, Constraint $constraint): void
    {
        /** @var OrderInterface $order */
        Assert::isInstanceOf($order, OrderInterface::class);

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

        /** @var OrderItemInterface[] $orderItems */
        $orderItems = $order->getItems();

        foreach ($orderItems as $orderItem) {
            if (!$orderItem->getProduct()->isEnabled()) {
                $this->context->addViolation(
                    $constraint->message,
                    ['%productName%' => $orderItem->getProduct()->getName()]
                );
            }
        }
    }
1303735
public function validate($value, Constraint $constraint)
    {
        $result = $this->repository->hasOtherNodeWithSameParentAndOrder(
            $value->getParentId(),
            $value->getOrder(),
            $value->getNodeId(),
            $value->getSiteId()
        );

        if (true === $result) {
            $this->context->buildViolation($constraint->message)->addViolation();
        }
    }
1060619
public function validate($propertyValue, Constraint $constraint)
    {
        if ($propertyValue === null) {
            return;
        }
        json_decode($propertyValue);
        if (JSON_ERROR_NONE === json_last_error()) {
            return;
        }

        // Finally, if not valid, add the violation
        $this->context->buildViolation($constraint->payload)
                      ->setParameter('{{ string }}', $propertyValue)
                      ->setParameter('{{ error }}', json_last_error_msg())
                      ->addViolation();
    }
196832
public function validate($value, Constraint $constraint)
  {
    $valid = false;
    foreach ($constraint->format as $format)
    {
      $date = \DateTime::createFromFormat($format, $value);
      if ($date instanceof \DateTime)
      {
        $valid = true;
        break;
      }
    }
    if ($valid === false)
    {
      $this->context->addViolation($constraint->message, array('%invalid%' => $value));
    }
  }
410580
public function validate($value, Constraint $constraint)
    {
        /** @var \Symfony\Component\Form\Form $root */
        $root = $this->context->getRoot();

        /** @var \Generated\Shared\Transfer\QuoteTransfer $data */
        $data = $root->getData();

        $validationMessages = $this->manageMandate($data, $constraint);

        if (count($validationMessages) === 0) {
            return;
        }

        foreach ($validationMessages as $validationMessage) {
            $this->context->buildViolation($validationMessage)
                ->addViolation();
        }
    }
1009799
protected function addViolation($value, Constraint $constraint)
    {
        $this->context->addViolation(
            $constraint->message,
            [
                '{{ id_field }}' => $constraint->getIdField(),
                '{{ value }}'    => $value
            ],
            $value
        );
    }
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();
        }
    }
676507
public function validate($value, Constraint $constraint)
    {
        if(!$constraint instanceof Rut) {
            throw new UnexpectedTypeException($constraint, Rut::class);
        }

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

        $ARut=explode("-",$value);

        if(false === $ARut) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ rut }}', $value)
                ->addViolation();
        }
        else {

            $rut_leido=$ARut[0];
            $d9=floor($rut_leido/100000000);
            $rut_leido=$rut_leido-$d9*100000000;
            $d8=floor($rut_leido/10000000);
            $rut_leido=$rut_leido-$d8*10000000;
            $d7=floor($rut_leido/1000000);
            $rut_leido=$rut_leido-$d7*1000000;
            $d6=floor($rut_leido/100000);
            $rut_leido=$rut_leido-$d6*100000;
            $d5=floor($rut_leido/10000);
            $rut_leido=$rut_leido-$d5*10000;
            $d4=floor($rut_leido/1000);
            $rut_leido=$rut_leido-$d4*1000;
            $d3=floor($rut_leido/100);
            $rut_leido=$rut_leido-$d3*100;
            $d2=floor($rut_leido/10);
            $rut_leido=$rut_leido-$d2*10;
            $d1=floor($rut_leido/1);
            $sum=$d1*2+$d2*3+$d3*4+$d4*5+$d5*6+$d6*7+$d7*2+$d8*3+$d9*4;
            $modu=$sum%11;
            $dv_leido=11-$modu;
            if ($dv_leido==11) {
                $dv_leido = 0;
            }
            if ($dv_leido==10) {
                $dv_leido = 'k';
            }

            if ($dv_leido!=$ARut[1]) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ rut }}', $value)
                    ->addViolation();
            }
        }
    }
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()
            );
        }
    }
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()]
                );
            }
        }
    }
515760
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof NotCompromisedPassword) {
            throw new UnexpectedTypeException($constraint, NotCompromisedPassword::class);
        }

        if ($this->disabled) {
            return;
        }

        if (null !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;
        if ('' === $value) {
            return;
        }

        if ('UTF-8' !== $this->charset) {
            $value = mb_convert_encoding($value, 'UTF-8', $this->charset);
        }

        $hash = strtoupper(sha1($value));
        $hashPrefix = substr($hash, 0, 5);
        $url = sprintf(self::RANGE_API, $hashPrefix);

        try {
            $result = $this->httpClient->request('GET', $url)->getContent();
        } catch (ExceptionInterface $e) {
            if ($constraint->skipOnError) {
                return;
            }

            throw $e;
        }

        foreach (explode("\r\n", $result) as $line) {
            list($hashSuffix, $count) = explode(':', $line);

            if ($hashPrefix.$hashSuffix === $hash && $constraint->threshold <= (int) $count) {
                $this->context->buildViolation($constraint->message)
                    ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
                    ->addViolation();

                return;
            }
        }
    }
401506
public function validate($value, Constraint $constraint): void
    {
        Assert::isInstanceOf($value, AttributeValueInterface::class);

        $defaultLocale = $this->localeProvider->getDefaultLocaleCode();
        $configuration = $value->getAttribute()->getConfiguration();

        if ($defaultLocale === $value->getLocaleCode()) {
            $configuration = array_merge($configuration, ['required' => true]);
        }

        /** @var AttributeTypeInterface $attributeType */
        $attributeType = $this->attributeTypeRegistry->get($value->getType());

        $attributeType->validate($value, $this->context, $configuration);
    }
401630
public function validate($value, Constraint $constraint)
    {
        if (null === $value || '' === $value) {
            return;
        }

        $value = (string) $value;
        $languages = $this->getLanguageNames();

        if (!array_key_exists($value,$languages)) {
            $this->context->addViolation($constraint->message, array('%string%' => $value));
        }
    }
1347187
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof LanguageCreateStruct) {
            return;
        }

        try {
            $language = $this->languageService->loadLanguage($value->languageCode);
            if ($language->id == $value->getId()) {
                return;
            }

            $this->context->buildViolation($constraint->message)
                ->atPath('language_code')
                ->setParameter('%language_code%', $value->languageCode)
                ->addViolation();
        } catch (NotFoundException $e) {
            // Do nothing
        } catch (InvalidArgumentException $e) {
            // Do nothing
        }
    }
613429
protected function createViolation($value, Constraint $constraint)
    {
        $this
            ->context
            ->buildViolation($constraint->message)
            ->setParameter('%filename%', $value)
            ->addViolation();
    }
1173011
public function validate($value, Constraint $constraint)
    {
        /** @var SetType $constraint */
        if (!$constraint->class) {
            throw new ConstraintDefinitionException('Target is not specified');
        }

        /** @var string $class class name of inheriting \Okapon\DoctrineSetTypeBundle\DBAL\Types\AbstractSetType */
        $class = $constraint->class;
        if (!class_exists($class)) {
            throw new TargetClassNotExistException('Target class not exist.');
        }

        $constraint->choices = $class::getValues();
        $constraint->multiple =true;

        parent::validate($value, $constraint);
    }