symfony/polyfill-intl-normalizer
Provides a fallback implementation of PHP’s Intl Normalizer class for environments without the intl extension. Part of Symfony’s polyfill suite, enabling Unicode normalization support across platforms with consistent behavior.
symfony/console, symfony/http-client). It provides feature parity for Unicode normalization without requiring the intl extension, which is critical for:
Str::ascii(), Str::slug(), and Str::upper() for consistent Unicode handling.normalizer_get_raw_decomposition() function unlocks low-level Unicode manipulation, useful for:
intl’s Normalizer class. Existing code (e.g., Normalizer::normalize()) requires no modifications.intl extension is unavailable, with no runtime configuration.mbstring (a PHP core extension).polyfill-ctype, polyfill-mbstring), simplifying dependency management.composer.json to:
"require": {
"symfony/polyfill-intl-normalizer": "^1.38.0"
}
normalizer_get_raw_decomposition() may introduce 2–10x slower performance compared to native intl. Critical for:
intl: Enforce the extension in php.ini or Dockerfiles if performance is non-negotiable.$testCases = [
'é', // Combining character
'🇺🇸', // Emoji sequence
'Café', // Precomposed character
'Cafe\u0301', // Decomposed character
];
foreach ($testCases as $text) {
$decomposed = Normalizer::getRawDecomposition($text);
// Assert expected behavior.
}
mbstring Requirement: Silent failure if disabled. Mitigate with runtime checks:
if (!extension_loaded('mbstring')) {
throw new RuntimeException('mbstring extension is required for Unicode polyfills.');
}
Is normalizer_get_raw_decomposition() a critical requirement?
What are the performance trade-offs?
intl:
$text = str_repeat('é', 10000);
$start = microtime(true);
Normalizer::getRawDecomposition($text);
$time = microtime(true) - $start;
// Compare with native `intl` extension.
intl extension or cache results aggressively.How will this affect Laravel-specific features?
Str::slug() or Str::ascii() behavior?Rule::custom())?What’s the long-term maintenance strategy?
intl if:
intl (e.g., PHP 8.1+).Normalizer usage (e.g., Str::ascii(), Str::slug()).$this->app->singleton('normalizer', function () {
return new \Symfony\Component\Polyfill\Intl\Normalizer();
});
composer require symfony/polyfill-intl-normalizer:^1.38.0
Normalizer calls (e.g., Normalizer::normalize()) continue to work.normalizer_get_raw_decomposition() for custom logic:
use Symfony\Component\Polyfill\Intl\Normalizer;
$decomposed = Normalizer::getRawDecomposition('Café');
mbstring: Mandatory (enabled by default in most Laravel deployments).intl: Optional (polyfill activates only if missing).mbstring is enabled.composer.json and run composer update.Str::slug()).intl extension if performance is critical.intl is missing.How can I help you explore Laravel packages today?