You are here

function _configuration_array_look_ahead in Configuration Management 6

Helper function to filter/modify matches by a look ahead

TODO: Support more functions and in a proper manner besides not() manually here

1 call to _configuration_array_look_ahead()
configuration_fetch in ./configuration.module
Find parts of an array based on a semi-compatible xpath syntax.

File

./configuration.module, line 1779
Provide a unified method for defining site configurations abstracted from their data format. Various data formats should be supported via a plugin architecture such as XML, YAML, JSON, PHP

Code

function _configuration_array_look_ahead(&$matches, $ahead, $token) {
  if (preg_match('/(.*?)\\((.*?)\\)/', $ahead, $m)) {
    switch (strtolower($m[1])) {
      case 'not':
        $not = true;
        $ahead = $m[2];
        break;
    }
  }
  if (is_numeric($ahead)) {
    if (isset($matches[$ahead])) {
      $matches = array(
        &$matches[$ahead],
      );
    }
    else {
      $matches = array();
    }
  }
  else {
    for ($i = count($matches) - 1; isset($matches[$i]); $i--) {
      $exist = false;
      if (configuration_fetch($ahead, $matches[$i])) {
        $exist = true;
      }
      if ($exist && $not || !$exist && !$not) {
        array_splice($matches, $i, 1);
      }
    }
  }
}