symfony/polyfill-intl-idn
Provides polyfills for the Intl IDN functions idn_to_ascii() and idn_to_utf8(), enabling Internationalized Domain Name conversion on PHP installations without the intl extension. Part of Symfony’s Polyfill suite, MIT licensed.
Intl extension is unavailable, enabling support for internationalized domain names (IDNs) without requiring infrastructure changes. This aligns with Laravel’s modular, dependency-light philosophy and avoids over-engineering.Intl extension is later enabled, the polyfill can be gradually phased out by checking extension_loaded('intl') and delegating to native functions. This minimizes technical debt and simplifies migrations.composer require and basic usage. No need for service providers, facades, or config overrides, reducing integration complexity.idn_to_ascii/idn_to_utf8 (unlikely in Laravel’s ecosystem).partialMock for Symfony\Component\Polyfill\Intl\Idn\IdnPolyfill). Existing PHPUnit or Pest tests can validate IDN conversion logic.例子.xn--test).xn-- labels with ASCII-only payloads, as fixed in v1.38.1).Intl:
idn_to_ascii('例子.测试') might return xn--fsq.xn--0zwm56d in both, but rare scripts (e.g., Tifinagh, Mongolian) could vary.Intl (~10–30ms vs. ~1–5ms per conversion). Benchmark in high-throughput paths (e.g., bulk email processing, API rate limits).Cache facade).idn_to_utf8('xn--bcher-kva.ch') should return bücher.ch, but normalization forms (NFC/NFD) might differ.Intl extension permanently unavailable (e.g., shared hosting) or temporarily disabled (e.g., CI/CD pipeline)? This affects the long-term viability of the polyfill.Intl (e.g., feature flag, phased rollout).URL::to(), email validation) or broader Unicode normalization (e.g., user-generated content, API payloads)?Str::of()->ascii()) or third-party packages (e.g., spatie/laravel-activitylog)?iconv() or preg_replace)?idn_to_ascii() returns false → default to filter_var($domain, FILTER_SANITIZE_STRING).idn_to_ascii/idn_to_utf8 with edge cases.idn/validate to cross-validate polyfill output.composer why symfony/polyfill-intl-idn
Str::of()->toAscii()) to avoid duplication.Intl extension is unavailable (e.g., serverless deployments, Docker containers).Dockerfile) without extension dependencies.symfony/string, symfony/mime), this polyfill reinforces consistency in Unicode handling.Symfony\Component\String\UnicodeString alongside the IDN polyfill for homogeneous Unicode processing.Intl is disabled by default.preg_replace hacks, custom IDN logic).grep -r "idn_to_ascii\|idn_to_utf8\|preg_replace.*IDN" app/
composer.json:
"require": {
"symfony/polyfill-intl-idn": "^1.38"
}
composer update symfony/polyfill-intl-idn.// Before (custom hack)
$asciiDomain = preg_replace('/[^\x20-\
How can I help you explore Laravel packages today?