Skip to content

Commit

Permalink
fix: if in phar package, cannot right to load env file
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 16, 2019
1 parent a0acbc0 commit 8046c15
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/framework/src/Processor/EnvProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Dotenv\Environment\Adapter\ServerConstAdapter;
use Dotenv\Environment\DotenvFactory;
use Dotenv\Dotenv;
use Swoft;
use Swoft\Log\Helper\CLog;
use function alias;
use Swoft\Stdlib\Helper\Str;
use function basename;
use function dirname;
use function file_exists;
use const IN_PHAR;

/**
* Env processor
Expand All @@ -32,21 +34,27 @@ public function handle(): bool
return false;
}

$envFile = alias($this->application->getEnvFile());
$path = dirname($envFile);
$name = basename($envFile);
$envFile = Swoft::getAlias($this->application->getEnvFile());

// Fix: In phar package, remove phar:// prefix
if (IN_PHAR) {
$envFile = Str::rmPharPrefix($envFile);
}

if (!file_exists($envFile)) {
CLog::warning('Env file(%s) is not exist! skip load it', $envFile);
return true;
}

// Load env
// Load env info
$factory = new DotenvFactory([
new EnvConstAdapter,
new PutenvAdapter,
new ServerConstAdapter
]);

$path = dirname($envFile);
$name = basename($envFile);
Dotenv::create($path, $name, $factory)->load();

CLog::info('Env file(%s) is loaded', $envFile);
Expand Down

0 comments on commit 8046c15

Please sign in to comment.