8000 Merge branch '5.3' into 5.4 · symfony/symfony@d7d2c48 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7d2c48

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: Fix KernelBrowser::loginUser() causing deprecation [Translation][Loco] Make http requests synchronous when reading the Loco API
2 parents cd3dddf + 81c2bfd commit d7d2c48

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function loginUser(object $user, string $firewallContext = 'main'): self
127127
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
128128
// @deprecated since Symfony 5.4
129129
if (method_exists($token, 'setAuthenticated')) {
130-
$token->setAuthenticated(true);
130+
$token->setAuthenticated(true, false);
131131
}
132132

133133
$container = $this->getContainer();

src/Symfony/Component/Translation/Bridge/Loco/LocoProvider.php

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,47 +90,37 @@ public function read(array $domains, array $locales): TranslatorBag
9090
{
9191
$domains = $domains ?: ['*'];
9292
$translatorBag = new TranslatorBag();
93-
$responses = [];
9493

9594
foreach ($locales as $locale) {
9695
foreach ($domains as $domain) {
97-
$responses[] = [
98-
'response' => $this->client->request('GET', sprintf('export/locale/%s.xlf', rawurlencode($locale)), [
99-
'query' => [
100-
'filter' => $domain,
101-
'status' => 'translated',
102-
],
103-
]),
104-
'locale' => $locale,
105-
'domain' => $domain,
106-
];
107-
}
108-
}
109-
110-
foreach ($responses as $response) {
111-
$locale = $response['locale'];
112-
$domain = $response['domain'];
113-
$response = $response['response'];
96+
// Loco forbids concurrent requests, so the requests must be synchronous in order to prevent "429 Too Many Requests" errors.
97+
$response = $this->client->request('GET', sprintf('export/locale/%s.xlf', rawurlencode($locale)), [
98+
'query' => [
99+
'filter' => $domain,
100+
'status' => 'translated',
101+
],
102+
]);
103+
104+
if (404 === $response->getStatusCode()) {
105+
$this->logger->warning(sprintf('Locale "%s" for domain "%s" does not exist in Loco.', $locale, $domain));
106+
continue;
107+
}
114108

115-
if (404 === $response->getStatusCode()) {
116-
$this->logger->warning(sprintf('Locale "%s" for domain "%s" does not exist in Loco.', $locale, $domain));
117-
continue;
118-
}
109+
$responseContent = $response->getContent(false);
119110

120-
$responseContent = $response->getContent(false);
111+
if (200 !== $response->getStatusCode()) {
112+
throw new ProviderException('Unable to read the Loco response: '.$responseContent, $response);
113+
}
121114

122-
if (200 !== $response->getStatusCode()) {
123-
throw new ProviderException('Unable to read the Loco response: '.$responseContent, $response);
124-
}
115+
$locoCatalogue = $this->loader->load($responseContent, $locale, $domain);
116+
$catalogue = new MessageCatalogue($locale);
125117

126-
$locoCatalogue = $this->loader->load($responseContent, $locale, $domain);
127-
$catalogue = new MessageCatalogue($locale);
118+
foreach ($locoCatalogue->all($domain) as $key => $message) {
119+
$catalogue->set($this->retrieveKeyFromId($key, $domain), $message, $domain);
120+
}
128121

129-
foreach ($locoCatalogue->all($domain) as $key => $message) {
130-
$catalogue->set($this->retrieveKeyFromId($key, $domain), $message, $domain);
122+
$translatorBag->addCatalogue($catalogue);
131123
}
132-
133-
$translatorBag->addCatalogue($catalogue);
134124
}
135125

136126
return $translatorBag;

0 commit comments

Comments
 (0)
0