mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
simplified code
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
function twig_array_filter($array, $arrow)
|
||||
{
|
||||
foreach ($array as $k => $v) {
|
||||
if ($arrow($v, $k)) {
|
||||
yield $k => $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user