library/smarty/libs/sysplugins/smarty_internal_resource_registered.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Smarty Internal Plugin Resource Registered
       
     4  *
       
     5  * @package    Smarty
       
     6  * @subpackage TemplateResources
       
     7  * @author     Uwe Tews
       
     8  * @author     Rodney Rehm
       
     9  */
       
    10 
       
    11 /**
       
    12  * Smarty Internal Plugin Resource Registered
       
    13  * Implements the registered resource for Smarty template
       
    14  *
       
    15  * @package    Smarty
       
    16  * @subpackage TemplateResources
       
    17  * @deprecated
       
    18  */
       
    19 class Smarty_Internal_Resource_Registered extends Smarty_Resource {
       
    20     /**
       
    21      * populate Source Object with meta data from Resource
       
    22      *
       
    23      * @param  Smarty_Template_Source $source source object
       
    24      * @param  Smarty_Internal_Template $_template template object
       
    25      *
       
    26      * @return void
       
    27      */
       
    28     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
       
    29         $source->filepath = $source->type . ':' . $source->name;
       
    30         $source->uid = sha1($source->filepath);
       
    31         if ($source->smarty->compile_check) {
       
    32             $source->timestamp = $this->getTemplateTimestamp($source);
       
    33             $source->exists = !!$source->timestamp;
       
    34         }
       
    35     }
       
    36 
       
    37     /**
       
    38      * populate Source Object with timestamp and exists from Resource
       
    39      *
       
    40      * @param  Smarty_Template_Source $source source object
       
    41      *
       
    42      * @return void
       
    43      */
       
    44     public function populateTimestamp(Smarty_Template_Source $source) {
       
    45         $source->timestamp = $this->getTemplateTimestamp($source);
       
    46         $source->exists = !!$source->timestamp;
       
    47     }
       
    48 
       
    49     /**
       
    50      * Get timestamp (epoch) the template source was modified
       
    51      *
       
    52      * @param  Smarty_Template_Source $source source object
       
    53      *
       
    54      * @return integer|boolean        timestamp (epoch) the template was modified, false if resources has no timestamp
       
    55      */
       
    56     public function getTemplateTimestamp(Smarty_Template_Source $source) {
       
    57         // return timestamp
       
    58         $time_stamp = false;
       
    59         call_user_func_array($source->smarty->registered_resources[$source->type][0][1], array($source->name, &$time_stamp, $source->smarty));
       
    60 
       
    61         return is_numeric($time_stamp) ? (int)$time_stamp : $time_stamp;
       
    62     }
       
    63 
       
    64     /**
       
    65      * Load template's source by invoking the registered callback into current template object
       
    66      *
       
    67      * @param  Smarty_Template_Source $source source object
       
    68      *
       
    69      * @return string                 template source
       
    70      * @throws SmartyException        if source cannot be loaded
       
    71      */
       
    72     public function getContent(Smarty_Template_Source $source) {
       
    73         // return template string
       
    74         $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$source->content, $source->smarty));
       
    75         if (is_bool($t) && !$t) {
       
    76             throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
       
    77         }
       
    78 
       
    79         return $source->content;
       
    80     }
       
    81 
       
    82     /**
       
    83      * Determine basename for compiled filename
       
    84      *
       
    85      * @param  Smarty_Template_Source $source source object
       
    86      *
       
    87      * @return string                 resource's basename
       
    88      */
       
    89     public function getBasename(Smarty_Template_Source $source) {
       
    90         return basename($source->name);
       
    91     }
       
    92 }