• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Smarty_Resource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Smarty_Resource的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Resource类的具体用法?PHP Smarty_Resource怎么用?PHP Smarty_Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Smarty_Resource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: setUp

 public function setUp()
 {
     $this->smarty = SmartyTests::$smarty;
     // reset cache for unit test
     Smarty_Resource::$resources = array();
     SmartyTests::init();
 }
开发者ID:jjs180,项目名称:dance-america,代码行数:7,代码来源:ResourcePluginTests.php


示例2: populate

 /**
  * populate Source Object with meta data from Resource
  *
  * @param  Smarty_Template_Source   $source    source object
  * @param  Smarty_Internal_Template $_template template object
  *
  * @return void
  */
 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
 {
     $uid = '';
     $sources = array();
     $timestamp = 0;
     foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
         try {
             $s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name);
             if (!$s->exists) {
                 continue;
             }
             $sources[$s->uid] = $s;
             $uid .= $s->filepath;
             $timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
         } catch (SmartyException $e) {
         }
     }
     if (!$sources) {
         $source->exists = false;
         return;
     }
     $sources = array_reverse($sources, true);
     reset($sources);
     $s = current($sources);
     $source->components = $sources;
     $source->filepath = $s->filepath;
     $source->uid = sha1($uid . $_template->smarty->_joined_template_dir);
     $source->exists = true;
     $source->timestamp = $timestamp;
 }
开发者ID:Wicloz,项目名称:UniversityWebsite,代码行数:38,代码来源:resource.extendsall.php


示例3: populate

 /**
  * populate Source Object with meta data from Resource
  *
  * @param Smarty_Template_Source   $source    source object
  * @param Smarty_Internal_Template $_template template object
  */
 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
 {
     $uid = '';
     $sources = array();
     $components = explode('|', $source->name);
     $exists = true;
     foreach ($components as $component) {
         $s = Smarty_Resource::source(null, $source->smarty, $component);
         if ($s->type == 'php') {
             throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type");
         }
         $sources[$s->uid] = $s;
         $uid .= $s->filepath;
         if ($_template && $_template->smarty->compile_check) {
             $exists = $exists && $s->exists;
         }
     }
     $source->components = $sources;
     $source->filepath = $s->filepath;
     $source->uid = sha1($uid);
     if ($_template && $_template->smarty->compile_check) {
         $source->timestamp = $s->timestamp;
         $source->exists = $exists;
     }
     // need the template at getContent()
     $source->template = $_template;
 }
开发者ID:Setrino,项目名称:collabtive,代码行数:33,代码来源:smarty_internal_resource_extends.php


示例4: _getDefaultTemplate

 /**
  * get default content from template or config resource handler
  *
  * @param Smarty_Template_Source $source
  *
  * @throws \SmartyException
  */
 public static function _getDefaultTemplate(Smarty_Template_Source $source)
 {
     if ($source->isConfig) {
         $default_handler = $source->smarty->default_config_handler_func;
     } else {
         $default_handler = $source->smarty->default_template_handler_func;
     }
     $_content = $_timestamp = null;
     $_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
     if (is_string($_return)) {
         $source->exists = is_file($_return);
         if ($source->exists) {
             $source->timestamp = filemtime($_return);
         } else {
             throw new SmartyException("Default handler: Unable to load " . ($source->isConfig ? 'config' : 'template') . " default file '{$_return}' for '{$source->type}:{$source->name}'");
         }
         $source->name = $source->filepath = $_return;
         $source->uid = sha1($source->filepath);
     } elseif ($_return === true) {
         $source->content = $_content;
         $source->exists = true;
         $source->uid = $source->name = sha1($_content);
         $source->handler = Smarty_Resource::load($source->smarty, 'eval');
     } else {
         $source->exists = false;
         throw new SmartyException('Default handler: No ' . ($source->isConfig ? 'config' : 'template') . " default content for '{$source->type}:{$source->name}'");
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:35,代码来源:smarty_internal_method_registerdefaulttemplatehandler.php


示例5: populate

 /**
  * populate Source Object with meta data from Resource
  *
  * @param  Smarty_Template_Source   $source    source object
  * @param  Smarty_Internal_Template $_template template object
  *
  * @return void
  */
 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
 {
     $uid = '';
     $sources = array();
     $exists = true;
     foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
         try {
             $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name);
             if (!$s->exists) {
                 continue;
             }
             $sources[$s->uid] = $s;
             $uid .= $s->filepath;
         } catch (SmartyException $e) {
         }
     }
     if (!$sources) {
         $source->exists = false;
         $source->template = $_template;
         return;
     }
     $sources = array_reverse($sources, true);
     reset($sources);
     $s = current($sources);
     $source->components = $sources;
     $source->filepath = $s->filepath;
     $source->uid = sha1($uid);
     $source->exists = $exists;
     if ($_template && $_template->smarty->compile_check) {
         $source->timestamp = $s->timestamp;
     }
     // need the template at getContent()
     $source->template = $_template;
 }
开发者ID:gelcaas,项目名称:newpi,代码行数:42,代码来源:resource.extendsall.php


示例6: decodeProperties

 /**
  * This function is executed automatically when a compiled or cached template file is included
  * - Decode saved properties from compiled template and cache files
  * - Check if compiled or cache file is valid
  *
  * @param  array $properties special template properties
  * @param  bool  $cache      flag if called from cache file
  *
  * @return bool  flag if compiled or cache file is valid
  */
 public function decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
 {
     $is_valid = true;
     if (Smarty::SMARTY_VERSION != $properties['version']) {
         // new version must rebuild
         $is_valid = false;
     } elseif ($is_valid && !empty($properties['file_dependency']) && (!$cache && $tpl->smarty->compile_check || $tpl->smarty->compile_check == 1)) {
         // check file dependencies at compiled code
         foreach ($properties['file_dependency'] as $_file_to_check) {
             if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
                 if ($tpl->source->filepath == $_file_to_check[0]) {
                     // do not recheck current template
                     continue;
                     //$mtime = $tpl->source->getTimeStamp();
                 } else {
                     // file and php types can be checked without loading the respective resource handlers
                     $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false;
                 }
             } elseif ($_file_to_check[2] == 'string') {
                 continue;
             } else {
                 $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]);
                 if ($handler->checkTimestamps()) {
                     $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[0]);
                     $mtime = $source->getTimeStamp();
                 } else {
                     continue;
                 }
             }
             if (!$mtime || $mtime > $_file_to_check[1]) {
                 $is_valid = false;
                 break;
             }
         }
     }
     if ($cache) {
         // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
         if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && time() > $tpl->cached->timestamp + $properties['cache_lifetime']) {
             $is_valid = false;
         }
         $tpl->cached->cache_lifetime = $properties['cache_lifetime'];
         $tpl->cached->valid = $is_valid;
         $resource = $tpl->cached;
     } else {
         $tpl->mustCompile = !$is_valid;
         $resource = $tpl->compiled;
         $resource->includes = isset($properties['includes']) ? $properties['includes'] : array();
     }
     if ($is_valid) {
         $resource->unifunc = $properties['unifunc'];
         $resource->has_nocache_code = $properties['has_nocache_code'];
         //            $tpl->compiled->nocache_hash = $properties['nocache_hash'];
         $resource->file_dependency = $properties['file_dependency'];
         if (isset($properties['tpl_function'])) {
             $tpl->tpl_function = $properties['tpl_function'];
         }
     }
     return $is_valid && !function_exists($properties['unifunc']);
 }
开发者ID:cywymch,项目名称:testMvc,代码行数:69,代码来源:smarty_internal_runtime_validatecompiled.php


示例7: init

 public static function init()
 {
     error_reporting(E_ALL | E_STRICT);
     self::_init(SmartyTests::$smarty);
     self::_init(SmartyTests::$smartyBC);
     SmartyTests::$smartyBC->registerPlugin('block', 'php', 'smarty_php_tag');
     Smarty_Resource::$sources = array();
     Smarty_Resource::$compileds = array();
 }
开发者ID:noiselabs,项目名称:smarty,代码行数:9,代码来源:smartytestdebug.inc.php


示例8: setUp

 public function setUp()
 {
     $this->smarty = SmartyTests::$smarty;
     SmartyTests::init();
     // empty the template dir
     $this->smarty->setTemplateDir(array());
     // kill cache for unit test
     Smarty_Resource::$resources = array();
     $this->smarty->_resource_handlers = array();
 }
开发者ID:jjs180,项目名称:dance-america,代码行数:10,代码来源:CustomResourceAmbiguousTests.php


示例9: populate

 /**
  * populate Source Object with meta data from Resource
  *
  * @param Smarty_Template_Source   $source    source object
  * @param Smarty_Internal_Template $_template template object
  */
 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
 {
     $filePath = $this->buildFilepath($source, $_template);
     $s = Smarty_Resource::source(null, $source->smarty, $filePath);
     $source->components = $s;
     $source->filepath = $s->filepath;
     $source->uid = $s->uid;
     if ($_template && $_template->smarty->compile_check) {
         $source->timestamp = $s->timestamp;
         $source->exists = $s->exists;
     }
     $source->template = $_template;
 }
开发者ID:ClaudioThomas,项目名称:shopware-4,代码行数:19,代码来源:resource.parent.php


示例10: makeFiles

 /**
  * generate compiled files
  * @uses $_files to store references
  * @return array list of files array( id => path )
  */
 protected function makeFiles()
 {
     $this->_files = array();
     $directory_length = strlen($this->smarty->getCompileDir());
     $templates = array('helloworld.tpl' => array(null, 'compile1', 'compile2'), 'helloworld2.tpl' => array(null, 'compile1', 'compile2'), 'ambiguous/case1/foobar.tpl' => array(null, 'compile1', 'compile2'), '[1]ambiguous/case1/foobar.tpl' => array(null, 'compile1', 'compile2'));
     foreach ($templates as $template => $compile_ids) {
         foreach ($compile_ids as $compile_id) {
             $tpl = $this->smarty->createTemplate($template, null, $compile_id);
             $tpl->fetch();
             $this->_files[$template . '#' . $compile_id] = substr($tpl->compiled->filepath, $directory_length - 1);
         }
     }
     Smarty_Resource::$sources = array();
     $this->smarty->template_objects = array();
     return $this->_files;
 }
开发者ID:mrsank,项目名称:work_sample,代码行数:21,代码来源:ClearCompiledTests.php


示例11: load

 /**
  * initialize Source Object for given resource
  * Either [$_template] or [$smarty, $template_resource] must be specified
  *
  * @param  Smarty_Internal_Template $_template         template object
  * @param  Smarty                   $smarty            smarty object
  * @param  string                   $template_resource resource identifier
  *
  * @return Smarty_Template_Config Source Object
  * @throws SmartyException
  */
 public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
 {
     static $_incompatible_resources = array('extends' => true, 'php' => true);
     $template_resource = $_template->template_resource;
     if (empty($template_resource)) {
         throw new SmartyException('Missing config name');
     }
     // parse resource_name, load resource handler
     list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type);
     // make sure configs are not loaded via anything smarty can't handle
     if (isset($_incompatible_resources[$type])) {
         throw new SmartyException("Unable to use resource '{$type}' for config");
     }
     $source = new Smarty_Template_Config($_template->smarty, $template_resource, $type, $name);
     $source->handler->populate($source, $_template);
     if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
         Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
     }
     return $source;
 }
开发者ID:vanderlee,项目名称:smarty,代码行数:31,代码来源:smarty_template_config.php


示例12: setSource

 /**
  * Set source object of inline template by $uid
  *
  * @param \Smarty_Internal_Template $tpl
  * @param  string                   $uid
  *
  * @throws \SmartyException
  */
 public function setSource(Smarty_Internal_Template $tpl, $uid = null)
 {
     // $uid is set if template is inline
     if (isset($uid)) {
         // inline templates have same compiled resource
         $tpl->compiled = $tpl->parent->compiled;
         if (isset($tpl->compiled->file_dependency[$uid])) {
             list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
             $tpl->source = new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ? $tpl->smarty->_cache['resource_handlers'][$resource] : Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty, $filepath, $resource, $filepath);
             $tpl->source->filepath = $filepath;
             $tpl->source->timestamp = $timestamp;
             $tpl->source->exists = true;
             $tpl->source->uid = $uid;
         } else {
             $tpl->source = null;
         }
     } else {
         $tpl->source = null;
         unset($tpl->compiled);
     }
     if (!isset($tpl->source)) {
         $tpl->source = Smarty_Template_Source::load($tpl);
     }
 }
开发者ID:visense,项目名称:smarty,代码行数:32,代码来源:smarty_internal_runtime_inline.php


示例13: clearCompiledTemplate

 /**
  * Delete compiled template file
  *
  * @param  string  $resource_name template name
  * @param  string  $compile_id    compile id
  * @param  integer $exp_time      expiration time
  * @param  Smarty  $smarty        Smarty instance
  *
  * @return integer number of template files deleted
  */
 public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty)
 {
     $_compile_dir = realpath($smarty->getCompileDir()) . '/';
     $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null;
     $_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
     if (isset($resource_name)) {
         $_save_stat = $smarty->caching;
         $smarty->caching = false;
         $tpl = new $smarty->template_class($resource_name, $smarty);
         $smarty->caching = $_save_stat;
         // remove from template cache
         $tpl->source;
         // have the template registered before unset()
         if ($smarty->allow_ambiguous_resources) {
             $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
         } else {
             $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
         }
         if (isset($_templateId[150])) {
             $_templateId = sha1($_templateId);
         }
         unset($smarty->template_objects[$_templateId]);
         if ($tpl->source->exists) {
             $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
             $_resource_part_1_length = strlen($_resource_part_1);
         } else {
             return 0;
         }
         $_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1);
         $_resource_part_2_length = strlen($_resource_part_2);
     }
     $_dir = $_compile_dir;
     if ($smarty->use_sub_dirs && isset($_compile_id)) {
         $_dir .= $_compile_id . $_dir_sep;
     }
     if (isset($_compile_id)) {
         $_compile_id_part = str_replace('\\', '/', $_compile_dir . $_compile_id . $_dir_sep);
         $_compile_id_part_length = strlen($_compile_id_part);
     }
     $_count = 0;
     try {
         $_compileDirs = new RecursiveDirectoryIterator($_dir);
         // NOTE: UnexpectedValueException thrown for PHP >= 5.3
     } catch (Exception $e) {
         return 0;
     }
     $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($_compile as $_file) {
         if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
             continue;
         }
         $_filepath = str_replace('\\', '/', (string) $_file);
         if ($_file->isDir()) {
             if (!$_compile->isDot()) {
                 // delete folder if empty
                 @rmdir($_file->getPathname());
             }
         } else {
             $unlink = false;
             if ((!isset($_compile_id) || isset($_filepath[$_compile_id_part_length]) && ($a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) && (!isset($resource_name) || isset($_filepath[$_resource_part_1_length]) && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0 || isset($_filepath[$_resource_part_2_length]) && substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0)) {
                 if (isset($exp_time)) {
                     if (time() - @filemtime($_filepath) >= $exp_time) {
                         $unlink = true;
                     }
                 } else {
                     $unlink = true;
                 }
             }
             if ($unlink && @unlink($_filepath)) {
                 $_count++;
             }
         }
     }
     // clear compiled cache
     Smarty_Resource::$sources = array();
     Smarty_Resource::$compileds = array();
     return $_count;
 }
开发者ID:Geo-Developers,项目名称:geo-developers-site,代码行数:88,代码来源:smarty_internal_utility.php


示例14: __get

 /**
  * get Smarty property in template context
  *
  * @param  string $property_name property name
  *
  * @return \Smarty_Config_Source|\Smarty_Template_Compiled
  * @throws SmartyException if $property_name is not valid
  */
 public function __get($property_name)
 {
     switch ($property_name) {
         case 'source':
             if (empty($this->config_resource)) {
                 throw new SmartyException("Unable to parse resource name \"{$this->config_resource}\"");
             }
             $this->source = Smarty_Resource::config($this);
             return $this->source;
         case 'compiled':
             $this->compiled = $this->source->getCompiled($this);
             return $this->compiled;
     }
     throw new SmartyException("config attribute '{$property_name}' does not exist.");
 }
开发者ID:huwenshu,项目名称:dding,代码行数:23,代码来源:smarty_internal_config.php


示例15: decodeProperties

 /**
  * This function is executed automatically when a compiled or cached template file is included
  * - Decode saved properties from compiled template and cache files
  * - Check if compiled or cache file is valid
  *
  * @param  array $properties special template properties
  * @param  bool  $cache flag if called from cache file
  *
  * @return bool  flag if compiled or cache file is valid
  */
 public function decodeProperties($properties, $cache = false)
 {
     $properties['version'] = isset($properties['version']) ? $properties['version'] : '';
     $is_valid = true;
     if (Smarty::SMARTY_VERSION != $properties['version']) {
         // new version must rebuild
         $is_valid = false;
     } elseif ((!$cache && $this->smarty->compile_check || $cache && ($this->smarty->compile_check === true || $this->smarty->compile_check === Smarty::COMPILECHECK_ON)) && !empty($properties['file_dependency'])) {
         // check file dependencies at compiled code
         foreach ($properties['file_dependency'] as $_file_to_check) {
             if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'php') {
                 if ($this->source->filepath == $_file_to_check[0] && isset($this->source->timestamp)) {
                     // do not recheck current template
                     $mtime = $this->source->timestamp;
                 } else {
                     // file and php types can be checked without loading the respective resource handlers
                     $mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false;
                 }
             } elseif ($_file_to_check[2] == 'string') {
                 continue;
             } else {
                 $source = Smarty_Resource::source(null, $this->smarty, $_file_to_check[0]);
                 $mtime = $source->timestamp;
             }
             if (!$mtime || $mtime > $_file_to_check[1]) {
                 $is_valid = false;
                 break;
             }
         }
     }
     if ($cache) {
         // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
         if ($this->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && time() > $this->cached->timestamp + $properties['cache_lifetime']) {
             $is_valid = false;
         }
         $this->cached->valid = $is_valid;
     } else {
         $this->mustCompile = !$is_valid;
     }
     if ($is_valid) {
         $this->has_nocache_code = $properties['has_nocache_code'];
         //            $this->properties['nocache_hash'] = $properties['nocache_hash'];
         if (isset($properties['cache_lifetime'])) {
             $this->properties['cache_lifetime'] = $properties['cache_lifetime'];
         }
         if (isset($properties['file_dependency'])) {
             $this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']);
         }
         if (isset($properties['tpl_function'])) {
             $this->properties['tpl_function'] = array_merge($this->properties['tpl_function'], $properties['tpl_function']);
         }
         $this->properties['version'] = $properties['version'];
         $this->properties['unifunc'] = $properties['unifunc'];
     }
     return $is_valid;
 }
开发者ID:hejxing,项目名称:jt,代码行数:66,代码来源:smarty_internal_template.php


示例16: logInclude

 /**
  * log include count
  *
  * @param \Smarty_Internal_SmartyTemplateCompiler $compiler
  * @param   string                                $include_file
  * @param    bool                                 $variable_template
  */
 private function logInclude(Smarty_Internal_SmartyTemplateCompiler $compiler, $include_file, $variable_template)
 {
     if ($variable_template) {
         return;
     }
     list($name, $type) = Smarty_Resource::parseResourceName(trim($include_file, '\'"'), $compiler->template->smarty->default_resource_type);
     if (in_array($type, array('eval', 'string'))) {
         return;
     }
     $include_name = $type . ':' . $name;
     $compiled = $compiler->parent_compiler->template->compiled;
     $compiled->includes[$include_name] = isset($compiled->includes[$include_name]) ? $compiled->includes[$include_name] + 1 : 1;
 }
开发者ID:kewldrankofh2o,项目名称:smarty,代码行数:20,代码来源:smarty_internal_compile_include.php


示例17: getTemplateId

 /**
  * Get unique template id
  *
  * @param string     $template_name
  * @param null|mixed $cache_id
  * @param null|mixed $compile_id
  *
  * @return string
  */
 public function getTemplateId($template_name, $cache_id = null, $compile_id = null)
 {
     $cache_id = isset($cache_id) ? $cache_id : $this->cache_id;
     $compile_id = isset($compile_id) ? $compile_id : $this->compile_id;
     $smarty = isset($this->smarty) ? $this->smarty : $this;
     if ($smarty->allow_ambiguous_resources) {
         $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}";
     } else {
         $_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}";
     }
     if (isset($_templateId[150])) {
         $_templateId = sha1($_templateId);
     }
     return $_templateId;
 }
开发者ID:dower-d,项目名称:shop,代码行数:24,代码来源:smarty_internal_templatebase.php


示例18: clearCompiledTemplate

 /**
  * Delete compiled template file
  *
  * @param string  $resource_name template name
  * @param string  $compile_id    compile id
  * @param integer $exp_time      expiration time
  * @param Smarty  $smarty        Smarty instance
  * @return integer number of template files deleted
  */
 public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty)
 {
     $_compile_dir = $smarty->getCompileDir();
     $_compile_id = isset($compile_id) ? preg_replace('![^\\w\\|]+!', '_', $compile_id) : null;
     $_dir_sep = $smarty->use_sub_dirs ? DS : '^';
     if (isset($resource_name)) {
         $_save_stat = $smarty->caching;
         $smarty->caching = false;
         $tpl = new $smarty->template_class($resource_name, $smarty);
         $smarty->caching = $_save_stat;
         if ($tpl->source->exists) {
             $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
             // remove from template cache
             unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
         } else {
             // remove from template cache
             unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
             return 0;
         }
         $_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1);
     } else {
         $_resource_part = '';
     }
     $_dir = $_compile_dir;
     if ($smarty->use_sub_dirs && isset($_compile_id)) {
         $_dir .= $_compile_id . $_dir_sep;
     }
     if (isset($_compile_id)) {
         $_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep;
     }
     $_count = 0;
     $_compileDirs = new RecursiveDirectoryIterator($_dir);
     $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($_compile as $_file) {
         if (substr($_file->getBasename(), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
             continue;
         }
         if ($_file->isDir()) {
             if (!$_compile->isDot()) {
                 // delete folder if empty
                 @rmdir($_file->getPathname());
             }
         } else {
             if ((!isset($_compile_id) || strlen((string) $_file) > strlen($_compile_id_part) && substr_compare((string) $_file, $_compile_id_part, 0, strlen($_compile_id_part)) == 0) && (!isset($resource_name) || strlen((string) $_file) > strlen($_resource_part_1) && substr_compare((string) $_file, $_resource_part_1, -strlen($_resource_part_1), strlen($_resource_part_1)) == 0 || strlen((string) $_file) > strlen($_resource_part_2) && substr_compare((string) $_file, $_resource_part_2, -strlen($_resource_part_2), strlen($_resource_part_2)) == 0)) {
                 if (isset($exp_time)) {
                     if (time() - @filemtime($_file) >= $exp_time) {
                         $_count += @unlink((string) $_file) ? 1 : 0;
                     }
                 } else {
                     $_count += @unlink((string) $_file) ? 1 : 0;
                 }
             }
         }
     }
     // clear compiled cache
     Smarty_Resource::$sources = array();
     Smarty_Resource::$compileds = array();
     return $_count;
 }
开发者ID:harmofwk,项目名称:harmofwk,代码行数:68,代码来源:smarty_internal_utility.php


示例19: getUniqueTemplateName

 /**
  * modify template_resource according to resource handlers specifications
  *
  * @param  \Smarty_Internal_Template|\Smarty $obj               Smarty instance
  * @param  string                            $template_resource template_resource to extract resource handler and name of
  *
  * @return string unique resource name
  */
 public static function getUniqueTemplateName($obj, $template_resource)
 {
     $smarty = $obj->_objType == 2 ? $obj->smarty : $obj;
     list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
     // TODO: optimize for Smarty's internal resource types
     $resource = Smarty_Resource::load($smarty, $type);
     // go relative to a given template?
     $_file_is_dotted = $name[0] == '.' && ($name[1] == '.' || $name[1] == '/');
     if ($obj->_objType == 2 && $_file_is_dotted && ($obj->source->type == 'file' || $obj->parent->source->type == 'extends')) {
         $name = dirname($obj->source->filepath) . DS . $name;
     }
     return $resource->buildUniqueResourceName($smarty, $name);
 }
开发者ID:dayday0769,项目名称:smarty,代码行数:21,代码来源:smarty_resource.php


示例20: render

 /**
  * Runtime function to render subtemplate
  *
  * @param \Smarty_Internal_Template $parent
  * @param string                    $template       template name
  * @param mixed                     $cache_id       cache id
  * @param mixed                     $compile_id     compile id
  * @param integer                   $caching        cache mode
  * @param integer                   $cache_lifetime life time of cache data
  * @param array                     $data           passed parameter template variables
  * @param int                       $scope          scope in which {include_test} should execute
  * @param bool                      $forceTplCache  cache template object
  * @param string                    $uid            file dependency uid
  * @param string                    $content_func   function name
  *
  */
 public function render(Smarty_Internal_Template $parent, $template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $scope, $forceTplCache, $uid = null, $content_func = null)
 {
     // if there are cached template objects calculate $templateID
     $_templateId = !empty($this->tplObjects) ? $parent->smarty->_getTemplateId($template, $cache_id, $compile_id, $caching) : null;
     // already in template cache?
     /* @var Smarty_Internal_Template $tpl */
     if (isset($_templateId) && isset($this->tplObjects[$_templateId])) {
         // clone cached template object because of possible recursive call
         $tpl = clone $this->tplObjects[$_templateId];
         $tpl->parent = $parent;
         // if $caching mode changed the compiled resource is invalid
         if ((bool) $tpl->caching !== (bool) $caching) {
             unset($tpl->compiled);
         }
         // get variables from calling scope
         $tpl->tpl_vars = $parent->tpl_vars;
         $tpl->config_vars = $parent->config_vars;
         // get template functions
         $tpl->tpl_function = $parent->tpl_function;
         // copy inheritance object?
         if (isset($parent->ext->_inheritance)) {
             $tpl->ext->_inheritance = $parent->ext->_inheritance;
         } else {
             unset($tpl->ext->_inheritance);
         }
     } else {
         $tpl = clone $parent;
         $tpl->parent = $parent;
         if (!isset($tpl->templateId) || $tpl->templateId !== $_templateId) {
             $tpl->templateId = $_templateId;
             $tpl->template_resource = $template;
             $tpl->cache_id = $cache_id;
             $tpl->compile_id = $compile_id;
             if (isset($uid)) {
                 // for inline templates we can get all resource information from file dependency
                 if (isset($tpl->compiled->file_dependency[$uid])) {
                     list($filepath, $timestamp, $resource) = $tpl->compiled->file_dependency[$uid];
                     $tpl->source = new Smarty_Template_Source(isset($tpl->smarty->_cache['resource_handlers'][$resource]) ? $tpl->smarty->_cache['resource_handlers'][$resource] : Smarty_Resource::load($tpl->smarty, $resource), $tpl->smarty, $filepath, $resource, $filepath);
                     $tpl->source->filepath = $filepath;
                     $tpl->source->timestamp = $timestamp;
                     $tpl->source->exists = true;
                     $tpl->source->uid = $uid;
                 } else {
                     $tpl->source = null;
                 }
             } else {
                 $tpl->source = null;
             }
             if (!isset($tpl->source)) {
                 $tpl->source = Smarty_Template_Source::load($tpl);
                 unset($tpl->compiled);
             }
             unset($tpl->cached);
         }
     }
     $tpl->caching = $caching;
     $tpl->cache_lifetime = $cache_lifetime;
     if ($caching == 9999) {
         $tpl->cached = $parent->cached;
     }
     // set template scope
     $tpl->scope = $scope;
     $scopePtr = false;
     if ($scope & ~Smarty::SCOPE_BUBBLE_UP) {
         if ($scope == Smarty::SCOPE_GLOBAL) {
             $tpl->tpl_vars = Smarty::$global_tpl_vars;
             $tpl->config_vars = $tpl->smarty->config_vars;
             $scopePtr = true;
         } else {
             if ($scope == Smarty::SCOPE_PARENT) {
                 $scopePtr = $parent;
             } elseif ($scope == Smarty::SCOPE_SMARTY) {
                 $scopePtr = $tpl->smarty;
             } else {
                 $scopePtr = $tpl;
                 while (isset($scopePtr->parent)) {
                     if ($scopePtr->parent->_objType != 2 && $scope & Smarty::SCOPE_TPL_ROOT) {
                         break;
                     }
                     $scopePtr = $scopePtr->parent;
                 }
             }
             $tpl->tpl_vars = $scopePtr->tpl_vars;
             $tpl->config_vars = $scopePtr->config_vars;
//.........这里部分代码省略.........
开发者ID:Hjsmallfly,项目名称:musex_old,代码行数:101,代码来源:smarty_internal_runtime_subtemplate.php



注:本文中的Smarty_Resource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Smarty_Template_Source类代码示例发布时间:2022-05-23
下一篇:
PHP Smarty_Internal_Write_File类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap