Updates slice so that it still accepts a SimpleXMLElement

This commit is contained in:
Thomas Pomfret
2015-02-26 15:25:06 -05:00
parent fb8b04ef15
commit aea075b3a8
2 changed files with 5 additions and 3 deletions
+1 -1
View File
@@ -707,7 +707,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese
$item = $item->getIterator();
}
if ($start >= 0 && $length >= 0) {
if ($start >= 0 && $length >= 0 && $item instanceof Iterator) {
try {
return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys);
} catch (OutOfBoundsException $exception) {
+4 -2
View File
@@ -24,8 +24,9 @@
{{ arr|slice(3)|join('') }}
{{ arr[2:]|join('') }}
{{ xml|slice(1)|join('')}}
--DATA--
return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4)))
return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4)), 'xml' => new SimpleXMLElement('<items><item>1</item><item>2</item></items>'))
--EXPECT--
23
23
@@ -49,4 +50,5 @@ bc
1
4
34
34
2