Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Polyfill Intl Idn

Polyfill Intl Idn Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions

Frequently asked questions about Polyfill Intl Idn
How do I install symfony/polyfill-intl-idn in a Laravel project?
Run `composer require symfony/polyfill-intl-idn` in your Laravel project directory. The package auto-registers the `idn_to_ascii()` and `idn_to_utf8()` functions globally, requiring no additional configuration. It works alongside Laravel’s autoloader without conflicts.
Will this package work if my server already has the PHP Intl extension enabled?
Yes, the polyfill dynamically checks for the Intl extension at runtime. If it’s available, the native functions are used instead, ensuring zero performance penalty. This makes it safe to include even in environments where Intl is enabled.
Can I use this polyfill with Laravel’s Str helper methods?
Yes, you can wrap the polyfill functions in Laravel’s `Str` helper for consistency. For example, add `Str::idnToAscii($domain)` and `Str::idnToUtf8($punycode)` to your `app/Helpers/Str.php` file. This aligns with Laravel’s API style and reduces boilerplate.
Does this support Laravel’s validator for Unicode domain validation?
While the polyfill itself doesn’t include validation rules, you can extend Laravel’s validator with custom rules like `Rule::idnDomain()` to validate Unicode domains. Combine it with the polyfill’s conversion functions for full Unicode domain handling in forms or API requests.
What Laravel and PHP versions does symfony/polyfill-intl-idn support?
The package supports PHP 7.2.5 and above, with full compatibility in Laravel 5.5+. It has no breaking changes since version 1.34.0 and is regularly updated to align with Symfony’s polyfill suite. Always check the [Symfony Polyfill changelog](https://github.com/symfony/polyfill/blob/main/CHANGELOG.md) for version-specific notes.
Is there a performance impact compared to using the native PHP Intl extension?
Yes, the pure PHP implementation introduces a 10–30% overhead compared to the native `ext-intl`. For high-volume operations (e.g., bulk domain processing in Laravel Queues), consider caching results with Redis or benchmarking to determine if the native extension is worth enabling in your environment.
How do I handle homograph attacks (e.g., Cyrillic ‘аpple.com’ vs. Latin ‘apple.com’) with this polyfill?
The polyfill alone doesn’t prevent homograph attacks, as it only normalizes domains. To mitigate risks, integrate additional checks like `idn_check()` (if available) or use a third-party library like `rubix/ml` for Unicode domain validation. Log suspicious conversions via Laravel’s exception handler for review.
Can I use this polyfill in Laravel Artisan commands or model observers?
Absolutely. The polyfill’s functions are globally available, so you can use them directly in Artisan commands (e.g., `php artisan domain:normalize`) or model observers (e.g., `Domain::observes('creating', 'normalizeIdn')`). This enables seamless IDN handling during domain registration or migrations.
What happens if I pass invalid Unicode input to `idn_to_ascii()` or `idn_to_utf8()`?
The polyfill may not replicate all native Intl error codes, so invalid input will return `false`. Always check return values and log warnings using Laravel’s exception handler. For stricter validation, combine it with Laravel’s validator or a custom rule to catch edge cases early.
Are there alternatives to symfony/polyfill-intl-idn for IDN support in Laravel?
If you need broader Intl features beyond IDN, consider enabling the native `ext-intl` extension in your PHP environment. For minimal IDN support, alternatives like `mnapoli/idna-convert` exist, but Symfony’s polyfill is preferred for its compatibility with Laravel’s ecosystem, zero-config setup, and alignment with Symfony’s standards.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai