Commit Graph

3411 Commits

Author SHA1 Message Date
Fabien Potencier eadba855bb minor #2764 Document combining JSON constants (pbowyer)
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes #2764).

Discussion
----------

Document combining JSON constants

Working out how to do this took a Slack conversation and a StackOverflow answer. I'm adding ti to the documentation so others can get the answer immediately.

Apologies for any reST errors, it's been 10+ years since I wrote any.

Commits
-------

7f4ecd66 Document combining JSON constants
2018-10-12 05:51:40 -07:00
Peter Bowyer 7f4ecd66f1 Document combining JSON constants
Working out how to do this took Slack and StackOverflow. Documenting so others know what to do.
2018-10-12 05:51:35 -07:00
Fabien Potencier 4eea72c25c minor #2754 Improved the code of an example (javiereguiluz)
This PR was merged into the 1.x branch.

Discussion
----------

Improved the code of an example

The original code contains an unneeded *"pop culture"* reference. For those unaware of it, it contains two strong words ("kill" and "bastard").

The concern about this example was firstly raised in the `#diversity` channel of [Symfony Slack](https://symfony.com/support).

Commits
-------

f07a876d Improved the code of an example
2018-09-27 16:33:24 +02:00
Javier Eguiluz f07a876de6 Improved the code of an example 2018-09-27 16:26:19 +02:00
Fabien Potencier 1e99fb4eb3 bug #2751 Fix multi-byte UFT-8 in escape('html_attr') (nicolas-grekas)
This PR was merged into the 1.x branch.

Discussion
----------

Fix multi-byte UFT-8 in escape('html_attr')

same as #2750 but on  1.x

Commits
-------

8863b68c Fix multi-byte UFT-8 in escape('html_attr')
2018-09-20 16:23:43 +02:00
Nicolas Grekas 8863b68c93 Fix multi-byte UFT-8 in escape('html_attr') 2018-09-20 16:15:47 +02:00
Fabien Potencier 82515f6339 added missing test 2018-08-03 07:53:41 +02:00
Fabien Potencier bbe8b3fcdf feature #2696 [RFC] Added new "deprecated" tag (yceruto)
This PR was merged into the 1.x branch.

Discussion
----------

[RFC] Added new "deprecated" tag

```twig
{% deprecated 'The message...' %}
```

This new tag would allow us to define a deprecation warning anywhere within a template, useful for Frameworks, bundles, etc. where breaking the BC is frequently when templates are involved.

It will be easy to guarantee a smooth migration path when we want e.g. rename/remove a template or block, as well as displaying an accurate depreciation message.

**Deprecating a whole template `{# base.twig #}`**
```twig
{% deprecated 'The "' ~ _self ~ '" template is deprecated, use "layout.twig" instead' %}

{% extends 'layout.twig' %}
```
If we're extending from this template `{% extends 'base.twig' %}` then:
```
The "base.twig" template is deprecated, use "layout.twig" instead ("base.twig" at line 1).
```
**Deprecating a block {# greeting/blocks.twig #}**
```twig
{% block hey %}
    {% deprecated 'The "hey" block is deprecated, use "greet" block instead' %}

    {{ block('greet') }}
{% endblock %}

{% block greet %}
    Hey you!
{% endblock %}
```
If we're using this block `{{ block('hey') }}` then:
```
The "hey" block is deprecated, use "greet" block instead ("greeting/blocks.twig" at line 2).
```
also other examples come from my mind like deprecating macros, and any other extension point.

Commits
-------

2ab43383 Added "deprecated" tag
2018-07-31 14:56:40 +02:00
Yonel Ceruto 2ab433833e Added "deprecated" tag 2018-07-31 08:18:50 -04:00
Fabien Potencier a14d249004 feature #2730 Add support for dynamic tests (fabpot)
This PR was squashed before being merged into the 1.x branch (closes #2730).

Discussion
----------

Add support for dynamic tests

fixes #2589

Commits
-------

4beb7bfb Add support for dynamic tests
2018-07-31 11:11:03 +02:00
Fabien Potencier 4beb7bfb0b Add support for dynamic tests 2018-07-31 11:10:58 +02:00
Fabien Potencier 7a3d825969 bug #2726 Fix GlobalsInterface extends for IDE (ogizanagi)
This PR was merged into the 1.x branch.

Discussion
----------

Fix GlobalsInterface extends for IDE

Commits
-------

0b819abb Fix GlobalsInterface extends for IDE
2018-07-25 15:16:22 +02:00
Maxime Steinhausser 0b819abb0d Fix GlobalsInterface extends for IDE 2018-07-25 15:11:25 +02:00
Fabien Potencier 03542492e9 updated CHANGELOG 2018-07-20 15:30:04 +02:00
Fabien Potencier 3491e3590e bug #2721 Don't throw error on validate or parse name if throw var is false (yceruto)
This PR was merged into the 1.x branch.

Discussion
----------

Don't throw error on validate or parse name if throw var is false

As spotted here https://github.com/symfony/symfony/issues/28001 `$loader->exists('@foo')` shouldn't throw an exception. e.g.: https://github.com/symfony/symfony/blob/9bfa971bc5662a6f90408b58a7b2453d7dae4f83/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php#L145

Commits
-------

a0e8d58a Do not throw error on validate or parse name if throw var is false
2018-07-20 15:28:02 +02:00
Yonel Ceruto a0e8d58a6e Do not throw error on validate or parse name if throw var is false 2018-07-20 08:04:00 -04:00
Fabien Potencier cb848ee0a4 bumped version to 1.35.5-DEV 2018-07-13 09:13:09 +02:00
Fabien Potencier 7e081e9837 prepared the 1.35.4 release v1.35.4 2018-07-13 09:12:17 +02:00
Fabien Potencier c45939350b updated CHANGELOG 2018-07-13 09:11:45 +02:00
Fabien Potencier 76cc34554b minor #2714 Fix test (jderusse)
This PR was merged into the 1.x branch.

Discussion
----------

Fix test

Commits
-------

625ac797 Fix test
2018-06-25 17:02:19 +02:00
Jérémy Derussé 625ac79766 Fix test 2018-06-25 16:36:38 +02:00
Fabien Potencier 0f45c2a677 minor #2710 Use isset before array_key_exists (jderusse)
This PR was merged into the 1.x branch.

Discussion
----------

Use isset before array_key_exists

Small performance improvment when using

```
{% set foo = foo|default("bar") %}
```
Will render the following code
```
$context["foo"] = (((isset($context["foo"]) || array_key_exists("foo", $context))) ? (_twig_default_filter((isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : (function () { throw new Twig_Error_Runtime('Variable "foo" does not exist.', 1, $this->source); })()), "bar")) : ("bar"));
```

instead of
```
$context["foo"] = ((array_key_exists("foo", $context)) ? (_twig_default_filter((isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : (function () { throw new Twig_Error_Runtime('Variable "foo" does not exist.', 1, $this->source); })()), "bar")) : ("bar"));
```

Commits
-------

230d3412 Use isset before array_key_exists
2018-06-25 15:41:18 +02:00
Jérémy Derussé 230d34128d Use isset before array_key_exists 2018-06-25 14:32:40 +02:00
Fabien Potencier 3b71efb7b4 bug #2701 Ensure that syntax errors are triggered with the right line (stof)
This PR was merged into the 1.x branch.

Discussion
----------

Ensure that syntax errors are triggered with the right line

When throwing the syntax error without any line and source in these places, the guessing logic enters into action. For the main template, it won't find anything. But for included templates (or any other template loaded during the rendering of another one, even as main one), the guessing will find a template (the caller one) and set the source and line based on it. The source will then be replaced by the proper template by `\Twig_Environment::compileSource`, but the guessed line number will make no sense then.

I searched for all places triggering a syntax error in Twig, to ensure that they always set the actual line number or set the source directly (so that the guessing logic knows that the template it found is the wrong one and so does not try to use it for guessing). There were only a few missing ones.

Commits
-------

6fab6b0b Ensure that syntax errors are triggered with the right line
2018-06-07 07:40:46 +02:00
Christophe Coevoet 6fab6b0bfa Ensure that syntax errors are triggered with the right line 2018-06-06 20:59:03 +02:00
Fabien Potencier b9c60342a3 minor #2695 fix a typo (xabbuh)
This PR was merged into the 1.x branch.

Discussion
----------

fix a typo

Commits
-------

36787f01 fix a typo
2018-05-31 07:46:32 +02:00
Christian Flothmann 36787f01d2 fix a typo 2018-05-30 21:54:04 +02:00
Fabien Potencier b705a3a028 fixed typo 2018-05-18 09:45:47 +02:00
Fabien Potencier f4c020923f fixed doc markup 2018-05-18 09:23:18 +02:00
Fabien Potencier 5f18e99163 minor #2678 Added missing edge-cases (ismael-miguel)
This PR was merged into the 1.x branch.

Discussion
----------

Added missing edge-cases

Discussion on: https://github.com/twigphp/Twig/issues/2677

Commits
-------

22739e7d Added missing edge-cases
2018-05-12 11:39:44 +02:00
Fabien Potencier ed02b30a17 minor #2681 Fixed PHPDoc of Twig_Token::test (lyrixx)
This PR was merged into the 1.x branch.

Discussion
----------

Fixed PHPDoc of Twig_Token::test

For exemple `Twig_TokenParser_Set` use `->test('endset')`

Commits
-------

35a1070a Fixed PHPDoc of Twig_Token::test
2018-05-02 17:04:18 +02:00
Grégoire Pineau 35a1070a62 Fixed PHPDoc of Twig_Token::test
For exemple Twig_TokenParser_Set use ->test('endset')
2018-05-02 16:04:55 +02:00
Fabien Potencier 257d0656cc minor #2680 Add the Symfony ctype polyfill as a dependency (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Add the Symfony ctype polyfill as a dependency

Commits
-------

5b9a70b3 added the Symfony ctype polyfill as a dependency
2018-05-02 07:48:32 +02:00
Fabien Potencier 5b9a70b3a3 added the Symfony ctype polyfill as a dependency 2018-05-01 21:12:10 +02:00
ismael-miguel 22739e7d13 Added missing edge-cases
Discussion on: https://github.com/twigphp/Twig/issues/2677
2018-04-25 20:48:23 +01:00
Fabien Potencier 4f57c6eab8 use HTTPS whenever possible 2018-04-20 08:05:14 +02:00
Fabien Potencier 28690681d1 fixed website URL 2018-04-20 07:23:43 +02:00
Fabien Potencier d11c1f1a69 minor #2670 Fix partial template caching after update when auto_reload is on (ay-git)
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes #2670).

Discussion
----------

Fix partial template caching after update when auto_reload is on

**Description of the bug:**
This bug manifests itself on production servers.
And with a high load the probability of getting on this bug tends to 100%
The bug results in the caching of a partial template and the failure of a part of the site working with this template. Can only be corrected by deleting the cache.

**What's happening:**
If in the process of uploading the template file, a render() is called, the partially uploaded file gets into the cache and after the template file is fully uploaded, the cache is not updated anymore.

**How to demonstrate:**
To demonstrate the bug, you can create 2 files:
File simulating the download of a file to the server (twig_test_write.php):

```
$classTwig = new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../../site_templates/"), array(
	'cache' => __DIR__.'/../../site_templates_cache',
	'auto_reload'=>true
));

file_put_contents(__DIR__."/../../site_templates/"."test.twig","\n<br>Template start write to filesystem");

echo $classTwig->render("test.twig", array());

file_put_contents(__DIR__."/../../site_templates/"."test.twig"," - Template end write to filesystem",FILE_APPEND);

```

File for template rendering (twig_test_read.php):
```
$classTwig = new Twig_Environment( new Twig_Loader_Filesystem(__DIR__."/../../site_templates/"), array(
	'cache' => __DIR__.'/../../site_templates_cache',
	'auto_reload'=>true
));

echo $classTwig->render("test.twig", array());
```

Result executeing file twig_test_write.php:
```
Template start write to filesystem
```

Result executeing file twig_test_read.php:
```
Template start write to filesystem
```

**After this fix:**
Result executeing file twig_test_read.php:
```
Template start write to filesystem - Template end write to filesystem
```

Commits
-------

50d990e2 Fix cache update after uploading the template file (when auto-update is enabled).
2018-04-19 10:56:23 +02:00
AY_W 50d990e23d Fix cache update after uploading the template file (when auto-update is enabled).
If in the process of uploading the template file, a render() is called, the partially uploaded file gets into the cache and after the template file is fully uploaded, the cache is not updated anymore.
2018-04-19 10:56:18 +02:00
Fabien Potencier 3bc9686dc5 minor #2668 Small optimization for Twig_NodeTraverser::traverseForVisitor (covex-nn)
This PR was merged into the 1.x branch.

Discussion
----------

Small optimization for Twig_NodeTraverser::traverseForVisitor

During traversing a node tree `Twig_NodeTraverser::traverseForVisitor` (`Twig_NodeVisitorInterface::leaveNode`) often returns a same child node (a same object). So, there is no need to set it back to its parent.

This PR adds a check if a child node was changed. With this check a lot of calls to `Twig_Node::setNode` will be skipped.

Closes #2665

Commits
-------

555d01f3 Small optimization for Twig_NodeTraverser::traverseForVisitor
2018-04-01 20:24:34 +02:00
Andrey F. Mindubaev 555d01f327 Small optimization for Twig_NodeTraverser::traverseForVisitor 2018-03-26 09:53:48 +03:00
Fabien Potencier ce4aff66cc bug #2581 Add JSON escape strategy (c960657)
This PR was squashed before being merged into the 1.x branch (closes #2581).

Discussion
----------

Add JSON escape strategy

The `js` escape strategy used `\xNN`-style escape sequences. This is not allowed in JSON, only `\uNNNN` is allowed.

This PR adds a new escape strategy, `json` that is similar to `js` except that it does not use `\xNN` but uses `\uNNNN` instead.

I know that I can use `json_decode()`, but it came as a surprise to me that `escape('js')` did not work. You probably shouldn't be generating JSON structures in your templates, but sometimes it comes in handy. My use-case was generating a piece of [JSON-LD](https://json-ld.org).

A different approach that would perhaps be less confusing to users would be to change `js` to not use `\xNN`. This output is still valid JavaScript, it just uses two more bytes per occurrence. Let me know what you think.

Commits
-------

5c7b080b Add JSON escape strategy
2018-03-25 10:27:49 +02:00
Christian Schmidt 5c7b080b31 Add JSON escape strategy 2018-03-25 10:27:41 +02:00
Fabien Potencier c35ad8c4e3 bumped version to 1.35.4-DEV 2018-03-20 05:26:35 +01:00
Fabien Potencier b48680b6eb prepared the 1.35.3 release v1.35.3 2018-03-20 05:25:58 +01:00
Fabien Potencier dc53726ff0 updated CHANGELOG 2018-03-20 05:25:36 +01:00
Fabien Potencier 4b14c38ad5 bug #2664 Fix block names unicity (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Fix block names unicity

closes #2658

Commits
-------

6da72c6d fixed block names unicity
2018-03-20 05:05:35 +01:00
Fabien Potencier 6da72c6d8c fixed block names unicity 2018-03-20 04:57:51 +01:00
Fabien Potencier 3ff78ec072 minor #2663 Remove dev deps in composer.json (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Remove dev deps in composer.json

Commits
-------

64349bcf removed dev deps in composer.json
2018-03-19 18:22:57 +01:00
Fabien Potencier 64349bcf49 removed dev deps in composer.json 2018-03-19 18:18:16 +01:00