You are here

private static function PathChecker::duplicateCheck in Optimizely 8.3

Compare paths to ensure each item resolves to a unique entry.

Parameters

array $paths: A set of paths to be reviewed for uniqueness.

Return value

bool|array FALSE if no duplicates found, otherwise the duplicate path is returned.

1 call to PathChecker::duplicateCheck()
PathChecker::uniquePaths in src/Util/PathChecker.php
Compare target path against the project paths to confirm they're unique.

File

src/Util/PathChecker.php, line 263

Class

PathChecker
Provides static methods to check path validity, etc.

Namespace

Drupal\optimizely\Util

Code

private static function duplicateCheck(array $paths) {
  $unreviewed_paths = $paths;

  // Check all of the paths.
  foreach ($paths as $path) {

    // Remove path that's being processed from the front of the list.
    array_shift($unreviewed_paths);

    // "*" found in path.
    if (strpos($path, '*') !== FALSE) {

      // Look for wild card match that's not sitewide (position not zero (0))
      if (strpos($path, '*') !== 0) {
        $path = substr($path, 0, -2);
        foreach ($unreviewed_paths as $unreviewed_path) {
          if (strpos($unreviewed_path, $path) !== FALSE) {
            return $path . '/*';
          }
        }
      }
      elseif (strpos($path, '*') === 0 && count($paths) > 1) {
        return $path;
      }
    }
    elseif (in_array($path, $unreviewed_paths)) {
      return $path;
    }
  }
  return FALSE;
}