From 6edb03db418739276026790d9e0fa5cfa7444cfd Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 14 Dec 2023 21:24:26 +0100 Subject: [PATCH] refactoring --- src/Latte/Compiler/Nodes/Php/FilterNode.php | 2 +- src/Latte/Compiler/Nodes/Php/ModifierNode.php | 8 +++++--- src/Latte/Compiler/PrintContext.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Latte/Compiler/Nodes/Php/FilterNode.php b/src/Latte/Compiler/Nodes/Php/FilterNode.php index a38df2272..666f67c72 100644 --- a/src/Latte/Compiler/Nodes/Php/FilterNode.php +++ b/src/Latte/Compiler/Nodes/Php/FilterNode.php @@ -34,7 +34,7 @@ public function print(PrintContext $context): string public function printSimple(PrintContext $context, string $expr): string { - return '($this->filters->' . $this->name . ')(' + return '($this->filters->' . $context->objectProperty($this->name) . ')(' . $expr . ($this->args ? ', ' . $context->implode($this->args) : '') . ')'; diff --git a/src/Latte/Compiler/Nodes/Php/ModifierNode.php b/src/Latte/Compiler/Nodes/Php/ModifierNode.php index 6f71d09e7..4f15b9611 100644 --- a/src/Latte/Compiler/Nodes/Php/ModifierNode.php +++ b/src/Latte/Compiler/Nodes/Php/ModifierNode.php @@ -49,19 +49,21 @@ public function printSimple(PrintContext $context, string $expr): string { $escape = $this->escape; $check = $this->check; + $expr = new Expression\AuxiliaryNode(fn() => $expr); foreach ($this->filters as $filter) { $name = $filter->name->name; - if (['nocheck' => 1, 'noCheck' => 1][$name] ?? null) { + if ($name === 'nocheck' || $name === 'noCheck') { $check = false; } elseif ($name === 'noescape') { $escape = false; } else { - if (['datastream' => 1, 'dataStream' => 1][$name] ?? null) { + if ($name === 'datastream' || $name === 'dataStream') { $check = false; } - $expr = $filter->printSimple($context, $expr); + $expr = new Expression\FilterCallNode($expr, $filter); } } + $expr = $expr->print($context); $escaper = $context->getEscaper(); if ($check) { diff --git a/src/Latte/Compiler/PrintContext.php b/src/Latte/Compiler/PrintContext.php index f0a9466ca..8dd463065 100644 --- a/src/Latte/Compiler/PrintContext.php +++ b/src/Latte/Compiler/PrintContext.php @@ -102,7 +102,7 @@ function ($m) use (&$pos) { function ($m) use ($args) { [, $pos, $fn, $var] = $m; $var = substr($var, 1, -1); - /** @var Nodes\FilterNode[] $args */ + /** @var Nodes\ModifierNode[] $args */ return match ($fn) { 'modify' => $args[$pos]->printSimple($this, $var), 'modifyContent' => $args[$pos]->printContentAware($this, $var),