public function compileTemplateSource()
{
if (!$this->source->recompiled) {
$this->properties['file_dependency'] = array();
$this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
}
// compile locking
if ($this->smarty->compile_locking && !$this->source->recompiled) {
if ($saved_timestamp = $this->compiled->timestamp) {
touch($this->compiled->filepath);
}
}
// call compiler
$compiler = null;
try {
$compiler = new \Box\Brainy\Compiler\TemplateCompiler($this->smarty);
$code = $compiler->compileTemplate($this);
unset($compiler);
} catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
touch($this->compiled->filepath, $saved_timestamp);
}
if ($compiler) {
unset($compiler);
}
throw $e;
}
// compiling succeded
if (!$this->source->recompiled) {
// write compiled template
$_filepath = $this->compiled->filepath;
if ($_filepath === false) {
throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
}
self::writeFile($_filepath, $code, $this->smarty);
$this->compiled->exists = true;
$this->compiled->isCompiled = true;
}
return $code;
}