function AutoloadGenerator::buildExclusionRegex
Parameters
array<string> $excluded:
Return value
non-empty-string|null
2 calls to AutoloadGenerator::buildExclusionRegex()
- AutoloadGenerator::createLoader in vendor/
composer/ composer/ src/ Composer/ Autoload/ AutoloadGenerator.php - Registers an autoloader based on an autoload-map returned by parseAutoloads
- AutoloadGenerator::dump in vendor/
composer/ composer/ src/ Composer/ Autoload/ AutoloadGenerator.php
File
-
vendor/
composer/ composer/ src/ Composer/ Autoload/ AutoloadGenerator.php, line 485
Class
- AutoloadGenerator
- @author Igor Wiedler <igor@wiedler.ch> @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\AutoloadCode
private function buildExclusionRegex(string $dir, array $excluded) : ?string {
if ([] === $excluded) {
return null;
}
// filter excluded patterns here to only use those matching $dir
// exclude-from-classmap patterns are all realpath'd so we can only filter them if $dir exists so that realpath($dir) will work
// if $dir does not exist, it should anyway not find anything there so no trouble
if (file_exists($dir)) {
// transform $dir in the same way that exclude-from-classmap patterns are transformed so we can match them against each other
$dirMatch = preg_quote(strtr(realpath($dir), '\\', '/'));
foreach ($excluded as $index => $pattern) {
// extract the constant string prefix of the pattern here, until we reach a non-escaped regex special character
$pattern = Preg::replace('{^(([^.+*?\\[^\\]$(){}=!<>|:\\\\#-]+|\\\\[.+*?\\[^\\]$(){}=!<>|:#-])*).*}', '$1', $pattern);
// if the pattern is not a subset or superset of $dir, it is unrelated and we skip it
if (0 !== strpos($pattern, $dirMatch) && 0 !== strpos($dirMatch, $pattern)) {
unset($excluded[$index]);
}
}
}
return \count($excluded) > 0 ? '{(' . implode('|', $excluded) . ')}' : null;
}