mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
fix batch filter with zero items
also added a test for preserving keys behavior
This commit is contained in:
@@ -1488,7 +1488,7 @@ function twig_array_batch($items, $size, $fill = null)
|
|||||||
|
|
||||||
$result = array_chunk($items, $size, true);
|
$result = array_chunk($items, $size, true);
|
||||||
|
|
||||||
if (null !== $fill) {
|
if (null !== $fill && !empty($result)) {
|
||||||
$last = count($result) - 1;
|
$last = count($result) - 1;
|
||||||
if ($fillCount = $size - count($result[$last])) {
|
if ($fillCount = $size - count($result[$last])) {
|
||||||
$result[$last] = array_merge(
|
$result[$last] = array_merge(
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
--TEST--
|
||||||
|
"batch" filter preserves array keys
|
||||||
|
--TEMPLATE--
|
||||||
|
{{ {'foo': 'bar', 'key': 'value'}|batch(4)|first|keys|join(',') }}
|
||||||
|
{{ {'foo': 'bar', 'key': 'value'}|batch(4, 'fill')|first|keys|join(',') }}
|
||||||
|
--DATA--
|
||||||
|
return array()
|
||||||
|
--EXPECT--
|
||||||
|
foo,key
|
||||||
|
foo,key,0,1
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
--TEST--
|
||||||
|
"batch" filter with zero elements
|
||||||
|
--TEMPLATE--
|
||||||
|
{{ []|batch(3)|length }}
|
||||||
|
{{ []|batch(3, 'fill')|length }}
|
||||||
|
--DATA--
|
||||||
|
return array()
|
||||||
|
--EXPECT--
|
||||||
|
0
|
||||||
|
0
|
||||||
Reference in New Issue
Block a user