fixed the join filter when several items have the same key

This commit is contained in:
Fabien Potencier
2012-01-02 15:10:19 +01:00
parent 64e3ce6a11
commit b44dba5c7c
2 changed files with 30 additions and 7 deletions
+1 -1
View File
@@ -489,7 +489,7 @@ function twig_array_merge($arr1, $arr2)
function twig_join_filter($value, $glue = '')
{
if ($value instanceof Traversable) {
$value = iterator_to_array($value);
$value = iterator_to_array($value, false);
}
return implode($glue, (array) $value);
+29 -6
View File
@@ -114,20 +114,18 @@ function test_foo($value = 'foo')
return $value;
}
class Foo implements IteratorAggregate
class Foo implements Iterator
{
const BAR_NAME = 'bar';
public $position = 0;
public $array = array(1, 2);
public function bar($param1 = null, $param2 = null)
{
return 'bar'.($param1 ? '_'.$param1 : '').($param2 ? '-'.$param2 : '');
}
public function getIterator()
{
return new ArrayObject(array(1, 2));
}
public function getFoo()
{
return 'foo';
@@ -157,6 +155,31 @@ class Foo implements IteratorAggregate
{
return strtolower($value);
}
public function rewind()
{
$this->position = 0;
}
public function current()
{
return $this->array[$this->position];
}
public function key()
{
return 'a';
}
public function next()
{
++$this->position;
}
public function valid()
{
return isset($this->array[$this->position]);
}
}
class TestTokenParser_☃ extends Twig_TokenParser