symfony/polyfill-intl-grapheme
Native PHP polyfill for the Intl Grapheme functions, for working with UTF-8 grapheme clusters. Provides grapheme_strlen, grapheme_substr, grapheme_strpos/stripos, grapheme_extract, grapheme_str_split, and related helpers when ext-intl isn’t available.
Str helper.intl extension.grapheme_strrev() and other grapheme functions (e.g., grapheme_str_split()), which are now more stable with fixes like #616 for PCRE compatibility.strrev() suffices. The PCRE fix in grapheme_str_split() may introduce minor edge cases in regex-heavy applications.Str facade via macros, enabling fluent syntax (e.g., Str::graphemeReverse()). The fix for grapheme_str_split() ensures compatibility with regex-based operations (e.g., Laravel’s validation or search features).strrev() usage. The new release does not introduce breaking changes, maintaining stability.@reverseGraphemes), and validation rules can leverage grapheme-aware reversal for palindrome checks.| Risk | Likelihood | Impact | Mitigation |
|---|---|---|---|
| PHP 8.6+ dependency | High | High | Document requirement clearly; provide fallback logic (e.g., intl extension or custom polyfill) for older PHP versions. |
| Performance overhead | Low | Medium | Benchmark against native strrev(); optimize only if critical paths are affected. |
| Incomplete Unicode support | Medium | Medium | Prefer intl extension if available for broader Unicode coverage (e.g., IntlGraphemeClusterIterator). |
| Breaking changes in future PHP | Low | High | Monitor PHP deprecations; update polyfill as needed. |
| Hosting environment constraints | Medium | High | Test in target environments (e.g., shared hosting may lack PHP 8.6 or PCRE updates). |
| PCRE compatibility issues | Low | Medium | Test grapheme_str_split() with regex patterns in Laravel validation/search. |
PHP Version Strategy:
Fallback Mechanisms:
grapheme_str_split() and fall back to preg_split() or intl for environments with PCRE issues?function grapheme_str_split_fallback($str, $pattern) {
return function_exists('grapheme_str_split')
? grapheme_str_split($str, $pattern)
: preg_split($pattern, $str); // or intl-based fallback
}
Laravel Core Integration:
grapheme_str_split() be added to Laravel’s core Str helper or left as a community package?Testing Scope:
grapheme_str_split() (e.g., Arabic, Hebrew, emoji sequences like 👨👩👧👦)?grapheme_str_split() with complex regex patterns (e.g., \p{L}+)?Documentation:
intl-based solutions or custom regex splits?Str Facade: Extend with graphemeSplit() macro for fluent regex splitting:
Str::macro('graphemeSplit', function ($pattern) {
return grapheme_str_split($this->value, $pattern);
});
@graphemeSplit directive for RTL content processing.grapheme_split rule for complex pattern validation (e.g., usernames with RTL characters).grapheme_str_split() is used; PCRE fix ensures compatibility with regex patterns.intl extension or custom polyfill (not recommended for production).Assessment Phase (1 day):
preg_split()/explode() usage in codebase, especially for RTL/emoji-heavy features.\p{L}+, [^\s]+).Integration Phase (3–5 days):
symfony/polyfill-intl-grapheme to composer.json (PHP 8.6+ only).Str helper with graphemeSplit():
Str::macro('graphemeSplit', function ($pattern) {
return grapheme_str_split($this->value, $pattern);
});
Blade::directive('graphemeSplit', function ($expression, $pattern) {
return "<?php echo implode(',', grapheme_str_split({$expression}, {$pattern})); ?>";
});
Rule::macro('graphemeSplit', function ($pattern) {
return function ($attribute, $value, $fail) {
$parts = grapheme_str_split($value, $pattern);
// Custom logic (e.g., check part lengths)
};
});
Testing Phase (2–3 days):
👨👩👧👦 split by whitespace).éléphant split by vowels).Deployment Phase (1 day):
composer.json and run composer update.grapheme_str_split() issues.symfony/polyfill-intl-grapheme (but grapheme_str_split() may still fail on older PCRE).intl extension or custom logic.intl extension + PCRE updates.Prioritization for Laravel Projects:
grapheme_str_split().How can I help you explore Laravel packages today?