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

Breadcrumb

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

function ClassMapGenerator::createMap

Same name in this branch
  1. 11.1.x vendor/composer/class-map-generator/src/ClassMapGenerator.php \Composer\ClassMapGenerator\ClassMapGenerator::createMap()

Iterate over all files in the given directory searching for classes

Parameters

\Traversable<\SplFileInfo>|string|array<\SplFileInfo> $path The path to search in or an iterator:

non-empty-string|null $excluded Regex that matches file paths to be excluded from the classmap:

?IOInterface $io IO object:

null|string $namespace Optional namespace prefix to filter by:

null|'psr-0'|'psr-4'|'classmap' $autoloadType psr-0|psr-4 Optional autoload standard to use mapping rules:

array<non-empty-string, true> $scannedFiles:

Return value

array<class-string, non-empty-string> A class map array

Throws

\RuntimeException When the path is neither an existing file nor directory

1 call to ClassMapGenerator::createMap()
ClassMapGenerator::dump in vendor/composer/composer/src/Composer/Autoload/ClassMapGenerator.php
Generate a class map file

File

vendor/composer/composer/src/Composer/Autoload/ClassMapGenerator.php, line 63

Class

ClassMapGenerator
ClassMapGenerator

Namespace

Composer\Autoload

Code

public static function createMap($path, ?string $excluded = null, ?IOInterface $io = null, ?string $namespace = null, ?string $autoloadType = null, array &$scannedFiles = []) : array {
    $generator = new \Composer\ClassMapGenerator\ClassMapGenerator([
        'php',
        'inc',
        'hh',
    ]);
    $fileList = new FileList();
    $fileList->files = $scannedFiles;
    $generator->avoidDuplicateScans($fileList);
    $generator->scanPaths($path, $excluded, $autoloadType ?? 'classmap', $namespace);
    $classMap = $generator->getClassMap();
    $scannedFiles = $fileList->files;
    if ($io !== null) {
        foreach ($classMap->getPsrViolations() as $msg) {
            $io->writeError("<warning>{$msg}</warning>");
        }
        foreach ($classMap->getAmbiguousClasses() as $class => $paths) {
            if (count($paths) > 1) {
                $io->writeError('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found ' . (count($paths) + 1) . 'x: in "' . $classMap->getClassPath($class) . '" and "' . implode('", "', $paths) . '", the first will be used.</warning>');
            }
            else {
                $io->writeError('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $classMap->getClassPath($class) . '" and "' . implode('", "', $paths) . '", the first will be used.</warning>');
            }
        }
    }
    return $classMap->getMap();
}

API Navigation

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