sabre/uri
Lightweight, RFC3986-compliant PHP URI utility library. Resolve relative URLs, normalize for comparisons, parse/build (like parse_url with Windows path edge cases), and split URIs into dirname/basename. Fully unit tested and inspired by Node’s URL APIs.
url(), route()) by providing low-level URI parsing/resolution for edge cases (e.g., Windows paths, Unicode, or relative references).Illuminate\Support\Str::of() or parse_url() for complex URI scenarios (e.g., resolving relative paths against a base URL).file:// or s3:// URIs in storage logic).| Risk Area | Assessment | Mitigation |
|---|---|---|
| Behavioral Changes | Minor edge-case fixes (e.g., Windows paths in 3.0.0) were reverted in 3.0.1+. No breaking changes in 3.0.x. | Test thoroughly against existing URI logic (e.g., parse_url(), Laravel’s url() helper) to validate consistency. |
| Performance Overhead | Negligible (pure-PHP, no external calls). Benchmark against native parse_url() for critical paths (e.g., request routing). |
Profile in staging with real-world URI payloads (e.g., user-generated links, API endpoints). |
| Unicode/Internationalization | Handles non-ASCII characters correctly (e.g., Chinese/Hebrew URLs via RFC3986 compliance). | Validate against multilingual test cases (e.g., Laravel’s localization features). |
| Windows Path Support | Special handling for file:///C:/ paths (fixed in 2.2.4/3.0.1). |
Test with Windows-based storage integrations (e.g., S3, local filesystem drivers). |
| Static Analysis | PHPStan 2+ support reduces false positives but may require minor type adjustments in calling code. | Audit existing URI logic for type mismatches (e.g., null returns from parse()). |
| Long-Term Maintenance | Community-driven (fruux) with infrequent releases (last update: 2026-04-01). No active Laravel-specific support, but no Laravel dependencies. | Monitor GitHub issues for critical bugs. Consider forking if maintenance becomes a blocker (low risk given stability). |
parse_url(), Str::of()) or only specific components (e.g., API request validation)?Route::dispatch)?sabre/uri?parse_url() for performance-critical paths (e.g., request routing)?@deprecated in 1–2 releases)?parse_url() to sabre/uri incrementally?Illuminate\Http\Request URI parsing (e.g., normalize incoming URIs before routing).normalize() to canonicalize route URIs (e.g., /user/1 vs. /user/1/).file:// or s3:// URIs in filesystem drivers (e.g., Storage::disk()).resolve() relative paths against a base URL)./v1/endpoint vs. /v1/endpoint/).normalize() for consistent storage).parse() to validate URI structure).| Phase | Action | Tools/Dependencies |
|---|---|---|
| Assessment | Audit existing URI logic (e.g., parse_url(), custom functions) for edge cases (Windows paths, Unicode, relative resolution). |
phpstan, robo (for static analysis), manual code review. |
| Pilot Integration | Replace one high-impact component (e.g., API request validation or storage URI resolution) with sabre/uri. |
Laravel’s app/Providers/AppServiceProvider (bind sabre/uri as a singleton). |
| Core Integration | Extend Laravel’s Request class to use sabre/uri for URI parsing (e.g., override getRequestUri()). |
Laravel’s Illuminate\Http\Request facade. |
| Testing | Write RFC3986-compliant test cases for all URI operations (e.g., resolve(), normalize()). |
PestPHP or PHPUnit, sabre/uri test suite as reference. |
| Deprecation | Mark custom URI functions as @deprecated and replace them in 2–3 releases. |
Laravel’s deprecation helper. |
| Optimization | Benchmark against native parse_url() and optimize critical paths (e.g., caching parsed URIs in Request). |
Laravel’s Benchmark facade or Blackfire. |
url() helper (for building URIs from parsed components).Storage facade (for resolving file:// or s3:// URIs).Route model binding (for normalizing route parameters).Illuminate\Http\Request to use sabre/uri for getRequestUri().Illuminate\Support\Str::of() for URI-specific logic.intl or mbstring (handles Unicode via RFC3986).parse_url() wrappers).How can I help you explore Laravel packages today?