Commit Graph

3325 Commits

Author SHA1 Message Date
Fabien Potencier 5a9a2ccbaf minor #2254 Clean ups (SpacePossum)
This PR was submitted for the master branch but it was merged into the 2.x branch instead (closes #2254).

Discussion
----------

Clean ups

Commits
-------

1f6fd67 Clean ups
2016-11-17 11:07:31 -05:00
SpacePossum 1f6fd6700e Clean ups 2016-11-17 11:07:31 -05:00
Fabien Potencier 3ea0f326e3 Merge branch '1.x' into 2.x
* 1.x:
  1 x cleanups
  added support for PHP 7 null coalescing operator
2016-11-17 11:06:28 -05:00
Fabien Potencier bee35de653 minor #2256 1 x cleanups (SpacePossum)
This PR was squashed before being merged into the 1.x branch (closes #2256).

Discussion
----------

1 x cleanups

Commits
-------

2ea7d78 1 x cleanups
2016-11-17 11:06:11 -05:00
SpacePossum 2ea7d78f17 1 x cleanups 2016-11-17 11:06:10 -05:00
Fabien Potencier 59522d88b8 feature #2250 Add support for PHP 7 null coalescing operator (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Add support for PHP 7 null coalescing operator

This is just one case where we can "optimize" the ternary operator. PHP 7 also supports more complex expressions that can return `null`. The rule here seems to be that you cannot have more than one level of undefinedness.

So, for instance, if `log` is defined, `log("foo") ?? "NOPE"` works, but `log($a["foo"]) ?? "NOPE"` does not if `$a["foo"]` is not defined. If we want to convert the code to always use `??` when possible, this should probably be implemented in the Optimizer node visitor, not here. But the question is: is it worth it in terms of performance? It cleans up the generated code quite a bit though.

closes #1979

Commits
-------

cfc3931 added support for PHP 7 null coalescing operator
2016-11-17 09:17:22 -05:00
Fabien Potencier cfc3931f6e added support for PHP 7 null coalescing operator 2016-11-17 09:16:42 -05:00
Fabien Potencier 50c6b24038 minor #2253 Use ** operator over function pow() (SpacePossum)
This PR was submitted for the master branch but it was merged into the 2.x branch instead (closes #2253).

Discussion
----------

Use ** operator over function pow()

With Twig PHP dep. raised to 5.6 the arithmetic operator [`**`](http://php.net/manual/en/language.operators.arithmetic.php) can be used.

Besides slightly faster it is also harder to override an operator than it is the `pow()` function.

Commits
-------

97f8159 Use ** operator over function pow()
2016-11-17 08:18:26 -05:00
SpacePossum 97f815930e Use ** operator over function pow() 2016-11-17 08:18:21 -05:00
Fabien Potencier eeed841497 Merge branch '1.x' into 2.x
* 1.x:
  Simplify power
2016-11-17 08:16:03 -05:00
Fabien Potencier 9514ca3272 minor #2255 Simplify power (SpacePossum)
This PR was merged into the 1.x branch.

Discussion
----------

Simplify power

Commits
-------

9307bba Simplify power
2016-11-17 08:15:48 -05:00
SpacePossum 9307bba111 Simplify power 2016-11-16 11:04:17 +01:00
Fabien Potencier d0d5475dc9 Merge branch '1.x' into 2.x
* 1.x:
  fixed phpdocs
2016-11-15 17:03:16 -05:00
Fabien Potencier 61bf5da0ac fixed phpdocs 2016-11-15 17:01:44 -05:00
Fabien Potencier 183f062bbf removed obsolete code 2016-11-15 17:01:14 -05:00
Fabien Potencier 5a7b20205d Merge branch '1.x' into 2.x
* 1.x:
  exposed a way to access template data and methods in a portable way
  removed optimization as it's not compatible with Symfony cache system
2016-11-15 16:57:15 -05:00
Fabien Potencier 4b48d614b5 feature #2236 Expose a way to access template data and methods in a portable way (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Expose a way to access template data and methods in a portable way

`Twig_Template` is an internal class, and most of its methods are marked as being `@internal` as they are not "safe" to use by end users.

But some of its features are interesting like `renderBlock()` which is very useful when rendering emails for instance (see #1873).

This PR tries to address both issues by marking the whole `Twig_Template` class as being internal  and by exposing a new way to safely interact with a template besides the obvious `render()`/`display()` methods via `$twig->load("...")`.

If also add some convenient methods like `hasBlock()` or `getBlocks()` (see ~#1831~ and #1882):

```php
$template = $twig->load('index');

echo $template->render($context);
$template->display($context);

if ($template->hasBlock('name') {
   $template->displayBlock('name', $context);
}

foreach ($template->getBlocks() as $block) {
    echo $template->render($block, $context);
}
```

Commits
-------

d7062f3 exposed a way to access template data and methods in a portable way
2016-11-15 16:12:57 -05:00
Fabien Potencier 08bd6f15a5 feature #2249 Remove optimization as it's not compatible with Symfony cache system (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Remove optimization as it's not compatible with Symfony cache system

fixes #2243

@nicolas-grekas Instead of fixing Symfony cache system (which will only happen in a new patch release), I propose to revert these changes. It means no optimization for Twig 1.x, but the optimization is the default in Twig 2.0. So, I don't think this is a big deal.

Commits
-------

d64d320 removed optimization as it's not compatible with Symfony cache system
2016-11-13 07:12:56 -08:00
Fabien Potencier d7062f35b8 exposed a way to access template data and methods in a portable way 2016-11-12 19:45:39 -08:00
Fabien Potencier 863f18e780 removed deprecated code 2016-11-12 19:43:22 -08:00
Fabien Potencier c500bedbd9 Merge branch '1.x' into 2.x
* 1.x:
  changed context access to use the PHP 7 null coalescing operator when available
  renamed blockExists to hasBlock
2016-11-12 19:42:58 -08:00
Fabien Potencier 827d8e7795 minor #2238 added support for PHP 7 null coalescing operator (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added support for PHP 7 null coalescing operator

fixes #1979

Commits
-------

6effc9a changed context access to use the PHP 7 null coalescing operator when available
2016-11-12 19:33:53 -08:00
Fabien Potencier 6effc9aa34 changed context access to use the PHP 7 null coalescing operator when available 2016-11-12 19:30:09 -08:00
Fabien Potencier d64d320b4a removed optimization as it's not compatible with Symfony cache system 2016-11-12 19:22:49 -08:00
Fabien Potencier dc43edaa87 removed obsolete code 2016-11-12 18:55:08 -08:00
Fabien Potencier 4419ff3ae4 minor #2248 renamed blockExists to hasBlock (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

renamed blockExists to hasBlock

As `hasBlock()` is marked as internal and because it's not even used anywhere in Twig, I've replaced its implementation with the one of `blockExists()`, and I also kept BC with a deprecation notice just in case someone is using it.

Commits
-------

59770a3 renamed blockExists to hasBlock
2016-11-12 18:47:19 -08:00
Fabien Potencier 59770a33f7 renamed blockExists to hasBlock 2016-11-12 18:29:20 -08:00
Fabien Potencier 4c39e930cd remove obsolete docs 2016-11-12 18:12:38 -08:00
Fabien Potencier 26fefedbae Merge branch '1.x' into 2.x
* 1.x:
  updated CHANGELOG
  added with tag
  added missing docs
  added support for a custom template on the block() function
2016-11-12 18:11:17 -08:00
Fabien Potencier a50f765ad9 updated CHANGELOG 2016-11-12 17:42:35 -08:00
Fabien Potencier aa2ca14e88 feature #2246 Add a "with" tag (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Add a "with" tag

Closes #719, alternative implementation of #1054

Commits
-------

4366907 added with tag
2016-11-12 17:41:49 -08:00
Fabien Potencier 4366907d73 added with tag 2016-11-12 17:40:47 -08:00
Fabien Potencier 02b084e2f5 feature #2245 added support for a custom template on the block() function (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added support for a custom template on the block() function

`block()` allows one to render a block of the current template.

This PR adds the possibility to use `block()` to render a block of another template:

```twig
{{ block('footer', template_name) }}
```

As it uses the same logic as for the regular `block()`, you can also use it in a test:

```twig
{% if block('footer', template_name) is defined %}
    ...
{% endif %}
```

This removes the needs to use the internal `Twig_Template::renderBlock()` method in the Symfony Web Profiler for instance. And combined with #2236, it allows us to really mark the whole `Twig_Template` class as being internal.

I'm aware that #1302 asked for being able to pass a context to `block()` (implemented in #1433), but I prefer not to in favor of adding the `with` tag (see #719 and #1054).

When the `with` will be implemented, the code in the Symfony Web Profiler will become something along the lines of:

```twig
        {% with {
            'collector': profile.getcollector(name),
            'profiler_url': profiler_url,
            'token': profile.token,
            'name': name
          } %}
            {{ block('toolbar', template) }}
        {% endwith %}
```

Commits
-------

5ed59be added support for a custom template on the block() function
2016-11-12 17:38:59 -08:00
Fabien Potencier bbd30b03a5 minor #2247 Missing docs (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Missing docs

Commits
-------

065b2e2 added missing docs
2016-11-12 17:37:58 -08:00
Fabien Potencier 065b2e26a2 added missing docs 2016-11-12 17:36:55 -08:00
Fabien Potencier 5ed59be9c5 added support for a custom template on the block() function 2016-11-12 17:34:29 -08:00
Fabien Potencier 05e1c68c4b Merge branch '1.x' into 2.x
* 1.x:
  added some more tests
  added 'is defined' support for constant
  added 'is defined' support for block()
  Add test to check if a block exists
2016-11-11 13:50:46 -08:00
Fabien Potencier c19448545a minor #2241 added some more tests (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added some more tests

Commits
-------

b23cc3b added some more tests
2016-11-11 13:49:36 -08:00
Fabien Potencier 1c2bec9112 feature #2242 added 'is defined' support for constant (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added 'is defined' support for constant

Commits
-------

c81bae4 added 'is defined' support for constant
2016-11-11 13:49:19 -08:00
Fabien Potencier b23cc3b4a1 added some more tests 2016-11-11 13:45:13 -08:00
Fabien Potencier c81bae489e added 'is defined' support for constant 2016-11-11 13:40:51 -08:00
Fabien Potencier 0d6581bf64 feature #2239 Add "is defined" support for block() (hason, fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

Add "is defined" support for block()

replaces #1831, fixes #1821

I think reusing the semantic of the `defined` test is more idiomatic and easily discoverable.

/cc @hason

Commits
-------

3ce06af added 'is defined' support for block()
4f013e0 Add test to check if a block exists
2016-11-11 12:08:12 -08:00
Fabien Potencier 3ce06af6b4 added 'is defined' support for block() 2016-11-11 12:03:32 -08:00
Martin Hasoň 4f013e09ea Add test to check if a block exists 2016-11-11 12:02:25 -08:00
Fabien Potencier 80fa648663 Merge branch '1.x' into 2.x
* 1.x:
  removed old code that is not needed anymore
2016-11-11 12:00:59 -08:00
Fabien Potencier c577631f39 minor #2240 removed old code that is not needed anymore (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

removed old code that is not needed anymore

Commits
-------

60bed59 removed old code that is not needed anymore
2016-11-11 11:59:57 -08:00
Fabien Potencier 60bed59266 removed old code that is not needed anymore 2016-11-11 11:38:25 -08:00
Fabien Potencier 52cd58cbab Merge branch '1.x' into 2.x
* 1.x:
  added a proper error message when block() is called without arguments
  removed some unneeded phpdocs
2016-11-11 08:44:36 -08:00
Fabien Potencier 9cede85c5f minor #2234 removed some unneeded phpdocs (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

removed some unneeded phpdocs

Commits
-------

f21c44c removed some unneeded phpdocs
2016-11-11 08:37:49 -08:00
Fabien Potencier fc53b5ab18 bug #2237 added a proper error message when block() is called without arguments (fabpot)
This PR was merged into the 1.x branch.

Discussion
----------

added a proper error message when block() is called without arguments

Commits
-------

a63ee7c added a proper error message when block() is called without arguments
2016-11-11 07:07:12 -08:00