Implements Twig_Environment::loadTemplate().
We need to overwrite this function to integrate with drupal_php_storage().
This is a straight copy from loadTemplate() changed to use drupal_php_storage().
public function loadTemplate($name, $index = NULL) {
$cls = $this
->getTemplateClass($name, $index);
if (isset($this->loadedTemplates[$cls])) {
return $this->loadedTemplates[$cls];
}
if (!class_exists($cls, FALSE)) {
$cache_filename = $this
->getCacheFilename($name);
if ($cache_filename === FALSE) {
$source = $this->loader
->getSource($name);
$compiled_source = $this
->compileSource($source, $name);
eval('?' . '>' . $compiled_source);
}
else {
// If autoreload is on, check that the template has not been
// modified since the last compilation.
if ($this
->isAutoReload() && $this
->needsUpdate($cache_filename, $name)) {
$this
->updateCompiledTemplate($cache_filename, $name);
}
if (!$this
->storage()
->load($cache_filename)) {
$this
->updateCompiledTemplate($cache_filename, $name);
$this
->storage()
->load($cache_filename);
}
}
}
if (!$this->runtimeInitialized) {
$this
->initRuntime();
}
return $this->loadedTemplates[$cls] = new $cls($this);
}