11
11
12
12
namespace Symfony \Component \Translation \Bridge \Phrase ;
13
13
14
- use Psr \Cache \CacheItemInterface ;
15
14
use Psr \Cache \CacheItemPoolInterface ;
16
15
use Psr \Log \LoggerInterface ;
17
16
use Symfony \Component \Mime \Part \DataPart ;
18
17
use Symfony \Component \Mime \Part \Multipart \FormDataPart ;
19
- use Symfony \Component \Translation \Bridge \Phrase \Config \ReadConfig ;
20
- use Symfony \Component \Translation \Bridge \Phrase \Config \WriteConfig ;
21
18
use Symfony \Component \Translation \Dumper \XliffFileDumper ;
22
19
use Symfony \Component \Translation \Exception \ProviderException ;
23
20
use Symfony \Component \Translation \Loader \LoaderInterface ;
@@ -42,8 +39,9 @@ public function __construct(
42
39
private readonly CacheItemPoolInterface $ cache ,
43
40
private readonly string $ defaultLocale ,
44
41
private readonly string $ endpoint ,
45
- private readonly ReadConfig $ readConfig ,
46
- private readonly WriteConfig $ writeConfig ,
42
+ private array $ readConfig ,
43
+ private array $ writeConfig ,
44
+ private readonly bool $ isFallbackLocaleEnabled = false ,
47
45
) {
48
46
}
49
47
@@ -58,7 +56,7 @@ public function write(TranslatorBagInterface $translatorBag): void
58
56
59
57
foreach ($ translatorBag ->getCatalogues () as $ catalogue ) {
60
58
foreach ($ catalogue ->getDomains () as $ domain ) {
61
- if (0 === \count ($ catalogue ->all ($ domain ))) {
59
+ if (! \count ($ catalogue ->all ($ domain ))) {
62
60
continue ;
63
61
}
64
62
@@ -67,7 +65,9 @@ public function write(TranslatorBagInterface $translatorBag): void
67
65
$ content = $ this ->xliffFileDumper ->formatCatalogue ($ catalogue , $ domain , ['default_locale ' => $ this ->defaultLocale ]);
68
66
$ filename = sprintf ('%d-%s-%s.xlf ' , date ('YmdHis ' ), $ domain , $ catalogue ->getLocale ());
69
67
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 ' )]);
71
71
72
72
$ formData = new FormDataPart ($ fields );
73
73
@@ -93,13 +93,13 @@ public function read(array $domains, array $locales): TranslatorBag
93
93
$ phraseLocale = $ this ->getLocale ($ locale );
94
94
95
95
foreach ($ domains as $ domain ) {
96
- $ this ->readConfig -> setTag ( $ domain) ;
96
+ $ this ->readConfig [ ' tags ' ] = $ domain ;
97
97
98
- if ($ this ->readConfig -> isFallbackLocaleEnabled () && null !== $ fallbackLocale = $ this ->getFallbackLocale ($ locale )) {
99
- $ this ->readConfig -> setFallbackLocale ( $ fallbackLocale) ;
98
+ if ($ this ->isFallbackLocaleEnabled && null !== $ fallbackLocale = $ this ->getFallbackLocale ($ locale )) {
99
+ $ this ->readConfig [ ' fallback_locale_id ' ] = $ fallbackLocale ;
100
100
}
101
101
102
- $ cacheKey = $ this ->generateCacheKey ($ locale , $ domain , $ this ->readConfig -> getOptions () );
102
+ $ cacheKey = $ this ->generateCacheKey ($ locale , $ domain , $ this ->readConfig );
103
103
$ cacheItem = $ this ->cache ->getItem ($ cacheKey );
104
104
105
105
$ headers = [];
@@ -110,7 +110,7 @@ public function read(array $domains, array $locales): TranslatorBag
110
110
}
111
111
112
112
$ response = $ this ->httpClient ->request ('GET ' , 'locales/ ' .$ phraseLocale .'/download ' , [
113
- 'query ' => $ this ->readConfig -> getOptions () ,
113
+ 'query ' => $ this ->readConfig ,
114
114
'headers ' => $ headers ,
115
115
]);
116
116
@@ -124,7 +124,7 @@ public function read(array $domains, array $locales): TranslatorBag
124
124
$ translatorBag ->addCatalogue ($ this ->loader ->load ($ content , $ locale , $ domain ));
125
125
126
126
// using weak etags, responses for requests with fallback locale enabled can not be reliably cached...
127
- if (false === $ this ->readConfig -> isFallbackLocaleEnabled () ) {
127
+ if (! $ this ->isFallbackLocaleEnabled ) {
128
128
$ headers = $ response ->getHeaders (false );
129
129
$ cacheItem ->set (['etag ' => $ headers ['etag ' ][0 ], 'modified ' => $ headers ['last-modified ' ][0 ], 'content ' => $ content ]);
130
130
$ this ->cache ->save ($ cacheItem );
0 commit comments