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 Laravel Package

symfony/polyfill-intl-idn

Provides polyfills for PHP’s Intl IDN functions idn_to_ascii and idn_to_utf8, enabling internationalized domain name conversion on systems where the Intl extension isn’t available. Part of Symfony’s Polyfill components, MIT licensed.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer:

composer require symfony/polyfill-intl-idn

It’s automatically autoloaded—no manual setup or config required. The polyfill registers idn_to_ascii() and idn_to_utf8() functions globally only if they don’t already exist (i.e., when ext-intl is absent).
First use case: Sanitize user-submitted international domains for storage or validation:

$domain = idn_to_ascii('москва.рф'); 
// → 'xn--80acaazcfs.xn--p1ai'

Implementation Patterns

  • Drop-in Replacement for Native Functions: Call idn_to_ascii()/idn_to_utf8() directly anywhere—no namespace imports. Works identically to ext-intl when available.
  • Input Normalization Pipeline: Integrate into form request validation or middleware to convert Unicode domains to ASCII before DB storage or comparison:
    $normalized = idn_to_ascii($input['domain'] ?? '');
    if ($normalized === false) {
        // Handle invalid domain
    }
    
  • Dual Conversion Workflow: Use idn_to_ascii() for storage/comparison and idn_to_utf8() for UI display—ensures both safety and readability:
    $ascii = idn_to_ascii($domain); // Stored in DB
    $ui = idn_to_utf8($ascii);      // Shown in profile view
    
  • Compliance Validation Stack: Chain with filter_var(..., FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) after ASCII conversion for robust RFC-compliant validation.

Gotchas and Tips

  • Silent Failures: idn_to_ascii() returns false and triggers E_WARNING on invalid input (e.g., malformed labels). Use @idn_to_ascii() or check intl_get_error_code() (if ext-intl is present) for graceful handling.
  • Contextual Flags: Default behavior (IDNA_DEFAULT) may not suit all cases. For email addresses (RFC 6142), explicitly set flags:
    idn_to_ascii('test@café.com', IDNA_CHECK_BIDI | IDNA_NONTRANSITIONAL_TO_ASCII);
    
  • Dependency Order: Requires symfony/polyfill-intl-normalizer. Composer handles this automatically—verify composer.lock isn’t stale if IDN calls fail silently.
  • Environment Awareness: Even in ext-intl-enabled environments, include the polyfill for consistency across dev/staging/prod (avoids "works on my machine" edge cases). The polyfill safely self-deactivates if native functions exist.
  • Avoid Overuse: Not suitable for DNS validation, MX record lookups, or complex locale-aware IDN handling—reserve for ASCII/Unicode domain translation only.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport