mirror of
https://github.com/Mibew/handlebars.php-helpers.git
synced 2025-03-14 09:44:11 +03:00
Fix "first" helper for HHVM
This commit is contained in:
parent
fe2d21710a
commit
62ce4e8639
@ -49,6 +49,17 @@ class FirstHelper implements HelperInterface
|
||||
throw new \InvalidArgumentException('Wrong type of the argument in the "first" helper.');
|
||||
}
|
||||
|
||||
return reset($collection);
|
||||
if (is_array($collection)) {
|
||||
return reset($collection);
|
||||
}
|
||||
|
||||
// "reset" 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();
|
||||
|
||||
return $collection->valid() ? $collection->current() : false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user