update koneksi DB
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// Muat environment lokal untuk development/XAMPP. File .env tidak boleh di-commit.
|
||||
// Muat environment aplikasi tanpa bergantung pada putenv(). File .env tidak boleh di-commit.
|
||||
$localEnvFile = __DIR__ . DIRECTORY_SEPARATOR . '.env';
|
||||
if (is_file($localEnvFile) && is_readable($localEnvFile)) {
|
||||
foreach (file($localEnvFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $envLine) {
|
||||
@@ -9,7 +9,7 @@ if (is_file($localEnvFile) && is_readable($localEnvFile)) {
|
||||
}
|
||||
|
||||
list($envName, $envValue) = array_map('trim', explode('=', $envLine, 2));
|
||||
if (!preg_match('/^[A-Z][A-Z0-9_]*$/', $envName) || getenv($envName) !== false) {
|
||||
if (!preg_match('/^[A-Z][A-Z0-9_]*$/', $envName) || getenv($envName) !== false || array_key_exists($envName, $_ENV) || array_key_exists($envName, $_SERVER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,50 @@ if (is_file($localEnvFile) && is_readable($localEnvFile)) {
|
||||
$envValue = substr($envValue, 1, -1);
|
||||
}
|
||||
|
||||
putenv($envName . '=' . $envValue);
|
||||
$_ENV[$envName] = $envValue;
|
||||
$_SERVER[$envName] = $envValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('app_env')) {
|
||||
/**
|
||||
* Membaca environment server asli maupun nilai .env yang disimpan pada
|
||||
* superglobal. Tidak memakai putenv(), sehingga kompatibel dengan hosting
|
||||
* yang menonaktifkan fungsi tersebut.
|
||||
*/
|
||||
function app_env($name, $default = null)
|
||||
{
|
||||
$processValue = getenv($name);
|
||||
if ($processValue !== false) {
|
||||
return $processValue;
|
||||
}
|
||||
if (array_key_exists($name, $_ENV)) {
|
||||
return $_ENV[$name];
|
||||
}
|
||||
if (array_key_exists($name, $_SERVER)) {
|
||||
return $_SERVER[$name];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('app_env_all')) {
|
||||
function app_env_all()
|
||||
{
|
||||
$process = getenv();
|
||||
$environment = array();
|
||||
foreach (array($_SERVER, $_ENV, is_array($process) ? $process : array()) as $source) {
|
||||
foreach ($source as $name => $value) {
|
||||
if (!is_string($name) || !preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $name) || !is_scalar($value)) {
|
||||
continue;
|
||||
}
|
||||
$environment[$name] = (string) $value;
|
||||
}
|
||||
}
|
||||
return $environment;
|
||||
}
|
||||
}
|
||||
|
||||
// Composer autoload
|
||||
$composer_autoload = __DIR__ . '/vendor/autoload.php';
|
||||
if (file_exists($composer_autoload)) {
|
||||
|
||||
Reference in New Issue
Block a user