Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set default syntax from Latte\Engine #359

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
add ability to set default syntax from Latte\Engine
machina86 authored and machina86 committed May 2, 2024
commit b1c4e765d68e34a9491ce1168a42564f3e6d3590
10 changes: 10 additions & 0 deletions src/Latte/Compiler/TemplateParser.php
Original file line number Diff line number Diff line change
@@ -408,6 +408,16 @@ public function getContentType(): string
return $this->contentType;
}


/**
* Sets tag syntax for lexer
*/
public function setSyntax(?string $syntax): static
{
$this->lexer->setSyntax($syntax);
return $this;
}


/** @internal */
public function getStream(): TokenStream
13 changes: 13 additions & 0 deletions src/Latte/Engine.php
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ class Engine
private bool $sandboxed = false;
private ?string $phpBinary = null;
private ?string $cacheKey;
private ?string $defaultSyntax = null;


public function __construct()
@@ -147,6 +148,9 @@ public function compile(string $name): string
public function parse(string $template): TemplateNode
{
$parser = new Compiler\TemplateParser;
if ($this->defaultSyntax) {
$parser->setSyntax($this->defaultSyntax);
}
$parser->strict = $this->strictParsing;

foreach ($this->extensions as $extension) {
@@ -563,6 +567,15 @@ public function isStrictParsing(): bool
{
return $this->strictParsing;
}

/**
* Sets default tag syntax
*/
public function setDefaultSyntax(?string $defaultSyntax): static
{
$this->defaultSyntax = $defaultSyntax;
return $this;
}


public function setLoader(Loader $loader): static