removed support for using null as the locale

This commit is contained in:
Christian Flothmann 2019-08-21 14:28:14 +02:00
parent 0a1e244626
commit 0f4ed264d8
2 changed files with 3 additions and 15 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
5.0.0
-----
* removed support for using `null` as the locale in `Translator`
* removed `TranslatorInterface`
* removed `MessageSelector`
* removed `ChoiceMessageFormatterInterface`

View File

@ -84,12 +84,8 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
/**
* @throws InvalidArgumentException If a locale contains invalid characters
*/
public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false)
public function __construct(string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false)
{
if (null === $locale) {
@trigger_error(sprintf('Passing "null" as the $locale argument to %s() is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED);
}
$this->setLocale($locale, false);
if (null === $formatter) {
@ -149,10 +145,6 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
*/
public function setLocale($locale)
{
if (null === $locale && (2 > \func_num_args() || func_get_arg(1))) {
@trigger_error(sprintf('Passing "null" as the $locale argument to %s() is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED);
}
$this->assertValidLocale($locale);
$this->locale = $locale;
}
@ -178,9 +170,6 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
$this->catalogues = [];
foreach ($locales as $locale) {
if (null === $locale) {
@trigger_error(sprintf('Passing "null" as the $locale argument to %s() is deprecated since Symfony 4.4.', __METHOD__), E_USER_DEPRECATED);
}
$this->assertValidLocale($locale);
}
@ -431,11 +420,9 @@ EOF
/**
* Asserts that the locale is valid, throws an Exception if not.
*
* @param string $locale Locale to tests
*
* @throws InvalidArgumentException If the locale contains invalid characters
*/
protected function assertValidLocale($locale)
protected function assertValidLocale(string $locale)
{
if (1 !== preg_match('/^[a-z0-9@_\\.\\-]*$/i', $locale)) {
throw new InvalidArgumentException(sprintf('Invalid "%s" locale.', $locale));