Skip to content

Commit 5238983

Browse files
Merge branch '2.3' into 2.7
* 2.3: [Intl] Fix test [Translator][fallback catalogues] fixed circular reference. bumped Symfony version to 2.3.33 updated VERSION for 2.3.32 update CONTRIBUTORS for 2.3.32 updated CHANGELOG for 2.3.32 [FrameworkBundle] Fix templating.helper.code.file_link_format when defined by ini setting [console] Use the description when no help is available Conflicts: src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt src/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt src/Symfony/Component/HttpKernel/Kernel.php
2 parents 53020de + ca9e34a commit 5238983

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

MessageCatalogue.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ public function addCatalogue(MessageCatalogueInterface $catalogue)
190190
public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
191191
{
192192
// detect circular references
193+
$c = $catalogue;
194+
while ($c = $c->getFallbackCatalogue()) {
195+
if ($c->getLocale() === $this->getLocale()) {
196+
throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
197+
}
198+
}
199+
193200
$c = $this;
194201
do {
195202
if ($c->getLocale() === $catalogue->getLocale()) {

Tests/MessageCatalogueTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testAddFallbackCatalogue()
127127
/**
128128
* @expectedException \LogicException
129129
*/
130-
public function testAddFallbackCatalogueWithCircularReference()
130+
public function testAddFallbackCatalogueWithParentCircularReference()
131131
{
132132
$main = new MessageCatalogue('en_US');
133133
$fallback = new MessageCatalogue('fr_FR');
@@ -136,6 +136,20 @@ public function testAddFallbackCatalogueWithCircularReference()
136136
$main->addFallbackCatalogue($fallback);
137137
}
138138

139+
/**
140+
* @expectedException \LogicException
141+
*/
142+
public function testAddFallbackCatalogueWithFallbackCircularReference()
143+
{
144+
$fr = new MessageCatalogue('fr');
145+
$en = new MessageCatalogue('en');
146+
$es = new MessageCatalogue('es');
147+
148+
$fr->addFallbackCatalogue($en);
149+
$es->addFallbackCatalogue($en);
150+
$en->addFallbackCatalogue($fr);
151+
}
152+
139153
/**
140154
* @expectedException \LogicException
141155
*/
@@ -178,10 +192,10 @@ public function testMetadataSetGetDelete()
178192
$this->assertEquals(array(), $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 is array');
179193

180194
$catalogue->deleteMetadata('key2', 'messages');
181-
$this->assertEquals(null, $catalogue->getMetadata('key2', 'messages'), 'Metadata key2 should is deleted.');
195+
$this->assertNull($catalogue->getMetadata('key2', 'messages'), 'Metadata key2 should is deleted.');
182196

183197
$catalogue->deleteMetadata('key2', 'domain');
184-
$this->assertEquals(null, $catalogue->getMetadata('key2', 'domain'), 'Metadata key2 should is deleted.');
198+
$this->assertNull($catalogue->getMetadata('key2', 'domain'), 'Metadata key2 should is deleted.');
185199
}
186200

187201
public function testMetadataMerge()

Translator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,9 @@ private function loadFallbackCatalogues($locale)
445445
$this->doLoadCatalogue($fallback);
446446
}
447447

448-
$current->addFallbackCatalogue($this->catalogues[$fallback]);
449-
$current = $this->catalogues[$fallback];
448+
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());
449+
$current->addFallbackCatalogue($fallbackCatalogue);
450+
$current = $fallbackCatalogue;
450451
}
451452
}
452453

0 commit comments

Comments
 (0)