Merge branch 'dev' into main met behoud van live omgevingsconfiguratie en opschoning van overbodige bestanden
This commit is contained in:
+77
-24
@@ -1,40 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Fociz Applicatie- en Databaseconfiguratie
|
||||
* Fociz Applicatie- en Databaseconfiguratie (MAIN / LIVE BRANCH)
|
||||
* Laadt automatisch .env (of .env.example indien .env niet bestaat)
|
||||
*/
|
||||
|
||||
// Automatisch eenvoudige .env ondersteuning indien aanwezig
|
||||
$envFile = __DIR__ . '/../.env';
|
||||
if (file_exists($envFile)) {
|
||||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
if (str_starts_with(trim($line), '#')) continue;
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($name, $value) = explode('=', $line, 2);
|
||||
$name = trim($name);
|
||||
$value = trim($value, " \t\n\r\0\x0B\"'");
|
||||
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
|
||||
putenv(sprintf('%s=%s', $name, $value));
|
||||
$_ENV[$name] = $value;
|
||||
$_SERVER[$name] = $value;
|
||||
$envVars = [];
|
||||
|
||||
// 1. Zoek naar .env of val terug op .env.example
|
||||
$envCandidates = [
|
||||
__DIR__ . '/../.env',
|
||||
__DIR__ . '/../.env.example',
|
||||
];
|
||||
|
||||
foreach ($envCandidates as $envFile) {
|
||||
if (file_exists($envFile)) {
|
||||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
if ($lines !== false) {
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
// Negeer lege regels en commentaarregels (# of //)
|
||||
if ($line === '' || str_starts_with($line, '#') || str_starts_with($line, '//')) {
|
||||
continue;
|
||||
}
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($name, $value) = explode('=', $line, 2);
|
||||
$name = trim($name);
|
||||
$value = trim($value);
|
||||
// Verwijder omlijstende aanhalingstekens (" of ')
|
||||
$value = trim($value, " \t\n\r\0\x0B\"'");
|
||||
|
||||
// Sla op in array en zet in globale PHP variabelen
|
||||
$envVars[$name] = $value;
|
||||
$_ENV[$name] = $value;
|
||||
$_SERVER[$name] = $value;
|
||||
@putenv("{$name}={$value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
break; // Stop zodra we het eerste geldige bestand hebben ingeladen
|
||||
}
|
||||
}
|
||||
|
||||
// MariaDB Verbindingsgegevens (pas deze aan naar uw server instellingen of gebruik .env)
|
||||
define('DB_HOST', getenv('DB_HOST') ?: '127.0.0.1');
|
||||
define('DB_PORT', getenv('DB_PORT') ?: '3306');
|
||||
define('DB_NAME', getenv('DB_NAME') ?: 'fociz');
|
||||
define('DB_USER', getenv('DB_USER') ?: 'focizlive_user');
|
||||
define('DB_PASS', getenv('DB_PASS') !== false ? getenv('DB_PASS') : 'F0c1z_Live_Secure_2026!');
|
||||
/**
|
||||
* Veilige helper om een omgevingsvariabele op te vragen
|
||||
*/
|
||||
if (!function_exists('fociz_env')) {
|
||||
function fociz_env(string $key, $default = null) {
|
||||
global $envVars;
|
||||
if (isset($envVars[$key]) && $envVars[$key] !== '') {
|
||||
return $envVars[$key];
|
||||
}
|
||||
if (isset($_ENV[$key]) && $_ENV[$key] !== '') {
|
||||
return $_ENV[$key];
|
||||
}
|
||||
if (isset($_SERVER[$key]) && $_SERVER[$key] !== '') {
|
||||
return $_SERVER[$key];
|
||||
}
|
||||
$val = @getenv($key);
|
||||
if ($val !== false && $val !== '') {
|
||||
return $val;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
// MariaDB Verbindingsgegevens (Live defaults voor main branch; overschrijfbaar via server .env)
|
||||
define('DB_HOST', fociz_env('DB_HOST', '192.168.2.33'));
|
||||
define('DB_PORT', fociz_env('DB_PORT', '3306'));
|
||||
define('DB_NAME', fociz_env('DB_NAME', 'fociz'));
|
||||
define('DB_USER', fociz_env('DB_USER', 'focizlive_user'));
|
||||
define('DB_PASS', fociz_env('DB_PASS', 'F0c1z_Live_Secure_2026!'));
|
||||
define('DB_CHARSET', 'utf8mb4');
|
||||
|
||||
// Applicatie instellingen
|
||||
// Applicatie instellingen (Live defaults)
|
||||
define('APP_NAME', 'Fociz');
|
||||
define('APP_URL', getenv('APP_URL') ?: ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'localhost')));
|
||||
define('APP_SECRET', getenv('APP_SECRET') ?: 'fociz-maria-db-super-secret-key-998877');
|
||||
define('APP_URL', fociz_env('APP_URL', ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? 'fociz.nl'))));
|
||||
define('APP_SECRET', fociz_env('APP_SECRET', 'fociz-maria-db-super-secret-key-998877'));
|
||||
define('APP_ENV', fociz_env('APP_ENV', 'live')); // 'live' voor de main branch
|
||||
|
||||
// Tijdzone
|
||||
date_default_timezone_set('Europe/Amsterdam');
|
||||
|
||||
// Foutrapportage: in live verbergen we fouten voor bezoekers
|
||||
if (APP_ENV !== 'live') {
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
} else {
|
||||
ini_set('display_errors', '0');
|
||||
ini_set('display_startup_errors', '0');
|
||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user