欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php封装的smartyBC类完整实例

程序员文章站 2024-04-02 11:48:34
本文实例讲述了php封装的smartybc类。分享给大家供大家参考,具体如下:

本文实例讲述了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 '';
}

更多关于smarty相关内容感兴趣的读者可查看本站专题:《smarty模板入门基础教程》、《php模板技术总结》、《php基于pdo操作数据库技巧总结》、《php运算与运算符用法总结》、《php网络编程技巧总结》、《php基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家基于smarty模板的php程序设计有所帮助。