File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
src/Symfony/Component/Translation
tests/Symfony/Tests/Component/Translation Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class MessageCatalogue implements MessageCatalogueInterface
26
26
private $ locale ;
27
27
private $ resources ;
28
28
private $ fallbackCatalogue ;
29
+ private $ parent ;
29
30
30
31
/**
31
32
* Constructor.
@@ -183,13 +184,32 @@ public function addCatalogue(MessageCatalogueInterface $catalogue)
183
184
*/
184
185
public function addFallbackCatalogue (MessageCatalogueInterface $ catalogue )
185
186
{
187
+ // detect circular references
188
+ $ c = $ this ;
189
+ do {
190
+ if ($ c ->getLocale () === $ catalogue ->getLocale ()) {
191
+ throw new \LogicException (sprintf ('Circular reference detected when adding a fallback catalogue for locale "%s". ' , $ catalogue ->getLocale ()));
192
+ }
193
+ } while ($ c = $ c ->getParent ());
194
+
195
+ $ catalogue ->setParent ($ this );
186
196
$ this ->fallbackCatalogue = $ catalogue ;
187
197
188
198
foreach ($ catalogue ->getResources () as $ resource ) {
189
199
$ this ->addResource ($ resource );
190
200
}
191
201
}
192
202
203
+ public function getParent ()
204
+ {
205
+ return $ this ->parent ;
206
+ }
207
+
208
+ public function setParent (self $ parent )
209
+ {
210
+ $ this ->parent = $ parent ;
211
+ }
212
+
193
213
/**
194
214
* {@inheritdoc}
195
215
*
Original file line number Diff line number Diff line change @@ -124,6 +124,18 @@ public function testAddFallbackCatalogue()
124
124
$ this ->assertEquals (array ($ r , $ r1 ), $ catalogue ->getResources ());
125
125
}
126
126
127
+ /**
128
+ * @expectedException LogicException
129
+ */
130
+ public function testAddFallbackCatalogueWithCircularReference ()
131
+ {
132
+ $ main = new MessageCatalogue ('en_US ' );
133
+ $ fallback = new MessageCatalogue ('fr_FR ' );
134
+
135
+ $ fallback ->addFallbackCatalogue ($ main );
136
+ $ main ->addFallbackCatalogue ($ fallback );
137
+ }
138
+
127
139
/**
128
140
* @expectedException LogicException
129
141
*/
You can’t perform that action at this time.
0 commit comments