source: pro-violet-viettel/sourcecode/application/third_party/Smarty/sysplugins/smarty_resource_custom.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 2.8 KB
Line 
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 *
13 * Wrapper Implementation for custom resource plugins
14 *
15 * @package Smarty
16 * @subpackage TemplateResources
17 */
18abstract class Smarty_Resource_Custom extends Smarty_Resource {
19
20    /**
21     * fetch template and its modification time from data source
22     *
23     * @param string  $name    template name
24     * @param string  &$source template source
25     * @param integer &$mtime  template modification timestamp (epoch)
26     */
27    protected abstract function fetch($name, &$source, &$mtime);
28
29    /**
30     * Fetch template's modification timestamp from data source
31     *
32     * {@internal implementing this method is optional.
33     *  Only implement it if modification times can be accessed faster than loading the complete template source.}}
34     *
35     * @param string $name template name
36     * @return integer|boolean timestamp (epoch) the template was modified, or false if not found
37     */
38    protected function fetchTimestamp($name)
39    {
40        return null;
41    }
42
43    /**
44     * populate Source Object with meta data from Resource
45     *
46     * @param Smarty_Template_Source   $source    source object
47     * @param Smarty_Internal_Template $_template template object
48     */
49    public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
50    {
51        $source->filepath = strtolower($source->type . ':' . $source->name);
52        $source->uid = sha1($source->type . ':' . $source->name);
53
54        $mtime = $this->fetchTimestamp($source->name);
55        if ($mtime !== null) {
56            $source->timestamp = $mtime;
57        } else {
58            $this->fetch($source->name, $content, $timestamp);
59            $source->timestamp = isset($timestamp) ? $timestamp : false;
60            if( isset($content) )
61                $source->content = $content;
62        }
63        $source->exists = !!$source->timestamp;
64    }
65
66    /**
67     * Load template's source into current template object
68     *
69     * @param Smarty_Template_Source $source source object
70     * @return string template source
71     * @throws SmartyException if source cannot be loaded
72     */
73    public function getContent(Smarty_Template_Source $source)
74    {
75        $this->fetch($source->name, $content, $timestamp);
76        if (isset($content)) {
77            return $content;
78        }
79
80        throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
81    }
82
83    /**
84     * Determine basename for compiled filename
85     *
86     * @param Smarty_Template_Source $source source object
87     * @return string resource's basename
88     */
89    protected function getBasename(Smarty_Template_Source $source)
90    {
91        return basename($source->name);
92    }
93
94}
95
96?>
Note: See TracBrowser for help on using the repository browser.