*/
public function getTemplateClass($name, $index = null)
{
- return $this->templateClassPrefix.md5($this->loader->getCacheKey($name)).(null === $index ? '' : '_'.$index);
+ return $this->templateClassPrefix.md5($this->getLoader()->getCacheKey($name)).(null === $index ? '' : '_'.$index);
}
/**
if (!class_exists($cls, false)) {
if (false === $cache = $this->getCacheFilename($name)) {
- eval('?>'.$this->compileSource($this->loader->getSource($name), $name));
+ eval('?>'.$this->compileSource($this->getLoader()->getSource($name), $name));
} else {
if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
- $this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $name));
+ $this->writeCacheFile($cache, $this->compileSource($this->getLoader()->getSource($name), $name));
}
require_once $cache;
}
}
- return $this->loader->isFresh($name, $time);
+ return $this->getLoader()->isFresh($name, $time);
}
public function resolveTemplate($names)
*/
public function getLoader()
{
+ if (null === $this->loader) {
+ throw new LogicException('You must set a loader first.');
+ }
+
return $this->loader;
}
class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
{
+ /**
+ * @expectedException LogicException
+ * @expectedExceptionMessage You must set a loader first.
+ */
+ public function testRenderNoLoader()
+ {
+ $env = new Twig_Environment();
+ $env->render('test');
+ }
+
public function testAutoescapeOption()
{
$loader = new Twig_Loader_Array(array(