mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
Remove deprecated code
This commit is contained in:
@@ -484,12 +484,6 @@ able to call the ``getTitle()`` and ``getBody()`` methods on ``Article``
|
||||
objects, and the ``title`` and ``body`` public properties. Everything else
|
||||
won't be allowed and will generate a ``\Twig\Sandbox\SecurityError`` exception.
|
||||
|
||||
.. caution::
|
||||
|
||||
The ``extends`` and ``use`` tags are always allowed in a sandboxed
|
||||
template. That behavior will change in 4.0 where these tags will need to be
|
||||
explicitly allowed like any other tag.
|
||||
|
||||
The policy object is the first argument of the sandbox constructor::
|
||||
|
||||
$sandbox = new \Twig\Extension\SandboxExtension($policy);
|
||||
|
||||
@@ -538,10 +538,6 @@ class ExpressionParser
|
||||
|
||||
public function parseFilterExpressionRaw($node)
|
||||
{
|
||||
if (func_num_args() > 1) {
|
||||
trigger_deprecation('twig/twig', '3.12', 'Passing a second argument to "%s()" is deprecated.', __METHOD__);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$token = $this->parser->getStream()->expect(Token::NAME_TYPE);
|
||||
|
||||
|
||||
@@ -54,10 +54,6 @@ class Node implements \Countable, \IteratorAggregate
|
||||
$this->nodes = $nodes;
|
||||
$this->attributes = $attributes;
|
||||
$this->lineno = $lineno;
|
||||
|
||||
if (func_num_args() > 3) {
|
||||
trigger_deprecation('twig/twig', '3.12', sprintf('The "tag" constructor argument of the "%s" class is deprecated and ignored (check which TokenParser class set it to "%s"), the tag is now automatically set by the Parser when needed.', static::class, func_get_arg(3) ?: 'null'));
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
||||
@@ -83,13 +83,7 @@ final class SecurityPolicy implements SecurityPolicyInterface
|
||||
{
|
||||
foreach ($tags as $tag) {
|
||||
if (!\in_array($tag, $this->allowedTags)) {
|
||||
if ('extends' === $tag) {
|
||||
trigger_deprecation('twig/twig', '3.12', 'The "extends" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitely in your sandbox policy if needed.');
|
||||
} elseif ('use' === $tag) {
|
||||
trigger_deprecation('twig/twig', '3.12', 'The "use" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitely in your sandbox policy if needed.');
|
||||
} else {
|
||||
throw new SecurityNotAllowedTagError(\sprintf('Tag "%s" is not allowed.', $tag), $tag);
|
||||
}
|
||||
throw new SecurityNotAllowedTagError(\sprintf('Tag "%s" is not allowed.', $tag), $tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,7 @@ class SandboxTest extends TestCase
|
||||
yield ['deprecated', '{% deprecated "message" %}'];
|
||||
yield ['do', '{% do 1 + 2 %}'];
|
||||
yield ['embed', '{% embed "base.twig" %}{% endembed %}'];
|
||||
// To be uncommented in 4.0
|
||||
//yield ['extends', '{% extends "base.twig" %}'];
|
||||
yield ['extends', '{% extends "base.twig" %}'];
|
||||
yield ['flush', '{% flush %}'];
|
||||
yield ['for', '{% for i in 1..2 %}{% endfor %}'];
|
||||
yield ['from', '{% from "macros" import foo %}'];
|
||||
@@ -99,28 +98,8 @@ class SandboxTest extends TestCase
|
||||
yield ['macro', '{% macro foo() %}{% endmacro %}'];
|
||||
yield ['sandbox', '{% sandbox %}{% endsandbox %}'];
|
||||
yield ['set', '{% set foo = 1 %}'];
|
||||
// To be uncommented in 4.0
|
||||
//yield ['use', '{% use "1_empty" %}'];
|
||||
yield ['with', '{% with foo %}{% endwith %}'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getSandboxedForExtendsAndUseTagsTests
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testSandboxForExtendsAndUseTags(string $tag, string $template)
|
||||
{
|
||||
$this->expectDeprecation(sprintf('Since twig/twig 3.12: The "%s" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitely in your sandbox policy if needed.', $tag));
|
||||
|
||||
$twig = $this->getEnvironment(true, [], self::$templates, []);
|
||||
$twig->createTemplate($template, 'index')->render([]);
|
||||
}
|
||||
|
||||
public function getSandboxedForExtendsAndUseTagsTests()
|
||||
{
|
||||
yield ['extends', '{% extends "1_empty" %}'];
|
||||
yield ['use', '{% use "1_empty" %}'];
|
||||
yield ['with', '{% with foo %}{% endwith %}'];
|
||||
}
|
||||
|
||||
public function testSandboxWithInheritance()
|
||||
|
||||
Reference in New Issue
Block a user