From 1ebdffe2a68aa6ec1f26919fc33b4f546bb9a67d Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 13 Aug 2023 23:41:54 +0800 Subject: [PATCH] Fixed again non-existent env when interpolating vars --- src/Exporters/Abstract/AbstractConverter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Exporters/Abstract/AbstractConverter.php b/src/Exporters/Abstract/AbstractConverter.php index 8115ea8..46cb256 100644 --- a/src/Exporters/Abstract/AbstractConverter.php +++ b/src/Exporters/Abstract/AbstractConverter.php @@ -32,9 +32,9 @@ abstract class AbstractConverter implements ConverterContract protected array $vars = []; /** - * @var Environment + * @var Environment|null */ - protected Environment $env; + protected ?Environment $env = null; /** * Sets an environment with vars @@ -173,11 +173,11 @@ abstract class AbstractConverter implements ConverterContract */ protected function interpolate(string $content): string { - if (empty($this->vars) && !empty($this->env) && $this->env->hasVars()) { + if (empty($this->vars) && !$this->env?->hasVars()) { return $content; } $matches = []; - if (preg_match_all('/\{\{[a-zA-Z][a-zA-Z0-9]+}}/', $content, $matches, PREG_PATTERN_ORDER) > 0) { + if (preg_match_all('/\{\{[a-zA-Z][a-zA-Z0-9]*}}/m', $content, $matches, PREG_PATTERN_ORDER) > 0) { foreach ($matches[0] as $key => $var) { if (str_contains($content, $var)) { $content = str_replace($var, $this->vars[$var] ?? $this->env[$var] ?? $var, $content);