Add db secrets management
All checks were successful
Website Sync / website-sync (push) Successful in 6s

This commit is contained in:
2026-02-04 17:09:36 -03:00
parent 1f58571940
commit dd751fe671
3 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
function loadEnvironment($path) {
if (!file_exists($path)) {
throw new Exception(".env file not found at: $path");
}
# File method, parses each line as an array element
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
# Loops each line
foreach ($lines as $line) {
# First removes white spaces, then searches if the first character is a comment, skips iteration line.
// Skip comments
if (strpos(trim($line), '#') === 0) continue;
# Continues if it finds an = sign somewhere
// Parse KEY=value
if (strpos($line, '=') !== false) {
# Creates a list, array alike, the items are set by splitting (explode()) each line by the equal sign.
list($key, $value) = explode('=', $line, 2);
# Removes whitespaces and quotes
$key = trim($key);
$value = trim($value, '"\''); // Remove quotes
# Stores each value in $_ENV supergglobal
$_ENV[$key] = $value;
# Not sure what this does
putenv("$key=$value");
}
}
}
// Load at application bootstrap
# Not sure either
loadEnvironment(__DIR__ . '/.env');
// First found on ttps://levelup.gitconnected.com/how-to-securely-handle-production-credentials-in-php-without-exposing-them-in-git-237f4fd5cf91,
// Own comments using #