From 111a10bb178bfb8b1583297c9425883f66b5e1bc Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Sun, 4 Jan 2015 05:51:52 +0100 Subject: [PATCH] Move some classes into its own files --- libs/Autoloader.php | 7 +- libs/sysplugins/smarty_data.php | 66 ++++++++ libs/sysplugins/smarty_internal_data.php | 152 +----------------- libs/sysplugins/smarty_undefined_variable.php | 37 +++++ libs/sysplugins/smarty_variable.php | 55 +++++++ 5 files changed, 166 insertions(+), 151 deletions(-) create mode 100644 libs/sysplugins/smarty_data.php create mode 100644 libs/sysplugins/smarty_undefined_variable.php create mode 100644 libs/sysplugins/smarty_variable.php diff --git a/libs/Autoloader.php b/libs/Autoloader.php index dd47dba9..ad09ec29 100644 --- a/libs/Autoloader.php +++ b/libs/Autoloader.php @@ -60,6 +60,9 @@ class Smarty_Autoloader 'smarty_template_source' => true, 'smarty_template_compiled' => true, 'smarty_template_cached' => true, + 'smarty_data' => true, + 'smarty_variable' => true, + 'smarty_undefined_variable' => true, 'smartyexception' => true, 'smartycompilerexception' => true, ); @@ -123,8 +126,8 @@ class Smarty_Autoloader } elseif (0 !== strpos($_class, 'smarty_internal_')) { if (isset(self::$rootClasses[$class])) { $file = self::$SMARTY_DIR . self::$rootClasses[$class]; - require $file; - return; + require $file; + return; } self::$unknown[$class] = true; return; diff --git a/libs/sysplugins/smarty_data.php b/libs/sysplugins/smarty_data.php new file mode 100644 index 00000000..7ea810c2 --- /dev/null +++ b/libs/sysplugins/smarty_data.php @@ -0,0 +1,66 @@ +dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); + $this->smarty = $smarty; + if (is_object($_parent)) { + // when object set up back pointer + $this->parent = $_parent; + } elseif (is_array($_parent)) { + // set up variable values + foreach ($_parent as $_key => $_val) { + $this->tpl_vars[$_key] = new Smarty_variable($_val); + } + } elseif ($_parent != null) { + throw new SmartyException("Wrong type for template variables"); + } + } +} diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index df40f353..d954157e 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -127,7 +127,7 @@ class Smarty_Internal_Data if ($_key != '') { if (!isset($this->tpl_vars[$_key])) { $tpl_var_inst = $this->getVariable($_key, null, true, false); - if ($tpl_var_inst instanceof Undefined_Smarty_Variable) { + if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { $this->tpl_vars[$_key] = new Smarty_variable(null, $nocache); } else { $this->tpl_vars[$_key] = clone $tpl_var_inst; @@ -149,7 +149,7 @@ class Smarty_Internal_Data if ($tpl_var != '' && isset($value)) { if (!isset($this->tpl_vars[$tpl_var])) { $tpl_var_inst = $this->getVariable($tpl_var, null, true, false); - if ($tpl_var_inst instanceof Undefined_Smarty_Variable) { + if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { $this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache); } else { $this->tpl_vars[$tpl_var] = clone $tpl_var_inst; @@ -332,7 +332,7 @@ class Smarty_Internal_Data $x = $$variable; } - return new Undefined_Smarty_Variable; + return new Smarty_Undefined_Variable; } /** @@ -401,149 +401,3 @@ class Smarty_Internal_Data } } } - -/** - * class for the Smarty data object - * The Smarty data object will hold Smarty variables in the current scope - * - * @package Smarty - * @subpackage Template - */ -class Smarty_Data extends Smarty_Internal_Data -{ - /** - * Counter - * - * @var int - */ - static $count = 0; - - /** - * Data block name - * - * @var string - */ - public $dataObjectName = ''; - /** - * Smarty object - * - * @var Smarty - */ - public $smarty = null; - - /** - * create Smarty data object - * - * @param Smarty|array $_parent parent template - * @param Smarty|Smarty_Internal_Template $smarty global smarty instance - * @param string $name optional data block name - * - * @throws SmartyException - */ - public function __construct($_parent = null, $smarty = null, $name = null) - { - self::$count ++; - $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); - $this->smarty = $smarty; - if (is_object($_parent)) { - // when object set up back pointer - $this->parent = $_parent; - } elseif (is_array($_parent)) { - // set up variable values - foreach ($_parent as $_key => $_val) { - $this->tpl_vars[$_key] = new Smarty_variable($_val); - } - } elseif ($_parent != null) { - throw new SmartyException("Wrong type for template variables"); - } - } -} - -/** - * class for the Smarty variable object - * This class defines the Smarty variable object - * - * @package Smarty - * @subpackage Template - */ -class Smarty_Variable -{ - /** - * template variable - * - * @var mixed - */ - public $value = null; - /** - * if true any output of this variable will be not cached - * - * @var boolean - */ - public $nocache = false; - /** - * the scope the variable will have (local,parent or root) - * - * @var int - */ - public $scope = Smarty::SCOPE_LOCAL; - - /** - * create Smarty variable object - * - * @param mixed $value the value to assign - * @param boolean $nocache if true any output of this variable will be not cached - * @param int $scope the scope the variable will have (local,parent or root) - */ - public function __construct($value = null, $nocache = false, $scope = Smarty::SCOPE_LOCAL) - { - $this->value = $value; - $this->nocache = $nocache; - $this->scope = $scope; - } - - /** - * <> String conversion - * - * @return string - */ - public function __toString() - { - return (string) $this->value; - } -} - -/** - * class for undefined variable object - * This class defines an object for undefined variable handling - * - * @package Smarty - * @subpackage Template - */ -class Undefined_Smarty_Variable -{ - /** - * Returns FALSE for 'nocache' and NULL otherwise. - * - * @param string $name - * - * @return bool - */ - public function __get($name) - { - if ($name == 'nocache') { - return false; - } else { - return null; - } - } - - /** - * Always returns an empty string. - * - * @return string - */ - public function __toString() - { - return ""; - } -} diff --git a/libs/sysplugins/smarty_undefined_variable.php b/libs/sysplugins/smarty_undefined_variable.php new file mode 100644 index 00000000..88bc6f68 --- /dev/null +++ b/libs/sysplugins/smarty_undefined_variable.php @@ -0,0 +1,37 @@ +value = $value; + $this->nocache = $nocache; + $this->scope = $scope; + } + + /** + * <> String conversion + * + * @return string + */ + public function __toString() + { + return (string) $this->value; + } +} +