Checks if the passed value is valid.

@param mixed $protocol The value that should be validated
@param Constraint $constraint The constraint for the validation

@api
495318
public function validate($protocol, Constraint $constraint) {


        if (is_null($constraint->requireHash)) {
            $hashReg = '#{0,1}';
        } else if ($constraint->requireHash === true) {
            $hashReg = '#';
        } else if ($constraint->requireHash === false) {
            $hashReg = '';
        } else {
            throw new \Exception('The requireHash option value is NOT valid');
        }

        if (!$this->checkHexColor($protocol, $hashReg)) {
            $this->context->buildViolation($constraint->message)
                    ->setParameter('%color%', $protocol)
                    ->addViolation();
        }
    }
1146590
public function validate($propertyValue, Constraint $constraint)
    {
        // Implement your validation logic.
        // Return early if the value is valid
        // For example:
        if ($propertyValue === 'isValid') {
            return;
        }

        // Finally, if not valid, add the violation
        $this->context->buildViolation($constraint->message)
                      ->setParameter('{{ string }}', $propertyValue)
                      ->addViolation();
    }
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;
        }
    }
892773
protected function hasPayloadDocKey(Constraint $constraint, string $documentationKey) : bool
    {
        return array_key_exists($documentationKey, $constraint->payload[self::PAYLOAD_DOCUMENTATION_KEY]);
    }
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();
            }
        }
    }
442079
public function validate($location, Constraint $constraint)
    {
        if (null === $location) {
            $this->context->addViolation($constraint->message);

            return;
        }

        $isContainer = new IsContainer();
        if (!$isContainer->isSatisfiedBy($location)) {
            $this->context->addViolation($constraint->message);
        }
    }
383952
public function validate ($entity, Constraint $constraint)
    {
        if (!$entity instanceof ClientBillingAddressInterface) {
            throw new \InvalidArgumentException('Expected instance of ClientBillingAddressInterface');
        }
        
        if (false === $entity->isCompanyAddress()) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            
            if (false === $this->isValidCompanyName($entity)) {
                $this->context->buildViolation('client.company_name_not_valid')->atPath('companyName')->addViolation();
            }
            
            if (false === $this->isValidVatId($entity)) {
                $this->context->buildViolation('client.vatid_not_valid')->atPath('vatId')->addViolation();
            }
        }
    }
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();
            }
        }
    }
1351252
private function isValid(Constraint $constraint, int $difference): bool
    {
        /*
         * It's a earlier than today date?
         * Nothing to do
         */
        if ($constraint instanceof EarlierThanToday && $difference < 0) {
            return true;
        }

        /*
         * It's a earlier than or equal today date?
         * Nothing to do
         */
        if ($constraint instanceof EarlierThanOrEqualToday && $difference <= 0) {
            return true;
        }

        /*
         * It's a later than today date?
         * Nothing to do
         */
        if ($constraint instanceof LaterThanToday && $difference > 0) {
            return true;
        }

        /*
         * It's a later than or equal today date?
         * Nothing to do
         */
        if ($constraint instanceof LaterThanOrEqualToday && $difference >= 0) {
            return true;
        }

        return false;
    }
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;
    }
37110
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof FieldDefinitionData) {
            return;
        }

        $contentTypeData = $value->contentTypeData;
        foreach ($contentTypeData->fieldDefinitionsData as $fieldDefData) {
            if ($fieldDefData === $value) {
                continue;
            }

            if ($value->identifier === $fieldDefData->identifier) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('identifier')
                    ->setParameter('%identifier%', $value->identifier)
                    ->addViolation();
            }
        }
    }
1328159
public function isValid($value, Constraint $constraint)
    {
        $document = $this->parseDocument($value);
        $fields = $this->parseFields($constraint->fields);
        $caseInsensitive = $this->parseCaseInsensitive($constraint->caseInsensitive);

        $query = $this->createQuery($document, $fields, $caseInsensitive);
        $numberResults = $query->count();

        if (0 === $numberResults) {
            return true;
        }

        if (1 === $numberResults) {
            $result = $query->one();
            if ($result === $document) {
                return true;
            }
        }

        if ($this->context) {
            $this->addFieldViolation($fields[0], $constraint->message);
        }

        return false;
    }
91787
public function validate($group, Constraint $constraint)
    {
        $check = $this->container->get('admin.configuration.configgroup_manager')->getRepository()->findOneBySectionAndGroupName($group->getConfigSection()->getName(), $group->getName());
        if ( $check && $check->getId() != $group->getId()) {
            $message = $this->container->get('translator')->trans(
                $constraint->message,
                array(
                    '%group%' => $group->getName(),
                    '%section%' => $group->getConfigSection()->getName()
                ),
                'VinceTAdminConfigurationBundle'
            );
            $this->context->addViolation($message);
        }
    }
695625
public function validate($location, Constraint $constraint)
    {
        if (null === $location) {
            $this->context->addViolation($constraint->message);

            return;
        }
        $isRoot = new IsRoot();

        if ($isRoot->isSatisfiedBy($location)) {
            $this->context->addViolation($constraint->message);
        }
    }
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();
    }
637065
public function addConstraint(Constraint $constraint) : void
    {
        $constraint->setValidator($this);
        array_push($this->constraints, $constraint);
    }
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]);
            }
        }
    }