Commit Graph

2728 Commits

Author SHA1 Message Date
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
Fabien Potencier 00f6949bd9 minor #1857 Remove deprecated return types from the PHPDocs. (SpacePossum)
This PR was merged into the 1.x branch.

Discussion
----------

Remove deprecated return types from the PHPDocs.

There are deprecation warnings added to the environment (for example https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Environment.php#L1287).

This PR aims to remove the deprecated return types from the PHPDocs as well. It will be useful for developers, but for for IDE's/SCA as well.

Commits
-------

831fd60 Remove deprecated return types from the PHPDocs.
2015-09-30 08:17:44 +02:00
Possum 831fd601cd Remove deprecated return types from the PHPDocs. 2015-09-29 17:58:36 +02:00
Fabien Potencier 604e94883b feature #1844 changed template cache names to take into account the Twig C extension (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

changed template cache names to take into account the Twig C extension

Commits
-------

76ecd43 changed template cache names to take into account the Twig C extension
2015-09-24 16:39:22 +02:00
Fabien Potencier 76ecd43338 changed template cache names to take into account the Twig C extension 2015-09-24 16:37:46 +02:00
Fabien Potencier f0b5b8ce8e bumped version to 1.22.3-DEV 2015-09-22 16:03:12 +02:00
Fabien Potencier 79249fc8c9 prepared the 1.22.2 release v1.22.2 2015-09-22 15:59:32 +02:00
Lorenz Schori 40555fc16e Add test coverage for Twig_Cache_Filesystem 2015-09-21 16:03:23 +02:00
Fabien Potencier 821464ad01 removed unrelevant CHANGELOG entry 2015-09-21 09:07:22 +02:00
Fabien Potencier 86e0a92747 simplified code 2015-09-21 08:58:48 +02:00
Fabien Potencier 591a17fc39 updated CHANGELOG 2015-09-21 08:58:44 +02:00
Fabien Potencier 93914e5e75 bug #1840 Fix race condition in Environment::loadTemplate (1.x) (znerol)
This PR was merged into the 1.x branch.

Discussion
----------

Fix race condition in `Environment::loadTemplate` (1.x)

Fixes #1836 (1.x branch)

Commits
-------

1bb7000 Fix race condition in `Environment::loadTemplate`
2015-09-21 08:51:38 +02:00
Fabien Potencier 7ed34dae63 minor #1839 Fix instance variable declaration in Filesystem cache (znerol)
This PR was merged into the 1.x branch.

Discussion
----------

Fix instance variable declaration in Filesystem cache

Commits
-------

d88c8a9 Fix instance variable declaration in Filesystem cache
2015-09-21 08:08:41 +02:00
Fabien Potencier 2b6a9e023b minor #1843 Non-existing files are not cached by statcache (Tobion)
This PR was merged into the 1.x branch.

Discussion
----------

Non-existing files are not cached by statcache

Reverts #1583

Based on the docs this cannot happen because the stat cache is only active for existing files.

> You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file. However unlink() clears the cache automatically.

http://php.net/manual/en/function.clearstatcache.php

Also the arugments you pass to clearstatcache(false, $filename) make no sense according the documentation and are not effective.

> filename
Clear the realpath and the stat cache for a specific filename only; only used if clear_realpath_cache is TRUE.

Also doctrine cachee does't use this approach either: https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/FileCache.php#L185 And nobody reported problems with this as far as I can see.

Commits
-------

4edf3fd Non-existing files are not cached by statcache
2015-09-21 08:04:46 +02:00
Tobias Schultze 4edf3fd53d Non-existing files are not cached by statcache
Reverts #1583

Based on the docs this cannot happen because the stat cache is only active for existing files.

> You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file. However unlink() clears the cache automatically.

http://php.net/manual/en/function.clearstatcache.php

Also the arugments you pass to clearstatcache(false, $filename) make no sense according the documentation and are not effective.

> filename
Clear the realpath and the stat cache for a specific filename only; only used if clear_realpath_cache is TRUE.

Also doctrine cachee does't use this approach either: https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/FileCache.php#L185 And nobody reported problems with this as far as I can see.
2015-09-21 02:19:00 +02:00
Lorenz Schori 1bb7000a26 Fix race condition in Environment::loadTemplate 2015-09-20 18:08:49 +02:00
Lorenz Schori d88c8a9cc1 Fix instance variable declaration in Filesystem cache 2015-09-20 17:48:57 +02:00
Fabien Potencier fce1c80766 minor #1835 added @internal when appropriate (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added @internal when appropriate

Commits
-------

2c0839c added @internal when appropriate
2015-09-20 15:34:30 +02:00
Fabien Potencier 2c0839cd10 added @internal when appropriate 2015-09-20 15:32:25 +02:00
Fabien Potencier 9fde02fe55 bug #1833 fixed implementation of Null cache (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

fixed implementation of Null cache

fixes #1832

Commits
-------

b43e298 fixed implementation of Null cache
2015-09-16 10:32:19 +02:00
Fabien Potencier b43e298ccf fixed implementation of Null cache 2015-09-16 08:24:50 +02:00
Fabien Potencier 7ffa3a2ae1 bumped version to 1.22.2-DEV 2015-09-15 08:52:30 +02:00
Fabien Potencier b7fc2469fa prepared the 1.22.1 release v1.22.1 2015-09-15 08:50:16 +02:00
Fabien Potencier 443d1dbd02 updated CHANGELOG 2015-09-15 08:49:31 +02:00
Fabien Potencier c7940f89d1 bug #1830 String-cast in template_from_string (Tobion)
This PR was merged into the 1.x branch.

Discussion
----------

String-cast in template_from_string

Fixes #1829 caused by https://github.com/twigphp/Twig/pull/1807/files#diff-5e190f538c5c328c7473a5cfd3b7cd95R578

As twig allows many types in twig templates, e.g. array or traversable, we can do the same for string.
But we only take this approach for twig exposed function/filters etc, i.e. template code, but not core code.

Commits
-------

e1e3655 String-case in template_from_string
2015-09-15 07:16:37 +02:00
Tobias Schultze e1e3655722 String-case in template_from_string
Fixes #1829 caused by https://github.com/twigphp/Twig/pull/1807/files#diff-5e190f538c5c328c7473a5cfd3b7cd95R578

As twig allows many types in twig templates, e.g. array or traversable, we can do the same for string.
But we only take this approach for twig exposed function/filters etc, i.e. template code, but not core code.
2015-09-15 00:59:52 +02:00
Fabien Potencier 1292dcc69a bug #1828 Prevent potential doc comments in escaped inlined source (nicolas-grekas)
This PR was merged into the 1.x branch.

Discussion
----------

Prevent potential doc comments in escaped inlined source

Hopefully the last patch of this multi-patches feature...

Commits
-------

f35a540 Prevent potential doc comments in escaped inlined source
2015-09-14 10:36:12 +02:00
Nicolas Grekas f35a540b1f Prevent potential doc comments in escaped inlined source 2015-09-14 10:00:28 +02:00