欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php封裝的smartyBC類完整實(shí)例

 更新時(shí)間:2016年10月19日 09:20:05   作者:Love滿天星  
這篇文章主要介紹了php封裝的smartyBC類,通過(guò)自定義類實(shí)現(xiàn)針對(duì)Smarty2的有效兼容與擴(kuò)展,需要的朋友可以參考下

本文實(shí)例講述了php封裝的smartyBC類。分享給大家供大家參考,具體如下:

<?php
/**
 * Project:   Smarty: the PHP compiling template engine
 * File:    SmartyBC.class.php
 * SVN:     $Id: $
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * For questions, help, comments, discussion, etc., please join the
 * Smarty mailing list. Send a blank e-mail to
 * smarty-discussion-subscribe@googlegroups.com
 *
 * @link   http://www.smarty.net/
 * @copyright 2008 New Digital Group, Inc.
 * @author  Monte Ohrt <monte at ohrt dot com>
 * @author  Uwe Tews
 * @author  Rodney Rehm
 * @package  Smarty
 */
/**
 * @ignore
 */
require_once(dirname(__FILE__) . '/Smarty.class.php');
/**
 * Smarty Backward Compatability Wrapper Class
 *
 * @package Smarty
 */
class SmartyBC extends Smarty
{
  /**
   * Smarty 2 BC
   *
   * @var string
   */
  public $_version = self::SMARTY_VERSION;
  /**
   * Initialize new SmartyBC object
   *
   * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
   */
  public function __construct(array $options = array())
  {
    parent::__construct($options);
    // register {php} tag
    $this->registerPlugin('block', 'php', 'smarty_php_tag');
  }
  /**
   * wrapper for assign_by_ref
   *
   * @param string $tpl_var the template variable name
   * @param mixed &$value the referenced value to assign
   */
  public function assign_by_ref($tpl_var, &$value)
  {
    $this->assignByRef($tpl_var, $value);
  }
  /**
   * wrapper for append_by_ref
   *
   * @param string $tpl_var the template variable name
   * @param mixed  &$value the referenced value to append
   * @param boolean $merge  flag if array elements shall be merged
   */
  public function append_by_ref($tpl_var, &$value, $merge = false)
  {
    $this->appendByRef($tpl_var, $value, $merge);
  }
  /**
   * clear the given assigned template variable.
   *
   * @param string $tpl_var the template variable to clear
   */
  public function clear_assign($tpl_var)
  {
    $this->clearAssign($tpl_var);
  }
  /**
   * Registers custom function to be used in templates
   *
   * @param string $function   the name of the template function
   * @param string $function_impl the name of the PHP function to register
   * @param bool  $cacheable
   * @param mixed $cache_attrs
   */
  public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
  {
    $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
  }
  /**
   * Unregisters custom function
   *
   * @param string $function name of template function
   */
  public function unregister_function($function)
  {
    $this->unregisterPlugin('function', $function);
  }
  /**
   * Registers object to be used in templates
   *
   * @param string $object   name of template object
   * @param object $object_impl the referenced PHP object to register
   * @param array  $allowed   list of allowed methods (empty = all)
   * @param boolean $smarty_args smarty argument format, else traditional
   * @param array  $block_methods list of methods that are block format
   *
   * @throws SmartyException
   * @internal param array $block_functs list of methods that are block format
   */
  public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
  {
    settype($allowed, 'array');
    settype($smarty_args, 'boolean');
    $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
  }
  /**
   * Unregisters object
   *
   * @param string $object name of template object
   */
  public function unregister_object($object)
  {
    $this->unregisterObject($object);
  }
  /**
   * Registers block function to be used in templates
   *
   * @param string $block   name of template block
   * @param string $block_impl PHP function to register
   * @param bool  $cacheable
   * @param mixed $cache_attrs
   */
  public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
  {
    $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
  }
  /**
   * Unregisters block function
   *
   * @param string $block name of template function
   */
  public function unregister_block($block)
  {
    $this->unregisterPlugin('block', $block);
  }
  /**
   * Registers compiler function
   *
   * @param string $function   name of template function
   * @param string $function_impl name of PHP function to register
   * @param bool  $cacheable
   */
  public function register_compiler_function($function, $function_impl, $cacheable = true)
  {
    $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
  }
  /**
   * Unregisters compiler function
   *
   * @param string $function name of template function
   */
  public function unregister_compiler_function($function)
  {
    $this->unregisterPlugin('compiler', $function);
  }
  /**
   * Registers modifier to be used in templates
   *
   * @param string $modifier   name of template modifier
   * @param string $modifier_impl name of PHP function to register
   */
  public function register_modifier($modifier, $modifier_impl)
  {
    $this->registerPlugin('modifier', $modifier, $modifier_impl);
  }
  /**
   * Unregisters modifier
   *
   * @param string $modifier name of template modifier
   */
  public function unregister_modifier($modifier)
  {
    $this->unregisterPlugin('modifier', $modifier);
  }
  /**
   * Registers a resource to fetch a template
   *
   * @param string $type   name of resource
   * @param array $functions array of functions to handle resource
   */
  public function register_resource($type, $functions)
  {
    $this->registerResource($type, $functions);
  }
  /**
   * Unregisters a resource
   *
   * @param string $type name of resource
   */
  public function unregister_resource($type)
  {
    $this->unregisterResource($type);
  }
  /**
   * Registers a prefilter function to apply
   * to a template before compiling
   *
   * @param callable $function
   */
  public function register_prefilter($function)
  {
    $this->registerFilter('pre', $function);
  }
  /**
   * Unregisters a prefilter function
   *
   * @param callable $function
   */
  public function unregister_prefilter($function)
  {
    $this->unregisterFilter('pre', $function);
  }
  /**
   * Registers a postfilter function to apply
   * to a compiled template after compilation
   *
   * @param callable $function
   */
  public function register_postfilter($function)
  {
    $this->registerFilter('post', $function);
  }
  /**
   * Unregisters a postfilter function
   *
   * @param callable $function
   */
  public function unregister_postfilter($function)
  {
    $this->unregisterFilter('post', $function);
  }
  /**
   * Registers an output filter function to apply
   * to a template output
   *
   * @param callable $function
   */
  public function register_outputfilter($function)
  {
    $this->registerFilter('output', $function);
  }
  /**
   * Unregisters an outputfilter function
   *
   * @param callable $function
   */
  public function unregister_outputfilter($function)
  {
    $this->unregisterFilter('output', $function);
  }
  /**
   * load a filter of specified type and name
   *
   * @param string $type filter type
   * @param string $name filter name
   */
  public function load_filter($type, $name)
  {
    $this->loadFilter($type, $name);
  }
  /**
   * clear cached content for the given template and cache id
   *
   * @param string $tpl_file  name of template file
   * @param string $cache_id  name of cache_id
   * @param string $compile_id name of compile_id
   * @param string $exp_time  expiration time
   *
   * @return boolean
   */
  public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
  {
    return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
  }
  /**
   * clear the entire contents of cache (all templates)
   *
   * @param string $exp_time expire time
   *
   * @return boolean
   */
  public function clear_all_cache($exp_time = null)
  {
    return $this->clearCache(null, null, null, $exp_time);
  }
  /**
   * test to see if valid cache exists for this template
   *
   * @param string $tpl_file name of template file
   * @param string $cache_id
   * @param string $compile_id
   *
   * @return boolean
   */
  public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
  {
    return $this->isCached($tpl_file, $cache_id, $compile_id);
  }
  /**
   * clear all the assigned template variables.
   */
  public function clear_all_assign()
  {
    $this->clearAllAssign();
  }
  /**
   * clears compiled version of specified template resource,
   * or all compiled template files if one is not specified.
   * This function is for advanced use only, not normally needed.
   *
   * @param string $tpl_file
   * @param string $compile_id
   * @param string $exp_time
   *
   * @return boolean results of {@link smarty_core_rm_auto()}
   */
  public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
  {
    return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
  }
  /**
   * Checks whether requested template exists.
   *
   * @param string $tpl_file
   *
   * @return boolean
   */
  public function template_exists($tpl_file)
  {
    return $this->templateExists($tpl_file);
  }
  /**
   * Returns an array containing template variables
   *
   * @param string $name
   *
   * @return array
   */
  public function get_template_vars($name = null)
  {
    return $this->getTemplateVars($name);
  }
  /**
   * Returns an array containing config variables
   *
   * @param string $name
   *
   * @return array
   */
  public function get_config_vars($name = null)
  {
    return $this->getConfigVars($name);
  }
  /**
   * load configuration values
   *
   * @param string $file
   * @param string $section
   * @param string $scope
   */
  public function config_load($file, $section = null, $scope = 'global')
  {
    $this->ConfigLoad($file, $section, $scope);
  }
  /**
   * return a reference to a registered object
   *
   * @param string $name
   *
   * @return object
   */
  public function get_registered_object($name)
  {
    return $this->getRegisteredObject($name);
  }
  /**
   * clear configuration values
   *
   * @param string $var
   */
  public function clear_config($var = null)
  {
    $this->clearConfig($var);
  }
  /**
   * trigger Smarty error
   *
   * @param string $error_msg
   * @param integer $error_type
   */
  public function trigger_error($error_msg, $error_type = E_USER_WARNING)
  {
    trigger_error("Smarty error: $error_msg", $error_type);
  }
}
/**
 * Smarty {php}{/php} block function
 *
 * @param array  $params  parameter list
 * @param string $content contents of the block
 * @param object $template template object
 * @param boolean &$repeat repeat flag
 *
 * @return string content re-formatted
 */
function smarty_php_tag($params, $content, $template, &$repeat)
{
  eval($content);
  return '';
}

更多關(guān)于Smarty相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《smarty模板入門基礎(chǔ)教程》、《PHP模板技術(shù)總結(jié)》、《PHP基于pdo操作數(shù)據(jù)庫(kù)技巧總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于smarty模板的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • php實(shí)現(xiàn)讀取內(nèi)存順序號(hào)

    php實(shí)現(xiàn)讀取內(nèi)存順序號(hào)

    這篇文章主要介紹了php實(shí)現(xiàn)讀取內(nèi)存順序號(hào),十分的簡(jiǎn)單實(shí)用,需要的朋友可以參考下
    2015-03-03
  • Laravel的throttle中間件失效問(wèn)題解決方法

    Laravel的throttle中間件失效問(wèn)題解決方法

    這篇文章主要介紹了Laravel的throttle中間件失效問(wèn)題解決方法,簡(jiǎn)單分析了throttle中間件失效問(wèn)題的原因并提出了解決方案,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-10-10
  • 雙冒號(hào) ::在PHP中的使用情況

    雙冒號(hào) ::在PHP中的使用情況

    前幾天在百度知道里面看到有人問(wèn)PHP中雙冒號(hào)::的用法,當(dāng)時(shí)給他的回答比較簡(jiǎn)潔因?yàn)槭謾C(jī)打字不大方便!今天突然想起來(lái),所以在這里總結(jié)一下我遇到的雙冒號(hào)::在PHP中使用的情況
    2015-11-11
  • thinkphp獲取欄目和文章當(dāng)前位置的方法

    thinkphp獲取欄目和文章當(dāng)前位置的方法

    這篇文章主要介紹了thinkphp獲取欄目和文章當(dāng)前位置的方法,通過(guò)一個(gè)自定義的遞歸函數(shù)讀取目錄來(lái)實(shí)現(xiàn)獲取欄目和文章當(dāng)前位置,是非常實(shí)用的技巧,需要的朋友可以參考下
    2014-10-10
  • Thinkphp 框架配置操作之配置加載與讀取配置實(shí)例分析

    Thinkphp 框架配置操作之配置加載與讀取配置實(shí)例分析

    這篇文章主要介紹了Thinkphp 框架配置操作之配置加載與讀取配置,結(jié)合實(shí)例形式分析了Thinkphp 框架配置操作中配置加載原理、操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2020-05-05
  • laravel框架實(shí)現(xiàn)為 Blade 模板引擎添加新文件擴(kuò)展名操作示例

    laravel框架實(shí)現(xiàn)為 Blade 模板引擎添加新文件擴(kuò)展名操作示例

    這篇文章主要介紹了laravel框架實(shí)現(xiàn)為 Blade 模板引擎添加新文件擴(kuò)展名操作,結(jié)合實(shí)例形式詳細(xì)分析了laravel框架Blade 模板引擎添加新文件擴(kuò)展名具體操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2020-01-01
  • php基礎(chǔ)設(shè)計(jì)模式大全(注冊(cè)樹(shù)模式、工廠模式、單列模式)

    php基礎(chǔ)設(shè)計(jì)模式大全(注冊(cè)樹(shù)模式、工廠模式、單列模式)

    在所有模式設(shè)計(jì)中,有三種基礎(chǔ)設(shè)計(jì)模式,單例模式,工廠模式,注冊(cè)樹(shù)模式,其他模式往往基于這幾種模式,接下來(lái)跟著小編一起來(lái)學(xué)習(xí)php基礎(chǔ)設(shè)計(jì)模式(注冊(cè)樹(shù)模式、工廠模式、單列模式),需要的朋友快來(lái)學(xué)習(xí)吧。
    2015-08-08
  • php array_reverse 以相反的順序返回?cái)?shù)組實(shí)例代碼

    php array_reverse 以相反的順序返回?cái)?shù)組實(shí)例代碼

    本篇文章主要介紹了php array_reverse 以相反的順序返回?cái)?shù)組實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-04-04
  • PHP面向?qū)ο笾ぷ鲉卧?實(shí)例講解)

    PHP面向?qū)ο笾ぷ鲉卧?實(shí)例講解)

    下面小編就為大家?guī)?lái)一篇PHP面向?qū)ο笾ぷ鲉卧?實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • PHP代碼實(shí)現(xiàn)爬蟲記錄——超管用

    PHP代碼實(shí)現(xiàn)爬蟲記錄——超管用

    這篇文章主要通過(guò)創(chuàng)建crawler數(shù)據(jù)庫(kù),使用robot.php記錄來(lái)訪的爬蟲信息從而將信息插入數(shù)據(jù)庫(kù),從而使用php代碼實(shí)現(xiàn)爬蟲記錄,有需要的小伙可以來(lái)參考下。
    2015-07-07

最新評(píng)論