Zero-config local module autoloading for Momo Framework.
Automatically discovers local modules and patches Composer's internal maps to enable seamless PSR-4 integration without manual configuration.
momo-framework/discovery is a Composer plugin that automatically registers local module namespaces after every composer dump-autoload. Drop a module into modules/ — its PSR-4 namespace is available immediately, with no edits to composer.json.
core/
modules/
Shop/ ← drop a module here
composer.json
src/
vendor/ ← namespace injected automatically
$ composer dump-autoload
momo-discovery: injected 1 local module namespace(s): Momo\Module\Shop\- PHP
>= 8.5 - Composer 2
Already included in Momo Framework core. For standalone use:
composer require momo-framework/discoveryThe plugin hooks into Composer's POST_AUTOLOAD_DUMP event. After each dump it scans modules/, collects PSR-4 declarations from each module's composer.json, and injects them into the autoloader.
Two files are patched:
vendor/composer/autoload_psr4.php — rewritten from scratch with the merged namespace map. Absolute paths are replaced with $baseDir expressions to keep the file portable across machines.
vendor/autoload_real.php — $loader->addPsr4() calls are injected just before return $loader;. This ensures module namespaces are registered regardless of whether --optimize or --classmap-authoritative flags are active. autoload_static.php is intentionally not touched — its format is not a stable Composer contract.
Both patches are idempotent — a guard comment prevents duplicate entries across repeated dump-autoload runs.
composer dump-autoload
│
▼
POST_AUTOLOAD_DUMP
│
├─ ModuleScanner::scan()
│ reads modules/*/composer.json
│ collects autoload.psr-4 entries
│ resolves relative paths to absolute
│
└─ AutoloadPatcher::patch()
rewrites vendor/composer/autoload_psr4.php
injects addPsr4() calls into vendor/autoload_real.php
Each module declares its own composer.json with metadata and autoload config. No require section — all modules share the root vendor/.
{
"name": "momo-module/shop",
"type": "momo-module",
"autoload": {
"psr-4": {
"Momo\\Module\\Shop\\": "src/"
}
},
"extra": {
"momo": {
"providers": [
"Momo\\Module\\Shop\\ShopServiceProvider"
]
}
}
}| Local module | Vendor module | |
|---|---|---|
| Location | core/modules/ |
core/vendor/ |
| Autoload | injected by this plugin | standard Composer |
| Dependencies | shared via core/composer.json |
own composer.json |
| Editable | yes — make:* commands work directly |
no — module:publish first |
| composer.json | metadata + autoload only | full package definition |
# install dependencies
composer install
# run tests
composer test
# run tests with coverage report (requires PCOV)
composer test:coverage
# static analysis — PHPStan level 10
composer stan
# code style check
composer lint
# code style fix
composer lint:fix
# rector — check for upgrades
composer rector:check
# run full CI pipeline locally
composer cicomposer ci
├── lint php-cs-fixer --dry-run
├── stan phpstan level 10
├── rector:check rector --dry-run
└── test phpunit