- Can I use symfony/polyfill-intl-normalizer in Laravel without the intl PHP extension?
- Yes, this polyfill provides a fallback implementation of PHP’s Intl Normalizer class. It works automatically when the intl extension is unavailable, requiring no configuration. Just install it via Composer, and Laravel’s Unicode-dependent features (like Str::slug()) will function as expected.
- How does this polyfill improve Laravel’s Str helper methods like Str::slug()?
- The polyfill ensures consistent Unicode normalization across environments, so Str::slug() handles accented characters (e.g., 'Café') or emojis predictably. Without it, slugs might break or produce inconsistent results on servers missing the intl extension. It aligns with Symfony’s normalization standards, which Laravel’s Str helper leverages internally.
- Will this polyfill work with Laravel Scout or Algolia for search relevance?
- Absolutely. The polyfill enables reliable Unicode normalization for search queries and indexing, which is critical for multilingual or global applications. Scout/Algolia rely on consistent text processing, and this package ensures decomposed or precomposed Unicode characters are handled uniformly, improving search accuracy.
- What Laravel versions officially support symfony/polyfill-intl-normalizer?
- This polyfill is framework-agnostic and works with any Laravel version (5.5+) as long as PHP 7.2+ is used. It’s part of Symfony’s polyfill suite, which Laravel’s dependency resolver handles seamlessly. No Laravel-specific versioning exists, but test thoroughly if using older Laravel (pre-6.x) due to minor PHP version quirks.
- Is there a performance penalty for using normalizer_get_raw_decomposition() in production?
- Yes, the polyfill’s decomposition function can be 2–10x slower than PHP’s native intl extension. For high-throughput systems (e.g., bulk exports or real-time APIs), profile with Blackfire or Xdebug. Cache decompositions in Redis or avoid this function if performance is critical—opt for the native intl extension instead.
- How do I handle edge cases like emojis (e.g., 🇺🇸) or combining characters (e.g., 'é')?
- Test rigorously with a mix of emojis, combining characters, and precomposed/decomposed Unicode. The polyfill may produce unexpected results for complex sequences (e.g., regional indicators). Validate with assertions like `Normalizer::getRawDecomposition($text)` and document edge-case behavior in your codebase.
- Can I remove this polyfill if I already have the intl extension installed?
- Yes, the polyfill is purely a fallback. If your server has the intl extension enabled, you can safely remove it from `composer.json` to reduce vendor size. Run `composer validate` and test Unicode-dependent features (e.g., Str::slug()) to confirm no regressions.
- What alternatives exist for Unicode normalization in Laravel without intl?
- Alternatives include: 1) **mbstring extension** (basic Unicode support but lacks normalization), 2) **custom regex** (limited and error-prone), or 3) **other polyfills** like `symfony/polyfill-ctype`. However, this polyfill is the most robust for Laravel, as it mirrors PHP’s Intl behavior and integrates with Symfony’s ecosystem (used by Laravel’s Str helper).
- How do I enforce the intl extension in Laravel if performance is critical?
- Add the extension to your `php.ini` or Dockerfile, then validate it at runtime with `if (!extension_loaded('intl')) { throw new RuntimeException('intl extension required.'); }`. For CI/CD, fail builds if intl is missing. This ensures optimal performance while avoiding polyfill overhead.
- Does this polyfill support Laravel’s validation rules for Unicode input?
- Yes, it enables custom validation logic for Unicode strings, such as enforcing decomposed forms (e.g., 'Café' instead of 'Café'). Use it in validation rules like `Rule::custom('unicode_normalized', function ($attribute, $value) { return Normalizer::isNormalized($value, Normalizer::FORM_D); })` to ensure consistent input formats.