mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
fixed iterator_to_array() usage (closes #57)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
Backward incompatibilities:
|
||||
* The short notation of the `block` tag changed.
|
||||
|
||||
* fixed iterator_to_array() usage
|
||||
* changed the date filter to support any date format supported by DateTime
|
||||
* added ignore_invalid_variables setting to throw an exception when an invalid variable is used in a template (disabled automatically when debug is true)
|
||||
* added the lexer, parser, and compiler as arguments to the Twig_Environment constructor
|
||||
|
||||
@@ -185,7 +185,7 @@ function twig_in_filter($value, $compare)
|
||||
} elseif (is_string($compare)) {
|
||||
return false !== strpos($compare, (string) $value);
|
||||
} elseif (is_object($compare) && $compare instanceof Traversable) {
|
||||
return in_array($value, iterator_to_array($compare));
|
||||
return in_array($value, iterator_to_array($compare, false));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -298,12 +298,12 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
function twig_iterator_to_array($seq)
|
||||
function twig_iterator_to_array($seq, $useKeys = true)
|
||||
{
|
||||
if (is_array($seq)) {
|
||||
return $seq;
|
||||
} elseif (is_object($seq) && $seq instanceof Traversable) {
|
||||
return $seq instanceof Countable ? $seq : iterator_to_array($seq);
|
||||
return $seq instanceof Countable ? $seq : iterator_to_array($seq, $useKeys);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface
|
||||
$compiler
|
||||
->write("\$context['_seq'] = twig_iterator_to_array(")
|
||||
->subcompile($this->seq)
|
||||
->raw(");\n")
|
||||
->raw(", ".($this->isMultitarget ? 'true' : 'false').");\n")
|
||||
;
|
||||
|
||||
if ($this->withLoop) {
|
||||
|
||||
Reference in New Issue
Block a user