Skip to content

Commit dbb892f

Browse files
Merge branch '4.3' into 4.4
* 4.3: [FrameworkBundle] Remove project dir from Translator cache vary scanned directories [HttpFoundation] Allow redirecting to URLs that contain a semicolon catch exceptions when using PDO directly [SecurityBundle] fix failing test
2 parents cde45e0 + 71a8bae commit dbb892f

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,18 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12341234
$files[$locale][] = (string) $file;
12351235
}
12361236

1237+
$projectDir = $container->getParameter('kernel.project_dir');
1238+
12371239
$options = array_merge(
12381240
$translator->getArgument(4),
12391241
[
12401242
'resource_files' => $files,
1241-
'scanned_directories' => array_merge($dirs, $nonExistingDirs),
1243+
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
1244+
'cache_vary' => [
1245+
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
1246+
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
1247+
}, $scannedDirectories),
1248+
],
12421249
]
12431250
);
12441251

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ function ($directory) {
838838
);
839839

840840
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
841+
842+
$this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][3]);
841843
}
842844

843845
/**

Tests/Translation/TranslatorTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange()
255255
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
256256
],
257257
],
258-
'scanned_directories' => [
259-
__DIR__.'/../Fixtures/Resources/translations/',
258+
'cache_vary' => [
259+
'scanned_directories' => [
260+
'/Fixtures/Resources/translations/',
261+
],
260262
],
261263
], 'yml');
262264

@@ -271,9 +273,11 @@ public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange()
271273
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
272274
],
273275
],
274-
'scanned_directories' => [
275-
__DIR__.'/../Fixtures/Resources/translations/',
276-
__DIR__.'/../Fixtures/Resources/translations2/',
276+
'cache_vary' => [
277+
'scanned_directories' => [
278+
'/Fixtures/Resources/translations/',
279+
'/Fixtures/Resources/translations2/',
280+
],
277281
],
278282
], 'yml');
279283

Translation/Translator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Translator extends BaseTranslator implements WarmableInterface
3434
'debug' => false,
3535
'resource_files' => [],
3636
'scanned_directories' => [],
37+
'cache_vary' => [],
3738
];
3839

3940
/**
@@ -61,9 +62,10 @@ class Translator extends BaseTranslator implements WarmableInterface
6162
*
6263
* Available options:
6364
*
64-
* * cache_dir: The cache directory (or null to disable caching)
65-
* * debug: Whether to enable debugging or not (false by default)
65+
* * cache_dir: The cache directory (or null to disable caching)
66+
* * debug: Whether to enable debugging or not (false by default)
6667
* * resource_files: List of translation resources available grouped by locale.
68+
* * cache_vary: An array of data that is serialized to generate the cached catalogue name.
6769
*
6870
* @throws InvalidArgumentException
6971
*/
@@ -82,9 +84,7 @@ public function __construct(ContainerInterface $container, MessageFormatterInter
8284
$this->resourceFiles = $this->options['resource_files'];
8385
$this->scannedDirectories = $this->options['scanned_directories'];
8486

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

9090
/**

0 commit comments

Comments
 (0)