Box\Brainy\Templates\Template::createTemplateCodeFrame PHP Method

createTemplateCodeFrame() public method

Create code frame for compiled and cached templates
public createTemplateCodeFrame ( string $content = '' ) : string
$content string optional template content
return string
    public function createTemplateCodeFrame($content = '')
    {
        $plugins_string = '';
        // include code for plugins
        if (!empty($this->required_plugins['compiled'])) {
            foreach ($this->required_plugins['compiled'] as $tmp) {
                foreach ($tmp as $data) {
                    $file = addslashes($data['file']);
                    if (is_Array($data['function'])) {
                        $func = $data['function'];
                        $plugins_string .= "if (!is_callable(array('{$func[0]}', '{$func[1]}'))) ";
                        $plugins_string .= "include '{$file}';\n";
                    } else {
                        $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$file}';\n";
                    }
                }
            }
        }
        // build property code
        $output = '';
        $this->properties['version'] = Brainy::SMARTY_VERSION;
        if (!isset($this->properties['unifunc'])) {
            $this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
        }
        if (!$this->source->recompiled) {
            $decode = "\$_smarty_tpl->decodeProperties(" . var_export($this->properties, true) . ')';
            $output .= 'if (' . $decode . ' && !is_callable(\'' . $this->properties['unifunc'] . "')) {\n";
            // Output a proper PHPDoc for Augmented Types users.
            $output .= <<<'PHPDOC'
/**
 * @param \Box\Brainy\Templates\TemplateBase $_smarty_tpl The smarty template instance
 * @return void
 */

PHPDOC;
            $output .= 'function ' . $this->properties['unifunc'] . "(\$_smarty_tpl) {\n";
        }
        $output .= $plugins_string;
        $output .= $content;
        if (!$this->source->recompiled) {
            $output .= "\n}\n}\n";
        }
        return $output;
    }

Usage Example

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;
 }
All Usage Examples Of Box\Brainy\Templates\Template::createTemplateCodeFrame