Add violation.

@param mixed      $value
@param Constraint $constraint

@return true
500348
protected function addViolation($value, Constraint $constraint)
    {
        $this->context->buildViolation($constraint->message)
            ->setParameter('%field%', null)
            ->setParameter('%value%', $value)
            ->addViolation()
        ;

        return true;
    }
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;
    }
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()]
                );
            }
        }
    }
350271
public function validate(
        ConstraintInterface $constraint,
        Value\ConcreteValueInterface &$value,
        PointerInterface $entryPoint = null
    ) {
        if (null === $entryPoint) {
            $entryPoint = new Pointer;
        }

        $this->clear();

        $this->pushContext(array($value, $entryPoint));
        $result = $constraint->accept($this);

        $this->clear();

        return $result;
    }
936349
public function validate($value, $constraints = null, $groups = null)
    {
        return $this->validator->validate($value, $constraints, $groups);
    }
1178737
public function set($path, $value, $constraint = null)
    {
        if ($constraint === null) {
            $constraint = $this->constraint;
        }

        if ($constraint) {
            $value = json_decode(json_encode($value), true);
        }

        if (is_null($path)) {
            $this->item[] = $value;
            return;
        }

        $path = explode($this->separator, $path);
        $last = array_pop($path);
        $item = &$this->item;

        foreach ($path as $key) {
            if (!array_key_exists($key, $item) || !is_array($item[$key])) {
                $item[$key] = array();
            }

            $item = &$item[$key];
        }

        $item[$last] = $value;
    }
14996
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof FieldDefinitionData) {
            return;
        }

        $fieldType = $this->fieldTypeService->getFieldType($value->getFieldTypeIdentifier());
        $this->processValidationErrors($fieldType->validateValidatorConfiguration($value->validatorConfiguration));
    }
461865
public function validate($value, Constraint $constraint)
    {
        $this->values = $constraint->values;
        $startMethod = 'get' . $constraint->startField;
        $endMethod = 'get' . $constraint->endField;
        for ($i = 0; $i < count($value); $i++) {
            $entity = $value[$i];

            $startIdx = $this->getIndex($entity->$startMethod());
            $endIdx = $this->getIndex($entity->$endMethod());

            if ($startIdx >= $endIdx) {
                $this->context->addViolation('error.start_end_time_incoherent');

                return false;
            }
            for ($j = $i + 1; $j < count($value); $j++) {
                $entityToCheck = $value[$j];
                $startIdxToCheck = $this->getIndex($entityToCheck->$startMethod());
                $endIdxToCheck = $this->getIndex($entityToCheck->$endMethod());
                if ($this->idxIsInOtherEntity($startIdx, $startIdxToCheck, $endIdxToCheck) ||
                    $this->idxIsInOtherEntity($endIdx, $startIdxToCheck, $endIdxToCheck) ||
                    $this->entityIsIncludedInAnother($startIdx, $endIdx, $startIdxToCheck, $endIdxToCheck) ||
                    $this->entityIsIncludedInAnother($startIdxToCheck, $endIdxToCheck, $startIdx, $endIdx)
                ) {
                    $this->context->addViolation('error.entities_overlapping', array(
                        '%firstElement%' => $i + 1,
                        '%secondElement%' => $j + 1,
                    ));

                    return false;
                }
            }
        }

        return true;
    }
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();
            }
        }
    }
162104
protected function validateDelimiter(Constraint $constraint)
    {
        if (strlen($constraint->delimiter) > 2) {
            throw new ConstraintDefinitionException(sprintf('"%s" is not a valid delimiter', $constraint->delimiter));
        }
    }
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();
    }
565490
public function add($key, Constraint\ConstraintInterface $constraint)
    {
        if (empty($this->constraints[$key])) {
            $this->constraints[$key] = [];
        }
        $this->constraints[$key][] = $constraint;

        return $this;
    }
1197008
public function validate($value, Constraint $constraint)
    {
        if(!$this->isValidNick($value)){
            $this->context->addViolation(
                $constraint->message,
                array('%nickValue%' => $value)
            );
        }
    }
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);
        }
    }
412022
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof SectionUpdateData) {
            return;
        }

        try {
            $section = $this->sectionService->loadSectionByIdentifier($value->identifier);
            if ($section->id == $value->getId()) {
                return;
            }

            $this->context->buildViolation($constraint->message)
                ->atPath('identifier')
                ->setParameter('%identifier%', $value->identifier)
                ->addViolation();
        } catch (NotFoundException $e) {
            // Do nothing
        }
    }
1058258
public function validate($value, Constraint $constraint)
    {
        if ($value === null) {
            return;
        }

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

        if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
            $newValue = clone $value;
            $newValue->setTime(0, 0, 0);
            $value = $newValue;
        }

        if (is_array($constraint->min)) {
            if (!(array_key_exists('service', $constraint->min) && array_key_exists('method', $constraint->min))) {
                throw new ConstraintDefinitionException(sprintf('The value of the option "min" as a factory expects the keys "service" and "method".'));
            }

            $minFactory = array($this->container->get($constraint->min['service']), $constraint->min['method']);
            if (!is_callable($minFactory)) {
                throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Range constraint is not a valid callable.', get_class($minFactory[0]), $minFactory[1]));
            }

            $min = call_user_func($minFactory);
            if ($min instanceof \DateTime || $min instanceof \DateTimeInterface) {
                $constraint->min = clone $min;
            } else {
                $constraint->min = $min;
            }
        }

        if (is_array($constraint->max)) {
            if (!(array_key_exists('service', $constraint->max) && array_key_exists('method', $constraint->max))) {
                throw new ConstraintDefinitionException(sprintf('The value of the option "max" as a factory expects the keys "service" and "method".'));
            }

            $maxFactory = array($this->container->get($constraint->max['service']), $constraint->max['method']);
            if (!is_callable($maxFactory)) {
                throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Range constraint is not a valid callable.', get_class($maxFactory[0]), $maxFactory[1]));
            }

            $max = call_user_func($maxFactory);
            if ($max instanceof \DateTime || $max instanceof \DateTimeInterface) {
                $constraint->max = clone $max;
            } else {
                $constraint->max = $max;
            }
        }

        return parent::validate($value, $constraint);
    }
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));
    }
  }