Add violation.

@param mixed           $error
@param Constraint|Yaml $constraint

@return true
505595
protected function addViolation($error, Constraint $constraint)
    {
        $this->context->buildViolation($constraint->message)
            ->setParameter('%error%', $error)
            ->addViolation()
        ;

        return true;
    }
217458
public function createConstraint(Constraint $constraint, $table)
    {
        $this->_execSql($this->_platform->getCreateConstraintSQL($constraint, $table));
    }
1224966
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Luhn) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Luhn');
        }

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

        // Work with strings only, because long numbers are represented as floats
        // internally and don't work with strlen()
        if (!\is_string($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if (!ctype_digit($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Luhn::INVALID_CHARACTERS_ERROR)
                ->addViolation();

            return;
        }

        $checkSum = 0;
        $length = \strlen($value);

        // Starting with the last digit and walking left, add every second
        // digit to the check sum
        // e.g. 7  9  9  2  7  3  9  8  7  1  3
        //      ^     ^     ^     ^     ^     ^
        //    = 7  +  9  +  7  +  9  +  7  +  3
        for ($i = $length - 1; $i >= 0; $i -= 2) {
            $checkSum += $value[$i];
        }

        // Starting with the second last digit and walking left, double every
        // second digit and add it to the check sum
        // For doubles greater than 9, sum the individual digits
        // e.g. 7  9  9  2  7  3  9  8  7  1  3
        //         ^     ^     ^     ^     ^
        //    =    1+8 + 4  +  6  +  1+6 + 2
        for ($i = $length - 2; $i >= 0; $i -= 2) {
            $checkSum += array_sum(str_split($value[$i] * 2));
        }

        if (0 === $checkSum || 0 !== $checkSum % 10) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Luhn::CHECKSUM_FAILED_ERROR)
                ->addViolation();
        }
    }
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;
    }
958237
public function validate($basket, Constraint $constraint)
    {
        foreach ($basket->getBasketElements() as $pos => $basketElement) {
            // create a new ErrorElement object
            $errorElement = new ErrorElement(
                $basket,
                $this->constraintValidatorFactory,
                $this->context,
                $this->context->getGroup()
            );

            $errorElement->with('basketElements['.$pos.']');

            // validate the basket element through the related service provider
            $this->productPool
                ->getProvider($basketElement->getProductCode())
                ->validateFormBasketElement($errorElement, $basketElement, $basket);
        }

        if (\count($this->context->getViolations()) > 0) {
            $this->context->addViolationAt('basketElements', $constraint->message);
        }
    }
1022925
public function validate($value, Constraint $constraint)
    {
        $object = $this->context->getObject();
        $name = null;
        if (is_object($object)) {
            if (method_exists($object, 'getConfig'))
                $name = $object->getConfig()->getName();
            if (! $name && method_exists($object, '__toString'))
                $name = $object->__toString();
            if (! $name && method_exists($object, 'getName'))
                $name = $object->getName();
            if (! $name)
                $name = get_class($object);
        } else
            $name = strval($object);
        $this->context->buildViolation($constraint->message)
            ->setParameter('%{name}', $name)
            ->addViolation();
    }
302150
protected function addError($error){

        $this->valid = false;

        if($error instanceof Exception){
            $this->errors[] = array(
                'file' => $error->getFile(),
                'line' => $error->getLine(),
                'message' => "[".get_class($error)."] ".$error->getMessage()
            );
        }elseif($error instanceof LibXMLError){
            $this->errors[] = array(
                'file' => $error->file,
                'line' => $error->line,
                'message' => "[".get_class($error)."] ".$error->message
            );
        }elseif(is_string($error)){
            $this->errors[] = array(
                'message' => $error
            );
        }
    }
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;
        }
    }
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();
    }
15409
protected function addViolationToOutput(array $errors, ConstraintViolationInterface $violation)
    {
        $path = $this->getPropertyPathAsArray($violation);

        // Drill into errors and find where the error message should be added, building nonexistent portions of the path
        $currentPointer = &$errors;

        while (count($path) > 0) {
            $currentField = array_shift($path);

            if (! array_key_exists($currentField, $currentPointer) or ! is_array($currentPointer[$currentField])) {
                $currentPointer[$currentField] = [];
            }

            if (is_numeric($currentField)) {
                for ($i = 0; $i < (int) $currentField; $i++) {
                    if (! array_key_exists($i, $currentPointer)) {
                        $currentPointer[(int) $i] = null;
                    }
                }

                // Sort the elements of this array so JsonResponse converts this to an array rather than an object
                ksort($currentPointer);
            }

            $currentPointer = &$currentPointer[$currentField];
        }

        $currentPointer[] = $violation->getMessage();

        return $errors;
    }
251785
public function addPropertyConstraint($property, Constraint $constraint)
    {
        if (!isset($this->properties[$property])) {
            $this->properties[$property] = new PropertyMetadata($this->getClassName(), $property);

            $this->addPropertyMetadata($this->properties[$property]);
        }

        $constraint->addImplicitGroupName($this->getDefaultGroup());

        $this->properties[$property]->addConstraint($constraint);

        return $this;
    }
1197119
public function validate($entity, Constraint $constraint)
    {
        if (!$entity instanceof Review) {
            throw new \InvalidArgumentException('Expected instance of ' . Review::class);
        }
        
        $checker = new BadWordsChecker();
        
        if (false === $checker->isBadWord($entity->getReview())) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            $this->context->buildViolation($constraint->message)
                ->atPath('review')
                ->addViolation();
        }
    }
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()]
                );
            }
        }
    }
1009799
protected function addViolation($value, Constraint $constraint)
    {
        $this->context->addViolation(
            $constraint->message,
            [
                '{{ id_field }}' => $constraint->getIdField(),
                '{{ value }}'    => $value
            ],
            $value
        );
    }
23397
public function validate($value, Constraint $constraint)
    {
        try {
            $value->getMainAlias();
        } catch (MainAliasNotExisting $exception) {
            foreach ($value->getAliases() as $name => $siteAlias) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('aliases['.$name.'].main')
                    ->addViolation();
            }
        }
    }
1090119
public function force($value, $rule, AppliesToResource $resource=null)
    {
        if (!$this->check($value, $rule, $resource)) {
            throw new ConstraintViolationException('Value does not match constraint.');
        }

        return true;
    }
42447
private function createDocFromConstraint(Constraint $constraint) : ?TypeDoc
    {
        $doc = null;

        if (null !== ($stringType = $this->getStringType($constraint))) {
            $doc = $this->normalizeType($stringType);
        } elseif ($constraint instanceof Assert\Callback) {
            $doc = $this->getTypeFromCallbackConstraint($constraint);
        } elseif ($constraint instanceof Assert\Existence && count($constraint->constraints) > 0) {
            $doc = $this->guess($constraint->constraints);
        }

        return $doc;
    }