Skip to content

Commit 49a59da

Browse files
committed
Remove WriteConfig
1 parent 28c3496 commit 49a59da

File tree

4 files changed

+28
-145
lines changed

4 files changed

+28
-145
lines changed

src/Symfony/Component/Translation/Bridge/Phrase/PhraseProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
namespace Symfony\Component\Translation\Bridge\Phrase;
1313

14-
use Psr\Cache\CacheItemInterface;
1514
use Psr\Cache\CacheItemPoolInterface;
1615
use Psr\Log\LoggerInterface;
1716
use Symfony\Component\Mime\Part\DataPart;
1817
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
19-
use Symfony\Component\Translation\Bridge\Phrase\Config\WriteConfig;
2018
use Symfony\Component\Translation\Dumper\XliffFileDumper;
2119
use Symfony\Component\Translation\Exception\ProviderException;
2220
use Symfony\Component\Translation\Loader\LoaderInterface;
@@ -42,8 +40,8 @@ public function __construct(
4240
private readonly string $defaultLocale,
4341
private readonly string $endpoint,
4442
private array $readConfig,
45-
private WriteConfig $writeConfig,
46-
private bool $isFallbackLocaleEnabled = false,
43+
private array $writeConfig,
44+
private readonly bool $isFallbackLocaleEnabled = false,
4745
) {
4846
}
4947

@@ -67,7 +65,9 @@ public function write(TranslatorBagInterface $translatorBag): void
6765
$content = $this->xliffFileDumper->formatCatalogue($catalogue, $domain, ['default_locale' => $this->defaultLocale]);
6866
$filename = sprintf('%d-%s-%s.xlf', date('YmdHis'), $domain, $catalogue->getLocale());
6967

70-
$fields = array_merge($this->writeConfig->setTag($domain)->setLocale($phraseLocale)->getOptions(), ['file' => new DataPart($content, $filename, 'application/xml')]);
68+
$this->writeConfig['tags'] = $domain;
69+
$this->writeConfig['locale_id'] = $phraseLocale;
70+
$fields = array_merge($this->writeConfig, ['file' => new DataPart($content, $filename, 'application/xml')]);
7171

7272
$formData = new FormDataPart($fields);
7373

src/Symfony/Component/Translation/Bridge/Phrase/PhraseProviderFactory.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Psr\Log\LoggerInterface;
16-
use Symfony\Component\Translation\Bridge\Phrase\Config\WriteConfig;
1716
use Symfony\Component\Translation\Dumper\XliffFileDumper;
1817
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
1918
use Symfony\Component\Translation\Loader\LoaderInterface;
@@ -36,6 +35,10 @@ class PhraseProviderFactory extends AbstractProviderFactory
3635
'enclose_in_cdata' => '1',
3736
],
3837
];
38+
private const WRITE_CONFIG_DEFAULT = [
39+
'file_format' => 'symfony_xliff',
40+
'update_translations' => '1',
41+
];
3942

4043
public function __construct(
4144
private readonly HttpClientInterface $httpClient,
@@ -68,7 +71,7 @@ public function create(Dsn $dsn): ProviderInterface
6871
]);
6972

7073
$readConfig = $this->readConfigFromDsn($dsn);
71-
$writeConfig = WriteConfig::fromDsn($dsn);
74+
$writeConfig = $this->writeConfigFromDsn($dsn);
7275

7376
return new PhraseProvider($client, $this->logger, $this->loader, $this->xliffFileDumper, $this->cache, $this->defaultLocale, $endpoint, $readConfig, $writeConfig, $this->isFallbackLocaleEnabled($dsn));
7477
}
@@ -100,4 +103,13 @@ private function readConfigFromDsn(Dsn $dsn): array
100103

101104
return array_merge(self::READ_CONFIG_DEFAULT, $options);
102105
}
106+
107+
private function writeConfigFromDsn(Dsn $dsn): array
108+
{
109+
$options = $dsn->getOptions()['write'] ?? [];
110+
111+
unset($options['file_format'], $options['tags'], $options['locale_id'], $options['file']);
112+
113+
return array_merge(self::WRITE_CONFIG_DEFAULT, $options);
114+
}
103115
}

src/Symfony/Component/Translation/Bridge/Phrase/Tests/Config/WriteConfigTest.php

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/Symfony/Component/Translation/Bridge/Phrase/Tests/PhraseProviderTest.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
use Symfony\Component\HttpClient\HttpClientTrait;
2020
use Symfony\Component\HttpClient\MockHttpClient;
2121
use Symfony\Component\HttpClient\Response\MockResponse;
22-
use Symfony\Component\Translation\Bridge\Phrase\Config\WriteConfig;
2322
use Symfony\Component\Translation\Bridge\Phrase\PhraseProvider;
2423
use Symfony\Component\Translation\Dumper\XliffFileDumper;
2524
use Symfony\Component\Translation\Exception\ProviderExceptionInterface;
2625
use Symfony\Component\Translation\Loader\LoaderInterface;
27-
use Symfony\Component\Translation\LoggingTranslator;
2826
use Symfony\Component\Translation\MessageCatalogue;
2927
use Symfony\Component\Translation\Provider\ProviderInterface;
3028
use Symfony\Component\Translation\TranslatorBag;
@@ -47,7 +45,7 @@ class PhraseProviderTest extends TestCase
4745
private string $defaultLocale;
4846
private string $endpoint;
4947
private array $readConfig;
50-
private MockObject&WriteConfig $writeConfig;
48+
private array $writeConfig;
5149

5250
/**
5351
* @dataProvider toStringProvider
@@ -670,7 +668,7 @@ public function testDeleteProviderExceptions(int $statusCode, string $expectedEx
670668
*/
671669
public function testWrite(string $locale, string $localeId, string $domain, string $content, TranslatorBag $bag)
672670
{
673-
$this->writeConfigWithDefaultValues($domain, $localeId);
671+
$this->getWriteConfig($domain, $localeId);
674672

675673
$responses = [
676674
'init locales' => $this->getInitLocaleResponseMock(),
@@ -1183,32 +1181,13 @@ private function getReadConfig(): array
11831181
];
11841182
}
11851183

1186-
private function getWriteConfig(): WriteConfig&MockObject
1184+
private function getWriteConfig(string $domain = 'messages', string $phraseLocale = 'en_GB'): array
11871185
{
1188-
return $this->writeConfig ??= $this->createMock(WriteConfig::class);
1189-
}
1190-
1191-
private function writeConfigWithDefaultValues(string $domain, string $phraseLocale): void
1192-
{
1193-
$this->getWriteConfig()
1194-
->method('getOptions')
1195-
->willReturn([
1196-
'file_format' => 'symfony_xliff',
1197-
'update_translations' => '1',
1198-
'tags' => $domain,
1199-
'locale_id' => $phraseLocale,
1200-
]);
1201-
1202-
$this->getWriteConfig()
1203-
->expects(self::once())
1204-
->method('setTag')
1205-
->with($domain)
1206-
->willReturnSelf();
1207-
1208-
$this->getWriteConfig()
1209-
->expects(self::once())
1210-
->method('setLocale')
1211-
->with($phraseLocale)
1212-
->willReturnSelf();
1186+
return $this->writeConfig ??= [
1187+
'file_format' => 'symfony_xliff',
1188+
'update_translations' => '1',
1189+
'tags' => $domain,
1190+
'locale_id' => $phraseLocale,
1191+
];
12131192
}
12141193
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy