<?php
if ( defined( 'WP_CLI' ) ) {
    $_SERVER['HTTP_HOST'] = 'localhost';
}

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

if (isset($_SERVER['HTTP_HOST'])) {
    $http_protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
    define('WP_HOME', $http_protocol . '://' . $_SERVER['HTTP_HOST']);
    define('WP_SITEURL', $http_protocol . '://' . $_SERVER['HTTP_HOST']);
}

/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the website, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
 *
 * @package WordPress
 */

// ** Database settings - You can get this info from your web host ** //
if ( file_exists( __DIR__ . '/db/config.php' ) ) {
    require_once __DIR__ . '/db/config.php';
}

/** The name of the database for WordPress */
if ( ! defined( 'DB_NAME' ) ) {
    define( 'DB_NAME', getenv( 'DB_NAME' ) ?: '' );
}

/** Database username */
if ( ! defined( 'DB_USER' ) ) {
    define( 'DB_USER', getenv( 'DB_USER' ) ?: '' );
}

/** Database password */
if ( ! defined( 'DB_PASSWORD' ) ) {
    if ( defined( 'DB_PASS' ) ) {
        define( 'DB_PASSWORD', DB_PASS );
    } else {
        define( 'DB_PASSWORD', getenv( 'DB_PASS' ) ?: ( getenv( 'DB_PASSWORD' ) ?: '' ) );
    }
}

/** Database hostname */
if ( ! defined( 'DB_HOST' ) ) {
    define( 'DB_HOST', getenv( 'DB_HOST' ) ?: '127.0.0.1' );
}
