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

Path Laravel Package

lastdragon-ru/path

Laravel/PHP utilities for working with filesystem-like paths: build, normalize, join, and resolve path segments with consistent behavior across platforms. Lightweight helper functions/classes aimed at safer path manipulation in applications and libraries.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require lastdragon-ru/path
    

    Add the service provider to config/app.php (if not auto-discovered):

    'providers' => [
        // ...
        LastDragon\Path\PathServiceProvider::class,
    ],
    
  2. First Usage

    use LastDragon\Path\Path;
    
    $path = Path::make('/var/www/project');
    echo $path->getPath(); // "/var/www/project"
    
  3. Key Initial Methods

    • Path::make($path) – Create a new path instance.
    • $path->getPath() – Retrieve the raw path string.
    • $path->exists() – Check if the path exists.

Implementation Patterns

Core Workflows

  1. Path Manipulation

    $path = Path::make('/var/www/project')->append('src')->append('Controller');
    echo $path->getPath(); // "/var/www/project/src/Controller"
    
  2. File/Directory Operations

    $path = Path::make('/var/www/storage');
    $path->createDirectory(); // mkdir()
    $path->delete();          // rmdir() (empty dirs only)
    
  3. Relative Paths

    $base = Path::make('/var/www');
    $relative = $base->relativeTo('/var/www/project');
    echo $relative->getPath(); // "project"
    
  4. File Operations

    $file = Path::make('/var/www/app.log');
    $file->exists() ? 'Exists' : 'Missing';
    $file->delete(); // unlink()
    

Integration with Laravel

  • Storage Paths

    $storage = Path::make(storage_path());
    $file = $storage->append('app.log');
    
  • Config Files

    $config = Path::make(config_path('app.php'));
    $config->exists() ? 'Config exists' : 'Missing';
    
  • Artisan Commands

    use LastDragon\Path\Path;
    
    public function handle()
    {
        $cacheDir = Path::make(cache_path())->append('temp');
        $cacheDir->createDirectory();
    }
    

Gotchas and Tips

Pitfalls

  1. Cross-Platform Paths

    • Uses / as separator by default. For Windows compatibility, ensure paths are normalized:
      $path = Path::make('C:\Users\file.txt')->normalize();
      
  2. Directory Deletion

    • delete() only removes empty directories. Use deleteDirectory() (if available) for recursive deletion.
  3. Case Sensitivity

    • Linux/macOS are case-sensitive. Test paths like:
      Path::make('/var/www/Project')->exists(); // May fail if actual path is '/var/www/project'
      
  4. Trailing Slashes

    • append() ignores trailing slashes. Use ensureTrailingSlash() if needed:
      $path->ensureTrailingSlash()->append('file.txt');
      

Debugging Tips

  • Inspect Paths

    $path->getPath(); // Raw string
    $path->getRealPath(); // Resolved symlinks (if supported)
    
  • Check Permissions

    $path->isWritable() ? 'Writable' : 'Read-only';
    

Extension Points

  1. Custom Path Classes Extend LastDragon\Path\Path to add domain-specific methods:

    class ProjectPath extends Path
    {
        public function getComposerJson()
        {
            return $this->append('composer.json')->getPath();
        }
    }
    
  2. Override Default Behavior Bind a custom path resolver in the service provider:

    $this->app->bind('path', function () {
        return new CustomPathResolver();
    });
    
  3. Path Normalization Use normalize() to handle edge cases (e.g., ./, ../, or duplicate slashes).

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.
terminal42/code-quality-tools
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