Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9ca86e

Browse files
minor #33825 [FrameworkBundle] encourage installing intl when String is available (nicolas-grekas)
This PR was merged into the 5.0-dev branch. Discussion ---------- [FrameworkBundle] encourage installing intl when String is available | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 215595b [FrameworkBundle] encourage installing intl when String is available
2 parents 35f319c + 215595b commit d9ca86e

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,18 @@ public function load(array $configs, ContainerBuilder $container)
196196
}
197197

198198
// If the slugger is used but the String component is not available, we should throw an error
199-
if (!class_exists(SluggerInterface::class)) {
199+
if (!interface_exists(SluggerInterface::class)) {
200200
$container->register('slugger', 'stdClass')
201-
->addError('You cannot use the "slugger" since the String component is not installed. Try running "composer require symfony/string".');
201+
->addError('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string".');
202+
} else {
203+
if (!interface_exists(LocaleAwareInterface::class)) {
204+
$container->register('slugger', 'stdClass')
205+
->addError('You cannot use the "slugger" service since the Translation contracts are not installed. Try running "composer require symfony/translation".');
206+
}
207+
208+
if (!\extension_loaded('intl')) {
209+
@trigger_error('Please install the "intl" PHP extension for best performance.', E_USER_DEPRECATED);
210+
}
202211
}
203212

204213
if (isset($config['secret'])) {

src/Symfony/Component/String/Slugger/AsciiSlugger.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function slug(string $string, string $separator = '-', string $locale = n
107107

108108
private function createTransliterator(string $locale): ?\Transliterator
109109
{
110-
if (isset($this->transliterators[$locale])) {
110+
if (\array_key_exists($locale, $this->transliterators)) {
111111
return $this->transliterators[$locale];
112112
}
113113

@@ -118,19 +118,16 @@ private function createTransliterator(string $locale): ?\Transliterator
118118

119119
// Locale not supported and no parent, fallback to any-latin
120120
if (false === $str = strrchr($locale, '_')) {
121-
return null;
121+
return $this->transliterators[$locale] = null;
122122
}
123123

124124
// Try to use the parent locale (ie. try "de" for "de_AT") and cache both locales
125125
$parent = substr($locale, 0, -\strlen($str));
126126

127127
if ($id = self::LOCALE_TO_TRANSLITERATOR_ID[$parent] ?? null) {
128128
$transliterator = \Transliterator::create($id.'/BGN') ?? \Transliterator::create($id);
129-
$this->transliterators[$locale] = $this->transliterators[$parent] = $transliterator;
130-
131-
return $transliterator;
132129
}
133130

134-
return null;
131+
return $this->transliterators[$locale] = $this->transliterators[$parent] = $transliterator ?? null;
135132
}
136133
}

src/Symfony/Component/String/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"php": "^7.2.9",
2020
"symfony/polyfill-intl-grapheme": "~1.0",
2121
"symfony/polyfill-intl-normalizer": "~1.0",
22-
"symfony/polyfill-mbstring": "~1.0"
22+
"symfony/polyfill-mbstring": "~1.0",
23+
"symfony/translation-contracts": "^1.1|^2.0"
2324
},
2425
"autoload": {
2526
"psr-4": { "Symfony\\Component\\String\\": "" },

0 commit comments

Comments
 (0)