bitandblack/pathinfo
Tiny PHP utility offering a consistent, OO wrapper around path information. Parse file paths into dirname, basename, extension, filename, and more, with simple getters and helpers for working with filesystem paths across environments.
Storage and Filesystem components by providing a domain-specific abstraction for path logic, reducing reliance on procedural pathinfo() calls.class TenantFilePath extends PathInfo {
public function getTenantPath(string $tenantId): string {
return "/tenants/{$tenantId}/" . $this->getNormalizedPath();
}
}
Path, Storage, and Filesystem without conflicts.$this->app->bind(PathInfo::class, function () {
return new PathInfo(config('app.default_path'));
});
Illuminate\Support\Path).Storage disks or Filesystem adapters out of the box.Path facade or str() helpers may suffice.C:\Users\file.txt).%20 vs. spaces).Illuminate\Support\Path or Str::of($path) for simplicity.symfony/finder or symfony/filesystem for advanced filesystem operations.tenant/{id}/uploads/ structure)./config/plugins/{name}.php).../ traversal).php artisan storage:link).PathInfo into services (e.g., FileUploadService, MediaProcessor).ValidateUploadPath).getFilePathAttribute()).pathinfo(), explode(), dirname(), and basename() calls in the codebase.PathInfo (expect negligible difference).basename($path) for $pathInfo->getFilename()).C:\Users\file.txt).%20 vs. spaces)./a/b/c/../d).PathInfo for all user-generated paths").PathInfo behind a Laravel-specific interface (e.g., App\Services\PathHandler) to ease future swaps.@deprecated tags for old path logic.PathInfo methods if using PHP 7.4+:
public function getExtension(): ?string { ... }
Path facade:
use BitAndBlack\PathInfo\PathInfo as CustomPathInfo;
PathInfo to work with Laravel’s Storage facade:
class LaravelPathInfo extends CustomPathInfo {
public function getStoragePath(string $disk = 'local'): string {
return Storage::disk($disk)->path($this->getNormalizedPath());
}
}
FormRequest or middleware:
public function rules(): array {
return [
'file_path' => ['required', function ($attribute, $value, $fail) {
$pathInfo = new PathInfo($value);
if ($pathInfo->hasTraversal()) {
$fail('Invalid path: traversal detected.');
}
}]
];
}
$normalized = str_replace('\\', '/', $pathInfo->getPath());
PathInfo into one critical module (e.g., file uploads).composer.json.pathinfo() calls with PathInfo methods.PathInfo.MediaLibraryService, ConfigLoader, and Artisan commands.PathInfo.How can I help you explore Laravel packages today?