mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Merge branch '1.x' into 2.x
* 1.x: Fixed counting children of SimpleXMLElement object
This commit is contained in:
@@ -1144,6 +1144,10 @@ function twig_length_filter(Twig_Environment $env, $thing)
|
||||
return mb_strlen($thing, $env->getCharset());
|
||||
}
|
||||
|
||||
if ($thing instanceof \SimpleXMLElement) {
|
||||
return count($thing);
|
||||
}
|
||||
|
||||
if (method_exists($thing, '__toString') && !$thing instanceof \Countable) {
|
||||
return mb_strlen((string) $thing, $env->getCharset());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
{{ null|length }}
|
||||
{{ magic|length }}
|
||||
{{ non_countable|length }}
|
||||
{{ simple_xml_element|length }}
|
||||
--DATA--
|
||||
return array(
|
||||
'array' => array(1, 4),
|
||||
@@ -21,6 +22,7 @@ return array(
|
||||
'null' => null,
|
||||
'magic' => new MagicCallStub(), /* used to assert we do *not* call __call */
|
||||
'non_countable' => new \StdClass(),
|
||||
'simple_xml_element' => new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><doc><elem/><elem/></doc>'),
|
||||
);
|
||||
--EXPECT--
|
||||
2
|
||||
@@ -32,3 +34,4 @@ return array(
|
||||
0
|
||||
1
|
||||
1
|
||||
2
|
||||
|
||||
Reference in New Issue
Block a user