Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Validator.php

class Validator

Same name in this branch
  1. 11.1.x vendor/ramsey/uuid/src/Rfc4122/Validator.php \Ramsey\Uuid\Rfc4122\Validator
  2. 11.1.x vendor/phpunit/phpunit/src/TextUI/Configuration/Xml/Validator/Validator.php \PHPUnit\TextUI\XmlConfiguration\Validator

A JsonSchema Constraint

@author Robert Schönthal <seroscho@googlemail.com> @author Bruno Prieto Reis <bruno.p.reis@gmail.com>

Hierarchy

  • class \JsonSchema\Constraints\BaseConstraint
    • class \JsonSchema\Validator extends \JsonSchema\Constraints\BaseConstraint

Expanded class hierarchy of Validator

See also

README.md

10 files declare their use of Validator
BaseConstraint.php in vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/BaseConstraint.php
ComponentValidator.php in core/lib/Drupal/Core/Theme/Component/ComponentValidator.php
Curl.php in vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/Curl.php
Factory.php in vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php
IconPackManager.php in core/lib/Drupal/Core/Theme/Icon/Plugin/IconPackManager.php

... See full list

6 string references to 'Validator'
ArgumentPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
Provide a form to edit options for this plugin.
Constraint::validatedBy in vendor/symfony/validator/Constraint.php
Returns the name of the class that validates this constraint.
ExpressionSyntax::validatedBy in vendor/symfony/validator/Constraints/ExpressionSyntax.php
Returns the name of the class that validates this constraint.
ValidatorDataCollector::getName in vendor/symfony/validator/DataCollector/ValidatorDataCollector.php
Returns the name of the collector.
views.data_types.schema.yml in core/modules/views/config/schema/views.data_types.schema.yml
core/modules/views/config/schema/views.data_types.schema.yml

... See full list

File

vendor/justinrainbow/json-schema/src/JsonSchema/Validator.php, line 23

Namespace

JsonSchema
View source
class Validator extends BaseConstraint {
    const SCHEMA_MEDIA_TYPE = 'application/schema+json';
    const ERROR_NONE = 0x0;
    const ERROR_ALL = 0xffffffff;
    const ERROR_DOCUMENT_VALIDATION = 0x1;
    const ERROR_SCHEMA_VALIDATION = 0x2;
    
    /**
     * 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.
     */
    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();
    }
    
    /**
     * Alias to validate(), to maintain backwards-compatibility with the previous API
     */
    public function check($value, $schema) {
        return $this->validate($value, $schema);
    }
    
    /**
     * Alias to validate(), to maintain backwards-compatibility with the previous API
     */
    public function coerce(&$value, $schema) {
        return $this->validate($value, $schema, Constraint::CHECK_MODE_COERCE_TYPES);
    }

}

Members

Title Sort descending Modifiers Object type Summary
BaseConstraint::$errorMask protected property
BaseConstraint::$errors protected property
BaseConstraint::$factory protected property
BaseConstraint::addError public function
BaseConstraint::addErrors public function
BaseConstraint::arrayToObjectRecursive public static function Recursively cast an associative array to an object
BaseConstraint::getErrorMask public function Get the error mask
BaseConstraint::getErrors public function
BaseConstraint::isValid public function
BaseConstraint::numErrors public function
BaseConstraint::reset public function Clears any reported errors. Should be used between
multiple validation checks.
BaseConstraint::__construct public function
Validator::check public function Alias to validate(), to maintain backwards-compatibility with the previous API
Validator::coerce public function Alias to validate(), to maintain backwards-compatibility with the previous API
Validator::ERROR_ALL constant
Validator::ERROR_DOCUMENT_VALIDATION constant
Validator::ERROR_NONE constant
Validator::ERROR_SCHEMA_VALIDATION constant
Validator::SCHEMA_MEDIA_TYPE constant
Validator::validate public function 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…
RSS feed
Powered by Drupal