Skip to content

Commit

Permalink
Updates and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Jul 4, 2021
1 parent 5027bfb commit ef316b4
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 379 deletions.
42 changes: 24 additions & 18 deletions Tina4/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ public function __construct(?string $forceEnvironment = "")
$this->readParams($environment);
}


private function parseLine($line): void
{
if ($line[0] === "#" || empty($line) || ($line[0] === "[" && $line[strlen($line) - 1] === "]")) {
return;
}
$variables = explode("=", $line, 2);
if (isset($variables[0], $variables[1]) && !defined(trim($variables[0]))) {
Debug::message("Defining {$variables[0]} = $variables[1]", TINA4_LOG_DEBUG);
$variable = trim($variables[0]);
if ($variables[1][0] === "[" || $variables[1][0] === "\"")
{
eval("\${$variable} = {$variables[1]};");
} else {
extract([$variable => $variables[1]], EXTR_OVERWRITE);
}

define(trim($variables[0]), ${$variable});

}
}

/**
* The readEnvParams reads the environment variables from the .env.{ENVIRONMENT} file
* @param string|null $environment
Expand All @@ -57,25 +79,9 @@ final public function readParams(?string $environment): void
} else {
$fileContents = explode("\n", $fileContents);
}

foreach ($fileContents as $id => $line) {
if ($line[0] === "#" || empty($line) || ($line[0] === "[" && $line[strlen($line) - 1] === "]")) {
continue;
}
$variables = explode("=", $line, 2);
if (isset($variables[0], $variables[1]) && !defined(trim($variables[0]))) {
Debug::message("Defining {$variables[0]} = $variables[1]", TINA4_LOG_DEBUG);
//echo 'return (defined("'.$variables[1].'") ? '.$variables[1].' : "'.$variables[1].'");';
if (defined($variables[1])) {
define(trim($variables[0]), eval('return (defined("' . $variables[1] . '") ? ' . $variables[1] . ' : "' . $variables[1] . '");'));
} else {
if (strpos($variables[1], '"') !== false || strpos($variables[1], '[') !== false) {
$variable = eval('return ' . $variables[1] . ';');
} else {
$variable = $variables[1];
}
define(trim($variables[0]), $variable);
}
}
$this->parseLine($line);
}
} else {
Debug::message("Created an ENV file for you {$fileName}");
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
}
},
"scripts": {
"run-tests": "./vendor/bin/phpunit tests --color --log-junit=tests/junit.xml",
"start": "php -S localhost:7147 index.php",
"test": "./vendor/bin/phpunit tests --color --log-junit=tests/junit.xml",
"phpmetrics": "phpmetrics --report-html=phpmetrics --junit=tests/junit.xml ./Tina4"
},
"require-dev": {
"phpunit/phpunit": "^9",
"overtrue/phplint": "^2.0"
},
"require": {
"overtrue/phplint": "^2.0",
"tina4stack/tina4php-debug": "^2.0"
}
}
Loading

0 comments on commit ef316b4

Please sign in to comment.