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

File Filter Laravel Package

sebastian/file-filter

Filter and whitelist/blacklist files and directories in PHP projects. Extracted from phpunit/phpunit, this lightweight library helps build file lists while honoring include/exclude rules—useful for test runners, coverage tools, and CLI utilities.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Lightweight & Niche: The sebastian/file-filter package is a small, focused utility for filtering files (e.g., by extension, path, or regex). It is not a full-fledged file system library (e.g., no async I/O, no metadata manipulation) but excels at precisely filtering files—ideal for:
    • Test suites (e.g., excluding vendor/, .git/, or specific file types).
    • Build pipelines (e.g., filtering test files, assets, or logs).
    • Data processing (e.g., selecting files for batch operations).
  • Extracted from PHPUnit: Proven in a high-traffic, well-tested ecosystem (PHPUnit), suggesting stability and low defect rates.
  • Stateless & Pure: No external dependencies (beyond PHP core), making it easy to reason about and safe to integrate.

Integration Feasibility

  • Composer-Based: Seamless integration via composer require sebastian/file-filter (or --dev for CI/test-only use).
  • PSR-4 Autoloading: Follows modern PHP standards, requiring zero manual configuration for basic usage.
  • Minimal API Surface:
    use SebastianBergmann\FileFilter\Filter;
    $filter = new Filter();
    $files = $filter->filter(['file1.php', 'file2.txt'], ['*.php']); // Returns ['file1.php']
    
    • No complex setup: Can be dropped into any Laravel service, command, or event listener.
    • Composable: Can be chained with other file operations (e.g., Storage::files(), File::exists()).

Technical Risk

Risk Area Assessment Mitigation Strategy
Performance Minimal overhead (pure PHP, no syscalls in filtering logic). Benchmark in target environment if processing millions of files.
Compatibility PHP 8.1+ (as of 2026). Check Laravel version compatibility (Laravel 10+ uses PHP 8.1+).
Thread Safety Stateless; safe for concurrent use (e.g., in queues or parallel jobs). No action required.
Future Maintenance Low activity (last release 2026-04-22). Monitor for breaking changes; fork if needed (BSD-3-Clause allows modification).
Edge Cases Handles Unicode paths, symlinks (configurable via Filter constructor). Test with Laravel’s filesystem (e.g., Storage::disk('local')->files()).

Key Questions

  1. Use Case Clarity:
    • Is this for test file filtering (e.g., phpunit.xml exclusions) or runtime file operations (e.g., asset processing)?
    • Example: Should it replace Laravel’s File::all() or augment it?
  2. Scalability Needs:
    • Will filtering operate on thousands of files? If so, test memory usage (though risk is low).
  3. Customization Requirements:
    • Does the default API meet needs, or are custom filters (e.g., by file size, modification time) needed?
  4. Dependency Scope:
    • Should this be a dev-only dependency (e.g., for tests) or runtime (e.g., for production file processing)?
  5. Alternatives:
    • Could Laravel’s built-in File facade or Illuminate\Support\Facades\Storage suffice?
    • If not, is this package’s simplicity worth the abstraction?

Integration Approach

Stack Fit

  • Laravel Compatibility:

    • Native PHP Integration: Works anywhere PHP runs (services, commands, middleware, etc.).
    • Filesystem Integration: Pairs well with Laravel’s Storage facade for path resolution:
      use Illuminate\Support\Facades\Storage;
      use SebastianBergmann\FileFilter\Filter;
      
      $filter = new Filter();
      $files = Storage::disk('public')->files();
      $filtered = $filter->filter($files, ['*.jpg', '!*.min.jpg']);
      
    • Artisan Commands: Ideal for CLI tools (e.g., php artisan filter:assets).
    • Event Listeners: Filter files on events like filesystem.updated.
  • Ecosystem Synergy:

    • Complements existing tools:
      • PHPUnit: If using PHPUnit, this is a direct dependency.
      • Laravel Mix/Vite: Filter assets during builds.
      • Spatie Laravel Media Library: Filter uploaded files.

Migration Path

Step Action Laravel-Specific Notes
1. Assessment Audit current file-filtering logic (e.g., custom regex, glob(), or manual loops). Identify pain points (e.g., complex exclusions, performance bottlenecks).
2. Proof of Concept Replace a single filtering use case (e.g., test files or asset processing). Example: Replace array_filter(glob('public/*.{jpg,png}'), fn($f) => !str_contains($f, 'thumb')).
3. Dependency Scope Add to composer.json as dev (tests) or require (runtime). Use --dev if only for testing; otherwise, ensure CI includes the package.
4. API Wrapping (Optional) Create a Laravel service class to standardize usage:
```php
namespace App\Services;
class FileFilterService {
public function filter(array $files, array $patterns): array {
return (new Filter())->filter($files, $patterns);
}
}
```
5. Testing Verify edge cases (Unicode paths, symlinks, empty inputs). Use Laravel’s Storage facade to test different disks (local, S3, etc.).
6. Documentation Add usage examples to Laravel’s internal docs or a README.md in the app. Note: Package has no Laravel-specific docs; custom examples will be needed.

Compatibility

  • PHP Version: Laravel 10+ (PHP 8.1+) is compatible. For older Laravel, check PHP version support.
  • Filesystem Abstraction:
    • Works with any iterable of paths (strings, SplFileInfo objects).
    • For Laravel’s Storage facade, ensure paths are absolute or disk-relative (e.g., 'public/image.jpg').
  • Path Handling:
    • Supports Unix/Windows paths and URL-encoded paths.
    • Configure symlink handling via Filter constructor if needed:
      $filter = new Filter(['allow-symlinks' => false]);
      

Sequencing

  1. Start Small:
    • Replace one filtering logic block (e.g., in a test suite or build script).
    • Example: Migrate from glob() to FileFilter in phpunit.xml.
  2. Expand Gradually:
    • Add to Artisan commands or jobs next.
    • Example: Use in HandleAssetUpload job to filter processed files.
  3. Monitor:
    • Track performance impact (if filtering large datasets).
    • Watch for upstream updates (though risk is low).

Operational Impact

Maintenance

  • Low Effort:
    • No configuration: Drop-in usage requires zero setup.
    • No dependencies: No risk of transitive dependency conflicts.
  • Update Strategy:
    • Monitor for major version bumps (unlikely; package is stable).
    • Forking risk: Low (BSD-3-Clause allows modification if needed).
  • Deprecation Risk:
    • No known deprecations in PHPUnit’s extraction history.
    • Laravel LTS: Since Laravel supports PHP 8.1+, this package will remain viable.

Support

  • Community:
    • Primary maintainer: Sebastian Bergmann (PHPUnit creator).
    • Issues: Open GitHub issues for bugs; expect fast responses (historically).
  • Debugging:
    • Simple API: Errors are likely user-input related (e.g., invalid patterns).
    • Logging: Add debug logs for complex filters:
      $filter = new Filter(['verbose' => true]); // If supported (check docs).
      
  • Laravel-Specific Help:
    • Leverage Laravel’s Storage facade for path resolution issues.
    • Use dd() or Log::debug()
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope