]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_resource_recompiled.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_resource_recompiled.php
1 <?php
2 /**
3  * Smarty Resource Plugin
4  *
5  * @package    Smarty
6  * @subpackage TemplateResources
7  * @author     Rodney Rehm
8  */
9
10 /**
11  * Smarty Resource Plugin
12  * Base implementation for resource plugins that don't compile cache
13  *
14  * @package    Smarty
15  * @subpackage TemplateResources
16  */
17 abstract class Smarty_Resource_Recompiled extends Smarty_Resource
18 {
19     /**
20      * Flag that it's an recompiled resource
21      *
22      * @var bool
23      */
24     public $recompiled = true;
25
26     /**
27      * Resource does implement populateCompiledFilepath() method
28      *
29      * @var bool
30      */
31     public $hasCompiledHandler = true;
32
33     /**
34      * compile template from source
35      *
36      * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
37      *
38      * @throws Exception
39      */
40     public function process(Smarty_Internal_Template $_smarty_tpl)
41     {
42         $compiled = &$_smarty_tpl->compiled;
43         $compiled->file_dependency = array();
44         $compiled->includes = array();
45         $compiled->nocache_hash = null;
46         $compiled->unifunc = null;
47         $level = ob_get_level();
48         ob_start();
49         $_smarty_tpl->loadCompiler();
50         // call compiler
51         try {
52             eval("?>" . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
53         }
54         catch (Exception $e) {
55             unset($_smarty_tpl->compiler);
56             while (ob_get_level() > $level) {
57                 ob_end_clean();
58             }
59             throw $e;
60         }
61         // release compiler object to free memory
62         unset($_smarty_tpl->compiler);
63         ob_get_clean();
64         $compiled->timestamp = time();
65         $compiled->exists = true;
66     }
67
68     /**
69      * populate Compiled Object with compiled filepath
70      *
71      * @param  Smarty_Template_Compiled $compiled  compiled object
72      * @param  Smarty_Internal_Template $_template template object
73      *
74      * @return void
75      */
76     public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
77     {
78         $compiled->filepath = false;
79         $compiled->timestamp = false;
80         $compiled->exists = false;
81     }
82
83     /*
84        * Disable timestamp checks for recompiled resource.
85        *
86        * @return bool
87        */
88     public function checkTimestamps()
89     {
90         return false;
91     }
92 }