mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 19:36:43 +00:00
Updates slice so that it still accepts a SimpleXMLElement
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user