Weave Code
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
Php Structure Discoverer

Php Structure Discoverer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Automatically discover classes within your PHP application

Frequently asked questions about Php Structure Discoverer
How do I install this package in a Laravel project?
Run `composer require spatie/php-structure-discoverer` in your project root. Laravel-specific features like Artisan commands and cache drivers are automatically available after installation. No additional configuration is required for basic usage.
Can I discover classes implementing a specific interface in Laravel?
Yes. Use `Discover::in(app_path())->classes()->implementing(YourInterface::class)->get()` to fetch all classes implementing your interface. The package supports interfaces, traits, enums, and classes with rich metadata like file paths and inheritance chains.
Does this package work with Laravel’s caching system?
Absolutely. The package includes a `LaravelDiscoverCacheDriver` that integrates with Laravel’s cache backends (Redis, database, etc.). Run `php artisan structure-scouts:cache` to pre-warm caches for faster production scans.
What Laravel versions does this package support?
The package is compatible with Laravel 9.x and 10.x. Check the [GitHub repository](https://github.com/spatie/php-structure-discoverer) for the latest version’s Laravel requirements, as newer releases may add support for newer Laravel versions.
How do I clear the cache after updating my codebase?
Use the Artisan command `php artisan structure-scouts:clear` to invalidate caches. For CI/CD pipelines, automate this step post-deploy to ensure scans reflect the latest code. Manual cache clearing is also supported via `Discover::clearCache()`.
Can I use this package in non-Laravel PHP projects?
Yes, but with limitations. The core discovery functionality works in vanilla PHP, but Laravel-specific features (Artisan commands, cache drivers) are unavailable. Use `FileDiscoverCacheDriver` for caching in non-Laravel environments.
How do I optimize performance for large codebases?
Enable caching (`Discover::cache()`) and use parallel processing with `->parallel()` for faster scans. Pre-warm caches during deployment (`php artisan structure-scouts:cache`) to avoid runtime delays. Test memory usage with `->full()` in high-load environments.
Are there alternatives to this package for class discovery in Laravel?
Yes. For simple cases, Laravel’s service container (`app()->tagged()`) or ReflectionClass may suffice. For advanced use cases, consider `phpDocumentor` or `Roave/BetterReflection`, but they lack Laravel-native optimizations like Artisan commands and caching.
How do I discover enums or traits in my Laravel project?
Use `Discover::in(app_path())->enums()->get()` for enums or `Discover::in(app_path())->traits()->get()` for traits. The package supports all PHP 8.1+ structures, including metadata like attributes or docblocks, for dynamic tooling like code generation.
Can I extend the package to add custom discovery conditions?
Yes. The package allows custom conditions via closures or method chaining (e.g., `->hasAttribute(YourAttribute::class)`). Extend functionality by creating custom `Discover` subclasses or using the `->where()` method for arbitrary logic.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony