Commits
-------
c920344 code style
50da1a2 don't modify function name
Discussion
----------
Fix crash in extension
This fixes a crash caused by `php_strtolower()` modifying its input. (Crashes on amd64, but not on x86 for me.)
Commits
-------
3bb822e . misspell function _twig_convert_encoding -> twig_convert_encoding
Discussion
----------
misspell function _twig_convert_encoding -> twig_convert_encoding
Located in _twig_escape_js_callback, the function call was misspelled and raised a PHP Fatal error: Call to undefined function _twig_convert_encoding() in ~/www/project/vendors/Twig/Extension/Core.php on line 585
Commits
-------
d41d10c simplification
2dbb420 moved hard-coded regexes
61986c1 shortcut for non-interpolated double quoted strings
062ed5c regex optimization
0e63abb integration tests for interpolated strings
773fff5 parser tests for interpolated strings
098634e parser support for interpolated strings
c8bba24 lexer tests for interpolated strings
a203686 lexer support for interpolated strings
0bd63dd stack lexer states
Discussion
----------
String interpolation syntax
This adds support for string interpolation:
```
{{ "foo #{ any expression here } bar" }}
```
I find string interpolation to be often more readable than concatenation, and doesn't have the precedence ambiguity of the concatenation operator:
```
Interpolation:
{{ "foo #{bar} baz" }}
{{ "foo #{1+2} baz" }}
{{ "foo #{1+2} baz"|escape }}
Concatenation:
{{ "foo "~bar~" baz" }}
{{ "foo "~(1+2)~" baz" }} extra parentheses
{{ ("foo "~(1+2)~" baz")|escape }} more extra parentheses
```
---------------------------------------------------------------------------
by nikic at 2011/11/12 12:41:54 -0800
Really nice idea. We should discuss the exact syntax though :) Dart for example uses `${expr}` for interpolation or `$name` if the expression is just a name. I think it makes sense to have a special short syntax for the name case, because it is the most common one.
---------------------------------------------------------------------------
by stof at 2011/11/12 13:06:51 -0800
@nikic could you comment on the PR instead of commenting on each commit individually ? it would make it easier to see what is concerned in the PR.
---------------------------------------------------------------------------
by arnaud-lb at 2011/11/12 14:22:14 -0800
@nikic Thanks for your review, I'll take care of your remarks.
For the syntax, I have no preference. I've taken this one because it has the same semantics. In Ruby and Coffeescript the `#{...}` allows any expression between the brackets. In PHP the expression in the `${...}` must start with a variable name. As you mentioned Dart's `${...}` seems to allow any expression.
---------------------------------------------------------------------------
by nikic at 2011/11/12 15:03:48 -0800
@arnaud-lb If Ruby and Coffeescript use this, the #{...} syntax should be okay. Especially as ${...} might be confusing for PHP developers as it has the semantics of variable variables in PHP.
@stof Thanks, will do so next time.
---------------------------------------------------------------------------
by damianb at 2011/11/12 15:38:31 -0800
@stof he doesn't need to - this is something github handles already. in the PR view, beside the "@nikic commented" bits, there's a set of links that shows where exactly the comment was in the format of commit sha, filename, and line inside the diff.
You can see for yourself right here, upper left:

---------------------------------------------------------------------------
by stof at 2011/11/13 01:20:38 -0800
@damianb The comment appears, but not the context in which the comment was. We have to follow each link to see it whereas comments done on the PR appear directly with their context. This is why I said it is easier when comments are on the PR.
---------------------------------------------------------------------------
by nikic at 2011/12/02 15:13:30 -0800
So what about this now?
Btw, `REGEX_STRING` and `REGEX_DQ_STRING_PART` still are hardcoded and do not depend on the specified `interpolation` tags. But this looks hard to change, at least the regexes are quite complicated.
---------------------------------------------------------------------------
by arnaud-lb at 2011/12/02 15:22:45 -0800
I think I've addressed all issues (except hardcoding of `#{` and `}` in `REGEX_STRING` and `REGEX_DQ_STRING_PART`.)
Can this be merged after v1.4 is release if the syntax is accepted ?
---------------------------------------------------------------------------
by nikic at 2011/12/03 01:53:41 -0800
This would be my go for `STRING` and `DQ_STRING_PART` (isn't tested):
```php
<?php
$interpolChar = preg_quote(substr($options['interpolation'][0], 0, 1), '/');
$interpolPart = '[^' . $interpolChar . '"\\\\]*';
if (strlen($options['interpolation'][0]) > 1) {
$interpolRest = preg_quote(substr($options['interpolation'][0], 1), '/');
$interpolRegex = $interpolPart . '(?:(?:\\\\.|' . $interpolChar . '(?!' . $interpolRest . '))' . $interpolPart . ')*';
} else {
$interpolRegex = $interpolPart . '(?:\\\\.' . $interpolPart . ')*';
}
$this->options['dq_string_part_regex'] = '/' . $interpolRegex . '/As';
$this->options['string_regex'] = '/"' . $interpolRegex . '"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As';
```
It should allow both a single char interpolation syntax (like `{`) and multichar ones (like `#{`).
By the way, could we maybe move the compiled regexes out of `$this->options` into `$this->regexes`?
Commits
-------
989bb22 Removed trailing white spaces
f880bab Help the developer when they specify an invalid filter by providing some alternatives
Discussion
----------
Help the developer when they specify an invalid filter by providing some...
... alternatives.
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Uses a simple `strpos` search (no fancy diff to determine what the filter could be). There is no impact to runtime performance because this is all happening during template compilation.
Examples:
```jinja
{{ my_entity|json }}
```
Shows exception:
`The filter "json" does not exist. Did you mean "json_encode"?`
```jinja
{{ my_date|dat }}
```
Shows:
`The filter "dat" does not exist. Did you mean "date"?`
```jinja
{{ my_var|f }}
```
Shows:
`The filter "f" does not exist. Did you mean "format", "default", "_default", "format_args", "format_args_as_text", "file_excerpt", "format_file", "format_file_from_text", "file_link"?`
Also good for custom filters created in your own domain `st_`:
```jinja
{{ my_var|st_ }}
```
Shows:
`The filter "st_" does not exist. Did you mean "st_friendly_date", "st_site_test_url"?`
---------------------------------------------------------------------------
by stof at 2011/12/04 16:34:27 -0800
I like the idea to provide help to the developer in case of error. You should probably do the same for functions
---------------------------------------------------------------------------
by Tobion at 2011/12/05 05:56:29 -0800
+1 for a combination of string starts with (suggesting domain specific filters, e.g. st_*) and levenshtein for typos
---------------------------------------------------------------------------
by chucktrukk at 2011/12/05 08:13:10 -0800
+1. This would be really helpful.
Commits
-------
11b8689 Refactoring: using && instead of nested if's
7aa6757 Bug correction: Parsing integers large than PHP_INT_MAX was generating trucated token values.
046e4ff Bug correction: Parsing integers large than PHP_INT_MAX was generating trucated token values.
Discussion
----------
Fixed bug that was trucating integers large then PHP_INT_MAX
The following code
{% set sizes = [7077888, 452984832, 28991029248, 1855425871872, 9223372036854775807] %}
{% for i in sizes %}
{{ i }}
{% endfor %}
was generating the following output
7077888
452984832
2147483647
2147483647
2147483647
With the fix, the output looks like the following on Ubuntu 11.04
7077888
452984832
28991029248
1855425871872
9.2233720368548E+18
Commits
-------
16d7800 fixed a crash when an object with __toString() method is passed as template name
Discussion
----------
fixed a crash when an object with __toString() method is passed as templ...
...ate name
---------------------------------------------------------------------------
by fabpot at 2011/12/01 03:58:47 -0800
Not sure about this one as the phpdoc clearly state that the name is a string. Do you have a specific user case in mind?
---------------------------------------------------------------------------
by hason at 2011/12/01 04:26:47 -0800
I use the class "Twig_Loader_Chain" as template loader in Symfony2 application. One of the embeded loaders is "Twig_Loader_Array". In Symfony2 is used "Symfony\Component\Templating\TemplateReferenceInterface" for internal representation of a template and it causes a crash.
Commits
-------
7b8d476 optimized twig_escape_filter
Discussion
----------
Optimized twig_escape_filter
This optimizes the part of twig_escape_filter that checks if the charset is supported by htmlspecialchars.
This uses a static variable to avoid initializing the charsets array each time the function is called; and does a hash lookup instead of array search (saves a function call too).
The optimized version takes 66% less time that the original version on html escaping :) (no difference on js escaping).
uses a static variable to avoid initializing the charsets array each
time the function is called; and does a hash lookup instead of array
search (saves a function call too).
Commits
-------
569f782 fix ZTS build
1606910 Fix undefined behavior
0ce8d3c Convert item argument to string
d807981 don't try to access non public property or method
7e566b8 test twig_template_get_attributes
Discussion
----------
twig_template_get_attributes tests and fixes
This enables testing of twig_template_get_attributes (every TemplateTest test is ran against twig_template_get_attributes too) and fixes some bugs I've found.
There is still 3 failing tests due to a difference of how twig_template_get_attributes and Twig_Template::getAttribute use Twig_Template::$cache.
Twig_Template::getAttribute doesn't cache properties, and twig_template_get_attributes expects $cache[$class]['properties'] to be set if $cache[$class] is set. So twig_template_get_attributes can fail if the cache is already populated by Twig_Template::getAttribute.
The callbacks are expected to return an integer, and returning void
instead was triggering weird bugs
I've also removed the casts to ensure that the signatures are compatible
Commits
-------
c65be3e Pass around the TSRM
09d3095 Moved zval declaration
c941552 Removed globals
ffb2460 Added config.w32 for windows builds
Discussion
----------
Fixed compilation on windows