You are here

protected static function GoogleAdwordsPathTracker::_matchPath_recursive in Google AdWords Conversion Tracking 8

Navigate down the path tree to try to match the path to a node in the tree

Parameters

array $tree:

array $path:

Return value

array configs that match the path

1 call to GoogleAdwordsPathTracker::_matchPath_recursive()
GoogleAdwordsPathTracker::matchPath in modules/google_adwords_path/src/GoogleAdwordsPathTracker.php
Try to match a single path to PathCongifs

File

modules/google_adwords_path/src/GoogleAdwordsPathTracker.php, line 257
Contains Drupal\google_adwords_path\GoogleAdwordsPathTracker.

Class

GoogleAdwordsPathTracker
Class GoogleAdwordsPathTracker.

Namespace

Drupal\google_adwords_path

Code

protected static function _matchPath_recursive(array $tree, array $path) {
  if (count($path) === 0) {
    if (isset($tree[static::GOOGLE_ADWORDS_PATH_TREE_NODEKEY])) {
      return $tree[static::GOOGLE_ADWORDS_PATH_TREE_NODEKEY];
    }
    return [];
  }
  else {

    /**
     * @var string $pathElement
     *   a single element of the path
     */
    $pathElement = '';
    while (empty($pathElement)) {
      if (count($path) == 0) {
        break;
      }
      $pathElement = array_shift($path);
    }
    if (isset($tree[static::GOOGLE_ADWORDS_PATH_TREE_WILDCARD])) {

      // we found a wildcard path, so it takes everything
      return static::_matchPath_recursive($tree[static::GOOGLE_ADWORDS_PATH_TREE_WILDCARD], []);
    }
    else {
      if (isset($tree[$pathElement])) {

        // we found a matching element
        return static::_matchPath_recursive($tree[$pathElement], $path);
      }
      else {

        // no match
        return [];
      }
    }
  }
}