Commit Graph

676 Commits

Author SHA1 Message Date
Fabien Potencier fba7f95bd2 simplified the implementation of the replace filter 2011-11-27 14:58:36 +01:00
Fabien Potencier 86214c4601 fixed a crash under certain versions of PHP when an object with a __toString() method is used with htmlspecialchars 2011-11-25 19:36:25 +01:00
Fabien Potencier 620b29a4d5 renamed an internal class 2011-11-23 23:45:02 +01:00
Fabien Potencier c90b3ec97a made a small speed optimization 2011-11-23 15:18:40 +01:00
Fabien Potencier 317f6e4725 fixed unit tests due to a difference between the PHP and C versions of Twig_Template::getAttribute() 2011-11-23 14:24:45 +01:00
Fabien Potencier bae4246356 updated Twig ext version 2011-11-23 12:19:09 +01:00
Tobias Schultze 4802f696a3 fixing and improving PHPDoc in Template.php 2011-11-22 09:11:56 +01:00
Fabien Potencier 82e3ecc6da added more unit tests 2011-11-21 14:50:30 +01:00
Pierre Joye 115edf2a71 - fix property access when the instance implements Iterator or similar cases, by using get_object_vars instead, thx Arnaud Leblanc for the hint. 2011-11-21 14:02:02 +01:00
Fabien Potencier 7bc07dc132 removed usage of Reflection in Twig_Template::getAttribute() (thanks Pierre Joye for the property tip) 2011-11-21 10:46:19 +01:00
Fabien Potencier fc6819cec2 added support for twig C extension 2011-11-21 09:36:32 +01:00
Fabien Potencier 9d2272efbf fixed previous merge and added some unit tests 2011-11-21 09:04:06 +01:00
Fabien Potencier b76a574944 merged branch shvchk/patch-2 (PR #522)
Commits
-------

5f30db0 !empty($date[0]) → !empty($date)
0182dbc indentation fix
c7a06cb php warning fix
a4a2d6f Support of negative timestamps

Discussion
----------

Support of negative timestamps

Date could be checked against this condition, as proposed in my patch:

```php
ctype_digit((string) $date)
|| (('-' === $date[0])
    && (ctype_digit(substr($date, 1))))
```
or this:

```php
preg_match('/^\-?\d+/', $date)
```
Second is maybe more readable, but 20% slower.

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

by nikic at 2011/11/20 01:59:16 -0800

Couldn't we do an int validation here? I.e. `if (false !== filter_var($date, FILTER_VALIDATE_INT)) { ... }`. That will allow both positive and negative integers in the allowed integer range. Note though that it will no longer allow ints starting with a zero (apart from zero itself). To support that one would need to pass the ALLOW_OCTAL flag.

Some tests: http://codepad.viper-7.com/w0MDTH

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

by damianb at 2011/11/20 07:50:39 -0800

@nikic why not `ctype_digit`?

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

by nikic at 2011/11/20 07:53:26 -0800

@damianb ctype_digit is what this PR wants to replace, because it does not allow negative numbers. Replacing it with `ctype_digit((string) $date) || (!empty($date[0]) && ('-' === $date[0]) && ctype_digit(substr($date, 1)))` seems like overkill to me though, that's why I proposed to use `false !== filter_var($date, FILTER_VALIDATE_INT)` instead, which apart from being shorter is also semantically more correct.

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

by damianb at 2011/11/20 08:03:09 -0800

@nikic But does filter_var with FILTER_VALIDATE_INT perform better than what's proposed?

Also, I would think that the `empty($date[0])` should just be replaced with an empty check on the `$date` var itself - seems quite pointless to check if the first character is empty, that'd imply that either a) the string itself is empty b) `date[0] == 0`, which could result in a nasty gotcha for someone down the road.

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

by shvchk at 2011/11/20 09:36:17 -0800

@damianb, you are right, I will update the code.
@nikic, on 32-bit systems ```PHP_INT_MAX``` is ```2147483647```, so your code will fail on such systems for 01.01.1900, for example, which is ```-2208988800``` and is not that rarely used.
2011-11-21 08:53:51 +01:00
Andrei Shevchuk 5f30db0f41 !empty($date[0]) → !empty($date) 2011-11-20 21:39:44 +04:00
Andrei Shevchuk 0182dbc3db indentation fix 2011-11-20 15:26:45 +04:00
Andrei Shevchuk c7a06cbbfe php warning fix 2011-11-20 15:18:57 +04:00
Fabien Potencier 2e268ccd9b prepared the 1.4.0-RC1 release 2011-11-20 10:41:28 +01:00
Andrei Shevchuk a4a2d6f763 Support of negative timestamps 2011-11-20 13:08:58 +04:00
Fabien Potencier 1b32617b97 optimized variable access when using PHP 5.4 2011-11-18 22:31:28 +01:00
Fabien Potencier 8ac3603a8b fixed a warning (PHP 5.4) 2011-11-16 08:07:47 +01:00
Fabien Potencier 0cbb13d8fa removed json_encode call in Twig_Error when the filename is a string (to avoid the escaping of /) 2011-11-07 20:00:46 +01:00
Fabien Potencier aa6b835816 converted item parameter of Twig_Template::getAttribute() to string 2011-11-07 14:18:48 +01:00
Fabien Potencier 40595b848e fixed for tag loop variable when using a condition 2011-11-07 14:01:06 +01:00
Fabien Potencier 25336fd6fd refactored "for" tag (moved some logic from the token parser to the node) 2011-11-07 13:45:45 +01:00
Fabien Potencier 10c799fd90 changed the precedence of the .. operator 2011-11-05 08:30:08 +01:00
Fabien Potencier f3f5afbb13 merged branch hason/arrayloader (PR #496)
Commits
-------

253f813 added an exception for undefined templates in ArrayLoader::isFresh

Discussion
----------

added an exception for undefined templates in ArrayLoader::isFresh
2011-11-05 08:02:41 +01:00
Fabien Potencier 23813770de fixed for tag when using a condition with strict_variables set to false 2011-11-04 13:32:43 +01:00
Martin Hasoň 253f8136c5 added an exception for undefined templates in ArrayLoader::isFresh 2011-11-03 12:01:29 +01:00
Fabien Potencier 103e857290 refactored code 2011-11-01 11:56:04 +01:00
Fabien Potencier 9117fc1ce0 added Twig_Function_Node to allow more complex functions to have their own Node class 2011-11-01 11:49:04 +01:00
Fabien Potencier 3427adc7ec added Twig_Filter_Node to allow more complex tests to have their own Node class (the default filter has been converted to use this new feature) 2011-11-01 11:48:05 +01:00
Fabien Potencier d1b5832ccd removed a function that is not used anymore 2011-11-01 11:29:09 +01:00
Fabien Potencier c2371dbbd6 migrated most tests to proper Node classes 2011-11-01 08:57:26 +01:00
Fabien Potencier c749c6b822 moved the defined test to a Twig_Test_Node class 2011-11-01 08:50:39 +01:00
Fabien Potencier b1d06ccbc9 added Twig_Test_Node to allow more complex tests to have their own Node class (sameas has been converted as an example) 2011-11-01 08:50:36 +01:00
Fabien Potencier 083d839000 added a better error message when a template is empty but contain a BOM 2011-10-31 18:49:47 +01:00
Fabien Potencier f5adcb6970 optimized tokenizer by pre-computing all start tag positions (memory and CPU) 2011-10-31 18:03:41 +01:00
Fabien Potencier 4b115d458f optimized a comparison in the tokenizer 2011-10-31 18:03:19 +01:00
nikic 930330fff0 Allow defined test and default filter on methods 2011-10-30 11:19:27 +01:00
Fabien Potencier cf6116c2a8 fixed previous commit 2011-10-29 15:13:27 +02:00
Fabien Potencier dfdd555b9a fixed in operator for empty strings 2011-10-29 14:50:10 +02:00
nikic 2ebc788abc Update extension docs and interface
Twig isn't using globals for functions anymore.
2011-10-29 14:05:14 +02:00
Fabien Potencier 1b46f06394 merged branch phmLabs/documentation_return (PR #483)
Commits
-------

389f2c2 Changed mode from 0755 to 0644
c48bd2f Fixed wrong used PHPDoc tags

Discussion
----------

Fixed wrong used PHPDoc tags

@param was used instead of @return

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

by fabpot at 2011/10/25 05:47:59 -0700

Can you revert the mode change (from 0644 to 0755)?
2011-10-27 21:47:32 +02:00
Fabien Potencier 29534aada8 fixed the "defined" test and the "default" filter 2011-10-27 18:26:17 +02:00
Fabien Potencier 3201b39f47 added missing supported charset for htmlspecialchars 2011-10-26 11:28:33 +02:00
Fabien Potencier 5e290cbb4d fixed deep nested defined tests 2011-10-26 11:20:38 +02:00
Fabien Potencier 5da378ceaa removed unneeded complexity in GetAttr node 2011-10-26 10:28:26 +02:00
Fabien Potencier 13e4b4800e Revert "fixed exception"
This reverts commit df47659e9d.
2011-10-26 08:05:11 +02:00
Nils Langner 389f2c2603 Changed mode from 0755 to 0644 2011-10-25 16:49:17 +02:00
Nils Langner c48bd2f809 Fixed wrong used PHPDoc tags 2011-10-25 14:32:16 +02:00