mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 05:16:30 +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();
|
$item = $item->getIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($start >= 0 && $length >= 0) {
|
if ($start >= 0 && $length >= 0 && $item instanceof Iterator) {
|
||||||
try {
|
try {
|
||||||
return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys);
|
return iterator_to_array(new LimitIterator($item, $start, $length === null ? -1 : $length), $preserveKeys);
|
||||||
} catch (OutOfBoundsException $exception) {
|
} catch (OutOfBoundsException $exception) {
|
||||||
|
|||||||
@@ -24,8 +24,9 @@
|
|||||||
|
|
||||||
{{ arr|slice(3)|join('') }}
|
{{ arr|slice(3)|join('') }}
|
||||||
{{ arr[2:]|join('') }}
|
{{ arr[2:]|join('') }}
|
||||||
|
{{ xml|slice(1)|join('')}}
|
||||||
--DATA--
|
--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--
|
--EXPECT--
|
||||||
23
|
23
|
||||||
23
|
23
|
||||||
@@ -49,4 +50,5 @@ bc
|
|||||||
1
|
1
|
||||||
|
|
||||||
4
|
4
|
||||||
34
|
34
|
||||||
|
2
|
||||||
|
|||||||
Reference in New Issue
Block a user