mirror of
https://github.com/symfony/http-kernel.git
synced 2026-03-24 01:12:09 +01:00
Merge branch '8.0' into 8.1
* 8.0: (26 commits) Fix merge [RateLimiter] Fix retryAfter when consuming exactly all remaining tokens in FixedWindow and TokenBucket [RateLimiter] Fix retryAfter value on last token consume (SlidingWindow) [RateLimiter] Fix reservations outside the second fixed window [Filesystem] makePathRelative with existing files, remove ending / [Config][Routing] Fix exclude option being ignored for non-glob and PSR-4 resources [Serializer][Validator] Fix propertyPath in ConstraintViolationListNormalizer with MetadataAwareNameConverter [Messenger][Amqp] Don't use retry routing key when sending to failure transport [Messenger] Fix re-sending failed messages to a different failure transport [DependencyInjection] Fix #[AsTaggedItem] discovery through multi-level decoration chains [Config] Fix ArrayShapeGenerator required keys with deep merging [Validator] Add a guard when `Parser::IGNORE_UNKNOWN_VARIABLES` is not defined [Validator] Correctly handle null `allowedVariables` in `ExpressionSyntaxValidator` [DependencyInjection] Fix PriorityTaggedServiceTrait not discovering #[AsTaggedItem] on decorated services [Mailer] Clarify the purpose of SentMessage's "message id" concept [ObjectMapper] fix nested mapping with class-level transform [TwigBridge] Fix Bootstrap 4 form error layout [Form] Fix merging POST params and files when collection entries have mismatched indices [Validator] Fix type error for non-array items when Unique::fields is set [HttpKernel] Fix default locale ignored when Accept-Language has no enabled-locale match ...
This commit is contained in:
@@ -36,7 +36,7 @@ class LocaleListener implements EventSubscriberInterface
|
||||
private bool $useAcceptLanguageHeader = false,
|
||||
private array $enabledLocales = [],
|
||||
) {
|
||||
$this->enabledLocales = array_filter($enabledLocales);
|
||||
$this->enabledLocales = $enabledLocales ? array_values(array_unique(array_merge([$defaultLocale], array_filter($enabledLocales)))) : [];
|
||||
}
|
||||
|
||||
public function setDefaultLocale(KernelEvent $event): void
|
||||
|
||||
@@ -188,6 +188,20 @@ class LocaleListenerTest extends TestCase
|
||||
$this->assertEquals('de', $request->getLocale());
|
||||
}
|
||||
|
||||
public function testDefaultLocaleReturnedWhenNoAcceptLanguageMatchAndDefaultLocaleIsNotFirstEnabledLocale()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
$request->headers->set('Accept-Language', 'es;q=0.9,ja;q=0.8');
|
||||
|
||||
// 'de' is the default locale but is NOT first in enabled_locales
|
||||
$listener = new LocaleListener(new RequestStack(), 'de', null, true, ['it', 'fr', 'de']);
|
||||
$event = $this->getEvent($request);
|
||||
|
||||
$listener->setDefaultLocale($event);
|
||||
$listener->onKernelRequest($event);
|
||||
$this->assertEquals('de', $request->getLocale());
|
||||
}
|
||||
|
||||
public function testRequestNoLocaleFromAcceptLanguageHeader()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
|
||||
Reference in New Issue
Block a user