You are here

private static function PathChecker::duplicateCheck in Optimizely 8

Same name and namespace in other branches
  1. 8.0 src/PathChecker.php \Drupal\optimizely\PathChecker::duplicateCheck()

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/PathChecker.php
Compare target path against the project paths to confirm they're unique.

File

src/PathChecker.php, line 261

Class

PathChecker
Provides static methods to check path validity, etc.

Namespace

Drupal\optimizely

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;
}