mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-20 14:36:57 +00:00
removed the array test and rename the traversable test to iterable
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
``array``
|
||||
=========
|
||||
|
||||
``array`` checks if a variable is an array:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{# evaluates to true if the foo variable is an array #}
|
||||
{% if foo is array %}
|
||||
...
|
||||
{% endif %}
|
||||
@@ -12,3 +12,4 @@ Tests
|
||||
constant
|
||||
defined
|
||||
empty
|
||||
iterable
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
``iterable``
|
||||
============
|
||||
|
||||
``iterable`` checks if a variable is an array or a traversable object:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{# evaluates to true if the foo variable is iterable #}
|
||||
{% if foo is iterable %}
|
||||
...
|
||||
{% endif %}
|
||||
@@ -1,11 +0,0 @@
|
||||
``traversable``
|
||||
=========
|
||||
|
||||
``traversable`` checks if a variable is an array or a traversable object:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{# evaluates to true if the foo variable is traversable #}
|
||||
{% if foo is traversable %}
|
||||
...
|
||||
{% endif %}
|
||||
@@ -202,8 +202,7 @@ class Twig_Extension_Core extends Twig_Extension
|
||||
'divisibleby' => new Twig_Test_Node('Twig_Node_Expression_Test_Divisibleby'),
|
||||
'constant' => new Twig_Test_Node('Twig_Node_Expression_Test_Constant'),
|
||||
'empty' => new Twig_Test_Function('twig_test_empty'),
|
||||
'array' => new Twig_Test_Function('is_array'),
|
||||
'traversable' => new Twig_Test_Function('twig_test_traversable'),
|
||||
'iterable' => new Twig_Test_Function('twig_test_iterable'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1030,7 +1029,7 @@ function twig_test_empty($value)
|
||||
*
|
||||
* @return Boolean true if the value is traversable
|
||||
*/
|
||||
function twig_test_traversable($value)
|
||||
function twig_test_iterable($value)
|
||||
{
|
||||
return $value instanceof Traversable || is_array($value);
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
"is_array" test
|
||||
--TEMPLATE--
|
||||
{{ foo is array ? 'ok' : 'ko' }}
|
||||
{{ obj is array ? 'ok' : 'ko' }}
|
||||
{{ val is array ? 'ok' : 'ko' }}
|
||||
--DATA--
|
||||
return array(
|
||||
'foo' => array(),
|
||||
'obj' => new stdClass(),
|
||||
'val' => 'test',
|
||||
);
|
||||
--EXPECT--
|
||||
ok
|
||||
ko
|
||||
ko
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
--TEST--
|
||||
"traversable" test
|
||||
"iterable" test
|
||||
--TEMPLATE--
|
||||
{{ foo is traversable ? 'ok' : 'ko' }}
|
||||
{{ traversable is traversable ? 'ok' : 'ko' }}
|
||||
{{ obj is traversable ? 'ok' : 'ko' }}
|
||||
{{ val is traversable ? 'ok' : 'ko' }}
|
||||
{{ foo is iterable ? 'ok' : 'ko' }}
|
||||
{{ traversable is iterable ? 'ok' : 'ko' }}
|
||||
{{ obj is iterable ? 'ok' : 'ko' }}
|
||||
{{ val is iterable ? 'ok' : 'ko' }}
|
||||
--DATA--
|
||||
return array(
|
||||
'foo' => array(),
|
||||
Reference in New Issue
Block a user