diff --git a/src/Config.php b/src/Config.php index 94ed136..5bb7f65 100644 --- a/src/Config.php +++ b/src/Config.php @@ -72,6 +72,7 @@ public function get($key, $flags = 0) } switch ($key) { case 'env-file': + case 'include-template-file': $val = rtrim($this->process($this->config[$key], $flags), '/\\'); return ($flags & self::RELATIVE_PATHS === 1) ? $val : $this->realpath($val); default: diff --git a/src/IncludeFile.php b/src/IncludeFile.php index ddd2aba..8790e13 100644 --- a/src/IncludeFile.php +++ b/src/IncludeFile.php @@ -52,7 +52,7 @@ public function __construct(Config $config, $loader, $includeFile = '', $include $this->filesystem = $filesystem ?: new Filesystem(); } - public function dump() + public function dump(): bool { $this->filesystem->ensureDirectoryExists(dirname($this->includeFile)); $successfullyWritten = false !== @file_put_contents($this->includeFile, $this->getIncludeFileContent()); @@ -73,10 +73,15 @@ public function dump() * @throws \InvalidArgumentException * @return string */ - private function getIncludeFileContent() + private function getIncludeFileContent(): string { if (!file_exists($this->includeFileTemplate)) { - throw new \RuntimeException('Include file template defined for helhum/dotenv-connector does not exist!', 1581515568); + if (!empty($this->includeFileTemplate)) { + throw new \RuntimeException('Include file template defined for helhum/dotenv-connector does not exist!', 1581515568); + } + // We get here when include file template is empty, which could be a misconfiguration, but more likely happens + // during plugin package upgrades. In this case we provide the default value for smoother upgrades. + $this->includeFileTemplate = __DIR__ . '/../res/PHP/dotenv-include.php.tmpl'; } $envFile = $this->config->get('env-file'); $pathToEnvFileCode = $this->filesystem->findShortestPathCode(