league/uri-components
Immutable value objects for concrete URI components (host, path, query, etc.) in the League URI ecosystem. Requires PHP 8.1+. Supports IDN hosts with intl (or polyfill) and IPv4 conversion via GMP/BCMath or 64-bit PHP.
Scheme, Host, Query, Path), aligning well with modern PHP (8.1+) and Laravel’s emphasis on immutability and functional programming patterns. This reduces side effects and simplifies state management in APIs, validation, or URL manipulation logic.UriInterface), enabling seamless adoption in Laravel’s HTTP layer (e.g., Illuminate\Http\Request, Symfony\Component\HttpFoundation\Request). This is critical for middleware, API routing, or request/response transformations.Domain::isSubdomainOf(), Query::getList(), or Modifier::redactPathSegments() offer granular control over URI manipulation, which is valuable for:
Uri\WhatWg\Url and Uri\Rfc3986\Uri ensures compatibility with modern web standards, critical for cross-browser or cross-platform applications (e.g., SPAs, mobile apps).Route::get('/{path}', ...)) with immutable components for dynamic path generation.Validator to enforce URI structure (e.g., validate Host components against allowed domains).Modifier to construct URLs for Guzzle or Illuminate\Http\Client requests with immutable components.<a href="...">) or redirects (redirect()->to()) using Modifier::toHtmlAnchor().league/uri (v7.8.1+) is required, which may introduce minor overhead but is well-maintained.intl or symfony/polyfill-intl-idn for IDN support (enable for internationalized domains).Modifier::withPath()->appendQuery()->redactUserInfo() require familiarity with method chaining, which may contrast with Laravel’s more imperative style (e.g., str_replace, parse_url).BackedEnum, HierarchicalPath, or URLSearchParams may need documentation or internal training.Query::withList()) may impact memory usage in high-throughput scenarios (e.g., bulk URL generation). Benchmark against parse_url/http_build_query.GMP/BCMath could block IPv4 conversion in legacy environments (mitigate with polyfills).parse_url/urlencode usages may need refactoring. Use Modifier::wrap() to bridge old and new APIs.league/uri) don’t introduce conflicts with Laravel’s service container or HTTP stack.league/uri package’s roadmap aligned with Laravel’s PHP version support?Route::get('/{path}', ...) with component-based path definitions (e.g., Route::get(new HierarchicalPath(['user', ':id']), ...)).Host::tryNew($domain)->isValid() in FormRequest or Validator rules.Http::get(), redirect()->to(), or Action responses using Modifier.Symfony\Component\HttpFoundation\Request compatibility via PSR-7 interfaces (e.g., Request::getUri()->getPath() → Path::fromString()).Modifier::unwrap() to access underlying Uri objects for testing with Laravel’s HttpTestCase.Query::fromPairs()) in unit tests for isolated validation logic.parse_str($_GET['query'], $params) with Query::fromString($_GET['query']).HierarchicalPath for dynamic segments.// Before
Route::get('/user/{id}/posts/{page}', ...);
// After
Route::get(
new HierarchicalPath(['user', ':id', 'posts', ':page']),
...
);
urlencode()/rawurlencode() with Component::encoded() methods.Http::get($url) → Modifier::wrap($url)->withQuery(...)).Host::isSubdomainOf('api.example.com')).Modifier::wrap() to convert existing UriInterface objects (e.g., from PSR-7) to immutable components.$uri = Modifier::wrap($request->getUri());
$path = $uri->getPath(); // Returns HierarchicalPath
parse_url results in components for gradual migration.$parsed = parse_url($url);
$host = Host::tryNew($parsed['host'] ?? '');
league/uri deprecations (e.g., Modifier::getUriString → Modifier::toString) and update Laravel-specific wrappers.league/uri-components and league/uri to composer.json with ^7.8.intl or symfony/polyfill-intl-idn if IDN support is needed.UriComponent facade or service provider to standardize usage (e.g., UriComponent::path()->append('segment')).http_build_query → Query::fromPairs()).Host::tryNew(): ?Host) catch errors early.Modifier::withPath()->appendQuery()->...) may obscure the final URI state. Use Modifier::toString() for debugging.How can I help you explore Laravel packages today?