App\Services\*) and classmaps for framework-specific files (e.g., config/, routes/).ClassNotFoundException in production, reducing reliance on Laravel’s ClassLoader runtime checks or config/app.php overrides.composer.json, addressing a common pain point in large-scale PHP projects.composer.json and filesystem structures, requiring no changes to Laravel’s AppServiceProvider, Bootstrap, or composer.lock.check-autoloading.php) can be invoked via:
composer.json scripts for local/dev validation:
"scripts": {
"post-autoload-dump": "php vendor/bin/check-autoloading.php",
"validate": "php vendor/bin/check-autoloading.php && @php artisan test"
}
illuminate/, symfony/) or other PHP tools (e.g., PHPStan, Psalm).Illuminate\Foundation\Application) if not explicitly defined in composer.json. Mitigation: Exclude vendor/laravel/ or whitelist Laravel’s autoload paths.ClassLoader::addPsr4() or eval). Mitigation: Document limitations or extend the tool to support dynamic paths.config/app.php may override autoload paths (e.g., ClassLoader::addClassMap()). Mitigation: Validate against the final classmap after Laravel’s bootstrapping.tests/, resources/lang/) if not configured in composer.json. Mitigation: Use autoload-exclude or suppress warnings via CLI flags.Illuminate\*)? If the latter, how to handle Laravel’s evolving class structure across versions?if: failure()) or be logged as warnings? What’s the acceptable false-positive rate?php artisan optimize, phpstan, pint)? Should this replace or complement them?MixManifest) are correctly autoloaded.- name: Validate Autoload
run: php vendor/bin/check-autoloading.php
test or deploy stage:
validate-autoload:
script: php vendor/bin/check-autoloading.php
allow_failure: true # Initially non-blocking
composer install:
- run:
name: Validate Autoload
command: php vendor/bin/check-autoloading.php
composer.json for local validation:
"scripts": {
"post-install-cmd": ["@validate-autoload"],
"validate-autoload": "php vendor/bin/check-autoloading.php"
}
// app/Console/Commands/ValidateAutoload.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ValidateAutoload extends Command {
protected $signature = 'autoload:validate';
protected $description = 'Validate Composer autoload paths';
public function handle() {
$exitCode = shell_exec('php vendor/bin/check-autoloading.php');
if ($exitCode !== 0) {
$this->error('Autoload validation failed!');
exit($exitCode);
}
$this->info('Autoload validation passed.');
}
}
# package.json
"husky": {
"hooks": {
"pre-commit": "composer validate-autoload"
}
}
require-dev and test in a staging environment or feature branch.composer.json:
"autoload-exclude": [
"tests/",
"resources/lang/",
"vendor/laravel/framework/src/Illuminate/Foundation/"
]
./vendor/bin/check-autoloading.php --verbose
# GitHub Actions example
- name: Validate Autoload (Warning)
run: php vendor/bin/check-autoloading.php || true
- name: Validate Autoload (Blocking)
run: php vendor/bin/check-autoloading.php
vendor/ directory by passing a custom root path:
./vendor/bin/check-autoloading.php ./app
composer.json to ignore Laravel’s autoload paths:
"autoload-exclude": ["vendor/laravel/**"]
packages/*)../vendor/bin/check-autoloading.php .).composer.json and filesystem structure match the host.composer install and composer dump-autoload but before tests or deployment:
composer install → composer dump-autoload → validate-autoload → run-tests → deploy
How can I help you explore Laravel packages today?