Returns true if and only if $value matches post code format.

@param string $value
@param array  $context

@return bool
161514
public function isValid($value = null, $context = null)
    {
        if (!is_scalar($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $this->setValue($value);

        $country = $this->getCountry();

        if (!array_key_exists($country, self::$postCodeRegex) && array_key_exists($country, $context)) {
            $country = $context[$country];
        }

        if (!array_key_exists($country, self::$postCodeRegex)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        $format = self::$postCodeRegex[$country];

        if ($format[0] !== '/') {
            $format = '/^' . $format;
        }

        if ($format[strlen($format) - 1] !== '/') {
            $format .= '$/';
        }

        if (!preg_match($format, $value)) {
            $this->error(self::NO_MATCH);

            return false;
        }

        return true;
    }
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)
        );
    }
1236557
public static function is($pattern, $value)
    {
        $patterns = is_array($pattern) ? $pattern : (array) $pattern;

        if (empty($patterns)) {
            return false;
        }

        foreach ($patterns as $pattern) {
            // If the given value is an exact match we can of course return true right
            // from the beginning. Otherwise, we will translate asterisks and do an
            // actual pattern match against the two strings to see if they match.
            if ($pattern == $value) {
                return true;
            }

            $pattern = preg_quote($pattern, '#');

            // Asterisks are translated into zero-or-more regular expression wildcards
            // to make it convenient to check if the strings starts with the given
            // pattern such as "library/*", making any string check convenient.
            $pattern = str_replace('\*', '.*', $pattern);

            if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
                return true;
            }
        }

        return false;
    }
840338
public function isContextMatching(ContextualValueInterface $value, array $context)
    {
        if (!$value->getContext()) {
            return true;
        }
        $value::checkContext($context);
        foreach ($this->getContextMask() as $key) {
            $contextKey = array_key_exists($key, $context) ? $context[$key] : null;
            if ($contextKey !== $value->getContextValue($key)) {
                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;
    }
1246554
public function setContext($context, $value = null)
    {
        if (is_null($value) && is_array($context)) {
            foreach ($context as $key => $value) {
                if (is_int($key)) {
                    throw new ContextException(sprintf('Context key must be a string, not an integer (key: "%s").', $key));
                }
                
                if ($value && !is_scalar($value)) {
                    throw new ContextException(sprintf('Context value must be scalar (key: "%s").', $key));
                }
                
                $this->context[$key] = $value;
            }
        } else {
            $key = $context;
            if (is_int($key)) {
                throw new ContextException(sprintf('Context key must be a string, not an integer (key: "%s").', $key));
            }
    
            if ($value && !is_scalar($value)) {
                throw new ContextException(sprintf('Context value must be scalar (key: "%s").', $key));
            }
    
            $this->context[$key] = $value;
        }
        
        return $this;
    }
272891
private static function check_contexts(context $context, $values) {
        if ($context->contextlevel > CONTEXT_COURSECAT) {
            return self::check_contexts($context->get_parent_context(), $values);
        } else if ($context->contextlevel == CONTEXT_COURSECAT) {
            if (in_array($context->instanceid, $values)) {
                return true;
            } else {
                return self::check_contexts($context->get_parent_context(), $values);
            }
        } else {
            return false;
        }
    }
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
                    ]));
        }
    }
851213
public function isValid($value)
    {
        $result = preg_match('/(.+)/i', $value);
        if (!$result) {
            $this->addMessage('notEmpty');
        }
        return (boolean) $result;
    }
962551
public function matches($value)
    {
        switch ($this->segmentType) {
            case Segment::LITERAL_SEGMENT:
                return $this->value === $value;
            case Segment::WILDCARD_SEGMENT:
                return self::isValidBinding($value);
            case Segment::DOUBLE_WILDCARD_SEGMENT:
                return self::isValidDoubleWildcardBinding($value);
            case Segment::VARIABLE_SEGMENT:
                return $this->template->matches($value);
            default:
                throw new ValidationException(
                    "Unexpected Segment type: {$this->segmentType}"
                );
        }
    }
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, []);
    }
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;
    }
261712
protected function validateValue($value)
    {
        // strip empty lines
        $lines = array_filter(
            explode("\n", $value)
        );

        // strip comments (lines beginning with "#")
        $lines = array_filter($lines, function ($line) {
            $line = trim($line);

            return !empty($line) && $line[0] !== '#';
        });

        // validate each line
        foreach ($lines as $line) {
            if (!$this->validateLine($line)) {
                return false;
            }
        }

        return true;
    }
614621
public static function encode($value, Context $context)
    {
        if (is_bool($value)) {
            return new BooleanValue($context->getIsolate(), $value);
        } elseif (is_string($value)) {
            return new StringValue($context->getIsolate(), $value);
        } elseif (is_float($value)) {
            return new NumberValue($context->getIsolate(), $value);
        } elseif (is_int($value)) {
            return new IntegerValue($context->getIsolate(), $value);
        } elseif ($value === null) {
            return new NullValue($context->getIsolate());
        } elseif ($value instanceof \DateTime) {
            return new DateObject($context, $value->getTimestamp() * 1000);
        } elseif ($value instanceof ObjectInterface) {
            return self::encode($value->getProperties(), $context);
        } elseif ($value instanceof \Closure || is_callable($value)) {
            return new FunctionObject($context, function(FunctionCallbackInfo $info) use ($value){
                $args   = $info->arguments();
                $params = [];
                foreach ($args as $arg) {
                    $params[] = Decoder::decode($arg, $info->getContext());
                }

                $return = call_user_func_array($value, $params);

                $info->getReturnValue()->set(self::encode($return, $info->getContext()));
            });
        } elseif ($value instanceof \ArrayObject) {
            return self::encode($value->getArrayCopy(), $context);
        } elseif ($value instanceof \Traversable) {
            return self::encode(iterator_to_array($value), $context);
        } elseif ($value instanceof \JsonSerializable) {
            return self::encode($value->jsonSerialize(), $context);
        } elseif ($value instanceof \stdClass || (is_array($value) && self::isAssoc($value))) {
            $object = new ObjectValue($context);
            foreach ($value as $key => $val) {
                $object->set(
                    $context,
                    self::encode($key, $context),
                    self::encode($val, $context)
                );
            }
            return $object;
        } elseif (is_array($value)) {
            $array = new ArrayObject($context);
            $index = 0;
            foreach ($value as $val) {
                $array->set(
                    $context,
                    self::encode($index, $context),
                    self::encode($val, $context)
                );
                $index++;
            }
            return $array;
        } elseif (is_object($value) && method_exists($value, '__toString')) {
            return new StringValue($context->getIsolate(), $value->__toString());
        } else {
            return new NullValue($context->getIsolate());
        }
    }
1234547
public static function postcode($value)
    {
        $bool = preg_match(self::$regularExpressions['postcode'], $value);

        if (!$bool) {
            return false;
        }

        return true;
    }
504136
public function check($value, array $context = [])
    {
        $hound = new TypeHound($value);

        return $this->expectedType === $hound->resolve();
    }
974119
private function matchValue($value, $pattern)
    {
        // basic check
        if ($value == $pattern) {
            return true;
        }

        // simple check in case of optional param
        if ($pattern == '?') {
            return true;
        }

        // simple match in case pattern is just "*"
        if ($pattern == '*' && $value != '') {
            return true;
        }

        // more complex match in case when wildcard is part of a larger match
        $pattern = str_replace('*', '(.+)', $pattern);

        // regex match
        if (strpos($pattern, '(') !== false || strpos($pattern, '[') !== false || strpos($pattern, '\\') !== false) {
            return preg_match('#^' . $pattern . '$#', $value);
        }

        return false;
    }