spatie/php-structure-discoverer
Discover PHP classes, interfaces, traits, and enums that match conditions (e.g., implement an interface) across your project. Fast scanning with built-in caching and rich metadata—ideal for auto-registration, tooling, and framework integrations.
LaravelDiscoverCacheDriver and Artisan commands (structure-scouts:cache, structure-scouts:clear), making it a seamless fit for Laravel-based applications.composer require), and Laravel-specific setup (config publishing, Artisan commands) is minimal.amphp/parallel) accelerates discovery in large codebases, though this adds a minor dependency.structure_scout_directories config may miss critical classes (e.g., vendor packages). Requires careful validation during integration.php artisan structure-scouts:clear) may be needed post-deployment if code changes affect discovery logic.app/?file vs. Laravel) aligns best with our infrastructure (e.g., shared storage vs. Redis)?class_uses, get_declared_classes) or augment it?ReflectionClass loops)?MyPackage\Scouts\CommandsScout).$models = Discover::in(app_path('Models'))->classes()->extending(Model::class)->get();
PolicyScout, EventScout).php artisan structure-scouts:cache --env=production
array_filter(get_declared_classes(), ...)).config/cache.php.ReflectionClass, get_class_methods).composer.json and publish config.ShouldBeDiscoverable classes are found").files-changed events).cache:clear or custom events to invalidate caches post-deploy.structure_scout_directories must be updated if codebase structure changes (e.g., new modules).ignored_files can grow over time (e.g., exclude test classes, generated files).structure_scout_directories.structure-scouts:clear).Discover::in(__DIR__)->full()->get() to inspect raw metadata.parallel(N).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Cache corruption | Stale/incorrect discovery results | Use NullDiscoverCacheDriver in tests; add health checks. |
| Missing directories in config | Critical classes undiscovered | Validate config in CI; use Discover::in()->get() to audit. |
| PHP reflection errors | Exceptions during discovery | Wrap discovery in try-catch; log errors. |
| Parallel processing deadlocks | Slow |
How can I help you explore Laravel packages today?