Validates a creditcard belongs to a specified scheme.

@param mixed      $value
@param Constraint $constraint
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);
        }
    }
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();
        }
    }
1318332
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof HasGuessableExtension) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\HasGuessableExtension');
        }

        if (!$value instanceof UploadedFile) {
            return;
        }

        $contentType = $this->mimeTypeGuesser->guess($value->getPathname());
        $pathInfo = pathinfo($value->getClientOriginalName());
        if (!array_key_exists('extension', $pathInfo)) {
            $pathInfo['extension'] = $this->extensionGuesser->guess($contentType);
        }

        if ($pathInfo['extension'] === null) {
            $this->context->buildViolation($constraint->notGuessableErrorMessage)
                ->setCode(HasGuessableExtension::NOT_GUESSABLE_ERROR)
                ->addViolation();
        }
    }
1141134
public function validate($value, Constraint $constraint)
    {
        if (!$value) {
            return;
        }

        $fileHistory = $this->em->getRepository('JbFileUploaderBundle:FileHistory')->find($value);
        if (!$fileHistory) {
            return;
        }

        // No userid associated with file. Every one can use it.
        if (!$fileHistory->getUserId()) {
            return;
        }

        // No token. Violation as there is a user id associate with file.
        $token = $this->tokenStorage->getToken();
        if (!$token) {
            return $this->createViolation($value, $constraint);
        }

        // No user. Violation as there is a user id associate with file.
        $user = $token->getUser();
        if (!$user) {
            return $this->createViolation($value, $constraint);
        }

        if ($user->getId() !== $fileHistory->getUserId()) {
            return $this->createViolation($value, $constraint);
        }

        return;
    }
322159
public function validate($value, Constraint $constraint)
    {
        if ($value->isInMenu() || $value->isInFooter()) {
            if (preg_match('/{.*}/', $value->getRoutePattern())) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('routePattern')
                    ->addViolation();
            }
        }
    }
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);
    }
1330059
public function validate($value, Constraint $constraint): void
    {
        if ($value !== null) {
            $type = $constraint->type;
            $values = $type::getValues();
            if (!\in_array($value, $values, true)) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ type }}', $constraint->type)
                    ->setParameter('{{ value }}', $value)
                    ->addViolation();
            }
        }
    }
1009799
protected function addViolation($value, Constraint $constraint)
    {
        $this->context->addViolation(
            $constraint->message,
            [
                '{{ id_field }}' => $constraint->getIdField(),
                '{{ value }}'    => $value
            ],
            $value
        );
    }
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;
    }
766909
public function validate($value, Constraint $constraint)
    {
        if ( !preg_match('/^[a-z0-9_]+$/', $value) ) {
            $message = $this->container->get('translator')->trans($constraint->message, array('%string%' => $value), 'VinceTAdminConfigurationBundle');
            $this->context->addViolation($message);
        }
    }
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();
            }
        }
    }
1144087
public function validate($value, Constraint $constraint)
    {
        if ($value === null) {
            return;
        }

        $chunks = \explode('.', (string) $value);
        if (\count($chunks) > 2) {
            throw new \Exception('Number can have only 1 "." character.');
        }

        $precision = \strlen(\implode('', $chunks));
        $scale = isset($chunks[1]) ? \strlen($chunks[1]) : 0;

        if ($constraint->precision !== null && $precision > $constraint->precision) {
            $this->context->addViolation($constraint->precisionMessage, [
                '%maxPrecision%' => $constraint->precision,
            ]);
        }

        if ($constraint->scale !== null && $scale > $constraint->scale) {
            $this->context->addViolation($constraint->scaleMessage, [
                '%maxScale%' => $constraint->scale,
            ]);
        }
    }
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;
    }
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
        }
    }
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
        }
    }
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();
        }
    }
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);
            }
        }
    }