Skip to content

Commit

Permalink
FilterNode::printContentAware() moved to ModifierNode [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 10, 2024
1 parent 1f88558 commit aaf493e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/Latte/Compiler/Nodes/Php/FilterNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Latte\Compiler\Nodes\Php;

use Latte\CompileException;
use Latte\Compiler\Node;
use Latte\Compiler\Position;
use Latte\Compiler\PrintContext;
Expand All @@ -34,20 +33,6 @@ public function print(PrintContext $context): string
}


public function printContentAware(PrintContext $context, string $expr): string
{
if ($this->nullsafe) {
throw new CompileException('Nullsafe pipe is not allowed here', $this->position);
}
return '$this->filters->filterContent('
. $context->encodeString($this->name->name)
. ', $ʟ_fi, '
. $expr
. ($this->args ? ', ' . $context->implode($this->args) : '')
. ')';
}


public function &getIterator(): \Generator
{
yield $this->name;
Expand Down
13 changes: 11 additions & 2 deletions src/Latte/Compiler/Nodes/Php/ModifierNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Latte\Compiler\Nodes\Php;

use Latte\CompileException;
use Latte\Compiler\Node;
use Latte\Compiler\Nodes\Php\Expression\FiltersCallNode;
use Latte\Compiler\Position;
Expand Down Expand Up @@ -85,9 +86,17 @@ public function printContentAware(PrintContext $context, string $expr): string
$name = $filter->name->name;
if ($name === 'noescape') {
$noescape = true;
} else {
$expr = $filter->printContentAware($context, $expr);
continue;
} elseif ($filter->nullsafe) {
throw new CompileException('Nullsafe pipe is not allowed here', $filter->position);
}

$expr = '$this->filters->filterContent('
. $context->encodeString($filter->name->name)
. ', $ʟ_fi, '
. $expr
. ($filter->args ? ', ' . $context->implode($filter->args) : '')
. ')';
}

if ($this->escape && empty($noescape)) {
Expand Down

0 comments on commit aaf493e

Please sign in to comment.