mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- bugfix remove special treatment of classes implementing ArrayAccess in {foreach}
https://github.com/smarty-php/smarty/issues/332
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
===== 3.1.32 - dev ===
|
===== 3.1.32 - dev ===
|
||||||
|
21.5.2017
|
||||||
|
- bugfix remove special treatment of classes implementing ArrayAccess in {foreach}
|
||||||
|
https://github.com/smarty-php/smarty/issues/332
|
||||||
|
|
||||||
19.5.2017
|
19.5.2017
|
||||||
- change properties $accessMap and $obsoleteProperties from private to protected
|
- change properties $accessMap and $obsoleteProperties from private to protected
|
||||||
https://github.com/smarty-php/smarty/issues/351
|
https://github.com/smarty-php/smarty/issues/351
|
||||||
|
@@ -108,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.32-dev-3';
|
const SMARTY_VERSION = '3.1.32-dev-5';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -50,7 +50,8 @@ class Smarty_Internal_Runtime_Foreach
|
|||||||
$total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1);
|
$total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1);
|
||||||
}
|
}
|
||||||
if (isset($tpl->tpl_vars[ $item ])) {
|
if (isset($tpl->tpl_vars[ $item ])) {
|
||||||
$saveVars[ 'item' ] = array($item, $tpl->tpl_vars[ $item ]);
|
$saveVars[ 'item' ] = array($item,
|
||||||
|
$tpl->tpl_vars[ $item ]);
|
||||||
}
|
}
|
||||||
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||||
if ($total === 0) {
|
if ($total === 0) {
|
||||||
@@ -58,7 +59,8 @@ class Smarty_Internal_Runtime_Foreach
|
|||||||
} else {
|
} else {
|
||||||
if ($key) {
|
if ($key) {
|
||||||
if (isset($tpl->tpl_vars[ $key ])) {
|
if (isset($tpl->tpl_vars[ $key ])) {
|
||||||
$saveVars[ 'key' ] = array($key, $tpl->tpl_vars[ $key ]);
|
$saveVars[ 'key' ] = array($key,
|
||||||
|
$tpl->tpl_vars[ $key ]);
|
||||||
}
|
}
|
||||||
$tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
$tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||||
}
|
}
|
||||||
@@ -69,7 +71,8 @@ class Smarty_Internal_Runtime_Foreach
|
|||||||
if ($name) {
|
if ($name) {
|
||||||
$namedVar = "__smarty_foreach_{$name}";
|
$namedVar = "__smarty_foreach_{$name}";
|
||||||
if (isset($tpl->tpl_vars[ $namedVar ])) {
|
if (isset($tpl->tpl_vars[ $namedVar ])) {
|
||||||
$saveVars[ 'named' ] = array($namedVar, $tpl->tpl_vars[ $namedVar ]);
|
$saveVars[ 'named' ] = array($namedVar,
|
||||||
|
$tpl->tpl_vars[ $namedVar ]);
|
||||||
}
|
}
|
||||||
$namedProp = array();
|
$namedProp = array();
|
||||||
if (isset($properties[ 'total' ])) {
|
if (isset($properties[ 'total' ])) {
|
||||||
@@ -90,6 +93,33 @@ class Smarty_Internal_Runtime_Foreach
|
|||||||
return $from;
|
return $from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
|
||||||
|
* for empty elements
|
||||||
|
*/
|
||||||
|
public function count($value)
|
||||||
|
{
|
||||||
|
if ($value instanceof IteratorAggregate) {
|
||||||
|
// Note: getIterator() returns a Traversable, not an Iterator
|
||||||
|
// thus rewind() and valid() methods may not be present
|
||||||
|
return iterator_count($value->getIterator());
|
||||||
|
} elseif ($value instanceof Iterator) {
|
||||||
|
return $value instanceof Generator ? 1 : iterator_count($value);
|
||||||
|
} elseif ($value instanceof Countable) {
|
||||||
|
return count($value);
|
||||||
|
} elseif ($value instanceof PDOStatement) {
|
||||||
|
return $value->rowCount();
|
||||||
|
} elseif ($value instanceof Traversable) {
|
||||||
|
return iterator_count($value);
|
||||||
|
}
|
||||||
|
return count((array) $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore saved variables
|
* Restore saved variables
|
||||||
*
|
*
|
||||||
@@ -114,36 +144,8 @@ class Smarty_Internal_Runtime_Foreach
|
|||||||
$tpl->tpl_vars[ $saveVars[ 'named' ][ 0 ] ] = $saveVars[ 'named' ][ 1 ];
|
$tpl->tpl_vars[ $saveVars[ 'named' ][ 0 ] ] = $saveVars[ 'named' ][ 1 ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$levels--;
|
$levels --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*
|
|
||||||
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
|
|
||||||
* for empty elements
|
|
||||||
*/
|
|
||||||
public function count($value)
|
|
||||||
{
|
|
||||||
if ($value instanceof Countable) {
|
|
||||||
return count($value);
|
|
||||||
} elseif ($value instanceof IteratorAggregate) {
|
|
||||||
// Note: getIterator() returns a Traversable, not an Iterator
|
|
||||||
// thus rewind() and valid() methods may not be present
|
|
||||||
return iterator_count($value->getIterator());
|
|
||||||
} elseif ($value instanceof Iterator) {
|
|
||||||
return $value instanceof Generator ? 1 : iterator_count($value);
|
|
||||||
} elseif ($value instanceof PDOStatement) {
|
|
||||||
return $value->rowCount();
|
|
||||||
} elseif ($value instanceof Traversable) {
|
|
||||||
return iterator_count($value);
|
|
||||||
} elseif ($value instanceof ArrayAccess) {
|
|
||||||
return $value->offsetExists(0) ? 1 : 0;
|
|
||||||
}
|
|
||||||
return count((array) $value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user