Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Jun 23, 2021
1 parent 8ae8198 commit 5027bfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
38 changes: 16 additions & 22 deletions Tina4/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function __construct(?string $forceEnvironment = "")
*/
final public function readParams(?string $environment): void
{
if (!defined("TINA4_DOCUMENT_ROOT"))
{
if (!defined("TINA4_DOCUMENT_ROOT")) {
define("TINA4_DOCUMENT_ROOT", "./");
}
$fileName = TINA4_DOCUMENT_ROOT . ".env";
Expand All @@ -59,27 +58,22 @@ final public function readParams(?string $environment): void
$fileContents = explode("\n", $fileContents);
}
foreach ($fileContents as $id => $line) {
if (empty($line)) {
//Ignore blanks
} elseif (($line[0] === "[" && $line[strlen($line) - 1] === "]") || ($line[0] === "#")) {
//Ignore [Sections] && Comments #
} else {
$variables = explode("=", $line, 2);
if (isset($variables[0], $variables[1])) {
if (!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);
}
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);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
const TINA4_DEBUG = true;
const TINA4_DEBUG_LEVEL = ["all"];
require_once "vendor/autoload.php";

echo $test;
Expand Down

0 comments on commit 5027bfb

Please sign in to comment.