Commit Graph

2755 Commits

Author SHA1 Message Date
Fabien Potencier 20249a0320 fixed CS 2015-11-02 15:44:22 +01:00
Fabien Potencier 52b8d992dc minor #1904 make cache per user (on linux) (remicollet)
This PR was merged into the 1.x branch.

Discussion
----------

make cache per user (on linux)

Just because I hate having failed test when I run test once on 1 account, then once on another account ;)

Commits
-------

da5cac6 make cache per user (on linux)
2015-11-02 15:44:00 +01:00
Remi Collet da5cac6b54 make cache per user (on linux) 2015-11-02 15:09:33 +01:00
Fabien Potencier b9b6f367e1 bumped version to 1.23.1-DEV 2015-10-29 16:33:13 -07:00
Fabien Potencier 5868cd822f prepared the 1.23.0 release v1.23.0 2015-10-29 16:29:01 -07:00
Fabien Potencier d83deb9f32 feature #1897 deprecated Twig_ExtensionInterface::getGlobals() (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

deprecated Twig_ExtensionInterface::getGlobals()

Commits
-------

e3a325f deprecated Twig_ExtensionInterface::getGlobals()
2015-10-29 16:18:41 -07:00
Fabien Potencier e3a325f249 deprecated Twig_ExtensionInterface::getGlobals() 2015-10-29 16:13:49 -07:00
Fabien Potencier 7220fd2d88 fixed typo 2015-10-27 22:39:34 -07:00
Fabien Potencier babf8f80e7 feature #1896 deprecated the possibility to override an extension by registering an other one with the same name (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

deprecated the possibility to override an extension by registering an other one with the same name

Commits
-------

72485c2 deprecated the possibility to override an extension by registering another one with the same name
2015-10-27 22:13:25 -07:00
Fabien Potencier 72485c2ea0 deprecated the possibility to override an extension by registering another one with the same name 2015-10-27 22:04:22 -07:00
Fabien Potencier 847d48e790 feature #1886 deprecated Twig_ExtensionInterface::initRuntime() (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

deprecated Twig_ExtensionInterface::initRuntime()

I'm working on splitting Twig extensions into 2 different phases: compilation and runtime. The goal is to avoid having to load the runtime environment of an extension when compiling templates. That also opens the way to be able to lazy-load Twig extensions.

While working on the split, I realized that the `initRuntime()` method on `Twig_ExtensionInterface` is not needed anymore. It was added at a time `needs_environment` did not exist and was a way to keep the environment around for custom filters/tests/functions. But nowadays, that's not needed anymore. I did a quick search on Github, and most of the implementation I found just store the environment in a local property, which is not needed anymore. So, I propose to deprecate it in 1.x and remove it in 2.0.

Commits
-------

9774f4f deprecated Twig_ExtensionInterface::initRuntime()
2015-10-27 20:46:45 -07:00
Fabien Potencier d4f699a089 minor #1894 removed useless phpdocs (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

removed useless phpdocs

Commits
-------

6450c87 removed useless phpdocs
2015-10-27 20:44:19 -07:00
Fabien Potencier dbd7884857 minor #1893 fixed message inconsistency (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

fixed message inconsistency

Commits
-------

12ea202 fixed message inconsistency
2015-10-27 20:40:16 -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 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 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 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 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 50e68e68f0 Revert "simplified logic and improve perf slightly"
This reverts commit 7030fdd767.
2015-10-20 19:44:50 +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 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