mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 07:37:43 +00:00
added Traversable objects support for the join filter
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
* 1.5.0
|
||||
|
||||
* added Traversable objects support for the join filter
|
||||
|
||||
* 1.5.0-RC2 (2011-12-30)
|
||||
|
||||
* added a way to set the default global date interval format
|
||||
|
||||
@@ -488,6 +488,14 @@ function twig_array_merge($arr1, $arr2)
|
||||
*/
|
||||
function twig_join_filter($value, $glue = '')
|
||||
{
|
||||
if ($value instanceof Traversable) {
|
||||
$values = array();
|
||||
foreach ($value as $v) {
|
||||
$values[] = $v;
|
||||
}
|
||||
$value = $values;
|
||||
}
|
||||
|
||||
return implode($glue, (array) $value);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
"join" filter
|
||||
--TEMPLATE--
|
||||
{{ ["foo", "bar"]|join(', ') }}
|
||||
{{ foo|join(', ') }}
|
||||
--DATA--
|
||||
return array('foo' => new Foo())
|
||||
--EXPECT--
|
||||
foo, bar
|
||||
1, 2
|
||||
@@ -114,7 +114,7 @@ function test_foo($value = 'foo')
|
||||
return $value;
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Foo implements IteratorAggregate
|
||||
{
|
||||
const BAR_NAME = 'bar';
|
||||
|
||||
@@ -123,6 +123,11 @@ class Foo
|
||||
return 'bar'.($param1 ? '_'.$param1 : '').($param2 ? '-'.$param2 : '');
|
||||
}
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayObject(array(1, 2));
|
||||
}
|
||||
|
||||
public function getFoo()
|
||||
{
|
||||
return 'foo';
|
||||
|
||||
Reference in New Issue
Block a user