summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Extension/Core.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/lib/Twig/Extension/Core.php')
-rwxr-xr-x[-rw-r--r--]inc/lib/Twig/Extension/Core.php22
1 files changed, 12 insertions, 10 deletions
diff --git a/inc/lib/Twig/Extension/Core.php b/inc/lib/Twig/Extension/Core.php
index e68687b4..60fe1936 100644..100755
--- a/inc/lib/Twig/Extension/Core.php
+++ b/inc/lib/Twig/Extension/Core.php
@@ -348,7 +348,7 @@ function twig_random(Twig_Environment $env, $values = null)
return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values);
}
- if ($values instanceof Traversable) {
+ if (is_object($values) && $values instanceof Traversable) {
$values = iterator_to_array($values);
} elseif (is_string($values)) {
if ('' === $values) {
@@ -620,7 +620,7 @@ function twig_array_merge($arr1, $arr2)
*/
function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false)
{
- if ($item instanceof Traversable) {
+ if (is_object($item) && $item instanceof Traversable) {
$item = iterator_to_array($item, false);
}
@@ -687,7 +687,7 @@ function twig_last(Twig_Environment $env, $item)
*/
function twig_join_filter($value, $glue = '')
{
- if ($value instanceof Traversable) {
+ if (is_object($value) && $value instanceof Traversable) {
$value = iterator_to_array($value, false);
}
@@ -829,7 +829,7 @@ function twig_in_filter($value, $compare)
}
return false !== strpos($compare, (string) $value);
- } elseif ($compare instanceof Traversable) {
+ } elseif (is_object($compare) && $compare instanceof Traversable) {
return in_array($value, iterator_to_array($compare, false), is_object($value));
}
@@ -1329,13 +1329,13 @@ function twig_constant($constant, $object = null)
*
* @param array $items An array of items
* @param integer $size The size of the batch
- * @param string $fill A string to fill missing items
+ * @param mixed $fill A value used to fill missing items
*
* @return array
*/
function twig_array_batch($items, $size, $fill = null)
{
- if ($items instanceof Traversable) {
+ if (is_object($items) && $items instanceof Traversable) {
$items = iterator_to_array($items, false);
}
@@ -1345,10 +1345,12 @@ function twig_array_batch($items, $size, $fill = null)
if (null !== $fill) {
$last = count($result) - 1;
- $result[$last] = array_merge(
- $result[$last],
- array_fill(0, $size - count($result[$last]), $fill)
- );
+ if ($fillCount = $size - count($result[$last])) {
+ $result[$last] = array_merge(
+ $result[$last],
+ array_fill(0, $fillCount, $fill)
+ );
+ }
}
return $result;