mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-18 05:16:30 +00:00
Deprecate the range function
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# 3.15.0 (2024-XX-XX)
|
# 3.15.0 (2024-XX-XX)
|
||||||
|
|
||||||
|
* Deprecate the `range` function, use the `..` operator
|
||||||
* Deprecate `TempNameExpression` in favor of `LocalVariable`
|
* Deprecate `TempNameExpression` in favor of `LocalVariable`
|
||||||
* Deprecate `NameExpression` in favor of `ContextVariable`
|
* Deprecate `NameExpression` in favor of `ContextVariable`
|
||||||
* Deprecate `AssignNameExpression` in favor of `AssignContextVariable`
|
* Deprecate `AssignNameExpression` in favor of `AssignContextVariable`
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ Functions
|
|||||||
|
|
||||||
Note that it won't be removed in 4.0 to allow a smoother upgrade path.
|
Note that it won't be removed in 4.0 to allow a smoother upgrade path.
|
||||||
|
|
||||||
|
* The ``range`` function is deprecated as of Twig 3.15, use the ``..`` operator
|
||||||
|
instead.
|
||||||
|
|
||||||
Extensions
|
Extensions
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
``range``
|
``range``
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
The ``range`` function is deprecated as of Twig 3.15. Use the ``..``
|
||||||
|
operator instead.
|
||||||
|
|
||||||
Returns a list containing an arithmetic progression of integers:
|
Returns a list containing an arithmetic progression of integers:
|
||||||
|
|
||||||
.. code-block:: twig
|
.. code-block:: twig
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ final class CoreExtension extends AbstractExtension
|
|||||||
new TwigFunction('attribute', null, ['parser_callable' => [self::class, 'parseAttributeFunction']]),
|
new TwigFunction('attribute', null, ['parser_callable' => [self::class, 'parseAttributeFunction']]),
|
||||||
new TwigFunction('max', 'max'),
|
new TwigFunction('max', 'max'),
|
||||||
new TwigFunction('min', 'min'),
|
new TwigFunction('min', 'min'),
|
||||||
new TwigFunction('range', 'range'),
|
new TwigFunction('range', 'range', ['deprecation_info' => new DeprecatedCallableInfo('twig/twig', '3.15')]),
|
||||||
new TwigFunction('constant', [self::class, 'constant']),
|
new TwigFunction('constant', [self::class, 'constant']),
|
||||||
new TwigFunction('cycle', [self::class, 'cycle']),
|
new TwigFunction('cycle', [self::class, 'cycle']),
|
||||||
new TwigFunction('random', [self::class, 'random'], ['needs_charset' => true]),
|
new TwigFunction('random', [self::class, 'random'], ['needs_charset' => true]),
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ final class SandboxNodeVisitor implements NodeVisitorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the .. operator is equivalent to the range() function
|
// the .. operator is equivalent to the range() function
|
||||||
|
// To be removed in 4.0
|
||||||
if ($node instanceof RangeBinary && !isset($this->functions['range'])) {
|
if ($node instanceof RangeBinary && !isset($this->functions['range'])) {
|
||||||
$this->functions['range'] = $node->getTemplateLine();
|
$this->functions['range'] = $node->getTemplateLine();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
"range" function
|
"range" function
|
||||||
|
--DEPRECATION--
|
||||||
|
Since twig/twig 3.15: Twig Function "range" is deprecated in index.twig at line 2.
|
||||||
--TEMPLATE--
|
--TEMPLATE--
|
||||||
{{ range(low=0+1, high=10+0, step=2)|join(',') }}
|
{{ range(low=0+1, high=10+0, step=2)|join(',') }}
|
||||||
--DATA--
|
--DATA--
|
||||||
@@ -2,13 +2,13 @@
|
|||||||
Whitespace trimming on tags.
|
Whitespace trimming on tags.
|
||||||
--TEMPLATE--
|
--TEMPLATE--
|
||||||
Trim on control tag:
|
Trim on control tag:
|
||||||
{% for i in range(1, 9) -%}
|
{% for i in 1..9 -%}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
|
||||||
Trim on output tag:
|
Trim on output tag:
|
||||||
{% for i in range(1, 9) %}
|
{% for i in 1..9 %}
|
||||||
{{- i -}}
|
{{- i -}}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user