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 this polyfill in a Laravel project?
Run `composer require symfony/polyfill-intl-idn` in your project root. No additional Laravel-specific configuration is needed—just use the `idn_to_ascii()` or `idn_to_utf8()` functions directly. The polyfill automatically replaces missing Intl extension functions.
Does this work with Laravel’s URL helpers (e.g., `url()`, `route()`) for IDNs?
No, this polyfill only handles domain name conversion (e.g., `例子.测试` → `xn--fsq.xn--0zwm56d`). For full Laravel URL support, you’ll need to manually convert domains before passing them to helpers or use middleware to normalize IDNs in incoming requests.
What Laravel versions are compatible with this package?
This polyfill is framework-agnostic and works with any Laravel version (5.5+) or standalone PHP project. It requires PHP 7.2+ and has no Laravel-specific dependencies, so it integrates seamlessly into modern Laravel apps.
How do I test IDN conversions in Laravel’s testing suite?
Mock the polyfill’s `IdnPolyfill` class in your tests using PHPUnit’s `partialMock` or create a test double. For example, test `idn_to_ascii('例子.测试')` returns `xn--fsq.xn--0zwm56d` and validate edge cases like mixed scripts or invalid Unicode. Use Pest or PHPUnit assertions for validation.
Will this polyfill break if the Intl extension is later enabled?
No, the polyfill gracefully falls back to the native Intl functions if the extension is loaded. Check `extension_loaded('intl')` in your code to conditionally use the polyfill or native functions, ensuring a smooth transition when the Intl extension becomes available.
Are there performance concerns for high-traffic Laravel apps?
Yes, the polyfill is ~5–10x slower than the native Intl extension (~10–30ms vs. ~1–5ms per conversion). For high-throughput paths (e.g., bulk email processing), cache conversions using Laravel’s `Cache` facade or pre-convert domains during initialization.
How does this handle edge cases like invalid Unicode or rare scripts?
The polyfill follows RFC 3490/3492 but may diverge from the native Intl extension for rare scripts (e.g., Tifinagh, Mongolian) or invalid input. Test with a reference dataset (e.g., Unicode IDN Test Cases) and define fallback behavior—like rejecting invalid domains or converting to ASCII—as needed.
Can I use this for email validation or DNS resolution in Laravel?
Yes, this polyfill is ideal for validating internationalized email addresses (e.g., `用户@例子.测试`) or resolving IDNs in DNS lookups. Integrate it with Laravel’s `Str::of()` or validation rules (e.g., `Rule::custom()`) to normalize domains before processing.
What are the alternatives to this polyfill for Laravel?
Alternatives include enabling PHP’s Intl extension (if possible) or using third-party libraries like `rubix/ml` for Unicode handling. However, this polyfill is the most lightweight and Laravel-friendly option, as it’s part of Symfony’s battle-tested suite and requires zero framework-specific setup.
How do I handle failures if the polyfill encounters unsupported input?
Define a fallback strategy in your Laravel app: reject invalid IDNs with a `400` error, convert to ASCII using `iconv()` or `preg_replace()`, or log the issue and continue processing. For example, wrap conversions in a try-catch block and handle exceptions gracefully.
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.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony