Check if the constraint is met.

@param mixed $value
@param array $context

@return mixed
431183
public function check($value, array $context = [])
    {
        if ($this->checkContainerType($value, $context) === false) {
            return false;
        }

        foreach ($value as $item) {
            if ($this->valueConstraint->check($item, $context) === false) {
                return false;
            }
        }

        return true;
    }
389529
protected function isMatchAnyInArray($value, $contextValue, $name)
    {
        if (!\is_array($value)) {
            return $this->isMatchScalarInArray($value, $contextValue, $name);
        }

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

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

                return $result;
        }

        return false;
    }
1165917
protected function formatObjectHandleArray($value, array $context)
    {
        if (is_array($value)) {
            $objs = array();
            foreach ($value as $key => $value2) {
                $objs[$key] = $this->format('', $value2, $context);
            }
            return $objs;
        } else {
            return $this->format('', $value, $context);
        }
    }
544971
public static function execute($value, ContextInterface $context): array
    {
        // parser guarantees that input will be an array of [$type => $id] where type and id are scalars

        // we will check the type of every pair and send further identities only
        $indexes          = [];
        $foundInvalidType = null;
        $expectedType     = $context->getProperties()->getProperty(static::PROPERTY_RESOURCE_TYPE);
        foreach ($value as $typeAndId) {
            assert(is_array($typeAndId) === true && count($typeAndId) === 1);
            $index = reset($typeAndId);
            $type  = key($typeAndId);
            assert(is_scalar($index) === true && is_scalar($type) === true);
            if ($type === $expectedType) {
                $indexes[] = $index;
            } else {
                $foundInvalidType = $type;
                break;
            }
        }

        $reply = $foundInvalidType === null ?
            static::createSuccessReply($indexes) :
            static::createErrorReply(
                $context,
                $foundInvalidType,
                ErrorCodes::INVALID_RELATIONSHIP_TYPE,
                Messages::INVALID_RELATIONSHIP_TYPE,
                []
            );

        return $reply;
    }
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']
        ]);
    }
397303
protected function validate_contextid($value) {
        global $DB;

        $context = context::instance_by_id($value, IGNORE_MISSING);
        if (!$context) {
            return new lang_string('invalidcontext', 'error');
        } else if ($context->contextlevel != CONTEXT_SYSTEM && $context->contextlevel != CONTEXT_COURSECAT) {
            return new lang_string('invalidcontext', 'error');
        }

        // During update.
        if ($this->get('id')) {

            // The context must never change.
            $oldcontextid = $DB->get_field(self::TABLE, 'contextid', array('id' => $this->get('id')), MUST_EXIST);
            if ($this->get('contextid') != $oldcontextid) {
                return new lang_string('invalidcontext', 'error');
            }
        }

        return true;
    }
521979
public function validate(
        string $path,
        $value,
        ValidatorContextInterface $context,
        ValidatorInterface $validator = null
    ) {
        if (null === $value) {
            return [];
        }

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

        if (!isset($value['lat']) || !isset($value['lon'])) {
            return [new Error($path, 'constraint.coordinatearray.invalidformat', ['value' => json_encode($value)])];
        }

        $lat = $value['lat'];
        $lon = $value['lon'];

        if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) {
            return [new Error($path, 'constraint.coordinatearray.invalidvalue', ['value' => json_encode($value)])];
        }

        return [];
    }
623888
public static function execute($value, ContextInterface $context): array
    {
        return is_numeric($value) === true ?
            static::createSuccessReply($value) :
            static::createErrorReply($context, $value, ErrorCodes::IS_NUMERIC, Messages::IS_NUMERIC, []);
    }
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)
        );
    }
61233
public static function execute($value, ContextInterface $context): array
    {
        $format = $context->getProperties()->getProperty(self::PROPERTY_FORMAT);
        if (is_string($value) === true && ($parsed = static::parseFromFormat($value, $format)) !== null) {
            return static::createSuccessReply($parsed);
        } elseif ($value instanceof DateTimeInterface) {
            return static::createSuccessReply($value);
        }

        return static::createErrorReply(
            $context,
            $value,
            ErrorCodes::IS_DATE_TIME,
            Messages::IS_DATE_TIME,
            [$format]
        );
    }
576289
protected function isValid(&$value): ConstraintInterface
    {
        if ($this->constraintsSet instanceof ConstraintsSetInterface) {
            $this->constraintsSet->isValid($value);
        }

        return $this;
    }
439150
public function context($context, $value = null)
    {
        if (! is_array($context)) {
            $context = [$context => $value];
        }

        foreach ($context as $key => $value) {
            $this->context[$key] = $value;
        }

        return $this;
    }
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;
    }
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;
    }
233231
public static function execute($value, ContextInterface $context): array
    {
        if (is_string($value) === true || is_numeric($value) === true) {
            return static::createSuccessReply((int)$value);
        }

        return static::createErrorReply($context, $value, ErrorCodes::IS_INT, Messages::IS_INT, []);
    }
107811
public function isValid($value, $context = null)
    {
        if (! is_array($value) && ! is_array($context)) {
            $this->error(self::MISSING_VALUE);
            return false;
        }

        if (! is_array($value) && is_array($context)) {
            $value = $context;
        }

        if (empty($value[$this->responseField])) {
            $this->error(self::MISSING_VALUE);
            return false;
        }

        $service = $this->getService();

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

        if (! $res->isSuccess()) {
            $result = $res->getErrorCodes();
            $this->error(self::BAD_CAPTCHA, end($result));
            return false;
        }

        return true;
    }
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,
                []
            );
    }