[Translation] fix memoryleak in PhpFileLoader

This commit is contained in:
Nicolas Grekas 2019-12-10 13:51:10 +01:00
parent 42712ee006
commit 5c9e3bac96

View File

@ -18,11 +18,25 @@ namespace Symfony\Component\Translation\Loader;
*/
class PhpFileLoader extends FileLoader
{
private static $cache = [];
/**
* {@inheritdoc}
*/
protected function loadResource($resource)
{
return require $resource;
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
self::$cache = null;
}
if (null === self::$cache) {
return require $resource;
}
if (isset(self::$cache[$resource])) {
return self::$cache[$resource];
}
return self::$cache[$resource] = require $resource;
}
}