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

Breadcrumb

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

function ObjectConstraint::validatePatternProperties

1 call to ObjectConstraint::validatePatternProperties()
ObjectConstraint::check in vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php
invokes the validation of an element

File

vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php, line 54

Class

ObjectConstraint
The ObjectConstraint Constraints, validates an object against a given schema

Namespace

JsonSchema\Constraints

Code

public function validatePatternProperties($element, ?JsonPointer $path, $patternProperties) {
    $try = array(
        '/',
        '#',
        '+',
        '~',
        '%',
    );
    $matches = array();
    foreach ($patternProperties as $pregex => $schema) {
        $delimiter = '/';
        // Choose delimiter. Necessary for patterns like ^/ , otherwise you get error
        foreach ($try as $delimiter) {
            if (strpos($pregex, $delimiter) === false) {
                // safe to use
                break;
            }
        }
        // Validate the pattern before using it to test for matches
        if (@preg_match($delimiter . $pregex . $delimiter . 'u', '') === false) {
            $this->addError($path, 'The pattern "' . $pregex . '" is invalid', 'pregex', array(
                'pregex' => $pregex,
            ));
            continue;
        }
        foreach ($element as $i => $value) {
            if (preg_match($delimiter . $pregex . $delimiter . 'u', $i)) {
                $matches[] = $i;
                $this->checkUndefined($value, $schema ?: new \stdClass(), $path, $i, in_array($i, $this->appliedDefaults));
            }
        }
    }
    return $matches;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal