gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

smarty_internal_extension_defaulttemplatehandler.php (2524B)


      1 <?php
      2 /**
      3  * Smarty Resource Extension
      4  *
      5  * @package    Smarty
      6  * @subpackage TemplateResources
      7  * @author     Uwe Tews
      8  */
      9 
     10 /**
     11  * Smarty Resource Extension
     12  * Default template and config file handling
     13  *
     14  * @package    Smarty
     15  * @subpackage TemplateResources
     16  */
     17 class Smarty_Internal_Extension_DefaultTemplateHandler
     18 {
     19 
     20     /**
     21      * get default content from template of config resource handler
     22      *
     23      * @param Smarty_Internal_Template        $_template
     24      * @param Smarty_Internal_Template_Source $source
     25      * @param  Smarty_Resource                $resObj
     26      */
     27     static function _getDefault(Smarty_Internal_Template $_template, &$source, &$resObj)
     28     {
     29         if ($source->isConfig) {
     30             $default_handler = $_template->smarty->default_config_handler_func;
     31         } else {
     32             $default_handler = $_template->smarty->default_template_handler_func;
     33         }
     34         $_content = $_timestamp = null;
     35         $_return = call_user_func_array($default_handler,
     36                                         array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
     37         if (is_string($_return)) {
     38             $source->exists = is_file($_return);
     39             if ($source->exists) {
     40                 $source->timestamp = filemtime($_return);
     41             }
     42             $source->filepath = $_return;
     43         } elseif ($_return === true) {
     44             $source->content = $_content;
     45             $source->timestamp = $_timestamp;
     46             $source->exists = true;
     47             $source->recompiled = true;
     48             $source->filepath = false;
     49         }
     50     }
     51 
     52     /**
     53      * register template default handler
     54      *
     55      * @param Smarty $smarty
     56      * @param mixed  $callback
     57      *
     58      * @throws SmartyException
     59      */
     60     static function registerDefaultTemplateHandler(Smarty $smarty, $callback)
     61     {
     62         if (is_callable($callback)) {
     63             $smarty->default_template_handler_func = $callback;
     64         } else {
     65             throw new SmartyException("Default template handler not callable");
     66         }
     67     }
     68 
     69     /**
     70      * register config default handler
     71      *
     72      * @param Smarty $smarty
     73      * @param mixed  $callback
     74      *
     75      * @throws SmartyException
     76      */
     77     static function registerDefaultConfigHandler(Smarty $smarty, $callback)
     78     {
     79         if (is_callable($callback)) {
     80             $smarty->default_config_handler_func = $callback;
     81         } else {
     82             throw new SmartyException("Default config handler not callable");
     83         }
     84     }
     85 }