mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 20:47:28 +00:00
minor #4162 Simplify usage of RawFilter (fabpot)
This PR was merged into the 3.x branch.
Discussion
----------
Simplify usage of RawFilter
Commits
-------
6e55b5f9 Simplify usage of RawFilter
This commit is contained in:
@@ -12,13 +12,27 @@
|
||||
namespace Twig\Node\Expression\Filter;
|
||||
|
||||
use Twig\Compiler;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\FilterExpression;
|
||||
use Twig\Node\Node;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class RawFilter extends FilterExpression
|
||||
{
|
||||
public function __construct(Node $node, ?ConstantExpression $filterName = null, ?Node $arguments = null, int $lineno = 0, ?string $tag = null)
|
||||
{
|
||||
if (null === $filterName) {
|
||||
$filterName = new ConstantExpression('raw', $node->getTemplateLine());
|
||||
}
|
||||
if (null === $arguments) {
|
||||
$arguments = new Node();
|
||||
}
|
||||
|
||||
parent::__construct($node, $filterName, $arguments, $lineno ?: $node->getTemplateLine(), $tag ?: $node->getNodeTag());
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
{
|
||||
$compiler->subcompile($this->getNode('node'));
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Tests\Node\Expression\Filter;
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\Filter\RawFilter;
|
||||
use Twig\Test\NodeTestCase;
|
||||
|
||||
class RawTest extends NodeTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$filter = new RawFilter($node = new ConstantExpression('foo', 12));
|
||||
|
||||
$this->assertSame(12, $filter->getTemplateLine());
|
||||
$this->assertSame('raw', $filter->getNode('filter')->getAttribute('value'));
|
||||
$this->assertSame($node, $filter->getNode('node'));
|
||||
$this->assertSame(0, count($filter->getNode('arguments')));
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
$node = new RawFilter(new ConstantExpression('foo', 12));
|
||||
|
||||
return [
|
||||
[$node, '"foo"'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user