Skip to content

Commit fa159a3

Browse files
Merge branch '4.4'
* 4.4: [DI] Dont cache classes with missing parents [HttpClient] Fix a crash when calling CurlHttpClient::__destruct() Unallow symfony/http-kernel ^5.0 [FrameworkBundle] fix SodiumVault after stof review [HttpClient] allow arbitrary JSON values in requests [DependencyInjection] Added option `ignore_errors: not_found` while importing config files [Validator] Add the missing translations for the Hebrew (\"he\") locale and fix 2 typos [FrameworkBundle][Translation] Invalidate cached catalogues when the scanned directories change
2 parents d7268fe + 160e2c4 commit fa159a3

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

Secrets/SodiumVault.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function generateKeys(bool $override = false): bool
5252

5353
try {
5454
$this->loadKeys();
55-
} catch (\LogicException $e) {
55+
} catch (\RuntimeException $e) {
5656
// ignore failures to load keys
5757
}
5858

@@ -186,7 +186,7 @@ private function loadKeys(): void
186186
} elseif ('' !== $this->decryptionKey) {
187187
$this->encryptionKey = sodium_crypto_box_publickey($this->decryptionKey);
188188
} else {
189-
throw new \LogicException(sprintf('Encryption key not found in "%s".', \dirname($this->pathPrefix)));
189+
throw new \RuntimeException(sprintf('Encryption key not found in "%s".', \dirname($this->pathPrefix)));
190190
}
191191
}
192192

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo: bar

Tests/Translation/TranslatorTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Config\Resource\FileExistenceResource;
1919
use Symfony\Component\Filesystem\Filesystem;
2020
use Symfony\Component\Translation\Formatter\MessageFormatter;
21+
use Symfony\Component\Translation\Loader\YamlFileLoader;
2122
use Symfony\Component\Translation\MessageCatalogue;
2223

2324
class TranslatorTest extends TestCase
@@ -206,6 +207,41 @@ public function testCatalogResourcesAreAddedForScannedDirectories()
206207
$this->assertEquals(new FileExistenceResource('/tmp/I/sure/hope/this/does/not/exist'), $resources[2]);
207208
}
208209

210+
public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange()
211+
{
212+
/** @var Translator $translator */
213+
$translator = $this->getTranslator(new YamlFileLoader(), [
214+
'cache_dir' => $this->tmpDir,
215+
'resource_files' => [
216+
'fr' => [
217+
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
218+
],
219+
],
220+
'scanned_directories' => [
221+
__DIR__.'/../Fixtures/Resources/translations/',
222+
],
223+
], 'yml');
224+
225+
// Cached catalogue is dumped
226+
$this->assertSame('répertoire', $translator->trans('folder', [], 'messages', 'fr'));
227+
228+
$translator = $this->getTranslator(new YamlFileLoader(), [
229+
'cache_dir' => $this->tmpDir,
230+
'resource_files' => [
231+
'fr' => [
232+
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
233+
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
234+
],
235+
],
236+
'scanned_directories' => [
237+
__DIR__.'/../Fixtures/Resources/translations/',
238+
__DIR__.'/../Fixtures/Resources/translations2/',
239+
],
240+
], 'yml');
241+
242+
$this->assertSame('bar', $translator->trans('foo', [], 'ccc', 'fr'));
243+
}
244+
209245
protected function getCatalogue($locale, $messages, $resources = [])
210246
{
211247
$catalogue = new MessageCatalogue($locale);

Translation/Translator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public function __construct(ContainerInterface $container, MessageFormatterInter
8282
$this->resourceFiles = $this->options['resource_files'];
8383
$this->scannedDirectories = $this->options['scanned_directories'];
8484

85-
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug']);
85+
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], [
86+
'scanned_directories' => $this->scannedDirectories,
87+
]);
8688
}
8789

8890
/**

0 commit comments

Comments
 (0)