Skip to content

Commit

Permalink
PrintContext: removed $escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 18, 2022
1 parent 227d835 commit 987bcd8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Latte/Compiler/PrintContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ final class PrintContext
'or' => [190, -1],
];
private int $counter = 0;
private Escaper $escaper;

/** @var Escaper[] */
private array $escaperStack = [];


public function __construct(string $contentType = ContentType::Html)
{
$this->escaper = new Escaper($contentType);
$this->escaperStack[] = new Escaper($contentType);
}


Expand Down Expand Up @@ -109,7 +108,7 @@ function ($m) use ($args) {
return match ($fn) {
'modify' => $args[$pos]->printSimple($this, $var),
'modifyContent' => $args[$pos]->printContentAware($this, $var),
'escape' => $this->escaper->escape($var),
'escape' => end($this->escaperStack)->escape($var),
};
},
$mask,
Expand Down Expand Up @@ -144,20 +143,19 @@ function ($m) use ($args) {

public function beginEscape(): Escaper
{
$this->escaperStack[] = $this->escaper;
return $this->escaper = clone $this->escaper;
return $this->escaperStack[] = $this->getEscaper();
}


public function restoreEscape(): void
{
$this->escaper = array_pop($this->escaperStack);
array_pop($this->escaperStack);
}


public function getEscaper(): Escaper
{
return clone $this->escaper;
return clone end($this->escaperStack);
}


Expand Down

0 comments on commit 987bcd8

Please sign in to comment.