bug #14705 [Translator] avoid serialize unserializable resources. (aitboudad)
This PR was merged into the 2.7 branch.
Discussion
----------
[Translator] avoid serialize unserializable resources.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Fixed tickets | #14689
| Tests pass? | yes
| License | MIT
Commits
-------
7220f2c
[Translator] avoid serialize unserializable resources.
This commit is contained in:
commit
34ad82e1d2
@ -74,41 +74,6 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('OK', $translator->trans($msgid), '-> caching does not work in '.($debug ? 'debug' : 'production'));
|
||||
}
|
||||
|
||||
public function testRefreshCacheWhenResourcesChange()
|
||||
{
|
||||
// prime the cache
|
||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||
$loader
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('fr', array(
|
||||
'foo' => 'foo A',
|
||||
))))
|
||||
;
|
||||
|
||||
$translator = new Translator('fr', null, $this->tmpDir, true);
|
||||
$translator->setLocale('fr');
|
||||
$translator->addLoader('loader', $loader);
|
||||
$translator->addResource('loader', 'foo', 'fr');
|
||||
|
||||
$this->assertEquals('foo A', $translator->trans('foo'));
|
||||
|
||||
// add a new resource to refresh the cache
|
||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||
$loader
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('fr', array(
|
||||
'foo' => 'foo B',
|
||||
))))
|
||||
;
|
||||
|
||||
$translator = new Translator('fr', null, $this->tmpDir, true);
|
||||
$translator->setLocale('fr');
|
||||
$translator->addLoader('loader', $loader);
|
||||
$translator->addResource('loader', 'bar', 'fr');
|
||||
|
||||
$this->assertEquals('foo B', $translator->trans('foo'));
|
||||
}
|
||||
|
||||
public function testCatalogueIsReloadedWhenResourcesAreNoLongerFresh()
|
||||
{
|
||||
/*
|
||||
@ -150,32 +115,6 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
|
||||
$translator->trans($msgid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider runForDebugAndProduction
|
||||
*/
|
||||
public function testDifferentTranslatorsForSameLocaleDoNotInterfere($debug)
|
||||
{
|
||||
$locale = 'any_locale';
|
||||
$format = 'some_format';
|
||||
$msgid = 'test';
|
||||
|
||||
// Create a Translator and prime its cache
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, new ArrayLoader());
|
||||
$translator->addResource($format, array($msgid => 'FAIL'), $locale);
|
||||
$translator->trans($msgid);
|
||||
|
||||
/*
|
||||
* Create another Translator with the same locale but a different resource.
|
||||
* It should not use the first translator's cache but return the value from its own resource.
|
||||
*/
|
||||
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||
$translator->addLoader($format, new ArrayLoader());
|
||||
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||
|
||||
$this->assertEquals('OK', $translator->trans($msgid), '-> different translators for the same domain interfere in '.($debug ? 'debug' : 'production'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider runForDebugAndProduction
|
||||
*/
|
||||
|
@ -419,12 +419,7 @@ EOF
|
||||
|
||||
private function getCatalogueCachePath($locale)
|
||||
{
|
||||
$catalogueHash = sha1(serialize(array(
|
||||
'resources' => isset($this->resources[$locale]) ? $this->resources[$locale] : array(),
|
||||
'fallback_locales' => $this->fallbackLocales,
|
||||
)));
|
||||
|
||||
return $this->cacheDir.'/catalogue.'.$locale.'.'.$catalogueHash.'.php';
|
||||
return $this->cacheDir.'/catalogue.'.$locale.'.'.sha1(serialize($this->fallbackLocales)).'.php';
|
||||
}
|
||||
|
||||
private function doLoadCatalogue($locale)
|
||||
|
Reference in New Issue
Block a user