/**
* Spawns a new instance of Twig.
*
* @return object
**/
protected function spawn()
{
// register the Twig autoloader.
Twig_Autoloader::register();
// Init the Twig loader.
$loader = new Twig_Loader_String();
// check if the cache dir is set.
if ($this->compile_dir) {
if (is_null($this->debug)) {
$this->debug = is_dev_mode();
}
$twig = new Twig_Environment($loader, array('autoescape' => FALSE, 'cache' => $this->compile_dir, 'debug' => $this->debug, 'charset' => $this->charset, 'base_template_class' => $this->base_template_class, 'strict_variables' => $this->strict_variables, 'autoescape' => $this->autoescape, 'optimizations' => $this->optimizations));
} else {
$twig = new Twig_Environment($loader, array('autoescape' => FALSE));
}
// init all functions as Twig functions.
foreach ($this->allowed_functions as $function) {
$twig->addFunction($function, new Twig_Function_Function($function));
}
// setup debugger
$twig->addExtension(new Twig_Extension_Debug());
// setup the Lexer
$lexer = new Twig_Lexer($twig, $this->delimiters);
$twig->setLexer($lexer);
// finally, return the object.
return $twig;
}