@@ -346,8 +346,9 @@ protected function initializeCatalogue($locale)
346
346
347
347
/**
348
348
* @param string $locale
349
+ * @param bool $forceRefresh
349
350
*/
350
- private function initializeCacheCatalogue ($ locale )
351
+ private function initializeCacheCatalogue ($ locale, $ forceRefresh = false )
351
352
{
352
353
if (isset ($ this ->catalogues [$ locale ])) {
353
354
return ;
@@ -361,7 +362,7 @@ private function initializeCacheCatalogue($locale)
361
362
362
363
$ this ->assertValidLocale ($ locale );
363
364
$ cache = new ConfigCache ($ this ->cacheDir .'/catalogue. ' .$ locale .'.php ' , $ this ->debug );
364
- if (!$ cache ->isFresh ()) {
365
+ if ($ forceRefresh || !$ cache ->isFresh ()) {
365
366
$ this ->initializeCatalogue ($ locale );
366
367
367
368
$ fallbackContent = '' ;
@@ -392,13 +393,15 @@ private function initializeCacheCatalogue($locale)
392
393
393
394
use Symfony\Component\Translation\MessageCatalogue;
394
395
396
+ \$resourcesHash = '%s';
395
397
\$catalogue = new MessageCatalogue('%s', %s);
396
398
397
399
%s
398
- return \$catalogue;
400
+ return array( \$catalogue, \$ resourcesHash) ;
399
401
400
402
EOF
401
403
,
404
+ $ this ->getResourcesHash ($ locale ),
402
405
$ locale ,
403
406
var_export ($ this ->catalogues [$ locale ]->all (), true ),
404
407
$ fallbackContent
@@ -409,7 +412,30 @@ private function initializeCacheCatalogue($locale)
409
412
return ;
410
413
}
411
414
412
- $ this ->catalogues [$ locale ] = include $ cache ;
415
+ $ catalogue = include $ cache ;
416
+
417
+ /**
418
+ * Old cache returns only the catalogue, without resourcesHash
419
+ */
420
+ $ resourcesHash = null ;
421
+ if (is_array ($ catalogue )) {
422
+ list ($ catalogue , $ resourcesHash ) = $ catalogue ;
423
+ }
424
+
425
+ if ($ this ->debug && $ resourcesHash !== $ this ->getResourcesHash ($ locale )) {
426
+ return $ this ->initializeCacheCatalogue ($ locale , true );
427
+ }
428
+
429
+ $ this ->catalogues [$ locale ] = $ catalogue ;
430
+ }
431
+
432
+ private function getResourcesHash ($ locale )
433
+ {
434
+ if (!isset ($ this ->resources [$ locale ])) {
435
+ return '' ;
436
+ }
437
+
438
+ return sha1 (serialize ($ this ->resources [$ locale ]));
413
439
}
414
440
415
441
private function doLoadCatalogue ($ locale )
0 commit comments