Commit Graph

7732 Commits

Author SHA1 Message Date
Fabien Potencier aca92bc53f fixed Windows support 2015-10-27 20:09:50 -07:00
Fabien Potencier f5cf424d0e added the Symfony mbstring polyfill 2015-10-27 20:05:04 -07:00
Fabien Potencier 4004a2b854 removed condition on iconv as it should be always available 2015-10-27 20:03:19 -07:00
Fabien Potencier 12ea20245c fixed message inconsistency 2015-10-26 19:17:27 +01:00
Fabien Potencier 6450c870ae removed useless phpdocs 2015-10-26 18:35:50 +01:00
Fabien Potencier 9caf7722cc renamed a method 2015-10-26 15:00:58 +01:00
Fabien Potencier 9774f4f1a4 deprecated Twig_ExtensionInterface::initRuntime() 2015-10-25 15:48:46 +01:00
Fabien Potencier 5f81f2b517 removed obsolete code 2015-10-25 12:45:50 +01:00
Fabien Potencier db9ca34f3a removed Twig_Environment::computeAlternatives, refactored code 2015-10-25 12:44:06 +01:00
Fabien Potencier 305ba4f314 Merge branch '1.x'
* 1.x:
  deprecated Twig_Environment::computeAlternatives()
2015-10-25 12:40:09 +01:00
Fabien Potencier 0468a7ede4 feature #1890 deprecated Twig_Environment::computeAlternatives() (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

deprecated Twig_Environment::computeAlternatives()

Commits
-------

d0a5ef8 deprecated Twig_Environment::computeAlternatives()
2015-10-25 12:39:22 +01:00
Fabien Potencier d0a5ef8cc0 deprecated Twig_Environment::computeAlternatives() 2015-10-25 09:10:27 +01:00
Fabien Potencier 3556284715 Merge branch '1.x'
* 1.x:
  made the tests semantically more correct
  bumped version to 1.23
  Fix adding mock extension to Twig environment
  removed obsolete documentation about requiring classes
2015-10-25 08:18:52 +01:00
Fabien Potencier 6ddd911aa5 minor #1891 made the tests semantically more correct (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

made the tests semantically more correct

Calling `initRuntime()` is just a side-effect of loading a template.

Commits
-------

f839ad3 made the tests semantically more correct
2015-10-25 08:16:08 +01:00
Fabien Potencier f839ad328e made the tests semantically more correct 2015-10-25 08:12:33 +01:00
Fabien Potencier f47af35457 bug #1874 Fix adding mock extension to Twig environment (GromNaN)
This PR was merged into the 1.x branch.

Discussion
----------

Fix adding mock extension to Twig environment

When the extension class is not defined in a file but in eval'd code we cannot assume `ReflectionObject::getFileName()` will return a valid file path.
https://bugs.php.net/bug.php?id=63901

This PR adds a test case that produce the following error without the fix:

```
1) Twig_Tests_EnvironmentTest::testAddMockExtension
filemtime(): stat failed for phar:///usr/local/php5-5.5.14-20140628-105310/bin/phpunit/phpunit-mock-objects/Framework/MockObject/Generator.php(335) : eval()'d code

/xxx/Twig/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php:40
/xxx/Twig/lib/Twig/Environment.php:769
/xxx/Twig/test/Twig/Tests/EnvironmentTest.php:304
```

I encountered this issue with mocked twig extensions in SonataAdminBundle test suite:
https://github.com/sonata-project/SonataAdminBundle/blob/master/Tests/Controller/HelperControllerTest.php#L254

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #1870
| License       | MIT
| Doc PR        | n/a

Commits
-------

a57b1cc Fix adding mock extension to Twig environment
2015-10-25 07:53:33 +01:00
Fabien Potencier f2664ddf4c minor #1885 simplified some code (fabpot)
This PR was merged into the 2.0-dev branch.

Discussion
----------

simplified some code

Commits
-------

b1e8893 simplified some code
2015-10-25 07:52:17 +01:00
Fabien Potencier a4597a4c00 bumped version to 1.23 2015-10-24 23:38:20 +02:00
Jérôme Tamarelle a57b1cc3be Fix adding mock extension to Twig environment
When the extension class is not defined in a file but in eval'd code
we cannot assume ReflectionObject::getFileName will return
a valid file path.

https://bugs.php.net/bug.php?id=63901
2015-10-23 13:31:04 +02:00
Fabien Potencier b1e8893fde simplified some code 2015-10-23 08:46:55 +02:00
Fabien Potencier 53aa70a3f4 minor #1884 removed obsolete documentation about requiring classes (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

removed obsolete documentation about requiring classes

Commits
-------

eac8c0c removed obsolete documentation about requiring classes
2015-10-23 08:29:28 +02:00
Fabien Potencier eac8c0cd3f removed obsolete documentation about requiring classes 2015-10-21 08:17:22 +02:00
Fabien Potencier 66e2275527 Merge branch '1.x'
* 1.x:
  Revert "simplified logic and improve perf slightly"
2015-10-21 08:08:09 +02:00
Fabien Potencier 50e68e68f0 Revert "simplified logic and improve perf slightly"
This reverts commit 7030fdd767.
2015-10-20 19:44:50 +02:00
Fabien Potencier 112c511260 Merge branch '1.x'
* 1.x:
  bumped version to 1.22.4-DEV
  prepared the 1.22.3 release
  updated CHANGELOG
  updated CHANGELOG
  simplified logic and improve perf slightly
  Added a cache for extension freshness test
  added a note about using .. and | together
  fixed BC break by allowing null as the cache strategy
  fixed CS
  Check if cached file exists
  fixed CS
2015-10-13 09:18:23 +02:00
Fabien Potencier 656ecc0a5c bumped version to 1.22.4-DEV 2015-10-13 09:16:21 +02:00
Fabien Potencier ebfc36b7e7 prepared the 1.22.3 release v1.22.3 2015-10-13 09:07:02 +02:00
Fabien Potencier 353e1a4e42 updated CHANGELOG 2015-10-13 09:03:42 +02:00
Fabien Potencier b75dab9e6d bug #1868 fixed BC break by allowing null as the cache strategy (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

fixed BC break by allowing null as the cache strategy

fixes #1851

Commits
-------

d6316d6 fixed BC break by allowing null as the cache strategy
2015-10-13 09:02:05 +02:00
Fabien Potencier 35a396418b minor #1869 added a note about using .. and | together (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added a note about using .. and | together

fixes #1860

Commits
-------

3802920 added a note about using .. and | together
2015-10-13 09:01:13 +02:00
Fabien Potencier 2802a87dc5 minor #1870 Improved performance of template freshness checks (superdav42, fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Improved performance of template freshness checks

Same as #1864 but with with even less perf impact.

Commits
-------

7030fdd simplified logic and improve perf slightly
77c94ea Added a cache for extension freshness test
2015-10-13 09:00:27 +02:00
Fabien Potencier 73306c5b4b updated CHANGELOG 2015-10-13 08:55:02 +02:00
Fabien Potencier 7030fdd767 simplified logic and improve perf slightly 2015-10-13 08:48:23 +02:00
David Stone 77c94ea205 Added a cache for extension freshness test
Freshness of each extension was been checked everytime a template was loaded.
Projects with many templates and extension benefit noticeably with this cache.
Only environments with debug or autoload set are affected.
2015-10-13 08:39:35 +02:00
Fabien Potencier 38029206d2 added a note about using .. and | together 2015-10-12 09:39:52 +02:00
Fabien Potencier d6316d6428 fixed BC break by allowing null as the cache strategy 2015-10-12 09:14:15 +02:00
Fabien Potencier e624d0849e fixed CS 2015-10-12 08:54:22 +02:00
Fabien Potencier 927d8141c2 bug #1866 Check if cached file exists (torzech)
This PR was squashed before being merged into the 1.x branch (closes #1866).

Discussion
----------

Check if cached file exists

Without this modification:

```
Array
(
    [code] => 2
    [message] => filemtime(): stat failed for /Users/torzech/code/[---cut---]/app/cache/6/9/69b8b36648330d23ccfb6e8b7542e0dbdd518a910ab986d602639e1b855de522.php
    [file] => /Users/torzech/code/[---cut---]/libs/twig/twig/lib/Twig/Cache/Filesystem.php
    [line] => 91
)
```

Commits
-------

154bc9d Check if cached file exists
2015-10-12 08:53:40 +02:00
Tomasz Orzechowski 154bc9d2c8 Check if cached file exists 2015-10-12 08:53:38 +02:00
Fabien Potencier aa1596785b fixed CS 2015-10-08 17:08:17 +02:00
Fabien Potencier ce074e5c0c Merge branch '1.x'
* 1.x:
  fixed CS
  Add test coverage for auto_reload
  fix template class name generation to prevent possible collisions and one inode per file
  Fix custom escaper null values
  remove duplicated phpdocs
  Remove deprecated return types from the PHPDocs.
  changed template cache names to take into account the Twig C extension
  Add test coverage for Twig_Cache_Filesystem
2015-10-04 10:43:21 +02:00
Fabien Potencier efaf5036e6 fixed CS 2015-10-04 10:38:04 +02:00
Fabien Potencier 3347b9040e minor #1846 Add test coverage for auto_reload (znerol)
This PR was squashed before being merged into the 1.x branch (closes #1846).

Discussion
----------

Add test coverage for auto_reload

Fixes #1841

Commits
-------

1769f84 Add test coverage for auto_reload
2015-10-04 10:31:01 +02:00
Lorenz Schori 1769f84a4d Add test coverage for auto_reload 2015-10-04 10:31:00 +02:00
Fabien Potencier ac718de74c minor #1845 Add unit tests for filesystem cache (znerol)
This PR was merged into the 1.x branch.

Discussion
----------

Add unit tests for filesystem cache

Fixes #1842

Commits
-------

40555fc Add test coverage for Twig_Cache_Filesystem
2015-10-04 10:30:00 +02:00
Fabien Potencier 41fbfb15fb bug #1852 fix template class name generation to prevent possible collisions (Tobion)
This PR was merged into the 1.x branch.

Discussion
----------

fix template class name generation to prevent possible collisions

- fix template class name generation to prevent possible collisions
- save one inode per file
- fix tests as they are broken with the cext since #1844

Commits
-------

f379e81 fix template class name generation to prevent possible collisions and one inode per file
2015-10-04 10:27:58 +02:00
Tobias Schultze f379e8141c fix template class name generation to prevent possible collisions and one inode per file 2015-10-03 20:59:41 +02:00
Fabien Potencier d6740f3682 bug #1855 Fix custom escaper null values (moufmouf)
This PR was squashed before being merged into the 1.x branch (closes #1855).

Discussion
----------

Fix custom escaper null values

First, a bit of context:

About 10 years ago, when I was doing some Java, I used to use a SQL mapper called iBatis (now moved to myBatis here: http://mybatis.github.io/mybatis-3/dynamic-sql.html)
The whole concept is to put SQL requests in XML files and use XML as a templating engine. Here is a code sample:

```xml
  SELECT * FROM BLOG
  WHERE state = ‘ACTIVE’
  <if test="title != null">
    AND title like #{title}
  </if>
```

Fast forward today. I just realized Twig could be a great tool to do exactly the same. Just imagine:

```SQL
  SELECT * FROM BLOG
  WHERE state = ‘ACTIVE’
  {% if title %}
    AND title like {{ title }}
  {% endif %}
```

All I need to do is write a custom escaper. Like this one:

```php
$twig->getExtension('core')->setEscaper('sql', function(\Twig_Environment $env, $string, $charset) use ($connection) {
    // $connection is a DBAL connection
    return $connection->quote($string);
});
```

Now, here is my problem:

For an SQL escaper to work, I would need *null* to translate into the 'NULL' string.

But in Twig, escapers are not triggered for null or numeric values. This is due to these lines of code: https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Extension/Core.php#L1021-L1027

```php
if (!is_string($string)) {
    if (is_object($string) && method_exists($string, '__toString')) {
        $string = (string) $string;
    } else {
        return $string;
    }
}
```

Everything that is not a string (i.e. a numeric value, null, an array...) is directly returned and completely bypasses the escaper.

I understand that this behaviour is ok in most cases (html, js, css, url, etc...), and that it allows some degree of optimisation, but it prevents from working on more specific escapers like a SQL escaper. It is also an undocumented behaviour of custom escapers.

This pull request tries to fix this without impacting performance.

In most Twig installations, no custom escapers are used. In this cases, returning early is a good idea since all default escapers share the same behaviour.
If there is a custom escaper configured however, I'm going the "long" route to be sure that the custom escaper is fed with all values (and not only non empty strings)

Commits
-------

6f84981 Fix custom escaper null values
2015-09-30 14:05:09 +02:00
David Négrier 6f84981ae6 Fix custom escaper null values 2015-09-30 14:05:05 +02:00
Fabien Potencier 008fc134e3 remove duplicated phpdocs 2015-09-30 14:04:32 +02:00