[FrameworkBundle] encourage installing intl when String is available
This commit is contained in:
parent
ebda9d1ae7
commit
215595be5a
@ -196,9 +196,18 @@ class FrameworkExtension extends Extension
|
||||
}
|
||||
|
||||
// If the slugger is used but the String component is not available, we should throw an error
|
||||
if (!class_exists(SluggerInterface::class)) {
|
||||
if (!interface_exists(SluggerInterface::class)) {
|
||||
$container->register('slugger', 'stdClass')
|
||||
->addError('You cannot use the "slugger" since the String component is not installed. Try running "composer require symfony/string".');
|
||||
->addError('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string".');
|
||||
} else {
|
||||
if (!interface_exists(LocaleAwareInterface::class)) {
|
||||
$container->register('slugger', 'stdClass')
|
||||
->addError('You cannot use the "slugger" service since the Translation contracts are not installed. Try running "composer require symfony/translation".');
|
||||
}
|
||||
|
||||
if (!\extension_loaded('intl')) {
|
||||
@trigger_error('Please install the "intl" PHP extension for best performance.', E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($config['secret'])) {
|
||||
|
@ -107,7 +107,7 @@ class AsciiSlugger implements SluggerInterface, LocaleAwareInterface
|
||||
|
||||
private function createTransliterator(string $locale): ?\Transliterator
|
||||
{
|
||||
if (isset($this->transliterators[$locale])) {
|
||||
if (\array_key_exists($locale, $this->transliterators)) {
|
||||
return $this->transliterators[$locale];
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ class AsciiSlugger implements SluggerInterface, LocaleAwareInterface
|
||||
|
||||
// Locale not supported and no parent, fallback to any-latin
|
||||
if (false === $str = strrchr($locale, '_')) {
|
||||
return null;
|
||||
return $this->transliterators[$locale] = null;
|
||||
}
|
||||
|
||||
// Try to use the parent locale (ie. try "de" for "de_AT") and cache both locales
|
||||
@ -126,11 +126,8 @@ class AsciiSlugger implements SluggerInterface, LocaleAwareInterface
|
||||
|
||||
if ($id = self::LOCALE_TO_TRANSLITERATOR_ID[$parent] ?? null) {
|
||||
$transliterator = \Transliterator::create($id.'/BGN') ?? \Transliterator::create($id);
|
||||
$this->transliterators[$locale] = $this->transliterators[$parent] = $transliterator;
|
||||
|
||||
return $transliterator;
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->transliterators[$locale] = $this->transliterators[$parent] = $transliterator ?? null;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,8 @@
|
||||
"php": "^7.2.9",
|
||||
"symfony/polyfill-intl-grapheme": "~1.0",
|
||||
"symfony/polyfill-intl-normalizer": "~1.0",
|
||||
"symfony/polyfill-mbstring": "~1.0"
|
||||
"symfony/polyfill-mbstring": "~1.0",
|
||||
"symfony/translation-contracts": "^1.1|^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Component\\String\\": "" },
|
||||
|
Reference in New Issue
Block a user