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

Filesystem Laravel Package

php-standard-library/filesystem

Type-safe filesystem helpers for PHP with consistent exception handling. Provides safer wrappers for common file and directory operations, aiming for clearer intent and fewer runtime surprises. Part of the PHP Standard Library ecosystem.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Complementarity: The package excels as a local filesystem utility layer, filling gaps where Laravel’s Storage facade lacks type safety or granularity (e.g., Directory::ensure() vs. Storage::makeDirectory()). Its event system can integrate with Laravel’s ecosystem but risks redundancy if not scoped (e.g., use for audit logs, not core business events).
  • Modular Adoption: Ideal for Laravel modules requiring filesystem ops (e.g., custom storage adapters, CLI tools) but not a replacement for Storage in HTTP-bound workflows. The PathResolver can standardize path logic across services, reducing base_path()/storage_path() sprawl.
  • Cross-Cutting Concerns: The exception-driven API enforces consistency in error handling, mitigating silent failures common in Laravel’s Storage (e.g., file_put_contents’s @ operator). However, its lack of cloud storage support limits use in production asset pipelines.

Integration Feasibility

  • Stack Compatibility:
    • PHP 8.1+: Aligns with Laravel’s minimum version (8.1+), but PHP 8.2+ features (e.g., read-only properties) may lag.
    • Laravel Services: Seamlessly integrates with Artisan commands, queue jobs, and console kernels via dependency injection.
    • Event System: The FilesystemEvent dispatcher can coexist with Laravel’s events if namespaced (e.g., \App\Events\Filesystem\FileCreated), but requires explicit bridging to avoid duplication.
  • Migration Path:
    • Low Risk: Replace custom path utilities (e.g., app/Helpers/PathHelper) and manual loops with PathResolver and BatchProcessor.
    • High Risk: Refactor Storage facade usage in HTTP controllers (avoid; use only in CLI/services).
  • API Overlap:
    • Redundancy Risk: Methods like File::read() mirror Storage::get(), but the package’s exceptions improve observability. Mitigate by documenting when to use each (e.g., Filesystem for local ops, Storage for cloud).
    • Path Normalization: The PathResolver can unify path construction across the codebase, reducing DIRECTORY_SEPARATOR hacks.

Technical Risk

  • Event System Collisions:
    • Risk: FilesystemEvent could compete with Laravel’s event system (e.g., fileCreated vs. FileUploaded).
    • Mitigation: Restrict usage to non-critical paths (e.g., logging, analytics) and bridge to Laravel events where needed.
  • Performance:
    • BatchProcessor: May introduce overhead for small datasets (e.g., <100 files). Benchmark against manual loops in queue workers.
    • Event Dispatching: Each event emits a new object; bulk operations (e.g., 10K files) could strain memory.
  • Dependency Management:
    • symfony/event-dispatcher: Adds ~1MB to vendor size. Justify only if using events; otherwise, skip the feature.
    • Breaking Changes: Future versions may deprecate opt-in events, requiring migration.
  • Cross-Platform Edge Cases:
    • Windows: UNC paths (\\server\share) or long paths (>260 chars) may need additional validation.
    • Permissions: The package’s Directory::ensure() auto-creates directories, which may mask permission issues in shared hosting.

Key Questions

  1. Adoption Scope:
    • Should this replace all custom filesystem logic, or only new projects?
    • How will we deprecate legacy path utilities (e.g., app/Helpers/PathHelper)?
  2. Event System:
    • Will we use FilesystemEvent for business logic (high risk) or only infrastructure (e.g., logging)?
    • How will we bridge to Laravel events (e.g., fileCreatedFileUploaded)?
  3. Performance Tradeoffs:
    • Is BatchProcessor faster/slower than manual loops for our typical dataset sizes?
    • How will we handle partial failures in batches (e.g., retry logic)?
  4. Error Handling:
    • Should we wrap package exceptions in custom exceptions for consistency?
    • How will we log/unhandle exceptions** (e.g., FileNotFoundException) in CLI tools?
  5. Testing:
    • How will we mock filesystem operations in unit tests (e.g., File::read())?
    • Should we add integration tests for cross-platform path resolution?

Integration Approach

Stack Fit

  • Laravel Services:
    • Artisan Commands: Replace manual filesystem ops with Filesystem methods (e.g., Directory::ensure()).
    • Queue Jobs: Use BatchProcessor for bulk file processing (e.g., image resizing).
    • Console Kernels: Integrate FilesystemEvent for reactive workflows (e.g., audit logs).
  • PHP Scripts:
    • Standalone Scripts: Ideal for data migration tools or CLI utilities (no Laravel dependencies).
    • Legacy Code: Use adapters to wrap existing Storage/Filesystem calls.
  • Event System:
    • Symfony Dispatcher: Use for non-Laravel events (e.g., internal monitoring). Bridge to Laravel’s events via listeners:
      $filesystem->on('fileCreated', fn($event) =>
          event(new \App\Events\FileCreated($event->getPath()))
      );
      

Migration Path

  1. Phase 1: Pilot Project
    • Scope: Refactor one Artisan command or queue job using the package.
    • Metrics: Measure development time saved and bug reduction.
  2. Phase 2: Standardize Paths
    • Replace base_path()/storage_path() with PathResolver in new services.
    • Deprecate custom path helpers (e.g., app/Helpers/PathHelper).
  3. Phase 3: Batch Processing
    • Replace manual loops in queue workers with BatchProcessor.
    • Benchmark performance for >1K files.
  4. Phase 4: Event System (Optional)
    • Enable FilesystemEvent for logging/audit use cases.
    • Bridge to Laravel events where needed.

Compatibility

  • Laravel Facades:
    • Avoid mixing Filesystem and Storage for the same operation (e.g., don’t use both for uploads).
    • Prefer Filesystem for local ops, Storage for cloud/cloud-adjacent ops.
  • Third-Party Packages:
    • No conflicts with league/flysystem or symfony/filesystem (disjoint APIs).
    • Potential overlap with spatie/laravel-medialibrary (use Filesystem for local assets).
  • PHP Extensions:
    • No dependencies beyond PHP 8.1+ and optional symfony/event-dispatcher.

Sequencing

  1. Add to composer.json:
    {
        "require": {
            "php-standard-library/filesystem": "^6.2"
        },
        "extra": {
            "aliases": {
                "symfony/event-dispatcher": "illuminate/events"
            }
        }
    }
    
  2. Register Service Provider (if using events):
    // app/Providers/AppServiceProvider.php
    public function register()
    {
        $this->app->bind(\PHPStandardLibrary\Filesystem\Filesystem::class, function () {
            $fs = new \PHPStandardLibrary\Filesystem\Filesystem();
            if ($this->app->bound('events')) {
                $fs->setEventDispatcher($this->app['events']);
            }
            return $fs;
        });
    }
    
  3. Replace Path Logic:
    // Before
    $path = base_path("storage/app/{$id}.txt");
    // After
    $path = app(\PHPStandardLibrary\Filesystem\PathResolver::class)
        ->resolveRelativeToProjectRoot("storage/app/{$id}.txt");
    
  4. Refactor Batch Operations:
    // Before
    foreach (Storage::allFiles('public/uploads') as $file) {
        ProcessFileJob::dispatch($file);
    }
    // After
    $batch = new \PHPStandardLibrary\Filesystem\BatchProcessor();
    $batch->process(Storage::allFiles('public/uploads'), 20, fn($file) =>
        ProcessFileJob::dispatch($file)
    );
    

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Eliminates custom path logic and error handling.
    • Consistent API: Single source of truth for filesystem ops across teams.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor