league/uri-interfaces
Interface definitions for RFC 3986-compliant URI objects. Targets PHP 8.1+, with optional intl (or polyfill) for IDN handling and GMP/BCMath or 64-bit PHP for IPv4 conversion. Part of the League URI project; docs at uri.thephpleague.com.
Strengths:
UriInterface, QueryInterface, and HostInterface enable mocking (e.g., for testing) and custom implementations (e.g., domain-specific URI logic).QueryComposeMode, HostType) and BackedEnum support, reducing legacy baggage.withUsername(), withoutPairByKey()), aligning with Laravel’s service container and dependency injection patterns.Gaps:
league/uri-components) or build one, adding indirect complexity.Illuminate\Support\Facades\URL compatibility), requiring wrapper classes for seamless adoption.intl extension or polyfills for IDN hosts and GMP/BCMath for IPv4/IPv6 conversions, which may not be enabled in all Laravel deployments (e.g., shared hosting).Laravel Ecosystem Fit:
UrlGenerator for RFC-compliant URLs (e.g., in API responses or redirects).QueryString::composeFromValue().HostInterface::isValid()).Url facade.Challenges:
Illuminate\Support\Str, Illuminate\Routing\UrlGenerator). Introducing this package may require refactoring to avoid duplication.UrlGenerator changes). The TPM must track deprecation cycles for both stacks.High:
UriInterface::getComponents → toComponents). Laravel’s LTS support (e.g., 8.x–10.x) may lag behind.intl, GMP, or BCMath could block adoption in constrained environments (e.g., Docker containers without extensions).Mitigation:
Uri::make()) to abstract interface usage and handle edge cases.Strategic Alignment:
Url facade? If the latter, how will conflicts be managed?Implementation Scope:
league/uri-components) or use an existing one?Illuminate\Routing\Router)?Operational Trade-offs:
intl, GMP) be handled in CI/CD and production?Performance:
Testing:
http://user:pass@[IPv6::1] or https://例子.测试) be tested in Laravel’s test suite?Laravel Core:
Illuminate\Routing\UrlGenerator for RFC-compliant URL generation (e.g., in route() helpers).Illuminate\Validation\Validator to enforce URI structure (e.g., HostInterface::isValid()).Illuminate\Http\Client for parsing/resolving URIs.Laravel Ecosystem:
queue:work with custom URI logic).Third-Party Integrations:
UriInterface::isValid().UriString::normalize().Assessment Phase:
url(), route(), Str::of()).Pilot Implementation:
composer.json and create a wrapper class (e.g., app/Services/UriService.php) to abstract interface usage.
namespace App\Services;
use League\Uri\Contracts\UriInterface;
use League\Uri\UriString;
class UriService {
public function createFromString(string $uri): UriInterface {
return UriString::createFromString($uri);
}
}
Gradual Rollout:
Fallback Strategy:
Laravel Versions:
Stringable) rely on Symfony’s stringable component (bundled with Laravel).UrlGenerator for changes that overlap with this package (e.g., toRoute() vs. UriInterface::resolve()).Extension Conflicts:
intl: Required for IDHow can I help you explore Laravel packages today?