refactor: replace hardcoded credentials with env vars
- Use getenv() with RuntimeException for missing required vars - Add .env.example template - Add .env to .gitignore - Fix missing return statement in config array
This commit is contained in:
4
.env.example
Normal file
4
.env.example
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Database configuration
|
||||||
|
DB_DSN=odbc:Driver=FreeTDS; Server=localhost; Port=1218; Database=mydb
|
||||||
|
DB_USER=myuser
|
||||||
|
DB_PASSWORD=changeme
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
vendor
|
vendor
|
||||||
*.lock
|
*.lock
|
||||||
|
.env
|
||||||
|
|||||||
24
config/configuration.local.php
Normal file
24
config/configuration.local.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database configuration - credentials loaded from environment variables
|
||||||
|
*/
|
||||||
|
|
||||||
|
$getEnvOrThrow = function(string $name): string {
|
||||||
|
$value = getenv($name);
|
||||||
|
if ($value === false || $value === '') {
|
||||||
|
throw new \RuntimeException("Environment variable {$name} is not set");
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
};
|
||||||
|
|
||||||
|
return array('db_req' =>
|
||||||
|
array(
|
||||||
|
'driver_class' => '\PDO',
|
||||||
|
'dsn' => $getEnvOrThrow('DB_DSN'),
|
||||||
|
'driver_params' => array(
|
||||||
|
'username' => $getEnvOrThrow('DB_USER'),
|
||||||
|
'password' => $getEnvOrThrow('DB_PASSWORD'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user