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

Skip to content

[FrameworkBundle] encourage installing intl when String is available #33825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,18 @@ public function load(array $configs, ContainerBuilder $container)
}

// 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'])) {
Expand Down
9 changes: 3 additions & 6 deletions src/Symfony/Component/String/Slugger/AsciiSlugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function slug(string $string, string $separator = '-', string $locale = n

private function createTransliterator(string $locale): ?\Transliterator
{
if (isset($this->transliterators[$locale])) {
if (\array_key_exists($locale, $this->transliterators)) {
return $this->transliterators[$locale];
}

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

// 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
$parent = substr($locale, 0, -\strlen($str));

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;
}
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/String/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\\": "" },
Expand Down