Skip to content

Commit 897dccf

Browse files
committed
[Translator] avoid serialize unserializable resources.
1 parent cc1907b commit 897dccf

File tree

2 files changed

+1
-67
lines changed

2 files changed

+1
-67
lines changed

Tests/TranslatorCacheTest.php

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,41 +74,6 @@ public function testThatACacheIsUsed($debug)
7474
$this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
7575
}
7676

77-
public function testRefreshCacheWhenResourcesChange()
78-
{
79-
// prime the cache
80-
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
81-
$loader
82-
->method('load')
83-
->will($this->returnValue($this->getCatalogue('fr', array(
84-
'foo' => 'foo A',
85-
))))
86-
;
87-
88-
$translator = new Translator('fr', null, $this->tmpDir, true);
89-
$translator->setLocale('fr');
90-
$translator->addLoader('loader', $loader);
91-
$translator->addResource('loader', 'foo', 'fr');
92-
93-
$this->assertEquals('foo A', $translator->trans('foo'));
94-
95-
// add a new resource to refresh the cache
96-
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
97-
$loader
98-
->method('load')
99-
->will($this->returnValue($this->getCatalogue('fr', array(
100-
'foo' => 'foo B',
101-
))))
102-
;
103-
104-
$translator = new Translator('fr', null, $this->tmpDir, true);
105-
$translator->setLocale('fr');
106-
$translator->addLoader('loader', $loader);
107-
$translator->addResource('loader', 'bar', 'fr');
108-
109-
$this->assertEquals('foo B', $translator->trans('foo'));
110-
}
111-
11277
public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
11378
{
11479
/*
@@ -150,32 +115,6 @@ public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
150115
$translator->trans($msgid);
151116
}
152117

153-
/**
154-
* @dataProvider runForDebugAndProduction
155-
*/
156-
public function testDifferentTranslatorsForSameLocaleDoNotInterfere($debug)
157-
{
158-
$locale = 'any_locale';
159-
$format = 'some_format';
160-
$msgid = 'test';
161-
162-
// Create a Translator and prime its cache
163-
$translator = new Translator($locale, null, $this->tmpDir, $debug);
164-
$translator->addLoader($format, new ArrayLoader());
165-
$translator->addResource($format, array($msgid => 'FAIL'), $locale);
166-
$translator->trans($msgid);
167-
168-
/*
169-
* Create another Translator with the same locale but a different resource.
170-
* It should not use the first translator's cache but return the value from its own resource.
171-
*/
172-
$translator = new Translator($locale, null, $this->tmpDir, $debug);
173-
$translator->addLoader($format, new ArrayLoader());
174-
$translator->addResource($format, array($msgid => 'OK'), $locale);
175-
176-
$this->assertEquals('OK', $translator->trans($msgid), '-> different translators for the same domain interfere in '.($debug ? 'debug' : 'production'));
177-
}
178-
179118
/**
180119
* @dataProvider runForDebugAndProduction
181120
*/

Translator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,7 @@ private function getFallbackContent(MessageCatalogue $catalogue)
419419

420420
private function getCatalogueCachePath($locale)
421421
{
422-
$catalogueHash = sha1(serialize(array(
423-
'resources' => isset($this->resources[$locale]) ? $this->resources[$locale] : array(),
424-
'fallback_locales' => $this->fallbackLocales,
425-
)));
426-
427-
return $this->cacheDir.'/catalogue.'.$locale.'.'.$catalogueHash.'.php';
422+
return $this->cacheDir.'/catalogue.'.$locale.'.'.sha1(serialize($this->fallbackLocales)).'.php';
428423
}
429424

430425
private function doLoadCatalogue($locale)

0 commit comments

Comments
 (0)