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',