Check if the constraint is met.

@param mixed $value
@param array $context

@return mixed
545635
public function check($value, array $context = [])
    {
        foreach ($context as $field => $value) {
            if (in_array($field, $this->fields)) {
                return true;
            }
        }

        return false;
    }
1107588
private function isConstantValue($value): bool
    {
        if (\is_array($value)) {
            foreach ($value as $item) {
                if (!$this->isConstantValue($item)) {
                    return false;
                }
            }

            return true;
        }

        return $value === null || is_scalar($value);
    }
450703
protected function isValid($value)
    {
        if (is_null($value)) {
            return;
        } elseif ($value) {
            $context = [$value];
        } else {
            $context = [];
        }

        $q = new FlowQuery($context);

        if ($q->is('[instanceof ' . $this->options['type'] . ']')) {
            return;
        }

        $this->addError('The value is expected to satisfy the %s flowQuery condition.', 1515144113, [
            $this->options['type']
        ]);
    }
908206
public function checkDate($value, ExecutionContextInterface $context)
    {
        $format = self::PHP_DATE_FORMAT;

        if (! empty($value) && false === \DateTime::createFromFormat($format, $value)) {
            $context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", [
                        '%fmt' => self::MOMENT_JS_DATE_FORMAT,
                        '%date' => $value
                    ]));
        }
    }
1321219
public static function isValid($value)
    {
        if($value === null){
            return false;
        }

        $reflection = new \ReflectionClass(get_called_class());
        return in_array($value, $reflection->getConstants());
    }
1175268
public function validate(
        string $path,
        $value,
        ValidatorContextInterface $context,
        ValidatorInterface $validator = null
    ) {
        if (null === $value) {
            return [];
        }

        if (!is_array($value) && !$value instanceof \Traversable) {
            return [new Error(
                $path.'[_all]',
                'constraint.all.invalidtype',
                ['type' => is_object($value) ? get_class($value) : gettype($value)]
            )];
        }

        $errors = [];
        foreach ($value as $i => $subValue) {
            foreach ($this->constraints as $constraint) {
                $errors = array_merge(
                    $errors,
                    $constraint->validate($path.'['.$i.']', $subValue, $context, $validator)
                );
            }
        }

        return $errors;
    }
553141
protected function _validate_const($value, $parameter = null)
    {
        $context = $this->_context;

        $model = $context->model;
        $constants = $model::consts($parameter ?: $context->field);
        if (isset($constants[$value])) {
            return $value;
        } else {
            return ($r = array_search($value, $constants, true)) !== false ? $r : null;
        }
    }
797900
public static function execute($value, ContextInterface $context): array
    {
        return is_string($value) === true ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::IS_STRING, Messages::IS_STRING, []);
    }
568539
public static function execute($value, ContextInterface $context): array
    {
        $properties = $context->getProperties();

        return static::createErrorReply(
            $context,
            $value,
            $properties->getProperty(self::PROPERTY_ERROR_CODE),
            $properties->getProperty(self::PROPERTY_ERROR_MESSAGE_TEMPLATE),
            $properties->getProperty(self::PROPERTY_ERROR_MESSAGE_PARAMETERS)
        );
    }
1178742
public function validFormat(string $value, array $context): bool
    {
        // one or more letter in upper case
        if ($this->getConfig('upperCase') && !preg_match('/[A-Z]/', $value)) {
            return false;
        }
        // one or more letter in lower case
        if ($this->getConfig('lowerCase') && !preg_match('/[a-z]/', $value)) {
            return false;
        }
        // one or more numeric value
        if ($this->getConfig('numericValue') && !preg_match('/[0-9]/', $value)) {
            return false;
        }
        // one ore more special char (no digit or letter)
        if ($this->getConfig('specialChars') && !preg_match('/[^äüößÄÜÖA-Za-z0-9]/', $value)) {
            return false;
        }

        return true;
    }
629622
public function isValid($value, $context = array())
    {
        $this->_setValue((string) $value);

        $fieldSet = (boolean) isset($context[$this->_fieldName]) && $context[$this->_fieldName];
        $valueSet = (boolean) $value;

        if ($valueSet && (! $fieldSet))  {
            return true;
        }

        if ((! $valueSet) && $fieldSet)  {
            return true;
        }

        $this->_error(self::NEITHER);
        return false;
    }
28374
public static function execute($value, ContextInterface $context): array
    {
        return is_int($value) === true ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::IS_INT, Messages::IS_INT, []);
    }
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;
    }
429094
public static function execute($value, ContextInterface $context): array
    {
        assert(is_int($value) || is_string($value));

        $apiClass = $context->getProperties()->getProperty(static::PROPERTY_API_CLASS);

        /** @var FactoryInterface $apiFactory */
        $apiFactory = $context->getContainer()->get(FactoryInterface::class);

        /** @var CrudInterface $api */
        $api = $apiFactory->createApi($apiClass);

        $data   = $api->withIndexFilter((string)$value)->indexIdentities();
        $result = !empty($data);

        return $result === true ?
            static::createSuccessReply($value) :
            static::createErrorReply(
                $context,
                $value,
                ErrorCodes::EXIST_IN_DATABASE_SINGLE,
                Messages::EXIST_IN_DATABASE_SINGLE,
                []
            );
    }
714002
public static function execute($value, ContextInterface $context): array
    {
        $values = $context->getProperties()->getProperty(static::PROPERTY_VALUES);
        $isOk   = in_array($value, $values);

        return $isOk === true ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::INVALID_VALUE, Messages::INVALID_VALUE, []);
    }
1005228
public function isValid($value, $context = null)
    {
        if (empty($value)) {
            $this->error(self::MISSING_VALUE);
            return false;
        }

        $service = $this->getService();

        $res = $service->verify($value);
        if (! $res) {
            $this->error(self::ERR_CAPTCHA);
            return false;
        }

        if (! $res->isSuccess()) {
            $this->error(self::BAD_CAPTCHA);
            return false;
        }

        return true;
    }
351786
public static function execute($value, ContextInterface $context): array
    {
        return $value instanceof DateTimeInterface ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::IS_DATE_TIME, Messages::IS_DATE_TIME, []);
    }