Commit Graph

988 Commits

Author SHA1 Message Date
Fabien Potencier 5c79de3a8e Merge branch '1.x' into 2.x
* 1.x:
  fixed tests
  Fix generating template name in createTemplate() method
  Prepare for php 7.2
  Fix typo in `advanced.rst` file
2017-05-11 13:26:47 -07:00
Fabien Potencier f4adaef9f1 fixed tests 2017-05-11 13:24:58 -07:00
Hidde Boomsma d2b7a01a18 Prepare for php 7.2
* allow `|length` of `null`
* allow `|length` of objects not implementing `\Countable`

* To get no errors when running with PHP 7.2 You need to use phpunit
^6.1, otherwise the `each` function, used by phpunit, triggers errors.
You can do so by running phpunit like:
`SYMFONY_PHPUNIT_VERSION=6.1 phpnightly vendor/bin/simple-phpunit` *
2017-05-08 09:03:00 +02:00
Fabien Potencier bda3380e6f Merge branch '1.x' into 2.x
* 1.x:
  bumped version to 1.33.3-DEV
  prepared the 1.33.2 release
  fixed edge case in the method cache for Twig attributes
2017-04-20 18:10:40 -06:00
Fabien Potencier 413be4167b fixed edge case in the method cache for Twig attributes 2017-04-18 16:52:31 -06:00
Fabien Potencier a601312031 Merge branch '1.x' into 2.x
* 1.x:
  Wrong stdClass class name generates warning
  added more is_object() safegaruds
  Autoescape test addition; collision fix in Array Loader.
  test if is_object before calling method_exists, fixes #2431
  bumped version to 1.33.1-DEV
  prepared the 1.33.0 release
2017-04-18 08:02:34 -06:00
Christophe SAUVEUR 38987c9349 Wrong stdClass class name generates warning 2017-04-18 07:53:53 -06:00
dave-newson da82b41ac2 Autoescape test addition; collision fix in Array Loader. 2017-04-05 16:19:30 -07:00
Fabien Potencier f5596be101 Merge branch '1.x' into 2.x
* 1.x:
  updated CHANGELOG
  Call clearstatcache() before calling is_dir().
  bumped version to 1.33
  fixed CHANGELOG
  Make "length" filter and "empty" test consider __toString [Twig 1.x]
2017-03-22 08:12:17 -07:00
Fabien Potencier f8d4c096ae feature #2420 Make "length" filter and "empty" test consider __toString [Twig 1.x] (mpdude)
This PR was squashed before being merged into the 1.x branch (closes #2420).

Discussion
----------

Make "length" filter and "empty" test consider __toString [Twig 1.x]

Use case: When you have variables in your views that are actually objects but implement `__toString`, they feel like strings: For example, `{{ something }}` will make use of that to-string-conversion.

What does *not* work is

**a)** `{{ something | length }}`, because that will only have a meaningful return value for objects implementing `\Countable`. This interface, however, may have a totally different semantic/purpose for the object in question.

**b)** `{% if something is empty %}`, because

> empty checks if a variable is an empty string, an empty array, an empty hash, exactly false, or exactly null  `[http://twig.sensiolabs.org/doc/2.x/tests/empty.html]`

... and obviously `something !== null` in this case.

For template designers, this may be surprising if they don't actually care about the object-or-string difference, they just "use" the variable.

This change tries to address this as it changes the behavior for  such objects that have a `__toString` method and are *not* `\Countable`.

*Yes*, it's a BC break in edge cases:

For a), objects that implement a `__toString` but not `\Countable` would previously yield `1` for `{{ object | length }}`, and now would return the length of the string returned by `__toString`.

For b), testing (defined) variables that are objects implementing  `__toString` and that return `''`,  the test now is `false`.

Commits
-------

f5193e92 Make "length" filter and "empty" test consider __toString [Twig 1.x]
2017-03-22 07:45:54 -07:00
Matthias Pigulla f5193e92c5 Make "length" filter and "empty" test consider __toString [Twig 1.x] 2017-03-22 07:33:03 -07:00
Fabien Potencier 4d40c66dbc Merge branch '1.x' into 2.x
* 1.x:
  fixed risky tests
2017-03-20 09:12:13 -07:00
Fabien Potencier 7259e52fa4 fixed risky tests 2017-03-20 08:35:32 -07:00
Fabien Potencier 563f6d0de4 Merge branch '1.x' into 2.x
* 1.x:
  Fixed JS escaping for unicode characters with higher code points
2017-03-17 10:22:07 -07:00
Mike Almond 7f9134952d Fixed JS escaping for unicode characters with higher code points 2017-03-17 10:19:06 -07:00
Fabien Potencier ea2ca30d00 Merge branch '1.x' into 2.x
* 1.x:
  Updated the vim-twig link
  PHPUnit 6 compatability
  Fix codeblock
  Update Compiler.php
2017-03-12 08:30:20 -07:00
Christian Flothmann 0d791de63d PHPUnit 6 compatability 2017-03-11 20:03:13 +01:00
Pierre du Plessis 4587f67621 Add error message when calling parent() in a block that doesn't exist 2017-03-10 08:55:35 -08:00
Fabien Potencier 82004b85f8 bug #2384 Fix undef. source in exception. (SpacePossum)
This PR was merged into the 2.x branch.

Discussion
----------

Fix undef. source in exception.

closes https://github.com/twigphp/Twig/issues/2383

Two things:
- the tests fails without a corrupt cache, so maybe the message is of or the cache generation is off (i.e. not respecting the `$index`)
- passing the `$source` seems superfluous (but maybe that is only the case in the exception message)

Commits
-------

772373cf Fix undef. source in exception.
2017-03-05 13:51:23 -08:00
Fabien Potencier d37b38d79b Merge branch '1.x' into 2.x
* 1.x:
  bumped version to 1.32.1-DEV
  prepared the 1.32.0 release
  udpated CHANGELOG
  improved some tests
  removed trailing space
2017-02-26 16:08:51 -08:00
Fabien Potencier b0ec8390f8 improved some tests 2017-02-23 06:58:09 -08:00
Fabien Potencier 4569e476a8 Merge branch '1.x' into 2.x
* 1.x:
  fixed CS
  #1802 left/right trim
2017-02-23 06:55:46 -08:00
Antony D'Andrea 7d8e75504c #1802 left/right trim 2017-02-23 06:52:03 -08:00
Fabien Potencier 236c429ee0 Merge branch '1.x' into 2.x
* 1.x:
  added some missing tests
2017-02-21 18:52:53 -08:00
Fabien Potencier 236c1bdc32 added some missing tests 2017-02-21 18:49:28 -08:00
Fabien Potencier 764927d0df updated tests for PHP 7+ 2017-02-17 11:34:19 -08:00
Fabien Potencier 9578c35227 Merge branch '1.x' into 2.x
* 1.x:
  fixed tests for PHP 5.2
  fixed tests for PHP 5.2
  fixed tests for PHP 5.2
  Fix typo in test filename
  added a note in the docs about the PSR-11 runtime loader
  fixed typo
  updated CHANGELOG
  bumped version to 1.32
  Add ContainerRuntimeLoader
  tweaked docs
  Update striptags.rst
  fixed CS
  Mention autoescape=true deprecation (issue #2386)
  Fix typo.
  bumped version to 1.31.1-DEV
  prepared the 1.31.0 release
  added a note about macros usage in the deprecated docs
2017-02-17 11:32:53 -08:00
Fabien Potencier b6a16a21f9 fixed tests for PHP 5.2 2017-02-17 11:29:51 -08:00
Fabien Potencier 7f9928d85c minor #2402 Fix typo in test filename (chalasr)
This PR was merged into the 1.x branch.

Discussion
----------

Fix typo in test filename

Commits
-------

e5860f1f Fix typo in test filename
2017-02-17 11:27:19 -08:00
Fabien Potencier f63c6e1a9a fixed tests for PHP 5.2 2017-02-17 11:26:43 -08:00
Fabien Potencier ef2a7d7c36 fixed tests for PHP 5.2 2017-02-17 11:23:47 -08:00
Robin Chalas e5860f1fac Fix typo in test filename 2017-02-17 20:19:55 +01:00
Robin Chalas 964a51bc02 Add ContainerRuntimeLoader 2017-02-17 19:29:40 +01:00
SpacePossum 772373cfd3 Fix undef. source in exception. 2017-01-31 10:46:11 +01:00
Robin Chalas 352c01a078 Remove legacy exception catches from 2.x 2017-01-23 22:20:42 +01:00
SpacePossum 61d31c8fef Fix typo. 2017-01-19 14:08:47 +01:00
Christian Flothmann 2c153bd10f do not overridde case-insentive cache entries 2017-01-11 18:30:44 +01:00
Fabien Potencier 4977bb5d1b removed obsolete code 2017-01-10 07:15:43 -08:00
Fabien Potencier 5c8a624963 fixed class names 2017-01-05 11:38:57 -08:00
Fabien Potencier ad0564a7ee Merge branch '1.x' into 2.x
* 1.x:
  updated copyright year
  Minor typo in class name
  fixed CS
2017-01-02 12:22:25 -08:00
Fabien Potencier 91938100bb fixed CS 2016-12-27 11:58:11 +01:00
Fabien Potencier b8bd97eaa0 Merge branch '1.x' into 2.x
* 1.x:
  Optimize usage of Traversable/Iterator
  Fix typo in phpdoc
  fix C89 compat
2016-12-27 11:56:33 +01:00
Fabien Potencier 289dad5898 minor #2265 Optimize usage of Traversable/Iterator (SpacePossum)
This PR was squashed before being merged into the 1.x branch (closes #2265).

Discussion
----------

Optimize usage of Traversable/Iterator

Commits
-------

2bdcfb6 Optimize usage of Traversable/Iterator
2016-12-27 11:56:08 +01:00
SpacePossum 2bdcfb6743 Optimize usage of Traversable/Iterator 2016-12-27 11:56:06 +01:00
Fabien Potencier 73e9104baa feature #2316 moved Twig_Template::getAttribute() to a function (fabpot)
This PR was merged into the 2.x branch.

Discussion
----------

moved Twig_Template::getAttribute() to a function

Commits
-------

6405684 moved Twig_Template::getAttribute() to a function
2016-12-23 12:18:13 +01:00
Fabien Potencier 1055dd5767 Merge branch '1.x' into 2.x
* 1.x:
  fixed CS
  updated CHANGELOG
  Add a Twig_FactoryRuntimeLoader
2016-12-23 11:51:01 +01:00
Fabien Potencier 640568437f moved Twig_Template::getAttribute() to a function 2016-12-23 11:50:47 +01:00
Fabien Potencier 2fd05fdd05 feature #2311 Add a simple Twig_RuntimeLoaderInterface implementation (chalasr)
This PR was merged into the 1.x branch.

Discussion
----------

Add a simple Twig_RuntimeLoaderInterface implementation

Next to https://github.com/symfony/symfony/pull/21023

This is related to the BC break reported in symfony/symfony#21008 which has been introduced in symfony/symfony#20093 when decoupling extensions from definitions.

What I propose here is to ease the upgrade to symfony 3.2+ by adding a simple `Twig_RuntimeLoaderInterface` implementation here, useful only when using the twig-bridge outside of the symfony fullstack framework (with the Form component for instance).

Upgrading would be as simple as:

```diff
$twig = new Twig_Environment(...);
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
- $twig->addExtension(new FormExtension(new TwigRenderer($rendererEngine, $csrfTokenManager)));
+ $twig->addExtension(new FormExtension());
+ $twig->addRuntimeLoader(new Twig_RuntimeLoader(array(TwigRenderer::class => new TwigRenderer($rendererEngine, $csrfTokenManager)));
```

Instead of having to write this runtime loader yourself.
Please see symfony/symfony#21008 for details and a concrete example of how this could help.

Commits
-------

91c8d59 Add a Twig_FactoryRuntimeLoader
2016-12-23 09:11:01 +01:00
Fabien Potencier 97a8c53ec6 tweaked a deprecation notice 2016-12-23 07:51:44 +01:00
Robin Chalas 91c8d59978 Add a Twig_FactoryRuntimeLoader 2016-12-23 01:04:02 +01:00