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

Finder Laravel Package

symfony/finder

Symfony Finder component provides a fluent API to locate and iterate files and directories. Filter by name, extension, size, date, contents, or path; search multiple locations; and traverse recursively with sorting and ignore rules for flexible filesystem searches.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. Buy Decision:

    • Buy: Eliminates the need to build and maintain custom file-search logic, reducing technical debt and accelerating development. Ideal for teams prioritizing maintainability, scalability, and reliability over bespoke solutions.
    • Leverage Existing Ecosystem: Symfony’s Finder is already integrated into Laravel’s core (e.g., Illuminate\Filesystem\Filesystem), making it a zero-cost upgrade for existing Laravel projects.
  • Feature Roadmap Enablement:

    • Asset Optimization Pipelines: Efficiently locate, filter, and process files (e.g., images, videos) based on metadata (size, extension, modification date) for compression, resizing, or format conversion.
    • CLI and Automation Tools: Power custom Laravel Artisan commands for bulk operations (e.g., backups, cleanups, migrations) with a clean, reusable API. Example: A storage:optimize command to find and compress large files in /storage/app.
    • Testing Infrastructure: Simplify test data management by dynamically discovering fixtures (e.g., tests/Fixtures/**/*.json) or generating test datasets based on file patterns.
    • Content Management Workflows: Enable dynamic content generation (e.g., blog post indexing, localization) by querying files with complex criteria (e.g., "all .md files modified in the last 30 days").
    • Deployment and CI/CD: Streamline file validation, checksum generation, or artifact collection during deployments (e.g., "find all .php files in /app and verify their checksums").
  • Use Cases:

    • Laravel-Specific:
      • Integrates natively with Laravel’s Storage facade, Filesystem manager, and Console component, reducing friction for developers.
      • Example: Replace glob() calls in custom packages or service providers with Finder for consistency and reliability.
    • Cross-Platform Compatibility: Handles path separators, symlinks, and hidden files reliably across Linux, Windows, and macOS, critical for multi-environment deployments.
    • Performance-Critical Scans: Lazy iteration avoids memory overload for large directories (e.g., scanning /public for assets or /storage for logs).
    • Metadata-Driven Operations: Filter files by size (minSize(), maxSize()), extension (name('*.png')), modification date (date('>1 month ago')), or permissions (permissible()).
  • Architectural Alignment:

    • Complements Laravel’s dependency injection and service container, enabling testable, reusable file-search logic across the application.
    • Aligns with Symfony’s ecosystem (e.g., Console, Process), which Laravel already leverages, reducing learning curves and tooling overhead.
    • Supports modern PHP features (e.g., typed iterators, generics in PHP 8.4+), future-proofing the codebase.

When to Consider This Package

Adopt when:

  • Your project requires complex, recursive file searches with multiple filters (e.g., name, extension, size, dates, permissions, content).
  • You need a fluent, chainable API to replace spaghetti glob()/scandir() calls, DirectoryIterator logic, or regex-based file matching.
  • You’re building Laravel tooling (e.g., packages, Artisan commands, deployment scripts, or migrations) that interacts with the filesystem.
  • Your team prioritizes maintainability and scalability over one-off scripts. Symfony’s Finder is used in Laravel’s core for tasks like config:clear, cache:clear, and route:clear.
  • You’re using PHP 8.1+ (or PHP 8.4+ for latest features) and want to leverage modern type safety and performance optimizations.
  • You need cross-platform compatibility for filesystem operations (e.g., handling Windows/Linux path differences, symlinks, or permission checks).
  • Your application involves large-scale file operations (e.g., processing thousands of files in /storage or /public) where memory efficiency matters.
  • You want to reduce technical debt by standardizing file-search logic across the codebase.

Look elsewhere if:

  • Your use case is trivial (e.g., single-directory glob() calls for fewer than 100 files). For simple cases, native glob() or scandir() may suffice.
  • You’re constrained by legacy PHP versions (<8.1). Use symfony/finder:6.4.x for PHP 7.4+ or 5.4.x for PHP 5.5+.
  • You require real-time filesystem monitoring or asynchronous file operations. Finder is synchronous; consider ReactPHP or Symfony/Process for async workflows.
  • Your project needs non-filesystem sources (e.g., database-driven file lists) or cloud storage-specific features (e.g., S3 presigned URLs, Google Drive). Use Laravel’s Storage facade or cloud SDKs instead.
  • You lack Symfony/Laravel familiarity and prefer a simpler API (e.g., SplFileInfo, RecursiveDirectoryIterator, or Iterator).
  • You’re working with non-standard filesystems (e.g., network drives with custom permissions, FTP, or SFTP). Use Laravel’s FtpManager or SftpManager alongside Finder for hybrid workflows.
  • Your team has strong preferences for alternative libraries (e.g., league/flysystem, spatie/laravel-medialibrary) that already include file-search capabilities.

How to Pitch It (Stakeholders)

To Executives: *"Symfony’s Finder is a pre-built, production-grade toolkit for filesystem operations—like a Swiss Army knife for file searches. It replaces error-prone custom scripts with a reliable, maintainable API, cutting development time and reducing bugs. Here’s why it’s a smart investment:

  • Faster Feature Delivery: Eliminates reinventing the wheel for file searches, letting teams focus on core business logic. For example, it could reduce the time to build an asset optimization pipeline from weeks to days.
  • Scalability: Handles large directories efficiently (e.g., scanning /storage for 10,000+ files without memory issues), critical for growth.
  • Cross-Platform Reliability: Works seamlessly across Linux, Windows, and macOS, reducing deployment headaches.
  • Zero Maintenance: Backed by Symfony (used in Laravel’s core), with 8,000+ stars and active development. For [X] dollars/year in dev time saved, we could fund [Y] feature or hire [Z] developer. Let’s pilot it in [specific use case, e.g., the backup tool or asset pipeline] to prove the ROI."

To Engineers: *"This replaces messy glob()/DirectoryIterator hacks with a type-safe, expressive API. Key wins:

  • Fluent Syntax: Finder::in('/path')->name('*.php')->size('>1M')->files() is self-documenting and easier to debug than nested if statements or regex.
  • Performance: Lazy iteration avoids loading entire directories into memory (critical for Laravel’s CLI tasks or large-scale scans).
  • Laravel Synergy: Works seamlessly with Storage, Filesystem, and Artisan commands—no context-switching. Example: Replace glob() in custom packages with Finder for consistency.
  • Future-Proof: Actively maintained (PHP 8.1+), with fixes for edge cases like glob patterns, empty iterators, and type safety.
  • Testability: Dependency-inject Finder instances for mocking in unit tests (e.g., with VfsStream or Mockery). Start using it for any non-trivial file ops—it’s already in our stack via Symfony’s Console component. Here’s how to migrate your current glob() calls:"

To Product Managers/Designers: *"This tool lets us build faster without sacrificing reliability. For example:

  • Asset Optimization: Scan all .jpg files in /public and auto-compress them—no manual loops or regex headaches.
  • Content Workflows: Find all untranslated .md files in /content for localization, or filter files by size/modification date for cleanup.
  • Debugging: Quickly locate large log files or outdated configs with a readable query (e.g., Finder::in('/storage/logs')->size('>100M')->files()).
  • Deployment: Validate file checksums or collect artifacts during CI/CD without writing custom scripts. No need to wait for devs—it’s a drop-in replacement for manual file searches, and it’s already used in Laravel’s core for tasks like cache:clear."

To Technical Leads: *"Symfony’s Finder aligns with Laravel’s architecture and reduces technical debt. Here’s how to adopt it:

  1. Replace Custom Logic: Swap glob()/scandir() for Finder in Artisan commands, service providers, or packages. Example:
    // Before
    $files = glob(storage_path('app/*.json'));
    // After
    $finder = new Finder();
    $files =
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport