find(); //add the document root to the include path $conf = parse_ini_file($config_path); set_include_path($conf['document.root']); //check if the config file exists $config_exists = file_exists($config_path) ? true : false; //set the server variables and define project path constant $_SERVER["DOCUMENT_ROOT"] = $conf['document.root']; $_SERVER["PROJECT_ROOT"] = $conf['document.root']; $_SERVER["PROJECT_PATH"] = $conf['project.path']; if (isset($conf['project.path'])) { $_SERVER["PROJECT_ROOT"] = $conf['document.root'].'/'.$conf['project.path']; if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root'].'/'.$conf['project.path']); } if (!defined('PROJECT_PATH')) { define("PROJECT_PATH", $conf['project.path']); } } else { if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root']); } if (!defined('PROJECT_PATH')) { define("PROJECT_PATH", ''); } } //add the database settings $this->db_type = $conf['database.0.type']; $this->db_name = $conf['database.0.name']; $this->db_username = $conf['database.0.username']; $this->db_password = $conf['database.0.password']; $this->db_sslmode = $conf['database.0.sslmode'] ?? ''; $this->db_secure = $conf['database.0.secure'] ?? ''; $this->db_cert_authority = $conf['database.0.db_cert_authority'] ?? ''; $this->db_host = $conf['database.0.host']; $this->db_path = $conf['database.0.path'] ?? ''; $this->db_port = $conf['database.0.port']; } /** * Find the path to the config.php * @var string $config_path - full path to the config.php file */ public function find() { //find the file if (file_exists("/etc/fusionpbx/config.conf")) { $this->config_path = "/etc/fusionpbx/config.conf"; } elseif (file_exists("/usr/local/etc/fusionpbx/config.conf")) { $this->config_path = "/usr/local/etc/fusionpbx/config.conf"; } elseif (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) { $this->config_path = $_SERVER["PROJECT_ROOT"]."/resources/config.php"; } elseif (file_exists("/etc/fusionpbx/config.php")) { $this->config_path = "/etc/fusionpbx/config.php"; } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { $this->config_path = "/usr/local/etc/fusionpbx/config.php"; } else { $this->config_path = ''; } //return the path return $this->config_path; } /** * Determine whether the config file exists */ public function exists() { $this->find(); if (!empty($this->config_path)) { return true; } else { return false; } } } /* $config = new config; $config_exists = $config->exists(); $config_path = $config->find(); $config->get(); $db_type = $config->db_type; $db_name = $config->db_name; $db_username = $config->db_username; $db_password = $config->db_password; $db_host = $config->db_host; $db_path = $config->db_path; $db_port = $config->db_port; echo "config_path: ".$config_path."\n"; if ($config_exists) { echo "config_exists: true\n"; } else { echo "config_exists: false\n"; } echo "db_type: ".$db_type."\n"; echo "db_name: ".$db_name."\n"; echo "db_username: ".$db_username."\n"; echo "db_password: ".$db_password."\n"; echo "db_host: ".$db_host."\n"; echo "db_path: ".$db_path."\n"; echo "db_port: ".$db_port."\n"; */ ?>