mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-06 07:27:17 +00:00
Turned fatal error into exception when a previously generated cache prevents loading its newly compiled version
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
* added Twig_NodeCaptureInterface for nodes that capture all output
|
||||
* fixed marking the environment as initialized too early
|
||||
* fixed C89 compat for the C extension
|
||||
* turned fatal error into exception when a previously generated cache is corrupted
|
||||
* fixed offline cache warm-ups for embedded templates
|
||||
|
||||
* 1.30.0 (2016-12-23)
|
||||
|
||||
|
||||
@@ -408,14 +408,18 @@ class Twig_Environment
|
||||
*
|
||||
* @return Twig_TemplateInterface A template instance representing the given template name
|
||||
*
|
||||
* @throws Twig_Error_Loader When the template cannot be found
|
||||
* @throws Twig_Error_Syntax When an error occurred during compilation
|
||||
* @throws Twig_Error_Loader When the template cannot be found
|
||||
* @throws Twig_Error_Runtime When a previously generated cache is corrupted
|
||||
* @throws Twig_Error_Syntax When an error occurred during compilation
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function loadTemplate($name, $index = null)
|
||||
{
|
||||
$cls = $this->getTemplateClass($name, $index);
|
||||
$cls = $mainCls = $this->getTemplateClass($name);
|
||||
if (null !== $index) {
|
||||
$cls .= '_'.$index;
|
||||
}
|
||||
|
||||
if (isset($this->loadedTemplates[$cls])) {
|
||||
return $this->loadedTemplates[$cls];
|
||||
@@ -425,7 +429,7 @@ class Twig_Environment
|
||||
if ($this->bcGetCacheFilename) {
|
||||
$key = $this->getCacheFilename($name);
|
||||
} else {
|
||||
$key = $this->cache->generateKey($name, $cls);
|
||||
$key = $this->cache->generateKey($name, $mainCls);
|
||||
}
|
||||
|
||||
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
|
||||
@@ -449,7 +453,7 @@ class Twig_Environment
|
||||
$this->cache->load($key);
|
||||
}
|
||||
|
||||
if (!class_exists($cls, false)) {
|
||||
if (!class_exists($mainCls, false)) {
|
||||
/* Last line of defense if either $this->bcWriteCacheFile was used,
|
||||
* $this->cache is implemented as a no-op or we have a race condition
|
||||
* where the cache was cleared between the above calls to write to and load from
|
||||
@@ -458,6 +462,10 @@ class Twig_Environment
|
||||
eval('?>'.$content);
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($cls, false)) {
|
||||
throw new Twig_Error_Runtime(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->runtimeInitialized) {
|
||||
|
||||
Reference in New Issue
Block a user