Condition::matchArray

protected Condition::matchArray(array $condition, array $data, array $needs_matching, array $parents = array())

Matches for an array representing one or more config paths.

Parameters

array $condition: The condition array as created by the condition() method.

array $data: The config array or part of it.

array $needs_matching: The list of config array keys needing a match. Can contain config keys and the * wildcard.

array $parents: The current list of parents.

Return value

bool TRUE when the condition matched to the data else FALSE.

File

core/lib/Drupal/Core/Config/Entity/Query/Condition.php, line 113

Class

Condition
Defines the condition class for the config entity query.

Namespace

Drupal\Core\Config\Entity\Query

Code

protected function matchArray(array $condition, array $data, array $needs_matching, array $parents = array()) {
  $parent = array_shift($needs_matching);
  if ($parent === '*') {
    $candidates = array_keys($data);
  }
  else {
    // Avoid a notice when calling match() later.
    if (!isset($data[$parent])) {
      $data[$parent] = NULL;
    }
    $candidates = array($parent);
  }
  foreach ($candidates as $key) {
    if ($needs_matching) {
      if (is_array($data[$key])) {
        $new_parents = $parents;
        $new_parents[] = $key;
        if ($this->matchArray($condition, $data[$key], $needs_matching, $new_parents)) {
          return TRUE;
        }
      }
    }
    // Only try to match a scalar if there are no remaining keys in
    // $needs_matching as this indicates that we are looking for a specific
    // subkey and a scalar can never match that.
    elseif ($this->match($condition, $data[$key])) {
      return TRUE;
    }
  }
  return FALSE;
}
doc_Drupal
2016-10-29 08:51:50
Comments
Leave a Comment

Please login to continue.