Create a new sub-validator.

@param mixed       $data
@param object      $schema
@param string|null $dataPath
@param string|null $schemaPath

@return Validator
431468
public function makeSubSchemaValidator($data, $schema, $dataPath = null, $schemaPath = null)
    {
        $validator = new Validator($data, $schema, $this->ruleSet);

        $validator->dataPath         = $dataPath ?: $this->dataPath;
        $validator->baseSchemaPath   = $schemaPath ?: $this->getSchemaPath();
        $validator->maxDepth         = $this->maxDepth;
        $validator->depth            = $this->depth + 1;

        return $validator;
    }
57010
function validateData(data, schema, fn) {
        debug('Schema:', schema);
        debug('Data:', data);

        if (!tv4.validate(data, schema)) {
            return fn(tv4.error);
        }

        return fn(null, true);
    }
175497
protected function validateString(/** @noinspection PhpUnusedParameterInspection */
        &$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag): bool
    {
        $ok = true;

        // minLength
        if (property_exists($schema, 'minLength')) {
            if (!is_int($schema->minLength)) {
                throw new SchemaKeywordException(
                    $schema,
                    'minLength',
                    $schema->minLength,
                    "'minLength' keyword must be an integer, " . gettype($schema->minLength) . " given"
                );
            }
            if ($schema->minLength < 0) {
                throw new SchemaKeywordException(
                    $schema,
                    'minLength',
                    $schema->minLength,
                    "'minLength' keyword must be positive, " . $schema->minLength . " given"
                );
            }
            $len = $this->helper->stringLength($data);
            if ($len < $schema->minLength) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'minLength', [
                    'min' => $schema->minLength,
                    'length' => $len,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
            unset($len);
        }

        // maxLength
        if (property_exists($schema, 'maxLength')) {
            if (!is_int($schema->maxLength)) {
                throw new SchemaKeywordException(
                    $schema,
                    'maxLength',
                    $schema->maxLength,
                    "'maxLength' keyword must be an integer, " . gettype($schema->maxLength) . " given"
                );
            }
            if ($schema->maxLength < 0) {
                throw new SchemaKeywordException(
                    $schema,
                    'maxLength',
                    $schema->maxLength,
                    "'maxLength' keyword must be positive, " . $schema->maxLength . " given"
                );
            }
            $len = $this->helper->stringLength($data);
            if ($len > $schema->maxLength) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'maxLength', [
                    'max' => $schema->maxLength,
                    'length' => $len,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
            unset($len);
        }

        // pattern
        if (property_exists($schema, 'pattern')) {
            if (!is_string($schema->pattern)) {
                throw new SchemaKeywordException(
                    $schema,
                    'pattern',
                    $schema->pattern,
                    "'pattern' keyword must be a string, " . gettype($schema->pattern) . " given"
                );
            }
            if ($schema->pattern === '') {
                throw new SchemaKeywordException(
                    $schema,
                    'pattern',
                    $schema->pattern,
                    "'pattern' keyword must not be empty"
                );
            }
            $match = @preg_match(self::BELL . $schema->pattern . self::BELL . 'u', $data);
            if ($match === false) {
                throw new SchemaKeywordException(
                    $schema,
                    'pattern',
                    $schema->pattern,
                    "'pattern' keyword must be a valid regex"
                );
            }
            if (!$match) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'pattern', [
                    'pattern' => $schema->pattern,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        // content encoding
        if (property_exists($schema, 'contentEncoding')) {
            if (!is_string($schema->contentEncoding)) {
                throw new SchemaKeywordException(
                    $schema,
                    'contentEncoding',
                    $schema->contentEncoding,
                    "'contentEncoding' keyword must be a string, " . gettype($schema->contentEncoding) . " given"
                );
            }

            switch ($schema->contentEncoding) {
                case "binary":
                    $decoded = $data;
                    break;
                case "base64":
                    $decoded = base64_decode($data, true);
                    break;
                default:
                    $decoded = false;
                    break;
            }

            if ($decoded === false) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'contentEncoding', [
                    'encoding' => $schema->contentEncoding,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        // media type
        if (property_exists($schema, 'contentMediaType')) {
            if (!is_string($schema->contentMediaType)) {
                throw new SchemaKeywordException(
                    $schema,
                    'contentMediaType',
                    $schema->contentMediaType,
                    "'contentMediaType' keyword must be a string, " . gettype($schema->contentMediaType) . " given"
                );
            }

            if (!$this->mediaTypes) {
                throw new UnknownMediaTypeException($schema, $schema->contentMediaType);
            }

            if (!isset($decoded)) {
                // is set in contentEncoding if any
                $decoded = $data;
            }

            $valid = false;

            if ($decoded !== false) {
                $media = $this->mediaTypes->resolve($schema->contentMediaType);
                if ($media === null) {
                    throw new UnknownMediaTypeException($schema, $schema->contentMediaType);
                } else {
                    $valid = $media->validate($decoded, $schema->contentMediaType);
                }
            }

            if (!$valid) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'contentMediaType', [
                    'media' => $schema->contentMediaType,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        return $ok;
    }
919024
function validationPlugin(Schema) {
    var constructor = Schema.prototype.constructor;

    Schema.prototype.constructor = function (name, schema) {
        var key;
        var fieldDefinition;

        if (arguments.length === 1) {
            schema = arguments[0];
        }

        // call super constructor
        constructor.apply(this, arguments);

        this.validators = {};

        for (key in schema) {
            if (schema.hasOwnProperty(key)) {
                fieldDefinition = schema[key];
                this.validators[key] = [];

                // predefined validators
                if (fieldDefinition.required) {
                    this.validators[key].push(defaultValidators.required());
                }
                if (value(fieldDefinition.enum).typeOf(Array)) {
                    this.validators[key].push(defaultValidators.enum(fieldDefinition.enum));
                }

                if (value(fieldDefinition.min).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.min(fieldDefinition.min));
                }

                if (value(fieldDefinition.max).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.max(fieldDefinition.max));
                }

                if (value(fieldDefinition.minLength).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.minLength(fieldDefinition.minLength));
                }

                if (value(fieldDefinition.maxLength).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.maxLength(fieldDefinition.maxLength));
                }

                if (value(fieldDefinition.hasLength).typeOf(Number)) {
                    this.validators[key].push(defaultValidators.hasLength(fieldDefinition.hasLength));
                }

                // The matches validators works on all types, so we just check if the key is present
                if ("matches" in fieldDefinition) {
                    this.validators[key].push(defaultValidators.matches(fieldDefinition.matches));
                }

                // custom validators
                if (value(fieldDefinition.validate).typeOf(Function)) {
                    this.validators[key].push(fieldDefinition.validate);
                } else if (value(fieldDefinition.validate).typeOf(Array)) {
                    this.validators[key] = this.validators[key].concat(fieldDefinition.validate);
                }
            }
        }
    };

    /**
     * Validate if given model matches schema definition. Returns a promise with the validation result object
     * which contains the intermediate result of all synchronous validators.
     *
     * @param {Object} model
     * @param {Function=} callback
     * @returns {Promise}
     */
    Schema.prototype.validate = function (model, callback) {
        var self = this;
        var pending = 0;
        var result = {
            model: model,
            result: true,
            errors: {}
        };
        var promise;

        function handleFieldErrors(key, fieldErrors) {
            if (fieldErrors.length > 0) {
                result.result = false;
                result.errors[key] = fieldErrors;
            }
        }

        function doCallback() {
            callback(result);
        }

        if (value(model).notTypeOf(Object)) {
            throw new TypeError("Model must be an object");
        }

        if (!this.validators) {
            throw new Error("Validators not defined: Have you registered the validate plugin before any schema definitions?");
        }

        promise = new Promise(function (resolve) {
            function done() {
                if (typeof callback === "function") {
                    setTimeout(doCallback, 0);
                }
                resolve(result);
            }

            if (self.fields.length === 0) {
                done();
                return;
            }

            pending = self.fields.length;

            self.fields.forEach(function (key) {
                var fieldErrors = runValidation(self.validators[key], model[key], model, function onFieldValidation(fieldErrors) {
                    pending--;
                    handleFieldErrors(key, fieldErrors);

                    if (pending === 0) {
                        done();
                    }
                });

                handleFieldErrors(key, fieldErrors);
            });
        });
        // Attach intermediate result to promise
        promise.validation = result;

        return promise;
    };
}
1055544
private function validate($id, $data): \JsonSchema\Validator
    {
        $modelData = [
            'id' => $id,
            'fields' => $data
        ];

        $validator = new \JsonSchema\Validator();
        $validator->validate($modelData, $this->model->jsonSchema(), Constraint::CHECK_MODE_TYPE_CAST|Constraint::CHECK_MODE_COERCE_TYPES);

        return $validator;
    }
705556
public static function validar($xml, $schemaFile)
    {
        //Para poder pegar os erros caso houver
        libxml_use_internal_errors(true);
        libxml_clear_errors();

        if (is_file($xml)) {
            $xml = file_get_contents($xml);
        }

        $dom = new DOMDocument('1.0', 'utf-8');

        $dom->loadXML($xml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);

        if (! $dom->schemaValidate($schemaFile)) {
            $errors = libxml_get_errors();
            $returnErrors = [];
            foreach ($errors as $error) {
                $returnErrors[] = $error->message . 'at line ' . $error->line;
            }

            $msg = "Erro ao validar XML:\r\n" . implode("\r\n", $returnErrors);

            throw new \Exception($msg);
        }

        return true;
    }
339375
public function raw(array $schema, array $data)
    {
        $errors = new Collection();

        if (count($schema) !== 0) {
            $validator = IlluminateValidator::make($data, $schema);

            foreach ($validator->errors()->getMessages() as $key => $error) {
                $errors[] = new Exceptions\DataBuilderInputException($key, $error[0], isset($data[$key]) ? $data[$key] : null);
            }
        }

        return $errors;
    }
915424
public function validate($schemaFile) {
        if (!$this->xmlString)
            throw new XmlParserException("attempting to validate before parsing");
            
        if (!extension_loaded("DOM")) {
            trigger_error("DOM extension not loaded, will not validate XML", E_USER_NOTICE);
            return $this;
        }

        libxml_use_internal_errors(true);
        $document = new \DOMDocument();
        $document->loadXML($this->xmlString);
        
        if (!$document->schemaValidate($schemaFile)) {
            $msg = "The following XML errors occurred while validating:";
            foreach (libxml_get_errors() as $error)
                $msg .= "\n" . $error->message;
            throw new XmlParserException($msg);
        }

        return $this;
    }
567749
public function validateSchema($schema = self::STRICT_SCHEMA)
    {
        $content = file_get_contents($this->path);
        $data = json_decode($content);

        if (null === $data && 'null' !== $content) {
            self::validateSyntax($content, $this->path);
        }

        $schemaFile = __DIR__ . '/../../../res/composer-schema.json';
        $schemaData = json_decode(file_get_contents($schemaFile));

        if ($schema === self::LAX_SCHEMA) {
            $schemaData->additionalProperties = true;
            $schemaData->required = array();
        }

        $validator = new Validator();
        $validator->check($data, $schemaData);

        // TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?

        if (!$validator->isValid()) {
            $errors = array();
            foreach ((array) $validator->getErrors() as $error) {
                $errors[] = ($error['property'] ? $error['property'].' : ' : '').$error['message'];
            }
            throw new JsonValidationException('"'.$this->path.'" does not match the expected JSON schema', $errors);
        }

        return true;
    }
909699
public void validate(final Node document) throws SchemaValidationException
	{
		try
		{
			final Validator validator = schema.newValidator();

			validator.validate(new DOMSource(document));
		}
		catch (SAXException | IOException e)
		{
			throw new SchemaValidationException(e.getMessage(), e);
		}
	}
333931
protected function checkExclusiveMinimum($entity, $schema, $entityName)
    {
        if (isset($schema->minimum) && isset($schema->exclusiveMinimum) && $schema->exclusiveMinimum) {
            if ($entity == $schema->minimum) {
                throw new ValidationException(sprintf('Invalid value for [%s], must be greater than [%s]', $entityName, $schema->minimum));
            }
        }

        return $this;
    }
1374334
public function create($schema, $meta)
    {
        $up = $this->createSchemaForUpMethod($schema, $meta);
        $down = $this->createSchemaForDownMethod($schema, $meta);

        return compact('up', 'down');
    }
652478
protected function checkMinimum($entity, $schema, $entityName)
    {
        if (isset($schema->minimum)) {
            if ($entity < $schema->minimum) {
                throw new ValidationException(sprintf('Invalid value for [%s], minimum is [%s]', $entityName, $schema->minimum));
            }
        }

        return $this;
    }
618994
private function validateExcessiveKeys(AbstractValidator $validator, CustomArrayObject $schema, $nodeData = null)
    {
        if ($this->strictMode === false) {
            return;
        }

        if (!$validator->isNested()) {
            $this->validateExcessiveKeysAbsent($schema, $nodeData);
        } else {
            foreach ($nodeData as $record) {
                $this->validateExcessiveKeysAbsent($schema, $record);
            }
        }
    }
537017
protected function checkTypeObject($entity, $schema, $entityName)
    {
        $this->validateProperties($entity, $schema, $entityName);

        return $this;
    }
1167967
protected function validateSchemaType(LdapObjectSchema $schema, array $schemaArray)
    {
        if (!((bool)count(array_filter(array_keys($schemaArray['attributes']), 'is_string')))) {
            throw new SchemaParserException('The attributes for a schema should be an associative array.');
        }
        if ($schema->getScope() && !in_array($schema->getScope(), QueryOperation::SCOPE)) {
            throw new SchemaParserException(sprintf(
                'The scope "%s" is not valid. Valid types are: %s',
                $schema->getScope(),
                implode(', ', QueryOperation::SCOPE)
            ));
        }
    }
293731
protected function validateFilters(/** @noinspection PhpUnusedParameterInspection */
        &$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag): bool
    {
        if (!property_exists($schema, Schema::FILTERS_PROP) || !$this->filters) {
            return true;
        }

        /** @var array $filters */
        $filters = null;
        if (is_string($schema->{Schema::FILTERS_PROP})) {
            $filters = [(object)[Schema::FUNC_NAME => $schema->{Schema::FILTERS_PROP}]];
        }
        elseif (is_object($schema->{Schema::FILTERS_PROP})) {
            $filters = [$schema->{Schema::FILTERS_PROP}];
        } elseif (is_array($schema->{Schema::FILTERS_PROP})) {
            $filters = $schema->{Schema::FILTERS_PROP};
            if (count($filters) === 0) {
                return true;
            }
            foreach ($filters as &$filter) {
                if (is_string($filter)) {
                    $filter = (object)[Schema::FUNC_NAME => $filter];
                }
            }
            unset($filter);
        } else {
            throw new SchemaKeywordException(
                $schema,
                Schema::FILTERS_PROP,
                $schema->{Schema::FILTERS_PROP},
                "'" . Schema::FILTERS_PROP . "' keyword must be a string, an object or an array of objects, " . gettype($schema->{Schema::FILTERS_PROP}) . " given"
            );
        }

        $type = $this->helper->type($data, true);
        $filter_name = null;
        $valid = true;
        foreach ($filters as $filter) {
            if (!is_object($filter)) {
                throw new SchemaKeywordException(
                    $schema,
                    Schema::FILTERS_PROP,
                    $schema->{Schema::FILTERS_PROP},
                    "'" . Schema::FILTERS_PROP . "' keyword must be a string, an object or an array of objects, found " . gettype($filter)
                );
            }
            if (!property_exists($filter, Schema::FUNC_NAME)) {
                throw new SchemaKeywordException(
                    $filter,
                    Schema::FUNC_NAME,
                    null,
                    "'" . Schema::FUNC_NAME . "' keyword is required"
                );
            }
            if (!is_string($filter->{Schema::FUNC_NAME})) {
                throw new SchemaKeywordException(
                    $filter,
                    Schema::FUNC_NAME,
                    $filter->{Schema::FUNC_NAME},
                    "'" . Schema::FUNC_NAME . "' keyword must be a string, " . gettype($filter->{Schema::FUNC_NAME}) . " given"
                );
            }

            $filterObj = $this->filters->get($type, $filter->{Schema::FUNC_NAME});
            if ($filterObj === null) {
                if ($type === 'integer') {
                    $filterObj = $this->filters->get('number', $filter->{Schema::FUNC_NAME});
                    if ($filterObj === null) {
                        throw new FilterNotFoundException($type, $filter->{Schema::FUNC_NAME});
                    }
                } else {
                    throw new FilterNotFoundException($type, $filter->{Schema::FUNC_NAME});
                }
            }

            if (property_exists($filter, Schema::VARS_PROP)) {
                if (!is_object($filter->{Schema::VARS_PROP})) {
                    throw new SchemaKeywordException(
                        $filter,
                        Schema::VARS_PROP,
                        $filter->{Schema::VARS_PROP},
                        "'" . Schema::VARS_PROP . "' keyword must be an object, " . gettype($filter->{Schema::VARS_PROP}) . " given"
                    );
                }
                $vars = $this->deepClone($filter->{Schema::VARS_PROP});
                $this->resolveVars($vars, $document_data, $data_pointer);
                $vars = (array)$vars;
                if ($this->globalVars) {
                    $vars += $this->globalVars;
                }
            } else {
                $vars = $this->globalVars;
            }

            if (!$filterObj->validate($data, $vars)) {
                $valid = false;
                $filter_name = $filter->{Schema::FUNC_NAME};
                break;
            }

            unset($vars, $filterObj);
        }

        if (!$valid) {
            $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, Schema::FILTERS_PROP, [
                'type' => $type,
                'filter' => $filter_name,
            ]));
            return false;
        }

        return true;
    }