league/uri
League URI is a PHP 8.1+ library with intuitive classes for parsing, validating, normalizing, and manipulating URIs. Supports PSR-7 integration plus optional IDN, IPv4 conversion, and HTML/DOM features when extensions are available.
isCrossOrigin(), isSameOrigin(), or isLocalFile() to mitigate XSS/CSRF risks in web apps or APIs.UriTemplate and expand() methods, reducing manual string concatenation errors.parse_url() hacks).intl extension or polyfills, critical for global applications or multilingual URLs.Http class or HttpFactory to align with modern PHP HTTP standards (e.g., for HTTP clients like Guzzle or Symfony’s HTTP components).Adopt if:
Uri implementation.例子.测试).mailto: schemes).Look elsewhere if:
parse_url() suffices).url or whatwg-url).For Executives:
"This package eliminates URI-related bugs and security gaps in our [web service/API/product] by providing a standardized, RFC-compliant way to handle URLs. It reduces technical debt from ad-hoc parsing logic, enables safer cross-origin checks, and supports international domains—critical for our [global/local] user base. With minimal integration effort (a composer require), we gain enterprise-grade URI validation, template-based dynamic URLs, and alignment with modern PHP HTTP standards (PSR-7/PSR-17). The MIT license and active maintenance (last release: 2026) ensure long-term reliability."
For Engineers: *"league/uri replaces fragile URI logic with a batteries-included library that handles:
mailto: schemes.withPath(), resolve(), or normalize() for safe URL construction.UriTemplate (e.g., for API routes or redirects).Why not roll our own?
file:// URIs, Windows/Unix paths, and query parameter ordering.Migration Path:
parse_url() or regex with Uri::new() or Uri::parse().Http class for PSR-7 compliance (e.g., in middleware).UriTemplate for dynamic URLs (e.g., /users/{id} → /users/123).isCrossOrigin() in auth/validation layers.Dependencies:
intl extension for IDN support (or symfony/polyfill-intl-idn)."*How can I help you explore Laravel packages today?