From 5335c4154889bc0218f61081674fd5bfa3732a7b Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Wed, 19 Oct 2022 09:32:29 +0200 Subject: [PATCH] Add EnvConfig --- README.md | 56 ++++++++++++++++---------------- src/EnvReader/EnvConfig.php | 50 ++++++++++++++++++++++++++++ tests/{test.php => test_env.php} | 6 ++-- 3 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 src/EnvReader/EnvConfig.php rename tests/{test.php => test_env.php} (78%) diff --git a/README.md b/README.md index ca7047d..5e098d8 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,28 @@ -# PhpEnvReader - -__Utility class for ENV file reading__ - -## Installation - -``` -composer require jrosset/envreader -``` - -## Usage - -```php - 'DEV', - 'WEBSITE_NAME' => 'Generic site' - ]; - } -} -``` +# PhpEnvReader + +__Utility class for ENV file reading__ + +## Installation + +``` +composer require jrosset/envreader +``` + +## Usage + +```php + 'DEV', + 'WEBSITE_NAME' => 'Generic site' + ]; + } +} +``` diff --git a/src/EnvReader/EnvConfig.php b/src/EnvReader/EnvConfig.php new file mode 100644 index 0000000..8f36f3b --- /dev/null +++ b/src/EnvReader/EnvConfig.php @@ -0,0 +1,50 @@ +#).*|(?[a-zA-Z\\d_-]+)=(?.+?))$/i', $line, $match) !== 1) { + continue; // Ligne invalide + } + if (isset($match['comment']) && trim($match['comment']) !== '') { + continue; // Commentaire + } + + if (preg_match('/^"(?.+)(?properties->set($match['key'], $match['value']); + } + } +} \ No newline at end of file diff --git a/tests/test.php b/tests/test_env.php similarity index 78% rename from tests/test.php rename to tests/test_env.php index 78b7ed8..29043c8 100644 --- a/tests/test.php +++ b/tests/test_env.php @@ -3,15 +3,15 @@ require_once __DIR__ . '/../vendor/autoload.php'; -use jrosset\EnvReader\BaseEnv; +use jrosset\EnvReader\EnvConfig; -class Env extends BaseEnv { +class Env extends EnvConfig { /** * @inheritdoc */ protected const PATH_ENV = __DIR__ . '/.env'; - protected function initProperties (): array { + protected function initialProperties (): array { return [ 'WEBSITE_MODE' => 'DEV', 'WEBSITE_NAME' => 'Generic site',