Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AutoloadGenerator.php

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\Autoload

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal