composer/class-map-generator
Generate PHP class maps by scanning directories to map classes/interfaces/traits/enums to file paths. Use a simple static helper or an advanced generator to scan multiple paths, sort results, and detect ambiguous class resolutions.
Utilities to generate class maps and scan PHP code.
Install the latest version with:
composer require composer/class-map-generator
If all you want is to scan a directory and extract a classmap with all classes/interfaces/traits/enums mapped to their paths, you can simply use:
use Composer\ClassMapGenerator\ClassMapGenerator;
$map = ClassMapGenerator::createMap('path/to/scan');
foreach ($map as $symbol => $path) {
// do your thing
}
For more advanced usage, you can instantiate a generator object and call scanPaths one or more time then call getClassMap to get a ClassMap object containing the resulting map + eventual warnings.
use Composer\ClassMapGenerator\ClassMapGenerator;
$generator = new ClassMapGenerator;
$generator->scanPaths('path/to/scan');
$generator->scanPaths('path/to/scan2');
$classMap = $generator->getClassMap();
$classMap->sort(); // optionally sort classes alphabetically
foreach ($classMap->getMap() as $symbol => $path) {
// do your thing
}
foreach ($classMap->getAmbiguousClasses() as $symbol => $paths) {
// warn user about ambiguous class resolution
}
composer/class-map-generator is licensed under the MIT License, see the LICENSE file for details.
How can I help you explore Laravel packages today?