/**
  * Write the rendered template output to cache
  *
  * @param Smurty_Internal_Template $_template template object
  * @param string                   $content   content to cache
  *
  * @return boolean success
  */
 public function writeCachedContent(Smurty_Internal_Template $_template, $content)
 {
     if (Smurty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smurty) === true) {
         $_template->cached->timestamp = @filemtime($_template->cached->filepath);
         $_template->cached->exists = !!$_template->cached->timestamp;
         if ($_template->cached->exists) {
             return true;
         }
     }
     return false;
 }
 /**
  * Compiles the template
  * If the template is not evaluated the compiled template is saved on disk
  */
 public function compileTemplateSource()
 {
     if (!$this->source->recompiled) {
         $this->properties['file_dependency'] = array();
         if ($this->source->components) {
             // for the extends resource the compiler will fill it
             // uses real resource for file dependency
             // $source = end($this->source->components);
             // $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
         } else {
             $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
         }
     }
     // compile locking
     if ($this->smurty->compile_locking && !$this->source->recompiled) {
         if ($saved_timestamp = $this->compiled->timestamp) {
             touch($this->compiled->filepath);
         }
     }
     // call compiler
     try {
         $code = $this->compiler->compileTemplate($this);
     } catch (Exception $e) {
         // restore old timestamp in case of error
         if ($this->smurty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
             touch($this->compiled->filepath, $saved_timestamp);
         }
         throw $e;
     }
     // compiling succeded
     if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
         // write compiled template
         $_filepath = $this->compiled->filepath;
         if ($_filepath === false) {
             throw new SmurtyException('getCompiledFilepath() did not return a destination to save the compiled template to');
         }
         Smurty_Internal_Write_File::writeFile($_filepath, $code, $this->smurty);
         $this->compiled->exists = true;
         $this->compiled->isCompiled = true;
     }
     // release compiler object to free memory
     unset($this->compiler);
 }
 /**
  * Compiles the config files
  *
  * @throws Exception
  */
 public function compileConfigSource()
 {
     // compile template
     if (!is_object($this->compiler_object)) {
         // load compiler
         $this->compiler_object = new Smurty_Internal_Config_File_Compiler($this->smurty);
     }
     // compile locking
     if ($this->smurty->compile_locking) {
         if ($saved_timestamp = $this->getCompiledTimestamp()) {
             touch($this->getCompiledFilepath());
         }
     }
     // call compiler
     try {
         $this->compiler_object->compileSource($this);
     } catch (Exception $e) {
         // restore old timestamp in case of error
         if ($this->smurty->compile_locking && $saved_timestamp) {
             touch($this->getCompiledFilepath(), $saved_timestamp);
         }
         throw $e;
     }
     // compiling succeeded
     // write compiled template
     Smurty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->getCompiledConfig(), $this->smurty);
 }