- bugfix error handling at stream resources

This commit is contained in:
uwe.tews@googlemail.com
2011-05-14 11:11:52 +00:00
parent 86586e5af4
commit 7c0e3c89c1
3 changed files with 110 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
===== SVN trunk =====
14/05/2011
- bugfix fopen() error handling at stream resources
- bugfix error handling at stream resources
13/05/2011
- bugfix condition starting with "-" did fail at {if} and {while} tags

View File

@@ -2,12 +2,12 @@
/**
* Smarty Internal Plugin Data
*
*
* This file contains the basic classes and methodes for template and variable creation
*
*
* @package Smarty
* @subpackage Templates
* @author Uwe Tews
* @author Uwe Tews
*/
/**
@@ -19,7 +19,7 @@ class Smarty_Internal_Data {
/**
* assigns a Smarty variable
*
*
* @param array $ |string $tpl_var the template variable name(s)
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
@@ -31,17 +31,17 @@ class Smarty_Internal_Data {
foreach ($tpl_var as $_key => $_val) {
if ($_key != '') {
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);
}
}
}
}
} else {
if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);
}
}
}
}
}
}
/**
* assigns a global Smarty variable
*
*
* @param string $varname the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
@@ -50,11 +50,11 @@ class Smarty_Internal_Data {
{
if ($varname != '') {
Smarty::$global_tpl_vars[$varname] = new Smarty_variable($value, $nocache);
}
}
}
}
/**
* assigns values to template variables by reference
*
*
* @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign
* @param boolean $nocache if true any output of this variable will be not cached
@@ -64,12 +64,12 @@ class Smarty_Internal_Data {
if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
$this->tpl_vars[$tpl_var]->value = &$value;
}
}
}
}
/**
* wrapper function for Smarty 2 BC
*
*
* @param string $tpl_var the template variable name
* @param mixed $ &$value the referenced value to assign
*/
@@ -78,10 +78,10 @@ class Smarty_Internal_Data {
if($this->smarty->deprecation_notices)
trigger_error("function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef'", E_USER_NOTICE);
$this->assignByRef($tpl_var, $value);
}
}
/**
* appends values to template variables
*
*
* @param array $ |string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged
@@ -99,20 +99,20 @@ class Smarty_Internal_Data {
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache);
} else {
$this->tpl_vars[$_key] = clone $tpl_var_inst;
}
}
}
}
if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$_key]->value, 'array');
}
}
if ($merge && is_array($_val)) {
foreach($_val as $_mkey => $_mval) {
$this->tpl_vars[$_key]->value[$_mkey] = $_mval;
}
}
} else {
$this->tpl_vars[$_key]->value[] = $_val;
}
}
}
}
}
}
} else {
if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) {
@@ -121,25 +121,25 @@ class Smarty_Internal_Data {
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache);
} else {
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
}
}
}
}
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$tpl_var]->value, 'array');
}
}
if ($merge && is_array($value)) {
foreach($value as $_mkey => $_mval) {
$this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
}
}
} else {
$this->tpl_vars[$tpl_var]->value[] = $value;
}
}
}
}
}
}
}
}
/**
* appends values to template variables by reference
*
*
* @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
@@ -149,22 +149,22 @@ class Smarty_Internal_Data {
if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) {
$this->tpl_vars[$tpl_var] = new Smarty_variable();
}
}
if (!@is_array($this->tpl_vars[$tpl_var]->value)) {
settype($this->tpl_vars[$tpl_var]->value, 'array');
}
}
if ($merge && is_array($value)) {
foreach($value as $_key => $_val) {
$this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
}
}
} else {
$this->tpl_vars[$tpl_var]->value[] = &$value;
}
}
}
}
}
}
/**
*
*
* @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
@@ -174,10 +174,10 @@ class Smarty_Internal_Data {
if($this->smarty->deprecation_notices)
trigger_error("function call 'append_by_ref' is unknown or deprecated, use 'appendByRef'", E_USER_NOTICE);
$this->appendByRef($tpl_var, $value, $merge);
}
}
/**
* Returns a single or all template variables
*
*
* @param string $varname variable name or null
* @return string variable value or or array of variables
*/
@@ -189,7 +189,7 @@ class Smarty_Internal_Data {
return $_var->value;
} else {
return null;
}
}
} else {
$_result = array();
if ($_ptr === null) {
@@ -199,28 +199,28 @@ class Smarty_Internal_Data {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
}
}
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
foreach (Smarty::$global_tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
}
}
}
return $_result;
}
}
}
}
/**
* clear the given assigned template variable.
*
*
* @param string $ |array $tpl_var the template variable(s) to clear
*/
public function clearAssign($tpl_var)
@@ -228,11 +228,11 @@ class Smarty_Internal_Data {
if (is_array($tpl_var)) {
foreach ($tpl_var as $curr_var) {
unset($this->tpl_vars[$curr_var]);
}
}
} else {
unset($this->tpl_vars[$tpl_var]);
}
}
}
}
/**
* clear all the assigned template variables.
@@ -240,24 +240,24 @@ class Smarty_Internal_Data {
public function clearAllAssign()
{
$this->tpl_vars = array();
}
}
/**
* load a config file, optionally load just selected sections
*
*
* @param string $config_file filename
* @param mixed $sections array of section names, single section or null
*/
public function configLoad($config_file, $sections = null)
{
{
// load Config class
$config = new Smarty_Internal_Config($config_file, $this->smarty, $this);
$config->loadConfigVars($sections);
}
}
/**
* gets the object of a Smarty variable
*
*
* @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data
@@ -271,18 +271,18 @@ class Smarty_Internal_Data {
if (isset($_ptr->tpl_vars[$_variable])) {
// found it, return it
return $_ptr->tpl_vars[$_variable];
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
}
}
if (isset(Smarty::$global_tpl_vars[$_variable])) {
// found it, return it
return Smarty::$global_tpl_vars[$_variable];
}
}
if ($this->smarty->error_unassigned && $error_enable) {
throw new SmartyException('Undefined Smarty variable "' . $_variable . '"');
} else {
@@ -291,11 +291,11 @@ class Smarty_Internal_Data {
$x = $$_variable;
}
return new Undefined_Smarty_Variable;
}
}
}
}
/**
* gets a config variable
*
*
* @param string $variable the name of the config variable
* @return mixed the value of the config variable
*/
@@ -306,22 +306,22 @@ class Smarty_Internal_Data {
if (isset($_ptr->config_vars[$_variable])) {
// found it, return it
return $_ptr->config_vars[$_variable];
}
}
// not found, try at parent
$_ptr = $_ptr->parent;
}
}
if ($this->smarty->error_unassigned) {
throw new SmartyException('Undefined config variable "' . $_variable . '"');
} else {
// force a notice
$x = $$_variable;
return null;
}
}
}
}
/**
* gets a stream variable
*
*
* @param string $variable the stream of the variable
* @return mixed the value of the stream variable
*/
@@ -329,23 +329,23 @@ class Smarty_Internal_Data {
{
$_result = '';
if ($fp = fopen($variable, 'r+')) {
while (!feof($fp)) {
$_result .= fgets($fp);
}
while (!feof($fp) && ($current_line = fgets($fp)) !== false ) {
$_result .= $current_line;
}
fclose($fp);
return $_result;
}
}
if ($this->smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else {
return null;
}
}
}
}
/**
* Returns a single or all config variables
*
*
* @param string $varname variable name or null
* @return string variable value or or array of variables
*/
@@ -361,24 +361,24 @@ class Smarty_Internal_Data {
}
} else {
$var_array = array_merge($_ptr->config_vars, $var_array);
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
}
}
if (isset($varname)) {
return '';
} else {
return $var_array;
}
}
}
}
/**
* Deassigns a single or all config variables
*
*
* @param string $varname variable name or null
*/
function clearConfig($varname = null)
@@ -389,25 +389,25 @@ class Smarty_Internal_Data {
} else {
$this->config_vars = array();
return;
}
}
}
}
}
}
/**
* class for the Smarty data object
*
*
* The Smarty data object will hold Smarty variables in the current scope
*
*
* @param object $parent tpl_vars next higher level of Smarty variables
*/
class Smarty_Data extends Smarty_Internal_Data {
// array of variable objects
public $tpl_vars = array();
public $tpl_vars = array();
// back pointer to parent object
public $parent = null;
public $parent = null;
// config vars
public $config_vars = array();
public $config_vars = array();
// Smarty object
public $smarty = null;
/**
@@ -423,15 +423,15 @@ class Smarty_Data extends Smarty_Internal_Data {
// 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
*/
class Smarty_Variable {
@@ -441,7 +441,7 @@ class Smarty_Variable {
public $scope;
/**
* 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 boolean $scope the scope the variable will have (local,parent or root)
@@ -451,17 +451,17 @@ class Smarty_Variable {
$this->value = $value;
$this->nocache = $nocache;
$this->scope = $scope;
}
}
public function __toString ()
{
return $this->value;
}
}
}
}
/**
* class for undefined variable object
*
*
* This class defines an object for undefined variable handling
*/
class Undefined_Smarty_Variable {
@@ -472,8 +472,8 @@ class Undefined_Smarty_Variable {
return false;
} else {
return null;
}
}
}
}
}
}
?>

View File

@@ -75,8 +75,8 @@ class Smarty_Internal_Resource_Stream {
// return template string
$_template->template_source = '';
if ($fp = fopen(str_replace(':', '://', $_template->template_resource),'r+')) {
while (!feof($fp)) {
$_template->template_source .= fgets($fp);
while (!feof($fp) && ($current_line = fgets($fp)) !== false ) {
$_template->template_source .= $current_line;
}
fclose($fp);
return true;