diff options
author | plegall <plg@piwigo.org> | 2015-12-10 14:02:22 +0100 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2015-12-10 14:02:22 +0100 |
commit | fa10e0945ecd45bfe78a2c8fb015a43092b4944b (patch) | |
tree | 19cf59c08877e43325efbe9a2584114011a25522 /include/smarty/libs/sysplugins/smarty_internal_runtime_foreach.php | |
parent | 16f6a54fa719cc79ff942e4bb8139d7ca09ed997 (diff) |
bug #385 update to smarty-3.1.28-dev (from Github)
Diffstat (limited to 'include/smarty/libs/sysplugins/smarty_internal_runtime_foreach.php')
-rw-r--r-- | include/smarty/libs/sysplugins/smarty_internal_runtime_foreach.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/smarty/libs/sysplugins/smarty_internal_runtime_foreach.php b/include/smarty/libs/sysplugins/smarty_internal_runtime_foreach.php new file mode 100644 index 000000000..87bb0cf4a --- /dev/null +++ b/include/smarty/libs/sysplugins/smarty_internal_runtime_foreach.php @@ -0,0 +1,44 @@ +<?php + +/** + * Foreach Runtime Methods count + * + * @package Smarty + * @subpackage PluginsInternal + * @author Uwe Tews + * + **/ +class Smarty_Internal_Runtime_Foreach +{ + /** + * [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 (is_array($value) === true || $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 iterator_count($value); + } elseif ($value instanceof PDOStatement) { + return $value->rowCount(); + } elseif ($value instanceof Traversable) { + return iterator_count($value); + } elseif ($value instanceof ArrayAccess) { + if ($value->offsetExists(0)) { + return 1; + } + } elseif (is_object($value)) { + return count($value); + } + return 0; + } +} |