mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Use the locale from the request if available, to generate cache keys
This hopefully fixes the problem with the wrong language of the tools tree in the demo.
This commit is contained in:
parent
2c03a6e683
commit
beeadef853
1 changed files with 7 additions and 2 deletions
|
@ -24,6 +24,7 @@ namespace App\Services\UserSystem;
|
||||||
|
|
||||||
use App\Entity\UserSystem\User;
|
use App\Entity\UserSystem\User;
|
||||||
use Locale;
|
use Locale;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,10 +33,12 @@ use Symfony\Component\Security\Core\Security;
|
||||||
class UserCacheKeyGenerator
|
class UserCacheKeyGenerator
|
||||||
{
|
{
|
||||||
protected Security $security;
|
protected Security $security;
|
||||||
|
protected RequestStack $requestStack;
|
||||||
|
|
||||||
public function __construct(Security $security)
|
public function __construct(Security $security, RequestStack $requestStack)
|
||||||
{
|
{
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
|
$this->requestStack = $requestStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +49,9 @@ class UserCacheKeyGenerator
|
||||||
*/
|
*/
|
||||||
public function generateKey(?User $user = null): string
|
public function generateKey(?User $user = null): string
|
||||||
{
|
{
|
||||||
$locale = Locale::getDefault();
|
$main_request = $this->requestStack->getMainRequest();
|
||||||
|
//Retrieve the locale from the request, if possible, otherwise use the default locale
|
||||||
|
$locale = $main_request ? $main_request->getLocale() : Locale::getDefault();
|
||||||
|
|
||||||
//If no user was specified, use the currently used one.
|
//If no user was specified, use the currently used one.
|
||||||
if (null === $user) {
|
if (null === $user) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue