From 5b258dc2bc58ea98e062ca3efc9345a4dcfb9cf7 Mon Sep 17 00:00:00 2001 From: Sarun Rattanasiri Date: Thu, 16 Oct 2025 23:58:25 +0700 Subject: [PATCH 1/3] Replace unmaintained ad-hoc parser with Dotenv's. --- composer.json | 5 +++-- src/Parser.php | 38 -------------------------------------- src/SecureEnvPHP.php | 16 ++++++++++++---- tests/ParserTest.php | 24 ------------------------ 4 files changed, 15 insertions(+), 68 deletions(-) delete mode 100644 src/Parser.php delete mode 100644 tests/ParserTest.php diff --git a/composer.json b/composer.json index dd84364..59689e9 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,11 @@ } ], "require": { - "php": ">=7.1" + "php": ">=7.4", + "symfony/dotenv": "^7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^8.5" }, "autoload": { "psr-4": { diff --git a/src/Parser.php b/src/Parser.php deleted file mode 100644 index a5a8880..0000000 --- a/src/Parser.php +++ /dev/null @@ -1,38 +0,0 @@ - 0 && strpos($value, '"') === 0 && substr($value, -1) === '"') { - $value = preg_replace('/\\n/gm', "\n", $value); - } - - $value = trim(preg_replace('/(^[\'"]|[\'"]$)/', '', $value)); - - $object[$key] = $value; - } - } - - return $object; - } -} diff --git a/src/SecureEnvPHP.php b/src/SecureEnvPHP.php index 719aa26..117427a 100644 --- a/src/SecureEnvPHP.php +++ b/src/SecureEnvPHP.php @@ -1,19 +1,27 @@ -decrypt($path, $secret, $algo)) { - $parsed = Parser::parse($decrypted) ?? []; - + $parsed = $this->dotenvInstance()->parse($decrypted, basename($path)) ?? []; foreach ($parsed as $key => $value) { if (isset($parsed[$key]) && !empty($parsed[$key])) { - putenv($key.'='.$value); + putenv($key . '=' . $value); } } } } + + private function dotenvInstance() + { + return $this->dotenv ??= new Dotenv(); + } } diff --git a/tests/ParserTest.php b/tests/ParserTest.php deleted file mode 100644 index 54ea24b..0000000 --- a/tests/ParserTest.php +++ /dev/null @@ -1,24 +0,0 @@ -decrypt(Constants::ENV_ENC_TEST, Constants::ENV_KEY_TEST); - - $parsed = Parser::parse($decrypt); - - $this->assertNotEmpty($parsed); - $this->assertSame(['FOO' => 'bar'], $parsed); - } -} From 263a15d08e254e8f46402461d5c116e328d49c36 Mon Sep 17 00:00:00 2001 From: Sarun Rattanasiri Date: Thu, 16 Oct 2025 23:58:59 +0700 Subject: [PATCH 2/3] Test PHP 7 and PHP 8 --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 66231e6..58aefd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: php php: - - 7.1 - - 7.2 - - 7.3 + - 7.4 + - 8.4 install: - travis_retry composer install --no-interaction --ignore-platform-reqs before_script: From 5807dba31b3899156576a2a6c5d4c059aa8397da Mon Sep 17 00:00:00 2001 From: Sarun Rattanasiri Date: Fri, 17 Oct 2025 00:22:43 +0700 Subject: [PATCH 3/3] Lowering Dotenv version requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 59689e9..2b4212c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=7.4", - "symfony/dotenv": "^7.3" + "symfony/dotenv": ">=5.4" }, "require-dev": { "phpunit/phpunit": "^8.5"