From 4c5a95b0dea557913134211c1dc61cd87a733028 Mon Sep 17 00:00:00 2001 From: Andre van Zuydam Date: Wed, 7 Jul 2021 14:23:54 +0200 Subject: [PATCH] Fixing ENV parsing and adding Readme --- README.md | 11 +++++++++++ Tina4/Env.php | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6708a8e..555ee2a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # tina4php-env Environment support for your PHP project + +An .env will be created for you when the system runs for the first +time. If you specify an environment variable on your OS called ENVIRONMENT then .env.ENVIRONMENT will be loaded instead. + +```bash +[Section] <-- Group section +MY_VAR=Test <-- Example declaration, no quotes required or escaping, quotes will be treated as part of the variable +# A commment <-- This is a comment +[Another Section] +VERSION=1.0.0 +``` \ No newline at end of file diff --git a/Tina4/Env.php b/Tina4/Env.php index a970a4a..8a35ddc 100644 --- a/Tina4/Env.php +++ b/Tina4/Env.php @@ -31,9 +31,15 @@ public function __construct(?string $forceEnvironment = "") $this->readParams($environment); } - + /** + * Parses a line into variables + * @param $line + */ private function parseLine($line): void { + if (empty($line)) { + return; + } if ($line[0] === "#" || empty($line) || ($line[0] === "[" && $line[strlen($line) - 1] === "]")) { return; }