if (null !==
$parentRequest =
$this->requestStack->
getParentRequest()) { $this->
setRouterContext($parentRequest);
} } private function setLocale(Request
$request): void
{ if ($locale =
$request->attributes->
get('_locale'
)) { $request->
setLocale($locale);
} elseif ($this->useAcceptLanguageHeader
) { if ($preferredLanguage =
$request->
getPreferredLanguage($this->enabledLocales
)) { $request->
setLocale($preferredLanguage);
} $request->attributes->
set('_vary_by_language', true
);
} } private function setRouterContext(Request
$request): void
{ $this->router?->
getContext()->
setParameter('_locale',
$request->
getLocale());
}