Skip to content

Commit f629ba9

Browse files
Merge branch '5.0' into 5.1
* 5.0: [String] Added a help message when translation-contracts is not installed Add: ExcludeList usage for PHPUnit 9.4 [Cache] Fix compat wth DBAL v3 [String] throw when Alpine is used and translit fails
2 parents ac70459 + d909085 commit f629ba9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

AbstractUnicodeString.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ public function ascii(array $rules = []): self
140140
} elseif (ICONV_IMPL === 'glibc') {
141141
$s = iconv('UTF-8', 'ASCII//TRANSLIT', $s);
142142
} else {
143-
$s = preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) {
144-
$c = iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0]);
143+
$s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) {
144+
if ('' === $c = (string) iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0])) {
145+
throw new \LogicException(sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class));
146+
}
145147

146148
return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : (\strlen($c) ? $c : '?');
147149
}, $s);

Slugger/AsciiSlugger.php

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
use Symfony\Component\String\UnicodeString;
1616
use Symfony\Contracts\Translation\LocaleAwareInterface;
1717

18+
if (!interface_exists(LocaleAwareInterface::class)) {
19+
throw new \LogicException('You cannot use the "Symfony\Component\String\Slugger\AsciiSlugger" as the "symfony/translation-contracts" package is not installed. Try running "composer require symfony/translation-contracts".');
20+
}
21+
1822
/**
1923
* @author Titouan Galopin <[email protected]>
2024
*/

0 commit comments

Comments
 (0)