Checks if the value is valid.

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

@throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
966944
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Bsn) {
            throw new UnexpectedTypeException($constraint, Bsn::class);
        }

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

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

        $value = (string) $value;

        if ('000000000' !== $value && preg_match('/^\d{9}$/', $value)) {
            list($a, $b, $c, $d, $e, $f, $g, $h, $i) = str_split($value);

            $sum = (9 * $a) + (8 * $b) + (7 * $c) + (6 * $d) + (5 * $e) + (4 * $f) + (3 * $g) + (2 * $h) + (-1 * $i);

            if (0 === $sum % 11) {
                return;
            }
        }

        $this->context->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->addViolation();
    }
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);
        }
    }
876872
public function validate($value, Constraint $constraint)
    {
        // collect urls
        $matches = [];

        // matches all urls withing a href's
        preg_match_all('#<a\s+(?:[^>]*?\s+)?href="((https*:)*//[^"]*)">.*</a>#U', $value, $matches);

        if (count($matches) === 0 || !isset($matches[1])) {
            return;
        }

        $externalUrls = $matches[1];

        // validate urls
        foreach ($externalUrls as $externalUrl) {
            if ($this->urlValidator->validate($externalUrl) === false) {
                $this->context
                    ->addViolation($constraint->message, ['%string%' => $externalUrl]);
            }
        }
    }
1101289
@Override
	public boolean validate(Object value) {
		if(constraints == null) {
			return false;
		}

		IConstraintChecker checker;
		for(BeanProperty constraint : constraints) {
			checker = checkers.get(constraint.getPropertyName());
			if(checker == null) {
				throw new RuntimeException("No checker found for constraint "
						+ "'" + constraint.getPropertyName() + "'"
				);
			}
			checker.check(value, constraint);
		}
		return true;
	}
1171271
protected function validateEscape(Constraint $constraint)
    {
        if (strlen($constraint->escape) > 2) {
            throw new ConstraintDefinitionException(sprintf('"%s" is not a valid escape', $constraint->escape));
        }
    }
944564
public function validate($value, Constraint $constraint)
    {
        $check = $this->container->get('admin.configuration.configvalue_manager')->getRepository()->findOneBySectionGroupAndValueName(
            $value->getConfigGroup()->getConfigSection()->getName(),
            $value->getConfigGroup()->getName(),
            $value->getName()
        );
        if ( $check && $check->getId() != $value->getId()) {
            $message = $this->container->get('translator')->trans(
                $constraint->message,
                array(
                    '%value%' => $value->getName(),
                    '%group%' => $value->getConfigGroup()->getName(),
                    '%section%' => $value->getConfigGroup()->getConfigSection()->getName()
                ),
                'VinceTAdminConfigurationBundle'
            );
            $this->context->addViolation($message);
        }
    }
1206390
public function validate($value, Constraint $constraint)
    {
        $parentGetter = 'get' . ucfirst($constraint->parent);
        $siblingsGetter = 'get' . ucfirst($constraint->siblings);
        $this->startFieldGetter = 'get' . $constraint->startField;
        $this->endFieldGetter = 'get' . $constraint->endField;
        $entities = $this->seasonManager->findByPerimeter($value->$parentGetter());

        foreach ($entities as $entity) {
            if ($entity->getId() != $value->getId() && (
                // value is contained in entity
                $this->entityIsIncludedInAnother($entity, $value) ||
                // entity is contained in value
                $this->entityIsIncludedInAnother($value, $entity) ||
                // value startDate is within another entity
                ($value->{$this->startFieldGetter}() >= $entity->{$this->startFieldGetter}() &&
                $value->{$this->startFieldGetter}() <= $entity->{$this->endFieldGetter}()) ||
                // value endDate is within another entity
                ($value->{$this->endFieldGetter}() >= $entity->{$this->startFieldGetter}() &&
                $value->{$this->endFieldGetter}() <= $entity->{$this->endFieldGetter}())
                )) {
                $this->context->addViolation(
                    'error.seasons_overlapping',
                    array(
                        '%saison_title%' => $entity->getTitle(),
                    )
                );

                return false;
            }
        }

        return true;
    }
257050
public function validate($data, Constraint $constraint)
    {
        if (!$constraint instanceof UniqueVariant) {
            throw new \UnexpectedValueException("Can't validate this type of constraint, please provide a UniqueVariant constraint");
        }
        if (!$data instanceof $this->dataClass) {
            $class = get_class($data);
            throw new \UnexpectedValueException("Can't validate data of class {$class}");
        }
        $family = $data->getFamily();
        if (!$family instanceof VariantFamily) {
            return;
        }
        $currentCombination = [];
        foreach ($family->getAxles() as $attribute) {
            if ($attribute->isMultiple()) {
                throw new \LogicException("Family axle '{$attribute->getCode()}' is multiple, multiple axles support is not implemented yet");
            }
            $currentCombination[$attribute->getCode()] = $data->getValueData($attribute);
        }

        /** @var DataInterface $variantData */
        foreach ($constraint->parentData->getValuesData($constraint->attribute) as $variantData) {
            if ($variantData->getFamilyCode() !== $family->getCode()) {
                continue;
            }
            if ($variantData->getId() === $data->getId()) {
                continue;
            }
            $variantDataCombination = [];
            foreach ($family->getAxles() as $attribute) {
                $variantDataCombination[$attribute->getCode()] = $variantData->getValueData($attribute);
            }
            if ($this->compareCombinations($currentCombination, $variantDataCombination)) {
                $this->context->buildViolation('sidus_eav_variant.errors.invalid_axle_combination')
                    ->addViolation();
            }
        }
    }
427188
public function validate($value, Constraint $constraint)
    {
        $block = $constraint->block;
        if ($block instanceof BlockInterface && true === $block->isTransverse() && !empty($value)) {
            $blockCode = $this->repository->findOneTransverseBlockByCode($value, $block->getLanguage(), $block->getSiteId());
            if (null !== $blockCode && $blockCode->getId() !== $block->getId()) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('code')
                    ->addViolation();
            }
        }

    }
510340
public function validate($entity, Constraint $constraint)
    {
        if (!$entity instanceof ClientDetailsInterface) {
            throw new \InvalidArgumentException('Expected instance of ClientDetailsInterface');
        }
        
        $result = $entity->isPasswordConfirmed();
        
        if (true === $result) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            $this->context
                ->buildViolation($constraint->message)
                ->atPath('hashedPassword')
                ->addViolation();
            
            $this->context
                ->buildViolation($constraint->message)
                ->atPath('passwordConfirm')
                ->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);
            }
        }
    }
1236724
public function validate($array, Constraint $constraint): void
    {
        if (\is_array($array)) {
            $type = $constraint->type;
            $values = $type::getValues();
            $badValues = [];
            foreach ($array as $v) {
                if (!\in_array($v, $values, true)) {
                    $badValues[] = $v;
                }
            }
            if ($badValues) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ type }}', $constraint->type)
                    ->setParameter('{{ value }}', implode(', ', $badValues))
                    ->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.');
        }
    }
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;
        }


    }
1373252
public function validate($value, Constraint $constraint)
    {
        if (null !== $value->getSpecialPageName()) {
            $countSpecialPage = $this->repository->countOtherNodeWithSameSpecialPageName(
                $value->getNodeId(),
                $value->getSiteId(),
                $value->getLanguage(),
                $value->getSpecialPageName()
            );

            if ($countSpecialPage > 0) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('specialPageName')
                    ->addViolation();
            }
        }
    }
576289
protected function isValid(&$value): ConstraintInterface
    {
        if ($this->constraintsSet instanceof ConstraintsSetInterface) {
            $this->constraintsSet->isValid($value);
        }

        return $this;
    }
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();
    }