Php Structure Discoverer

spatie/php-structure-discoverer image

Php Structure Discoverer stats

Downloads
82.7K
Stars
79
Open Issues
1
Forks
2

View on GitHub →

Automatically discover structures within your PHP application

Spatie PHP Structure Discoverer Package

The Spatie PHP Structure Discoverer package is a powerful tool designed to facilitate the discovery and organization of various structures within your PHP application, such as classes, interfaces, enums, and traits. Ideal for large-scale PHP projects, this package helps streamline the process of identifying and categorizing code elements based on specific attributes or implementations.

Key Features

  • Discover Various Structures: Easily find classes, interfaces, enums, and traits within your PHP application.
  • Flexible Search Criteria: Filter your searches by implementation details, extensions, attributes, and custom conditions.
  • Caching Mechanism: Built-in caching functionality ensures fast retrieval in production environments.
  • Configurable: Comes with a customizable configuration file when used with Laravel, allowing you to specify directories, ignored files, and cache settings.
  • Sorting and Conditions: Offers functionalities to sort discovered items and combine multiple conditions for precise discovery.
  • Parallel Processing: Supports parallel processing to expedite the scanning of large codebases.
  • Extensive Metadata: Each discovered item includes metadata for deeper insights and further processing.

Installation

Install the package via Composer:

composer require spatie/php-structure-discoverer

For Laravel users, publish the configuration file:

php artisan vendor:publish --tag="php-structure-discoverer-config"

Usage

Start by specifying the directory to search:

use Spatie\StructureDiscoverer\Discover;
 
// Basic usage
$classes = Discover::in(__DIR__)->classes()->get();
 
// Advanced usage with conditions
$classes = Discover::in(__DIR__)->classes()->implementing(Arrayable::class)->get();

You can also define custom filters, sort results, and utilize the package's caching capabilities to enhance performance.

Advanced Features

  • Chaining: Automatically resolves inheritance chains to include all relevant structures.
  • Full Information Retrieval: Access complete metadata about discovered structures, not just their names.
  • Customizable Caching: Choose from multiple caching strategies or define your own to optimize performance.

Caching and Performance

To leverage caching, define a structure scout class to specify what and where to discover, along with the cache driver. This can significantly speed up operations by avoiding repeated structure discovery:

EnumsStructureScout::create()->get();

Contributing

Contributions are welcome! Please refer to the package's contribution guidelines for more details.

Conclusion

The Spatie PHP Structure Discoverer package is an essential tool for developers working on complex PHP projects, providing a robust framework for managing and querying application structures efficiently. With its extensive customization options and powerful search and caching features, it helps maintain clean and manageable codebases.

For additional details on changes, security, and licensing, please consult the package's changelog, security policy, and license documentation.

spatie photo

We create open source, digital products and courses for the developer community

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Spatie Php Structure Discoverer Related Articles

Learn how to upload files in Laravel like a Pro image

Learn how to upload files in Laravel like a Pro

Read article
From idea, to blog, to live without leaving your IDE image

From idea, to blog, to live without leaving your IDE

Read article
Building your own Laravel Packages image

Building your own Laravel Packages

Read article
Create Select Options from Enums, Laravel Models, and more image

Create Select Options from Enums, Laravel Models, and more

Read article
Laravel Jetstream: Add CRUD with Spatie Permission image

Laravel Jetstream: Add CRUD with Spatie Permission

Read article
Laravel Package Training (sponsor) image

Laravel Package Training (sponsor)

Read article
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel