mirror of
https://github.com/Mibew/handlebars.php-helpers.git
synced 2025-03-14 09:44:11 +03:00
Fix "last" helper for HHVM
This commit is contained in:
parent
62ce4e8639
commit
3d1afa47bc
@ -49,6 +49,23 @@ class LastHelper implements HelperInterface
|
||||
throw new \InvalidArgumentException('Wrong type of the argument in the "last" helper.');
|
||||
}
|
||||
|
||||
return end($collection);
|
||||
if (is_array($collection)) {
|
||||
return end($collection);
|
||||
}
|
||||
|
||||
// "end" function does not work with \Traversable in HHVM. Thus we
|
||||
// need to get the element manually.
|
||||
while ($collection instanceof \IteratorAggregate) {
|
||||
$collection = $collection->getIterator();
|
||||
}
|
||||
|
||||
$collection->rewind();
|
||||
$item = false;
|
||||
while ($collection->valid()) {
|
||||
$item = $collection->current();
|
||||
$collection->next();
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user