Use LimitIterator on Iterable objects within the splice filter

This commit is contained in:
Anthony Sterling
2014-09-10 15:32:22 +01:00
parent 084ca201a7
commit fdddb1c91e
+10 -1
View File
@@ -692,7 +692,16 @@ function twig_array_merge($arr1, $arr2)
function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false)
{
if ($item instanceof Traversable) {
$item = iterator_to_array($item, false);
if ($item instanceof IteratorAggregate) {
$item = $item->getIterator();
}
if ($start >= 0 && $length >= 0) {
return iterator_to_array(new LimitIterator($item, $start, $length), $preserveKeys);
}
$item = iterator_to_array($item, $preserveKeys);
}
if (is_array($item)) {