Skip to content

Commit b6c2bdf

Browse files
committed
PrintNode::applyFilters() WIP
1 parent ee1bea7 commit b6c2bdf

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/Latte/Compiler/Nodes/PrintNode.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Latte\Compiler\Nodes;
1111

1212
use Latte;
13+
use Latte\Compiler\Nodes\Php\Expression\FilterCallNode;
1314
use Latte\Compiler\Nodes\Php\ExpressionNode;
1415
use Latte\Compiler\Nodes\Php\ModifierNode;
1516
use Latte\Compiler\PrintContext;
@@ -39,6 +40,7 @@ public static function create(Tag $tag, TemplateParser $parser): static
3940
$node->expression = $tag->parser->parseExpression();
4041
$node->modifier = $tag->parser->parseModifier();
4142
$node->modifier->escape = true;
43+
$node->applyFilters();
4244
return $node;
4345
}
4446

@@ -57,6 +59,20 @@ public function print(PrintContext $context): string
5759
}
5860

5961

62+
private function applyFilters(): void
63+
{
64+
$filters = &$this->modifier->filters;
65+
foreach ($filters as $i => $filter) {
66+
$name = $filter->name->name;
67+
if (!in_array($name, ['noescape', 'nocheck', 'noCheck'], true)) {
68+
$this->expression = new FilterCallNode($this->expression, $filter);
69+
unset($filters[$i]);
70+
}
71+
}
72+
$filters = array_values($filters);
73+
}
74+
75+
6076
public function &getIterator(): \Generator
6177
{
6278
yield $this->expression;

src/Latte/Compiler/TemplateParserHtml.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ private function parseAttribute(): ?Node
369369
&& $value instanceof Nodes\PrintNode
370370
&& !$value->modifier->filters
371371
) {
372-
// TODO: $value->modifier->filters
373372
// TODO: whitespacep před
374373
return new Html\DynamicAttributeNode(
375374
name: $name->content,

tests/tags/print.nodes.phpt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ Assert::match(<<<'XX'
1212
Fragment:
1313
Fragment:
1414
Print:
15-
Variable:
16-
name: var
17-
Modifier:
18-
Filter:
19-
Identifier:
20-
name: trim
15+
FilterCall:
16+
FilterCall:
17+
Variable:
18+
name: var
19+
Filter:
20+
Identifier:
21+
name: trim
2122
Filter:
2223
Identifier:
2324
name: upper
25+
Modifier:
2426
XX, exportTraversing('{=$var|trim|upper}'));
2527

2628

0 commit comments

Comments
 (0)