league/uri-components
Immutable value objects for URI components (host, path, query, etc.) from The PHP League. PHP 8.1+. Supports IDN hosts (intl or polyfill) and IPv4 conversion (GMP/BCMath/64-bit). Built atop league/uri, uri-interfaces, and PSR-7.
Feature Development:
getList, appendList, filter) for analytics tools, search engines, or form submissions.isSubdomainOf, commonAncestorWith for multi-tenant apps, CDN routing, or domain-based feature flags.Roadmap Prioritization:
explode('/'), preg_replace) with type-safe, immutable components, reducing bugs in URL-heavy features.Use Cases:
Host validation).parse_url()/http_build_query() to a structured, maintainable approach.Adopt When:
Look Elsewhere If:
parse_url().url core module or node:url).bobthecow/uri or polyfills.mathiasverraes/micro-uri.symfony/dom-crawler may suffice."This package lets us handle URLs like a first-class citizen—no more fragile string hacks or regex nightmares. For example:
/products?category[]=electronics&category[]=books&sort=-price) without manual encoding/decoding.例子.测试) and IPv6 out of the box, future-proofing our product for non-English markets.
It’s a drop-in replacement for messy URL logic, reducing bugs and dev time while adding enterprise-grade features. The MIT license and active maintenance make it a low-risk choice."*"Why this over homegrown solutions?
str_replace() hell—URI parts (query, path, host) are immutable value objects. Example:
$uri = Uri::create('https://example.com/search?q=php');
$updated = $uri->withQuery($uri->getQuery()->append('page', 2));
$query->appendList('tags', 'laravel')->appendList('tags', 'php').$domain->isSubdomainOf('example.com').$modifier->normalizeHost().BackedEnum support, no deprecated PSR-7 cruft).league/oauth2-client), with clear deprecation paths.Migration Path:
Uri::create() for parsing.http_build_query() with $query->toRFC3986().Modifier for chaining changes (e.g., $uri->withPath()->withQuery()).Domain/Path classes for complex logic.Trade-offs:
Next Steps:
composer.json as a dev dependency.How can I help you explore Laravel packages today?