league/uri-interfaces
RFC 3986-compliant URI interfaces for PHP 8.1+. Defines contracts for URI objects and related components used across the League URI ecosystem. Supports IDN hosts (intl or polyfill) and IPv4 conversion (GMP/BCMath/64-bit).
league/uri-components).Illuminate\Http\Request, Illuminate\Support\Str) could leverage these interfaces for type-safe URI manipulation, especially in APIs, redirects, or URL generation.url() helper) can be wrapped to conform to these contracts.League\Uri\UriString) to these interfaces for runtime flexibility.UriInterface for HTTP client tests).league/uri-components). Risk of orphaned interfaces if no implementation is chosen.intl (for IDN) and GMP/BCMath (for IPv4/IPv6), which may need runtime checks in Laravel’s environment.Url class or Str::of() be replaced, or just extended?league/uri-components, symfony/psr-http-message, or custom?)route('foo')) adapt to these interfaces?HostRecord caching)?HttpClient, Redirector)?Illuminate\Support\Str::of() or Url::from() with UriInterface for type-safe URI handling.UriInterface::resolve() for relative URL resolution (e.g., asset('images/foo.png')).HostInterface::isValid() or UriString::isValidScheme() in form requests or API gateways.UriInterface in feature tests for HTTP clients (e.g., Guzzle, Symfony HTTP Client).guzzlehttp/guzzle or spatie/array-to-xml.QueryInterface for query parameter manipulation in auth flows.league/uri-interfaces to composer.json.App\Services\UriService) implementing UriInterface to wrap Laravel’s Url or Str.class LaravelUriAdapter implements UriInterface {
public function __construct(private string $uri) {}
public function getScheme(): string { return parse_url($this->uri, PHP_URL_SCHEME); }
// ... other methods
}
MailService, PaymentGateway) with interface methods.// Before: Str::of($url)->contains('https')
// After: app(UriInterface::class)->getScheme() === 'https'
UriInterface in constructors.Url class and Str::of() won’t break, but new code should prefer interfaces.LaravelUriAdapter above).league/uri-components (500K+ downloads) for a drop-in replacement.symfony/psr-http-message if RFC 3986 compliance is critical (Symfony focuses on PSR-7).intl extension is enabled or use symfony/polyfill-intl-idn.GMP/BCMath support for IPv4/IPv6 conversion.| Priority | Task | Dependencies |
|---|---|---|
| 1 | Add league/uri-interfaces to composer.json |
None |
| 2 | Create LaravelUriAdapter to wrap existing URI logic |
league/uri-interfaces |
| 3 | Update unit tests to use UriInterface mocks |
Adapter |
| 4 | Replace Str::of() with UriInterface in critical services |
Adapter, tests |
| 5 | Enforce interfaces in new features/bug fixes | CI checks (PHPStan) |
| 6 | Deprecate old URI logic in favor of interfaces (long-term) | Full migration |
league/uri-components to symfony/psr-http-message) requires only interface updates.UriInterface::getHost() → UriString::parse()).league/uri-* is PHP-general; Laravel-specific quirks may need custom fixes.HostRecord caching in UriString for high-traffic APIs.| Scenario | Impact | Mitigation Strategy |
|---|---|---|
Missing intl extension |
IDN hosts fail (e.g., 例.测试) |
Use symfony/polyfill-intl-idn or fail gracefully. |
| IPv6 conversion errors | IPv4/IPv6 mismatches | Validate GMP/BCMath in AppServiceProvider. |
| RFC 3986 non-compliance | Broken redirects/APIs | Add validation middleware for incoming URIs. |
| Concrete implementation bugs | URI parsing failures | Pin to a stable version of league/uri-components. |
| Team resistance to interfaces | Slow adoption | Start with opt-in usage in new features. |
How can I help you explore Laravel packages today?