upgrade twig library

This commit is contained in:
Michael Foster
2013-09-19 16:08:25 +10:00
parent 01857d176a
commit 9c48084f3b
163 changed files with 275 additions and 94 deletions

22
inc/lib/Twig/Extension/Core.php Normal file → Executable file
View File

@@ -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;