load(); $loaded = true; } } } if (!function_exists('get_env')) { /** * Gets an environment variable with a default value * * @param string $key Variable name * @param mixed $default Default value if not exists * @return mixed */ function get_env(string $key, $default = null) { return $_ENV[$key] ?? $_SERVER[$key] ?? $default; } } if (!function_exists('env')) { /** * Alias for get_env to maintain compatibility * * @param string $key Variable name * @param mixed $default Default value if not exists * @return mixed */ function env(string $key, $default = null) { return get_env($key, $default); } } if (!function_exists('env_bool')) { /** * Gets an environment variable as boolean * * @param string $key Variable name * @param bool $default Default value if not exists * @return bool */ function env_bool(string $key, bool $default = false): bool { $value = get_env($key, $default); if (is_bool($value)) { return $value; } return filter_var($value, FILTER_VALIDATE_BOOLEAN); } } if (!function_exists('env_int')) { /** * Gets an environment variable as integer * * @param string $key Variable name * @param int $default Default value if not exists * @return int */ function env_int(string $key, int $default = 0): int { return (int) get_env($key, $default); } } if (!function_exists('get_db_config')) { /** * Gets database configuration from environment variables * * @return array */ function get_db_config(): array { return [ 'driver' => get_env('DB_DRIVER', get_env('DB_CONNECTION', 'mysql')), 'host' => get_env('DB_HOST', 'localhost'), 'port' => get_env('DB_PORT', '3306'), 'database' => get_env('DB_DATABASE', 'syscms'), 'username' => get_env('DB_USERNAME', 'root'), 'password' => get_env('DB_PASSWORD', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', ]; } } if (!function_exists('get_app_config')) { /** * Gets application configuration from environment variables * * @return array */ function get_app_config(): array { return [ 'name' => get_env('APP_NAME', 'SysCMS'), 'env' => get_env('APP_ENV', 'development'), 'debug' => env_bool('APP_DEBUG', true), 'url' => get_env('APP_URL', 'http://localhost:16240'), 'timezone' => get_env('APP_TIMEZONE', 'America/Sao_Paulo'), 'key' => get_env('APP_KEY', ''), ]; } } if (!function_exists('get_mail_config')) { /** * Gets email configuration from environment variables * * @return array */ function get_mail_config(): array { return [ 'transport' => get_env('MAIL_TRANSPORT', 'smtp'), 'host' => get_env('MAIL_HOST', 'localhost'), 'port' => get_env('MAIL_PORT', '587'), 'username' => get_env('MAIL_USERNAME', ''), 'password' => get_env('MAIL_PASSWORD', ''), 'encryption' => get_env('MAIL_ENCRYPTION', 'tls'), 'from_address' => get_env('MAIL_FROM_ADDRESS', ''), 'from_name' => get_env('MAIL_FROM_NAME', 'SysCMS'), ]; } }