danog/class-finder
Fast PHP class discovery utility. Scan directories/files and find classes, interfaces, and traits without manually maintaining lists. Useful for autoload-based plugins, reflection tooling, and package indexing, with a simple API and minimal setup.
Install via Composer (composer require danog/class-finder) and start by scanning a directory for classes implementing a known interface or extending an abstract class. The most common first use is discovering event listeners or plugin classes:
use Danog\ClassFinder\ClassFinder;
$finder = new ClassFinder();
$listeners = $finder->findClasses(app_path('Listeners'), 'App\Contracts\EventListener');
This returns fully-qualified class names as strings. Verify autoloading works by ensuring App\Listeners\* maps correctly in composer.json. No config files—just instantiating and scanning.
app/Actions for classes implementing HandlesRequestInterface, then bind them to a repository or container using a macroable tag.plugins/*, detect all classes implementing PluginInterface, load metadata from static methods (e.g., ::getName()), and register routes/permissions.*Test.php classes matching a convention, then generate coverage reports or execute filtered suites.implements MessageHandlerInterface) and map them to event classes via ::getSubscribedEvents() static method.ReflectionClass) → Instantiate → Register. Always wrap discovery in caching (e.g., file hash–based cache).composer dump-autoload after adding new classes, and avoid new directly on returned class names until autoloading is confirmed.ReflectionClass::getTraits() and getInterfaces() post-discovery.ClassFinder follows symlinks by default—critical when scanning storage/ or vendor/. Use ClassFinder::setFollowSymlinks(false) for production scans.md5_file('composer.json') . '-' . spl_object_hash($finder)). Laravel’s Cache facade integrates cleanly.Scanner or post-process with getAttributes() to detect tagged classes (e.g., #[Handler]).How can I help you explore Laravel packages today?