Skip to content

Commit bccfdfc

Browse files
authored
Merge pull request #23 from helhum/fix/template-change-upgrade
2 parents 4fa7d7c + 65fcb7d commit bccfdfc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Config.php

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function get($key, $flags = 0)
7272
}
7373
switch ($key) {
7474
case 'env-file':
75+
case 'include-template-file':
7576
$val = rtrim($this->process($this->config[$key], $flags), '/\\');
7677
return ($flags & self::RELATIVE_PATHS === 1) ? $val : $this->realpath($val);
7778
default:

src/IncludeFile.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(Config $config, $loader, $includeFile = '', $include
5252
$this->filesystem = $filesystem ?: new Filesystem();
5353
}
5454

55-
public function dump()
55+
public function dump(): bool
5656
{
5757
$this->filesystem->ensureDirectoryExists(dirname($this->includeFile));
5858
$successfullyWritten = false !== @file_put_contents($this->includeFile, $this->getIncludeFileContent());
@@ -73,10 +73,15 @@ public function dump()
7373
* @throws \InvalidArgumentException
7474
* @return string
7575
*/
76-
private function getIncludeFileContent()
76+
private function getIncludeFileContent(): string
7777
{
7878
if (!file_exists($this->includeFileTemplate)) {
79-
throw new \RuntimeException('Include file template defined for helhum/dotenv-connector does not exist!', 1581515568);
79+
if (!empty($this->includeFileTemplate)) {
80+
throw new \RuntimeException('Include file template defined for helhum/dotenv-connector does not exist!', 1581515568);
81+
}
82+
// We get here when include file template is empty, which could be a misconfiguration, but more likely happens
83+
// during plugin package upgrades. In this case we provide the default value for smoother upgrades.
84+
$this->includeFileTemplate = __DIR__ . '/../res/PHP/dotenv-include.php.tmpl';
8085
}
8186
$envFile = $this->config->get('env-file');
8287
$pathToEnvFileCode = $this->filesystem->findShortestPathCode(

0 commit comments

Comments
 (0)