Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/EnvironmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public function setResourceLimits(ResourceLimits $resourceLimits): EnvironmentFa

public function setRethrowErrors(bool $rethrowErrors = true): EnvironmentFactory
{
$this->defaultRenderContextOptions = new RenderContextOptions(
strictVariables: $this->defaultRenderContextOptions->strictVariables,
strictFilters: $this->defaultRenderContextOptions->strictFilters,
$this->defaultRenderContextOptions = $this->defaultRenderContextOptions->cloneWith(
rethrowErrors: $rethrowErrors,
);

Expand All @@ -98,21 +96,26 @@ public function setRethrowErrors(bool $rethrowErrors = true): EnvironmentFactory

public function setStrictVariables(bool $strictVariables = true): EnvironmentFactory
{
$this->defaultRenderContextOptions = new RenderContextOptions(
$this->defaultRenderContextOptions = $this->defaultRenderContextOptions->cloneWith(
strictVariables: $strictVariables,
strictFilters: $this->defaultRenderContextOptions->strictFilters,
rethrowErrors: $this->defaultRenderContextOptions->rethrowErrors,
);

return $this;
}

public function setStrictFilters(bool $strictFilters = true): EnvironmentFactory
{
$this->defaultRenderContextOptions = new RenderContextOptions(
strictVariables: $this->defaultRenderContextOptions->strictVariables,
$this->defaultRenderContextOptions = $this->defaultRenderContextOptions->cloneWith(
strictFilters: $strictFilters,
rethrowErrors: $this->defaultRenderContextOptions->rethrowErrors,
);

return $this;
}

public function setLazyParsing(bool $lazyParsing = true): EnvironmentFactory
{
$this->defaultRenderContextOptions = $this->defaultRenderContextOptions->cloneWith(
lazyParsing: $lazyParsing,
);

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Render/RenderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ public function getTemplateName(): ?string
return $this->templateName;
}

public function loadPartial(string $templateName, bool $parseIfMissing = false): Template
public function loadPartial(string $templateName): Template
{
if ($partial = $this->environment->templatesCache->get($templateName)) {
return $partial;
}

if (! $parseIfMissing) {
if ($this->options->lazyParsing === false) {
throw new StandardException(sprintf("The partial '%s' has not be loaded during parsing", $templateName));
}

Expand Down
18 changes: 18 additions & 0 deletions src/Render/RenderContextOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,23 @@ public function __construct(
* Rethrow exceptions that occur during rendering instead of rendering the error message.
*/
public readonly bool $rethrowErrors = false,
/**
* Allow parsing the template when it is rendered if it has not been parsed yet.
*/
public readonly bool $lazyParsing = true,
) {}

public function cloneWith(
?bool $strictVariables = null,
?bool $strictFilters = null,
?bool $rethrowErrors = null,
?bool $lazyParsing = null,
): RenderContextOptions {
return new RenderContextOptions(
strictVariables: $strictVariables ?? $this->strictVariables,
strictFilters: $strictFilters ?? $this->strictFilters,
rethrowErrors: $rethrowErrors ?? $this->rethrowErrors,
lazyParsing: $lazyParsing ?? $this->lazyParsing,
);
}
}
2 changes: 1 addition & 1 deletion src/Tags/RenderTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function loadPartial(RenderContext $context): Template
throw new SyntaxException('Template name must be a string');
}

return $context->loadPartial($templateName, parseIfMissing: $this->allowDynamicPartials());
return $context->loadPartial($templateName);
}

protected function buildPartialContext(RenderContext $rootContext, string $templateName, array $variables = []): RenderContext
Expand Down
Loading