src/Schema.php
public function validate($data, $options = []) {
        if (is_bool($options)) {
            trigger_error('The $sparse parameter is deprecated. Use [\'sparse\' => true] instead.', E_USER_DEPRECATED);
            $options = ['sparse' => true];
        }
        $options += ['sparse' => false];


        list($schema, $schemaPath) = $this->lookupSchema($this->schema, '');
        $field = new ValidationField($this->createValidation(), $schema, '', $schemaPath, $options);

        $clean = $this->validateField($data, $field);

        if (Invalid::isInvalid($clean) && $field->isValid()) {
            // This really shouldn't happen, but we want to protect against seeing the invalid object.
            $field->addError('invalid', ['messageCode' => 'The value is invalid.']);
        }

        if (!$field->getValidation()->isValid()) {
            throw new ValidationException($field->getValidation());
        }

        return $clean;
    }
public function validate($data, $options = []) {
        if (is_bool($options)) {
            trigger_error('The $sparse parameter is deprecated. Use [\'sparse\' => true] instead.', E_USER_DEPRECATED);
            $options = ['sparse' => true];
        }
        $options += ['sparse' => false];


        list($schema, $schemaPath) = $this->lookupSchema($this->schema, '');
        $field = new ValidationField($this->createValidation(), $schema, '', $schemaPath, $options);

        $clean = $this->validateField($data, $field);

        if (Invalid::isInvalid($clean) && $field->isValid()) {
            // This really shouldn't happen, but we want to protect against seeing the invalid object.
            $field->addError('invalid', ['messageCode' => 'The value is invalid.']);
        }

        if (!$field->getValidation()->isValid()) {
            throw new ValidationException($field->getValidation());
        }

        return $clean;
    }
public function validate ( $ data , $ options = [ ] ) { if ( is_bool ( $ options ) ) { trigger_error ( 'The $sparse parameter is deprecated. Use [\'sparse\' => true] instead.' , E_USER_DEPRECATED ) ; $ options = [ 'sparse' => true ] ; } $ options += [ 'sparse' => false ] ; list ( $ schema , $ schemaPath ) = $ this -> lookupSchema ( $ this -> schema , '' ) ; $ field = new ValidationField ( $ this -> createValidation ( ) , $ schema , '' , $ schemaPath , $ options ) ; $ clean = $ this -> validateField ( $ data , $ field ) ; if ( Invalid :: isInvalid ( $ clean ) && $ field -> isValid ( ) ) { // This really shouldn't happen, but we want to protect against seeing the invalid object. $ field -> addError ( 'invalid' , [ 'messageCode' => 'The value is invalid.' ] ) ; } if ( ! $ field -> getValidation ( ) -> isValid ( ) ) { throw new ValidationException ( $ field -> getValidation ( ) ) ; } return $ clean ; }
Validate data against the schema.

@param mixed $data The data to validate.
@param array $options Validation options.

- **sparse**: Whether or not this is a sparse validation.
@return mixed Returns a cleaned version of the data.
@throws ValidationException Throws an exception when the data does not validate against the schema.
@throws RefNotFoundException Throws an exception when a schema `$ref` is not found.
Validate data against the schema .