Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Class Map Generator

Class Map Generator Laravel Package

composer/class-map-generator

Scan PHP directories and extract a class map mapping every class, interface, trait, and enum to its file path. Supports multiple scans, sorted output, and detection of ambiguous classes for robust autoloading and code analysis.

View on GitHub
Deep Wiki
Context7

Utilities to scan PHP code and generate class maps.

Frequently asked questions about Class Map Generator
Is composer/class-map-generator a Laravel package?
No, it is not a Laravel package. It is the PHP class-scanning utility that Composer itself uses to build class maps. You can use it inside Laravel applications for build-time or tooling tasks, but it does not provide service providers, facades, or request-time autoloading features.
How do I install and use composer/class-map-generator in a Laravel project?
Install it with composer require composer/class-map-generator:^1.8. For a one-off scan, call ClassMapGenerator::createMap() with a directory path and iterate the returned symbol-to-path map. For more control, instantiate ClassMapGenerator, call scanPaths() one or more times, then use getClassMap() to retrieve a ClassMap object with sorting and ambiguity reporting.
What PHP and Laravel versions does composer/class-map-generator support?
The package requires PHP 7.2 or newer, which is below every currently supported Laravel version, so it will not add PHP constraint friction. It is not tied to a specific Laravel release. When using it alongside Laravel, verify the resolved symfony/finder version and check for any version intersection with composer/composer if that appears as a dev dependency.
Can composer/class-map-generator speed up Laravel autoloading at runtime?
No, using it as a runtime autoloader in a normal Laravel HTTP path duplicates what Composer already does. Composer's optimized autoloader is already a class map when you run composer dump-autoload -o or use --classmap-authoritative. Use this package for build-time discovery and tooling, not as a replacement loader on every request.
How do I detect ambiguous classes or case-colliding paths with class-map-generator?
Use ClassMap::getAmbiguousClasses() to find symbols that are defined in more than one file. Since version 1.8.0, ClassMap::getAmbiguousFolders() also helps detect case-only path collisions, which is valuable when developers mix Windows or macOS machines with Linux CI. Sort the map deterministically and fail loudly on ambiguity instead of silently accepting whichever class wins.
What are good use cases for class-map-generator in a Laravel application?
It fits build-time and tooling concerns, such as scanning plugin or theme bundles, tenant-uploaded modules, or extension directories that Composer cannot see. It is also useful for CI gates that fail on ambiguous class resolution or case-colliding folders. Internal tools such as static analyzers, IDE helpers, dependency extractors, and security scanners can use it instead of fragile glob-and-regex scanners.
Does composer/class-map-generator execute PHP files or use reflection?
No, it tokenizes PHP source code without including files, executing code, or using reflection. It maps classes, interfaces, traits, and enums to file paths and reports scan warnings. Because it is static analysis, it cannot see conditional declarations, class_alias calls, eval-generated classes, generated proxies, or anonymous classes as runtime truth.
How do I scan multiple directories, exclude folders, and sort the class map?
Instantiate ClassMapGenerator and call scanPaths() once per directory, passing exclude-dirs where needed. Then call getClassMap() to obtain the ClassMap object, call sort() if you want alphabetical output, and iterate getMap() for symbol-to-path entries. The static createMap() helper is convenient for simple one-directory scans.
What are the risks of treating a generated class map as an authoritative class loader?
A class map is a discovery hint, not runtime truth. Conditional or guarded declarations, class_alias, eval, generated proxies, and anonymous classes can make a map-derived class-exists assertion wrong in either direction. Pin exact versions in composer.lock and add a regression test that asserts a known file's map entry, because parsing and path-normalization behavior can shift across minor releases.
How does class-map-generator compare with writing my own glob and regex scanner?
A custom glob-and-regex scanner usually under-handles traits, enums, multiple declarations per file, and ambiguity reporting. This package is maintained by the Composer team and already handles those cases plus PSR-4 violations and case-colliding folders. Its low star count is misleading because it ships inside every Composer 2.x install, so evaluate it on Composer's track record rather than GitHub popularity.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections