1<?php
2/**
3 * Smarty Internal Plugin Compile Shared Inheritance
4 * Shared methods for {extends} and {block} tags
5 *
6 * @package    Smarty
7 * @subpackage Compiler
8 * @author     Uwe Tews
9 */
10
11/**
12 * Smarty Internal Plugin Compile Shared Inheritance Class
13 *
14 * @package    Smarty
15 * @subpackage Compiler
16 */
17class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_CompileBase
18{
19    /**
20     * Compile inheritance initialization code as prefix
21     *
22     * @param \Smarty_Internal_TemplateCompilerBase $compiler
23     * @param bool|false                            $initChildSequence if true force child template
24     */
25    public static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
26    {
27        $compiler->prefixCompiledCode .= "<?php \$_smarty_tpl->_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " .
28                                         var_export($initChildSequence, true) . ");\n?>\n";
29    }
30
31    /**
32     * Register post compile callback to compile inheritance initialization code
33     *
34     * @param \Smarty_Internal_TemplateCompilerBase $compiler
35     * @param bool|false                            $initChildSequence if true force child template
36     */
37    public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
38    {
39        if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) {
40            $compiler->registerPostCompileCallback(
41                array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'),
42                array($initChildSequence),
43                'inheritanceInit',
44                $initChildSequence
45            );
46            $compiler->_cache[ 'inheritanceInit' ] = true;
47        }
48    }
49}
50