PHP Class Webmozart\Json\JsonValidator

This class is a wrapper for {@link Validator} that adds exceptions and validation of schema files. A few edge cases that are not handled by {@link Validator} are handled by this class.
Since: 1.0
Author: Bernhard Schussek ([email protected])
Mostrar archivo Open project: webmozart/json Class Usage Examples

Public Methods

Method Description
__construct ( JsonSchema\Validator $validator = null, JsonSchema\Uri\UriRetriever $uriRetriever = null, JsonSchema\UriResolverInterface $uriResolver = null ) JsonValidator constructor.
validate ( mixed $data, string | object | null $schema = null ) : string[] Validates JSON data against a schema.

Private Methods

Method Description
assertSchemaValid ( $schema )
loadSchema ( $file )

Method Details

__construct() public method

JsonValidator constructor.
public __construct ( JsonSchema\Validator $validator = null, JsonSchema\Uri\UriRetriever $uriRetriever = null, JsonSchema\UriResolverInterface $uriResolver = null )
$validator JsonSchema\Validator JsonSchema\Validator instance to use
$uriRetriever JsonSchema\Uri\UriRetriever The retriever for fetching JSON schemas
$uriResolver JsonSchema\UriResolverInterface The resolver for URIs

validate() public method

The schema may be passed as file path or as object returned from json_decode($schemaFile).
public validate ( mixed $data, string | object | null $schema = null ) : string[]
$data mixed The decoded JSON data
$schema string | object | null The schema file or object. If `null`, the validator will look for a `$schema` property
return string[] The errors found during validation. Returns an empty array if no errors were found