Smarty::enableSecurity PHP Method

enableSecurity() public method

Loads security class and enables security
public enableSecurity ( string | Smarty_Security $security_class = null ) : Smarty
$security_class string | Smarty_Security if a string is used, it must be class-name
return Smarty current Smarty instance for chaining
    public function enableSecurity($security_class = null)
    {
        if ($security_class instanceof Smarty_Security) {
            $this->security_policy = $security_class;
            return $this;
        } elseif (is_object($security_class)) {
            throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
        }
        if ($security_class == null) {
            $security_class = $this->security_class;
        }
        if (!class_exists($security_class)) {
            throw new SmartyException("Security class '{$security_class}' is not defined");
        } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
            throw new SmartyException("Class '{$security_class}' must extend Smarty_Security.");
        } else {
            $this->security_policy = new $security_class($this);
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * 构造方法
  *
  * @return void
  */
 protected function __construct()
 {
     \Yaf_Loader::import(APP_PATH . 'library/Thirdpart/Smarty/libs/Smarty.class.php');
     $this->_smarty = new \Smarty();
     $this->_smarty->setTemplateDir('');
     $this->_smarty->setCompileDir(TMP_PATH . 'smarty-compile/');
     $this->_smarty->setCacheDir(TMP_PATH . 'smarty-cache/');
     $this->_smarty->setPluginsDir(APP_PATH . 'library/Smarty/Plugins/');
     $this->_smarty->left_delimiter = '<!--{';
     $this->_smarty->right_delimiter = '}-->';
     $this->_smarty->enableSecurity('Comm\\Smarty_Security_Policy');
 }
All Usage Examples Of Smarty::enableSecurity