@param string                    $path
@param mixed                     $value
@param ValidatorContextInterface $context
@param ValidatorInterface|null   $validator

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

        if (!in_array($value, $this->choices, true)) {
            return [
                new Error(
                    $path,
                    'constraint.choice.invalidvalue',
                    ['value' => $value, 'choices' => implode(', ', $this->choices)]
                ),
            ];
        }

        return [];
    }
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, []);
    }
351771
private function errorsByDateTimeLastErrors(
        string $path,
        string $value,
        string $errorType,
        int $dateTimeErrorCount,
        array $dateTimeErrors
    ): array {
        if (0 === $dateTimeErrorCount) {
            return [];
        }

        $errors = [];
        foreach ($dateTimeErrors as $message) {
            $errors[] = new Error(
                $path,
                sprintf('constraint.datetime.%s', $errorType),
                ['message' => $message, 'format' => $this->format, 'value' => $value]
            );
        }

        return $errors;
    }
934609
protected function validate_path($value) {

        // The last item should be the parent ID.
        $id = $this->get('parentid');
        if (substr($value, -(strlen($id) + 2)) != '/' . $id . '/') {
            return new lang_string('invaliddata', 'error');

        } else if (!preg_match('@/([0-9]+/)+@', $value)) {
            // The format of the path is not correct.
            return new lang_string('invaliddata', 'error');
        }

        return true;
    }
1020485
private function getComponentForPath( $path, $context )
	{
		foreach ( $path as $element )
		{
			if ( ! $context ) continue;
			if ( ! isset( $context[ $element ] ) )
			{
				$context = array();
				continue;
			}
			$context = $context[ $element ];
		}

		return $context;
	}
1088497
private function validateProperty(
        ValidatorContextInterface $context,
        ValidationPropertyMappingInterface $propertyMapping,
        string $path,
        $object
    ): array {
        if (!$this->isWithinGroup($context, $propertyMapping)) {
            return [];
        }

        $name = $propertyMapping->getName();

        $subPath = $this->getSubPathByName($path, $name);

        $this->logPath($subPath);

        $value = $propertyMapping->getAccessor()->getValue($object);

        $errors = [];
        foreach ($propertyMapping->getConstraints() as $constraint) {
            $this->logConstraint($subPath, $constraint);

            foreach ($constraint->validate($subPath, $value, $context, $this) as $error) {
                $this->logError($subPath, $constraint, $error);

                $errors[] = $error;
            }
        }

        return $errors;
    }
806006
protected function validateDecimal($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'decimal' must have argument in validator list for parameter {$parameter}");
        }

        $decimals = (int)$args[0];

        if ($decimals <= 0) {
            throw new ValidatorConfigException("Validator 'decimal' has invalid value which is lower or equal to zero; for parameter={$parameter}");
        }

        if ($decimals > 100) {
            throw new ValidatorConfigException("Validator 'decimal' can't have that large argument; parameter={$parameter}");
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = trim((string)$value);

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

        if (!is_numeric($value)) {
            return Message::getMessage(Message::NUMERIC, [
                'param' => $parameter,
                'value' => $value
            ]);
        }

        $parts = explode('.', $value);

        if (count($parts) == 1) {
            return null; // value is not decimal, it's probably integer, so it's ok
        }

        $valueDecimals = $parts[1];

        if (strlen($valueDecimals) > $decimals) {
            return Message::getMessage(Message::DECIMAL, [
                'param' => $parameter,
                'value' => $value,
                'decimals' => $decimals
            ]);
        }

        return null;
    }
411997
public function isValid($value, $context = null)
    {
        if (!is_scalar($value) || !is_numeric($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $country = $this->getCountry();

        if (array_key_exists($country, $context)) {
            $country = $context[$country];
        }

        if (!in_array($country, $this->countrySupported, true)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        $aba = false;

        switch ($country) {
            case 'US':
                if (strlen($value) < 9) {
                    $this->error(self::TOO_SHORT);

                    return false;
                }

                if (strlen($value) > 9) {
                    $this->error(self::TOO_LONG);

                    return false;
                }

                $aba = (int) substr($value, 0, 2);
                break;
            case 'CA':
                if (strlen($value) < 8) {
                    $this->error(self::TOO_SHORT);

                    return false;
                }

                if (strlen($value) > 8) {
                    $this->error(self::TOO_LONG);

                    return false;
                }

                $aba = (int) substr($value, -3);
                break;
        }

        if (!is_int($aba)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        /** @var array $abaLists */
        $abaLists = $this->aba[$country];
        $found    = false;

        foreach ($abaLists as $check) {
            if ($aba >= $check[0] && $aba <= $check[1]) {
                $found = true;
            }
        }

        if (!$found) {
            $this->error(self::NO_MATCH);

            return false;
        }

        if ($country === 'US') {
            /** @var string $value */
            $checksum = 7 * ($value[0] + $value[3] + $value[6]);
            $checksum += 3 * ($value[1] + $value[4] + $value[7]);
            $checksum += 9 * ($value[2] + $value[5]);

            if ($value[8] !== $checksum % 10) {
                $this->error(self::NO_MATCH);

                return false;
            }
        }

        return true;
    }
32986
public function validate($object, ValidatorContextInterface $context = null, string $path = '')
    {
        $context = $context ?? ValidatorContextBuilder::create()->getContext();

        $class = is_object($object) ? get_class($object) : $object;

        $objectMapping = $this->getObjectMapping($class);

        $errors = [];
        foreach ($this->validateClass(
            $context,
            $objectMapping->getValidationClassMapping($path),
            $path,
            $object
        ) as $classError) {
            $errors[] = $classError;
        }

        foreach ($objectMapping->getValidationPropertyMappings($path) as $propertyMapping) {
            foreach ($this->validateProperty($context, $propertyMapping, $path, $object) as $propertyError) {
                $errors[] = $propertyError;
            }
        }

        return $errors;
    }
204813
protected function validate_contextid($value) {
        $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');
        }
        return true;
    }
46405
protected function validateType($value)
    {
        if (!$value instanceof Closure && $value !== null) {
            $exception = new InvalidTypeException(sprintf(
                'Invalid type for path "%s". Expected closure, but got %s.',
                $this->getPath(),
                gettype($value)
            ));

            if ($hint = $this->getInfo()) {
                $exception->addHint($hint);
            }

            $exception->setPath($this->getPath());

            throw $exception;
        }
    }
938109
public static function execute($value, ContextInterface $context): array
    {
        $from = new DateTime('tomorrow');
        $to   = new DateTime('+5 days');

        $isValidDeliveryDate = $value instanceof DateTimeInterface === true && $value >= $from && $value <= $to;

        return $isValidDeliveryDate === true ?
            static::createSuccessReply($value) :
            static::createErrorReply(
                $context,
                $value,
                Errors::IS_DELIVERY_DATE,
                static::MESSAGE_TEMPLATE,
                [$from->getTimestamp(), $to->getTimestamp()]
            );
    }
25912
public function convert($value, string $path = '', bool $allowSerializeEmpty = false): AbstractNode
    {
        if (null === $value) {
            return NullNode::create();
        }

        $type = gettype($value);

        if (!isset($this->typeMapping[$type])) {
            throw new \InvalidArgumentException(
                sprintf('Type %s is not supported, at path %s', is_object($value) ? get_class($value) : $type, $path)
            );
        }

        $node = $this->typeMapping[$type];

        return $node::create($value, $allowSerializeEmpty);
    }
808939
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        $value = \mb_strtolower($value);
        return (\in_array($value, $this->truthy) || \in_array($value, $this->falsey));
    }
750688
protected function getErrors($value, $constraints = null, $groups = null)
    {
        /** @var ValidatorInterface $validator */
        $validator = $this->getContainer()->get(Config::getServiceName());

        return $validator->validate($value, $constraints, $groups);
    }
302318
protected function checkProperty($value, $validators)
    {
        $result = null;
        foreach ($validators as $validator) {
            if ($validator instanceof ObjectValidatorInterface) {
                $validator->setValidatedInstancesContainer($this->validatedInstancesContainer);
            }
            $currentResult = $validator->validate($value);
            if ($currentResult->hasMessages()) {
                if ($result === null) {
                    $result = $currentResult;
                } else {
                    $result->merge($currentResult);
                }
            }
        }
        return $result;
    }
861581
protected function validateCommonProperties(&$value, $schema = null, JsonPointer $path, $i = '')
    {
        // if it extends another schema, it must pass that schema as well
        if (isset($schema->extends)) {
            if (is_string($schema->extends)) {
                $schema->extends = $this->validateUri($schema, $schema->extends);
            }
            if (is_array($schema->extends)) {
                foreach ($schema->extends as $extends) {
                    $this->checkUndefined($value, $extends, $path, $i);
                }
            } else {
                $this->checkUndefined($value, $schema->extends, $path, $i);
            }
        }

        // Apply default values from schema
        if (!$path->fromDefault()) {
            $this->applyDefaultValues($value, $schema, $path);
        }

        // Verify required values
        if ($this->getTypeCheck()->isObject($value)) {
            if (!($value instanceof self) && isset($schema->required) && is_array($schema->required)) {
                // Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
                foreach ($schema->required as $required) {
                    if (!$this->getTypeCheck()->propertyExists($value, $required)) {
                        $this->addError(
                            ConstraintError::REQUIRED(),
                            $this->incrementPath($path ?: new JsonPointer(''), $required), array(
                                'property' => $required
                            )
                        );
                    }
                }
            } elseif (isset($schema->required) && !is_array($schema->required)) {
                // Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
                if ($schema->required && $value instanceof self) {
                    $propertyPaths = $path->getPropertyPaths();
                    $propertyName = end($propertyPaths);
                    $this->addError(ConstraintError::REQUIRED(), $path, array('property' => $propertyName));
                }
            } else {
                // if the value is both undefined and not required, skip remaining checks
                // in this method which assume an actual, defined instance when validating.
                if ($value instanceof self) {
                    return;
                }
            }
        }

        // Verify type
        if (!($value instanceof self)) {
            $this->checkType($value, $schema, $path, $i);
        }

        // Verify disallowed items
        if (isset($schema->disallow)) {
            $initErrors = $this->getErrors();

            $typeSchema = new \stdClass();
            $typeSchema->type = $schema->disallow;
            $this->checkType($value, $typeSchema, $path);

            // if no new errors were raised it must be a disallowed value
            if (count($this->getErrors()) == count($initErrors)) {
                $this->addError(ConstraintError::DISALLOW(), $path);
            } else {
                $this->errors = $initErrors;
            }
        }

        if (isset($schema->not)) {
            $initErrors = $this->getErrors();
            $this->checkUndefined($value, $schema->not, $path, $i);

            // if no new errors were raised then the instance validated against the "not" schema
            if (count($this->getErrors()) == count($initErrors)) {
                $this->addError(ConstraintError::NOT(), $path);
            } else {
                $this->errors = $initErrors;
            }
        }

        // Verify that dependencies are met
        if (isset($schema->dependencies) && $this->getTypeCheck()->isObject($value)) {
            $this->validateDependencies($value, $schema->dependencies, $path);
        }
    }