Skip to content

Commit

Permalink
Merge pull request #23 from helhum/fix/template-change-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed Feb 13, 2020
2 parents 4fa7d7c + 65fcb7d commit bccfdfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions src/IncludeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(
Expand Down

0 comments on commit bccfdfc

Please sign in to comment.