Skip to content

Commit c4038dd

Browse files
committed
[BREAKING] Possible breaking because change of the way the .env path is determined.
1 parent 99c78ab commit c4038dd

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
---------
44

5+
6.0.0
6+
~~~~~
7+
8+
a) [BREAKING] Possible breaking because change of the way the .env path is determined.
9+
510
5.0.0
611
~~~~~
712

src/Env.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class Env
1313
* @param string|null $configFile
1414
* @param string|null $envKey
1515
*/
16-
public function load(string $configFile = null, ?string $envKey = 'APP_ENV'): void
16+
public function load(?string $configFile = null, ?string $envKey = null): void
1717
{
1818
if (self::$envLoaded === false) {
19-
$configFile = $configFile ?? getcwd() . '/.env';
19+
$configFile = $configFile ?? $this->projectRootAbsolutePath() . '/.env';
2020
if (file_exists($configFile)) {
2121
$dotEnv = new Dotenv();
2222
if (method_exists($dotEnv, 'loadEnv')) {
@@ -33,11 +33,23 @@ public function load(string $configFile = null, ?string $envKey = 'APP_ENV'): vo
3333
}
3434

3535
/**
36-
* @param string $envName
3736
* @return mixed|null
3837
*/
3938
public function get(string $envName)
4039
{
4140
return $_ENV[$envName] ?? null;
4241
}
42+
43+
public function projectRootAbsolutePath(): string
44+
{
45+
$dir = __DIR__;
46+
while ((!is_file($dir . '/composer.json') && !is_file($dir . '/root_dir') && !is_file($dir . '/deploy.php')) || basename($dir) === 'deployer-instance') {
47+
if ($dir === \dirname($dir)) {
48+
break;
49+
}
50+
$dir = \dirname($dir);
51+
}
52+
53+
return $dir;
54+
}
4355
}

0 commit comments

Comments
 (0)