8000 [FrameworkBundle] Remove project dir from Translator cache vary scanned directories by fancyweb · Pull Request #34397 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Remove project dir from Translator cache vary scanned directories #34397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,18 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$files[$locale][] = (string) $file;
}

$projectDir = $container->getParameter('kernel.project_dir');

$options = array_merge(
$translator->getArgument(4),
[
'resource_files' => $files,
'scanned_directories' => array_merge($dirs, $nonExistingDirs),
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
'cache_vary' => [
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
}, $scannedDirectories),
],
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ function ($directory) {
);

$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');

$this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][3]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange()
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
],
],
'scanned_directories' => [
__DIR__.'/../Fixtures/Resources/translations/',
'cache_vary' => [
'scanned_directories' => [
'/Fixtures/Resources/translations/',
],
],
], 'yml');

Expand All @@ -271,9 +273,11 @@ public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange()
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
],
],
'scanned_directories' => [
__DIR__.'/../Fixtures/Resources/translations/',
__DIR__.'/../Fixtures/Resources/translations2/',
'cache_vary' => [
'scanned_directories' => [
'/Fixtures/Resources/translations/',
'/Fixtures/Resources/translations2/',
],
],
], 'yml');

Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Translator extends BaseTranslator implements WarmableInterface
'debug' => false,
'resource_files' => [],
'scanned_directories' => [],
'cache_vary' => [],
];

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

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

/**
Expand Down
0