Check if the constraint is met.

@param mixed $value
@param array $context

@throws UnknownTypeException
@return mixed
504136
public function check($value, array $context = [])
    {
        $hound = new TypeHound($value);

        return $this->expectedType === $hound->resolve();
    }
515760
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof NotCompromisedPassword) {
            throw new UnexpectedTypeException($constraint, NotCompromisedPassword::class);
        }

        if ($this->disabled) {
            return;
        }

        if (null !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;
        if ('' === $value) {
            return;
        }

        if ('UTF-8' !== $this->charset) {
            $value = mb_convert_encoding($value, 'UTF-8', $this->charset);
        }

        $hash = strtoupper(sha1($value));
        $hashPrefix = substr($hash, 0, 5);
        $url = sprintf(self::RANGE_API, $hashPrefix);

        try {
            $result = $this->httpClient->request('GET', $url)->getContent();
        } catch (ExceptionInterface $e) {
            if ($constraint->skipOnError) {
                return;
            }

            throw $e;
        }

        foreach (explode("\r\n", $result) as $line) {
            list($hashSuffix, $count) = explode(':', $line);

            if ($hashPrefix.$hashSuffix === $hash && $constraint->threshold <= (int) $count) {
                $this->context->buildViolation($constraint->message)
                    ->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)
                    ->addViolation();

                return;
            }
        }
    }
1271356
public static function execute($value, ContextInterface $context): array
    {
        $idExists = is_int($value) === true && $value < 3;

        return $idExists === true ?
            static::createSuccessReply($value) :
            static::createErrorReply(
                $context,
                $value,
                Errors::IS_VALID_SKU,
                static::MESSAGE_TEMPLATE,
                []
            );
    }
1315828
public static function execute($value, ContextInterface $context): array
    {
        return is_array($value) === true ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::IS_ARRAY, Messages::IS_ARRAY, []);
    }
663814
protected function checkType($value, $type, $nullable = false)
    {
        if (gettype($value) === $type) {
            return true;
        }
        return $nullable && null === $value;
    }
1208325
public function check($value, array $context = [])
    {
        $length = mb_strlen($value);

        return !Std::truthy(
            ($this->min > $length),
            ($this->max !== -1 && $this->max < $length)
        );
    }
395518
public static function execute($value, ContextInterface $context): array
    {
        if (is_string($value) === true) {
            $lcValue = strtolower($value);
            if ($lcValue === 'true' || $lcValue === '1' || $lcValue === 'on' || $lcValue === 'yes') {
                $reply = static::createSuccessReply(true);
            } elseif ($lcValue === 'false' || $lcValue === '0' || $lcValue === 'off' || $lcValue === 'no') {
                $reply = static::createSuccessReply(false);
            } else {
                $reply = static::createErrorReply($context, $value, ErrorCodes::IS_BOOL, Messages::IS_BOOL, []);
            }
        } elseif (is_bool($value) === true) {
            $reply = static::createSuccessReply($value);
        } else {
            $reply = static::createErrorReply($context, $value, ErrorCodes::IS_BOOL, Messages::IS_BOOL, []);
        }

        return $reply;
    }
1321219
public static function isValid($value)
    {
        if($value === null){
            return false;
        }

        $reflection = new \ReflectionClass(get_called_class());
        return in_array($value, $reflection->getConstants());
    }
776740
protected function checkType($value)
    {
        if (!$value instanceof AssetContract) {
            throw new InvalidArgumentException("You can only add values of '{$this->forceType}' to this list");
        }

        if (!$mimeType = $value->mimeType()) {
            throw new InvalidArgumentException('The added asset must have a mimeType to add it to this collection');
        }

        if (!$this->mimeType) {
            $this->mimeType = $mimeType;

            return;
        }

        if ($this->mimeType != $mimeType) {
            throw new InvalidArgumentException("This collection accepts only mimeType {$this->mimeType} not $mimeType");
        }
    }
561716
public function check($value, array $context = [])
    {
        return Std::falsy(
            Boa::string()->check($value, $context),
            (new RegexConstraint(
                '/^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$/'
            ))->check($value, $context)
        );
    }
495896
public function offsetSet($offset, $value)
    {
        $this->checkType($value);
        if ($offset != $value->name()) {
            throw new InvalidArgumentException("The offset has to be the name of the constraint");
        }
        $this->constraints[$value->name()] = $value;
    }
864359
public function isValid($value, $context = null) {
        $this->_setValue((string) $value);

        $token = $this->getToken();
        $pos = strrpos($token, '[');
        if ($pos !== false) {
            $token = rtrim($token, ']');
            $token = substr($token, $pos+1);
        }

        if (($context !== null) && isset($context) && array_key_exists($token, $context)) {
            $token = $context[$token];
        }

        if ($token === null) {
            $this->_error(self::MISSING_TOKEN);
            return false;
        }

        $strict = $this->getStrict();
        if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) {
            $this->_error(self::NOT_SAME);
            return false;
        }

        return true;
    }
537823
protected function isMatchAnyWithScalar($value, $contextValue, $name)
    {
        if (!\is_array($value)) {
            return $this->isMatchScalars($value, $contextValue, $name);
        }

        switch (\key($value)) {
            case self::OPERATOR_NOT:
                return !$this->isMatchScalars(\current($value), $contextValue, $name);
            case self::OPERATOR_AND:
                $result = true;
                foreach (\current($value) as $val) {
                    if (!$this->isMatchScalarWithScalar($val, $contextValue, $name)) {
                        $result = false;
                        break;
                    }
                }

                return $result;
            case self::OPERATOR_OR:
                $result = false;
                foreach (\current($value) as $val) {
                    if ($this->isMatchScalarWithScalar($val, $contextValue, $name)) {
                        $result = true;
                        break;
                    }
                }

                return $result;
        }

        return false;
    }
1045809
public function isValid($value, $context = null)
    {
        if (! $this->useContext) {
            $context = (array) $value;
        }

        $cleanedValue = $this->cleanSearchValue($value);
        $match        = $this->objectRepository->findOneBy($cleanedValue);

        if (! is_object($match)) {
            return true;
        }

        $expectedIdentifiers = $this->getExpectedIdentifiers($context);
        $foundIdentifiers    = $this->getFoundIdentifiers($match);

        if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) == 0) {
            return true;
        }

        $this->error(self::ERROR_OBJECT_NOT_UNIQUE, $value);
        return false;
    }
345178
public function matches($value): bool
    {
        if (!interface_exists($this->type) && !class_exists($this->type)) {
            throw new UndefinedTypeException($this->type);
        }

        return $value instanceof $this->type;
    }
708105
protected function instance(&$value)
    {
        foreach ($this->instances as &$tuple) {
            if ($tuple[0] === $value) {
                if (
                    is_array($value) &&
                    !$this->isArrayReference($tuple[0], $value)
                ) {
                    continue;
                }

                return $tuple[1];
            }
        }

        return null;
    }
609041
public static function execute($value, ContextInterface $context): array
    {
        return is_float($value) === true ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::IS_FLOAT, Messages::IS_FLOAT, []);
    }