createTemplateCodeFrame() public method

Create code frame for compiled and cached templates
public createTemplateCodeFrame ( string $content = '' ) : string
$content string optional template content
return string
Example #1
0
 /**
  * Method to compile a Smarty template
  *
  * @param  Template $template template object to compile
  * @return bool             true if compiling succeeded, false if it failed
  */
 public function compileTemplate(Template $template)
 {
     // save template object in compiler class
     $this->template = $template;
     // template header code
     $template_header = '';
     if (!$this->suppressHeader) {
         $template_header .= "<?php\n";
     }
     $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
     $compiledCode = $this->doCompile($this->template->source->getContent());
     // free memory
     unset($this->template);
     $code = $template_header . $template->createTemplateCodeFrame($compiledCode);
     return $code;
 }
 /**
  * Method to compile a Smarty template
  *
  * @param  Template $template template object to compile
  * @return bool             true if compiling succeeded, false if it failed
  */
 public function compileTemplate(Template $template)
 {
     // save template object in compiler class
     $this->template = $template;
     $save_source = $this->template->source;
     // template header code
     $template_header = '';
     if (!$this->suppressHeader) {
         $template_header .= "<?php /* Brainy version " . Brainy::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
         $template_header .= "         compiled from \"" . $this->template->source->filepath . "\" */\n";
     }
     if (empty($this->template->source->components)) {
         $this->sources = array($template->source);
     } else {
         // we have array of inheritance templates by extends: resource
         $this->sources = array_reverse($template->source->components);
     }
     $loop = 0;
     // the $this->sources array can get additional elements while compiling by the {extends} tag
     while ($this->template->source = array_shift($this->sources)) {
         $no_sources = count($this->sources);
         if ($loop || $no_sources) {
             $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
         }
         $loop++;
         $this->inheritance_child = (bool) $no_sources;
         $_compiled_code = '';
         // get template source
         if ($this->template->source->content) {
             $_compiled_code = $this->doCompile($this->template->source->content);
         }
     }
     // restore source
     $this->template->source = $save_source;
     unset($save_source);
     // free memory
     unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template);
     self::$_tag_objects = array();
     // return compiled code to template object
     $merged_code = '';
     if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) {
         foreach ($this->merged_templates as $code) {
             $merged_code .= $code;
         }
     }
     if ($this->suppressTemplatePropertyHeader) {
         $code = $_compiled_code . $merged_code;
     } else {
         $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code;
     }
     // unset content because template inheritance could have replace source with parent code
     unset($template->source->content);
     return $code;
 }