Merge branch '1.x' into 2.x

* 1.x:
  fixed tests
  Fix generating template name in createTemplate() method
  Prepare for php 7.2
  Fix typo in `advanced.rst` file
This commit is contained in:
Fabien Potencier
2017-05-11 13:26:47 -07:00
4 changed files with 18 additions and 4 deletions
+1 -1
View File
@@ -451,7 +451,7 @@ from the token stream (``$this->parser->getStream()``):
type/value a syntax error is thrown. Otherwise, if the type and value are correct,
the token is returned and the stream moves to the next token.
* ``look()``: Looks a the next token without consuming it.
* ``look()``: Looks at the next token without consuming it.
Parsing expressions is done by calling the ``parseExpression()`` like we did for
the ``set`` tag.
+1 -1
View File
@@ -399,7 +399,7 @@ class Twig_Environment
*/
public function createTemplate($template)
{
$name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false));
$name = sprintf('__string_template__%s', hash('sha256', $template, false));
$loader = new Twig_Loader_Chain(array(
new Twig_Loader_Array(array($name => $template)),
+9 -1
View File
@@ -1144,6 +1144,10 @@ function twig_convert_encoding($string, $to, $from)
*/
function twig_length_filter(Twig_Environment $env, $thing)
{
if (null === $thing) {
return 0;
}
if (is_scalar($thing)) {
return mb_strlen($thing, $env->getCharset());
}
@@ -1152,7 +1156,11 @@ function twig_length_filter(Twig_Environment $env, $thing)
return mb_strlen((string) $thing, $env->getCharset());
}
return count($thing);
if ($thing instanceof \Countable || is_array($thing)) {
return count($thing);
}
return 1;
}
/**
+7 -1
View File
@@ -6,7 +6,9 @@
{{ number|length }}
{{ to_string_able|length }}
{{ countable|length }}
{{ null|length }}
{{ magic|length }}
{{ non_countable|length }}
--DATA--
return array(
'array' => array(1, 4),
@@ -14,7 +16,9 @@ return array(
'number' => 1000,
'to_string_able' => new ToStringStub('foobar'),
'countable' => new CountableStub(42), /* also asserts we do *not* call __toString() */
'magic' => new MagicCallStub(), /* used to assert we do *not* call __call */
'null' => null,
'magic' => new MagicCallStub(), /* used to assert we do *not* call __call */
'non_countable' => new \StdClass(),
);
--EXPECT--
2
@@ -22,4 +26,6 @@ return array(
4
6
42
0
1
1