Skip to content

Commit fd7d00c

Browse files
authored
Merge pull request #171 from acasademont/fix_symfony5_depreactions
Fix Symfony 5.1 Dotenv component deprecations
2 parents 580622c + 5159de6 commit fd7d00c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Bootstraps/Symfony.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Contracts\Service\ResetInterface;
99
use function PHPPM\register_file;
1010
use Symfony\Component\HttpKernel\KernelInterface;
11+
use Symfony\Component\Dotenv\Dotenv;
1112

1213
/**
1314
* A default bootstrap for the Symfony framework
@@ -53,8 +54,13 @@ public function getApplication()
5354
}
5455

5556
// environment loading as of Symfony 3.3
56-
if (!getenv('APP_ENV') && class_exists('Symfony\Component\Dotenv\Dotenv') && file_exists(realpath('.env'))) {
57-
(new \Symfony\Component\Dotenv\Dotenv(true))->load(realpath('.env'));
57+
if (!getenv('APP_ENV') && class_exists(Dotenv::class) && file_exists(realpath('.env'))) {
58+
//Symfony >=5.1 compatibility
59+
if (method_exists(Dotenv::class, 'usePutenv')) {
60+
(new Dotenv())->usePutenv()->load(realpath('.env'));
61+
} else {
62+
(new Dotenv(true))->load(realpath('.env'));
63+
}
5864
}
5965

6066
$namespace = getenv('APP_KERNEL_NAMESPACE') ?: '\App\\';

0 commit comments

Comments
 (0)