simplified code

This commit is contained in:
Fabien Potencier
2019-05-18 10:40:04 +02:00
parent f31aa2185b
commit 3ed9fae6fa
2 changed files with 9 additions and 31 deletions
+9 -21
View File
@@ -1686,30 +1686,18 @@ function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
return $result;
}
if (\PHP_VERSION_ID < 50500) {
function twig_array_filter($array, $arrow)
{
if (\is_array($array)) {
if (\PHP_VERSION_ID >= 50600) {
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
}
return array_filter($array, $arrow);
function twig_array_filter($array, $arrow)
{
if (\is_array($array)) {
if (\PHP_VERSION_ID >= 50600) {
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
}
while ($array instanceof \IteratorAggregate) {
$array = $array->getIterator();
}
// some internal PHP classes are \Traversable but do not implement \Iterator
if ($array instanceof \Iterator) {
return new \CallbackFilterIterator($array, $arrow);
}
throw new RuntimeException('The "filter" filter argument only supports objects implementing \Iterator; upgrade to PHP 5.5+.');
return array_filter($array, $arrow);
}
} else {
require_once __DIR__.'/twig_array_filter_55.php';
// the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator
return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow);
}
function twig_array_map($array, $arrow)
-10
View File
@@ -1,10 +0,0 @@
<?php
function twig_array_filter($array, $arrow)
{
foreach ($array as $k => $v) {
if ($arrow($v, $k)) {
yield $k => $v;
}
}
}