Commit Graph

1262 Commits

Author SHA1 Message Date
Fabien Potencier 3bec772bea merged branch Tobion/test-coverage (PR #615)
Commits
-------

814cefd improve test coverage and support negative int for random function

Discussion
----------

improve test coverage and support negative int for random function
2012-01-26 15:06:02 +01:00
Tobias Schultze 814cefdad7 improve test coverage and support negative int for random function 2012-01-26 14:52:41 +01:00
Fabien Potencier cbadac91cd tweaked doc 2012-01-26 13:25:31 +01:00
Fabien Potencier 197a3115c7 merged branch Tobion/patch-4 (PR #614)
Commits
-------

a15e8f7 typo again
2561aa2 typo
faa90c9 updated doc for random function
fe66358 added tests for random function
6f5ceee Made the random function more versatile

Discussion
----------

Made the random function more versatile

The point is to meet user expectations and to make it more versatile, so it works under more circumstances.
At the moment the random function does only return the supplied parameter when it's not an array. That is not very useful. With this PR it will behave like

    random() => integer as with mt_rand()
    random(5) => integer between 0 and 5 as with mt_rand(0, 5)
    random('foobar') => random character from 'foobar'
    random(array(...)) => random element

I will add tests and documentation if you accept this PR.

---------------------------------------------------------------------------

by fabpot at 2012-01-26T07:29:35Z

Looks good to me. Can you update the docs and add some unit tests?

---------------------------------------------------------------------------

by Tobion at 2012-01-26T11:50:17Z

ready
2012-01-26 13:24:26 +01:00
Tobias Schultze a15e8f7c72 typo again 2012-01-26 12:48:56 +01:00
Tobias Schultze 2561aa212e typo 2012-01-26 12:48:04 +01:00
Tobias Schultze faa90c9268 updated doc for random function 2012-01-26 12:45:18 +01:00
Tobias Schultze fe663585b7 added tests for random function 2012-01-26 12:19:51 +01:00
Tobias Schultze 6f5ceeec10 Made the random function more versatile 2012-01-26 02:32:02 +01:00
Fabien Potencier f792b55141 merged branch Tobion/patch-3 (PR #613)
Commits
-------

e81a9e2 Improved random function

Discussion
----------

Improved random function

- dealing with empty array (otherwise PHP warning is raised)
- using array_rand() and thus saving the $keys variable

---------------------------------------------------------------------------

by Tobion at 2012-01-25T12:41:32Z

How about allowing `mt_rand ( int $min , int $max )` with optional parameters to be used when the $values ist not an array?
This would solve use case #612
2012-01-25 16:02:48 +01:00
Tobias Schultze e81a9e2e71 Improved random function 2012-01-25 13:34:39 +01:00
Fabien Potencier db9179c77d tweaked previous merge (no need to duplicate visitors, handlers and the expression parser when parsing a template inside another one) 2012-01-24 19:12:39 +01:00
Fabien Potencier f958d91e79 add a unit test for previous merge 2012-01-24 19:09:28 +01:00
Fabien Potencier b45f6b9bfc merged branch Seldaek/inception (PR #610)
Commits
-------

0d656f5 Add comments
0255764 Updated CHANGELOG
b327a48 Protect the Parser against recursive parsing issues

Discussion
----------

Make the parser Inception-Proof

Spent half a day debugging before I realized what happened, but I'll try to keep a long story short:

When the cache is empty, and the first template containing an assetic `{% javascripts %}` or similar tag is parsed, it will build up the assetic "assets" or recipes cache, this in turn will tokenize and parse all your templates to find assetic tags and cache that information.

At this point the parser is parsing something else in the middle of a parse() call, and since there is a single instance in the environment, it means all the instance vars are messed up and contain incorrect references to the latest TokenStream that was parsed by assetic, etc.

This had two effects on my application, both appearing seemingly randomly because it highly depends on the order of things, the state of your cache and probably other factors:

- The first thing that happened is that a template was compiled using the wrong template filename, which means I had a `__TwigTemplate_abcd` in the file named `dcba.php`, and it would never find the right class.
- The second issue (could not reproduce but I assume it was caused by this as well) is that the parse tree is completely broken and you end up with a parse error because it thinks it's at the end when it's not, or similar problem.

The proposed fix basically pushes/pops all the vars into a stack whenever the parser starts/stops, which worked very effectively here and does not introduce much breakage or complexity.

---------------------------------------------------------------------------

by stof at 2012-01-24T17:28:06Z

@Seldaek are you able to create a reproducible testcase for this (which should be failing before this fix) ? It would avoid further regressions

---------------------------------------------------------------------------

by Seldaek at 2012-01-24T17:45:37Z

I'll try to improve on this according to feedback tomorrow. I saw this enough for today :)

---------------------------------------------------------------------------

by fabpot at 2012-01-24T17:45:49Z

I'm writing some unit tests

---------------------------------------------------------------------------

by Seldaek at 2012-01-24T17:47:02Z

Ok then I'll add @dzuelke's comments real quick.
2012-01-24 19:09:17 +01:00
Jordi Boggiano 0d656f53af Add comments 2012-01-24 18:53:53 +01:00
Fabien Potencier a494438a0c merged branch Seldaek/typo (PR #609)
Commits
-------

d8527fe Fix docblock

Discussion
----------

Fix docblock
2012-01-24 17:59:21 +01:00
Jordi Boggiano 0255764455 Updated CHANGELOG 2012-01-24 17:41:37 +01:00
Jordi Boggiano b327a48a29 Protect the Parser against recursive parsing issues 2012-01-24 17:39:13 +01:00
Jordi Boggiano d8527fe6ca Fix docblock 2012-01-24 17:38:16 +01:00
Fabien Potencier d21592b189 removed duplicated tests 2012-01-24 13:11:53 +01:00
Fabien Potencier 0f9d7ffb4c added the possibility to skip some tests depending on the PHP version 2012-01-24 13:03:09 +01:00
Fabien Potencier a57804d204 fixed typo 2012-01-23 10:19:16 +01:00
Fabien Potencier e81c932e77 made a speed optimization to macro calls when imported via the from tag 2012-01-23 09:22:43 +01:00
Fabien Potencier 58f7fa3574 updated CHANGELOG 2012-01-23 08:58:03 +01:00
Fabien Potencier 883a93bb4d fixed the attribute function when passing arguments (closes #608) 2012-01-23 08:51:52 +01:00
Fabien Potencier f2195cfe3f added some unit tests for macros 2012-01-21 21:40:17 +01:00
Fabien Potencier 88389ac503 Revert "made a speed optimization to macro calls when imported via the from tag"
This reverts commit 3b87da344a.
2012-01-21 21:26:04 +01:00
Fabien Potencier 3b87da344a made a speed optimization to macro calls when imported via the from tag 2012-01-21 21:18:48 +01:00
Fabien Potencier f4512da0e7 merged branch Tobion/patch-2 (PR #606)
Commits
-------

83a3073 typo

Discussion
----------

typo
2012-01-21 07:18:00 +01:00
Tobias Schultze 83a30739b4 typo 2012-01-19 11:11:49 +01:00
Fabien Potencier 96596d5c7f fixed typo in doc (closes #604) 2012-01-19 10:31:26 +01:00
Fabien Potencier 3fbe8d8c46 merged branch Seldaek/globals_fix (PR #600)
Commits
-------

43ebae1 Reset parsers, visitors, filters, tests, functions when a new one or new extension is added
3db62da Reset globals when a new global is added

Discussion
----------

Reset globals when a new global is added

if getGlobals() is called before adding a new global, it is never taken into account

---------------------------------------------------------------------------

by fabpot at 2012-01-16T14:27:02Z

Is it related to #594?

---------------------------------------------------------------------------

by Seldaek at 2012-01-16T14:30:08Z

Seems like it yes. It means that reading globals + writing + reading again will call getGlobals on all extensions again though.

A slight improvement would be to cache the extension globals in another var that can be re-applied at once over the staged globals.

The fastest would be to just set directly in ->globals if it's already initalized, but that means addGlobal can override extension globals. Not sure if that is a problem, but it creates a somewhat non-deterministic factor.

I can adjust as required.

---------------------------------------------------------------------------

by stof at 2012-01-16T14:45:49Z

@Seldaek shouldn't the same be done for other methods (filters, functions, tags, tests and operators) ?

---------------------------------------------------------------------------

by Seldaek at 2012-01-16T14:53:28Z

Indeed, I was just focused on my crazy issue here :) Once @fabpot decides which way he prefers I can apply it to everything.

---------------------------------------------------------------------------

by fabpot at 2012-01-16T21:05:19Z

+1 for the the approach in this PR. @Seldaek: Can you apply it to everything else as well? Thanks.

---------------------------------------------------------------------------

by Seldaek at 2012-01-17T00:54:08Z

Done, also did it for adding and removing extensions since they potentially override stuff.
2012-01-17 07:17:24 +01:00
Jordi Boggiano 43ebae14ff Reset parsers, visitors, filters, tests, functions when a new one or new extension is added 2012-01-17 01:54:53 +01:00
Jordi Boggiano 3db62dae4b Reset globals when a new global is added 2012-01-16 15:22:29 +01:00
Fabien Potencier f5f1485ef2 merged branch Partugal/twig-ext (PR #598)
Commits
-------

75bfb4e Syncing Twig extension with latest changes in Twig master

Discussion
----------

Syncing Twig extension with latest changes in Twig master
2012-01-15 08:30:41 +01:00
Sergey Linnik 75bfb4e1a0 Syncing Twig extension with latest changes in Twig master 2012-01-15 01:15:28 +04:00
Fabien Potencier 249ec8b28a made a cosmetic change 2012-01-14 17:17:37 +01:00
Fabien Potencier 7ca986ccf7 merged branch lyrixx/patch-4 (PR #596)
Commits
-------

fa2501f Added a link to the documentation site

Discussion
----------

Added a link to the documentation site

Now, on the github project page, there is a link to http://twig.sensiolabs.org/documentation. (like silex)
2012-01-14 17:17:22 +01:00
Fabien Potencier 47c284fe87 merged branch aerialls/patch-2 (PR #597)
Commits
-------

924c8b3 fixed CS

Discussion
----------

fixed CS
2012-01-14 17:17:02 +01:00
Julien Brochet 924c8b352e fixed CS 2012-01-14 15:56:01 +01:00
Grégoire Pineau fa2501f3d4 Added a link to the documentation site 2012-01-14 15:12:39 +01:00
Fabien Potencier d8951853ba added support for optional length in the slice [] notation 2012-01-14 09:27:35 +01:00
Fabien Potencier d9dc813dfd added a slice filter 2012-01-14 08:49:51 +01:00
Fabien Potencier a4e1151d43 fixed core filters phpdoc 2012-01-14 08:49:16 +01:00
Fabien Potencier 4578c176e5 added string support for the reverse filter 2012-01-14 08:49:13 +01:00
Fabien Potencier d95db40838 tweaked doc for the merge filter 2012-01-13 13:14:08 +01:00
Fabien Potencier 087df0513e tweaked documentation 2012-01-13 10:18:17 +01:00
Fabien Potencier aa3c0d8457 fixed some phpdoc 2012-01-11 13:27:00 +01:00
Fabien Potencier fee85f2f1d fixed charset for previous commit 2012-01-09 20:51:54 +01:00
Fabien Potencier 68fa9c9bb8 fixed the empty test and the length filter for Twig_Markup instances (closes #589) 2012-01-09 20:32:51 +01:00