You are here

protected function xautoload_RegistryWildcard_RecursiveScan::validateCandidate in X Autoload 7.3

Parameters

$candidate: String to be checked against the wildcard.

$wildcard: Wildcard string like '*', '*.*' or '*.inc'.

Return value

bool TRUE, if $candidate matches $wildcard.

1 call to xautoload_RegistryWildcard_RecursiveScan::validateCandidate()
xautoload_RegistryWildcard_RecursiveScan::scanDirectoryLevel in lib/RegistryWildcard/RecursiveScan.php

File

lib/RegistryWildcard/RecursiveScan.php, line 142

Class

xautoload_RegistryWildcard_RecursiveScan
Scan directories for wildcard files[] instructions in a module's info file.

Code

protected function validateCandidate($candidate, $wildcard) {
  if ($candidate == '.' || $candidate == '..') {
    return FALSE;
  }
  if (strpos($candidate, '*') !== FALSE) {
    return FALSE;
  }
  if ($wildcard == '*' || $wildcard == '**') {
    return TRUE;
  }

  // More complex wildcard string.
  $fragments = array();
  foreach (explode('*', $wildcard) as $fragment) {
    $fragments[] = preg_quote($fragment);
  }
  $regex = implode('.*', $fragments);
  return preg_match("/^{$regex}\$/", $candidate);
}