Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad79d4e

Browse files
Merge branch '6.3' into 6.4
* 6.3: [AssetMapper] Handle assets with non-ascii characters in dev server [Translation] Fix `TranslationNodeVisitor` with constant domain [Messenger] [AMQP] Throw exception on `nack` callback [Validator] revise Latvian translations [ErrorHandler] Fix `RecursiveDirectoryIterator` exception with wrong composer autoload [HttpFoundation] Request without content-type or content-length header should result in null values, not empty strings [Cache] Fix possible infinite loop in `CachePoolPass` grab a service from the container only if it exists [Mime] Fix undefined array key 0 when empty sender [Console] Allow '0' as a $shortcut in InputOption.php fix multi-byte code area to convert [Validator] Make it explicit when English translation differs from its resource name
2 parents 2a9eb43 + 8914597 commit ad79d4e

79 files changed

Lines changed: 795 additions & 655 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/sync-translations.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ function dumpXliff1(string $defaultLocale, MessageCatalogue $messages, string $d
3333
$metadata = $messages->getMetadata($source, $domain);
3434

3535
$translation->setAttribute('id', $metadata['id']);
36+
if (isset($metadata['resname'])) {
37+
$translation->setAttribute('resname', $metadata['resname']);
38+
}
3639

3740
$s = $translation->appendChild($dom->createElement('source'));
3841
$s->appendChild($dom->createTextNode($source));
@@ -64,23 +67,32 @@ function dumpXliff1(string $defaultLocale, MessageCatalogue $messages, string $d
6467
$dir = __DIR__.'/../src/Symfony/Component/'.$component.'/Resources/translations';
6568

6669
$enCatalogue = (new XliffFileLoader())->load($dir.'/'.$domain.'.en.xlf', 'en', $domain);
70+
file_put_contents($dir.'/'.$domain.'.en.xlf', dumpXliff1('en', $enCatalogue, $domain));
71+
6772
$finder = new Finder();
6873

6974
foreach ($finder->files()->in($dir)->name('*.xlf') as $file) {
7075
$locale = substr($file->getBasename(), 1 + strlen($domain), -4);
7176

77+
if ('en' === $locale) {
78+
continue;
79+
}
80+
7281
$catalogue = (new XliffFileLoader())->load($file, $locale, $domain);
7382
$localeCatalogue = new MessageCatalogue($locale);
7483

75-
foreach ($enCatalogue->all($domain) as $id => $translation) {
84+
foreach ($enCatalogue->all($domain) as $resname => $source) {
7685
$metadata = [];
77-
if ($catalogue->defines($id, $domain)) {
78-
$translation = $catalogue->get($id, $domain);
79-
$metadata = $catalogue->getMetadata($id, $domain);
86+
if ($catalogue->defines($resname, $domain)) {
87+
$translation = $catalogue->get($resname, $domain);
88+
$metadata = $catalogue->getMetadata($resname, $domain);
89+
}
90+
$metadata['id'] = $enCatalogue->getMetadata($resname, $domain)['id'];
91+
if ($resname !== $source) {
92+
$metadata['resname'] = $resname;
8093
}
81-
$metadata['id'] = $enCatalogue->getMetadata($id, $domain)['id'];
82-
$localeCatalogue->set($id, $translation, $domain);
83-
$localeCatalogue->setMetadata($id, $metadata, $domain);
94+
$localeCatalogue->set($source, $translation, $domain);
95+
$localeCatalogue->setMetadata($source, $metadata, $domain);
8496
}
8597

8698
file_put_contents($file, dumpXliff1('en', $localeCatalogue, $domain));

src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ private function getReadDomainFromNode(Node $node): ?string
149149
return $node->getAttribute('value');
150150
}
151151

152+
if (
153+
$node instanceof FunctionExpression
154+
&& 'constant' === $node->getAttribute('name')
155+
) {
156+
$nodeArguments = $node->getNode('arguments');
157+
if ($nodeArguments->getIterator()->current() instanceof ConstantExpression) {
158+
$constantName = $nodeArguments->getIterator()->current()->getAttribute('value');
159+
if (\defined($constantName)) {
160+
$value = \constant($constantName);
161+
if (\is_string($value)) {
162+
return $value;
163+
}
164+
}
165+
}
166+
}
167+
152168
return self::UNDEFINED_DOMAIN;
153169
}
154170

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
class TwigExtractorTest extends TestCase
2424
{
25+
public const CUSTOM_DOMAIN = 'domain';
26+
2527
/**
2628
* @dataProvider getExtractData
2729
*/
@@ -76,6 +78,11 @@ public static function getExtractData()
7678
// make sure this works with twig's named arguments
7779
['{{ "new key" | trans(domain="domain") }}', ['new key' => 'domain']],
7880

81+
// make sure this works with const domain
82+
['{{ "new key" | trans({}, constant(\'Symfony\\\\Bridge\\\\Twig\\\\Tests\\\\Translation\\\\TwigExtractorTest::CUSTOM_DOMAIN\')) }}', ['new key' => self::CUSTOM_DOMAIN]],
83+
['{% trans from constant(\'Symfony\\\\Bridge\\\\Twig\\\\Tests\\\\Translation\\\\TwigExtractorTest::CUSTOM_DOMAIN\') %}new key{% endtrans %}', ['new key' => self::CUSTOM_DOMAIN]],
84+
['{{ t("new key", {}, constant(\'Symfony\\\\Bridge\\\\Twig\\\\Tests\\\\Translation\\\\TwigExtractorTest::CUSTOM_DOMAIN\')) | trans() }}', ['new key' => self::CUSTOM_DOMAIN]],
85+
7986
// concat translations
8087
['{{ ("new" ~ " key") | trans() }}', ['new key' => 'messages']],
8188
['{{ ("another " ~ "new " ~ "key") | trans() }}', ['another new key' => 'messages']],

src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272

7373
$poolNames = $input->getArgument('pools');
7474
$excludedPoolNames = $input->getOption('exclude');
75-
if ($input->getOption('all')) {
75+
if ($clearAll = $input->getOption('all')) {
7676
if (!$this->poolNames) {
7777
throw new InvalidArgumentException('Could not clear all cache pools, try specifying a specific pool or cache clearer.');
7878
}
@@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9191
foreach ($poolNames as $id) {
9292
if ($this->poolClearer->hasPool($id)) {
9393
$pools[$id] = $id;
94-
} else {
94+
} elseif (!$clearAll || $kernel->getContainer()->has($id)) {
9595
$pool = $kernel->getContainer()->get($id);
9696

9797
if ($pool instanceof CacheItemPoolInterface) {

src/Symfony/Component/AssetMapper/AssetMapperDevServerSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function onKernelRequest(RequestEvent $event): void
119119
return;
120120
}
121121

122-
$pathInfo = $event->getRequest()->getPathInfo();
122+
$pathInfo = rawurldecode($event->getRequest()->getPathInfo());
123123
if (!str_starts_with($pathInfo, $this->publicPrefix)) {
124124
return;
125125
}

src/Symfony/Component/AssetMapper/Tests/AssetMapperDevServerSubscriberFunctionalTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ public function testGettingAssetWorks()
3535
$this->assertTrue($response->headers->has('X-Assets-Dev'));
3636
}
3737

38+
public function testGettingAssetWithNonAsciiFilenameWorks()
39+
{
40+
$client = static::createClient();
41+
42+
$client->request('GET', '/assets/voilà-6344422da690fcc471f23f7a8966cd1c.css');
43+
$response = $client->getResponse();
44+
$this->assertSame(200, $response->getStatusCode());
45+
$this->assertSame(<<<EOF
46+
/* voilà.css */
47+
body {}
48+
49+
EOF, $response->getContent());
50+
}
51+
3852
public function test404OnUnknownAsset()
3953
{
4054
$client = static::createClient();

src/Symfony/Component/AssetMapper/Tests/Command/AssetMapperCompileCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testAssetsAreCompiled()
6969

7070
$finder = new Finder();
7171
$finder->in($targetBuildDir)->files();
72-
$this->assertCount(12, $finder); // 9 files + manifest.json & importmap.json + entrypoint.file6.json
72+
$this->assertCount(13, $finder); // 10 files + manifest.json & importmap.json + entrypoint.file6.json
7373
$this->assertFileExists($targetBuildDir.'/manifest.json');
7474

7575
$this->assertSame([
@@ -82,6 +82,7 @@ public function testAssetsAreCompiled()
8282
'subdir/file6.js',
8383
'vendor/@hotwired/stimulus/stimulus.index.js',
8484
'vendor/lodash/lodash.index.js',
85+
'voilà.css',
8586
], array_keys(json_decode(file_get_contents($targetBuildDir.'/manifest.json'), true)));
8687

8788
$this->assertFileExists($targetBuildDir.'/importmap.json');

src/Symfony/Component/AssetMapper/Tests/Fixtures/AssetMapperTestAppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
4343
'http_client' => true,
4444
'assets' => null,
4545
'asset_mapper' => [
46-
'paths' => ['dir1', 'dir2', 'assets'],
46+
'paths' => ['dir1', 'dir2', 'non_ascii', 'assets'],
4747
],
4848
'test' => true,
4949
]);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* voilà.css */
2+
body {}

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ public function process(ContainerBuilder $container)
181181
$container->removeDefinition('cache.early_expiration_handler');
182182
}
183183

184-
$notAliasedCacheClearerId = $aliasedCacheClearerId = 'cache.global_clearer';
185-
while ($container->hasAlias('cache.global_clearer')) {
186-
$aliasedCacheClearerId = (string) $container->getAlias('cache.global_clearer');
184+
$notAliasedCacheClearerId = 'cache.global_clearer';
185+
while ($container->hasAlias($notAliasedCacheClearerId)) {
186+
$notAliasedCacheClearerId = (string) $container->getAlias($notAliasedCacheClearerId);
187187
}
188-
if ($container->hasDefinition($aliasedCacheClearerId)) {
188+
if ($container->hasDefinition($notAliasedCacheClearerId)) {
189189
$clearers[$notAliasedCacheClearerId] = $allPools;
190190
}
191191

0 commit comments

Comments
 (0)