function Validator::validate
Same name in this branch
- 11.1.x vendor/ramsey/uuid/src/Rfc4122/Validator.php \Ramsey\Uuid\Rfc4122\Validator::validate()
- 11.1.x vendor/phpunit/phpunit/src/TextUI/Configuration/Xml/Validator/Validator.php \PHPUnit\TextUI\XmlConfiguration\Validator::validate()
Validates the given data against the schema and returns an object containing the results Both the php object and the schema are supposed to be a result of a json_decode call. The validation works as defined by the schema proposal in http://json-schema.org.
Note that the first argument is passed by reference, so you must pass in a variable.
2 calls to Validator::validate()
- Validator::check in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Validator.php - Alias to validate(), to maintain backwards-compatibility with the previous API
- Validator::coerce in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Validator.php - Alias to validate(), to maintain backwards-compatibility with the previous API
File
-
vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Validator.php, line 39
Class
- Validator
- A JsonSchema Constraint
Namespace
JsonSchemaCode
public function validate(&$value, $schema = null, $checkMode = null) {
// make sure $schema is an object
if (is_array($schema)) {
$schema = self::arrayToObjectRecursive($schema);
}
// set checkMode
$initialCheckMode = $this->factory
->getConfig();
if ($checkMode !== null) {
$this->factory
->setConfig($checkMode);
}
// add provided schema to SchemaStorage with internal URI to allow internal $ref resolution
if (is_object($schema) && property_exists($schema, 'id')) {
$schemaURI = $schema->id;
}
else {
$schemaURI = SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI;
}
$this->factory
->getSchemaStorage()
->addSchema($schemaURI, $schema);
$validator = $this->factory
->createInstanceFor('schema');
$validator->check($value, $this->factory
->getSchemaStorage()
->getSchema($schemaURI));
$this->factory
->setConfig($initialCheckMode);
$this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR));
return $validator->getErrorMask();
}