From 5159de6a0eed60315d1dc0f1cd7cc22936c508eb Mon Sep 17 00:00:00 2001 From: Albert Casademont Date: Thu, 4 Jun 2020 13:40:06 +0200 Subject: [PATCH] Fix Symfony 5.1 Dotenv component deprecations --- Bootstraps/Symfony.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index b3585ad..74f20c8 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -8,6 +8,7 @@ use Symfony\Contracts\Service\ResetInterface; use function PHPPM\register_file; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\Dotenv\Dotenv; /** * A default bootstrap for the Symfony framework @@ -53,8 +54,13 @@ public function getApplication() } // environment loading as of Symfony 3.3 - if (!getenv('APP_ENV') && class_exists('Symfony\Component\Dotenv\Dotenv') && file_exists(realpath('.env'))) { - (new \Symfony\Component\Dotenv\Dotenv(true))->load(realpath('.env')); + if (!getenv('APP_ENV') && class_exists(Dotenv::class) && file_exists(realpath('.env'))) { + //Symfony >=5.1 compatibility + if (method_exists(Dotenv::class, 'usePutenv')) { + (new Dotenv())->usePutenv()->load(realpath('.env')); + } else { + (new Dotenv(true))->load(realpath('.env')); + } } $namespace = getenv('APP_KERNEL_NAMESPACE') ?: '\App\\';