Update the config php class.

This commit is contained in:
markjcrane 2015-11-27 19:25:16 -07:00
parent e4d850aa10
commit ddcd8a5f23
1 changed files with 44 additions and 21 deletions

View File

@ -4,12 +4,13 @@
* destinations * destinations
* *
* @method get config.php * @method get config.php
* @method exists check to see if the config.php exists * @method exists determin if the the config.php file exists
* @method exists determin if the the config.php file exists
*/ */
class config { class config {
/** /**
* destinations array * database variables and config path
*/ */
public $db_type; public $db_type;
public $db_name; public $db_name;
@ -18,6 +19,7 @@ class config {
public $db_host; public $db_host;
public $db_path; public $db_path;
public $db_port; public $db_port;
public $config_path;
/** /**
* Called when the object is created * Called when the object is created
@ -47,13 +49,9 @@ class config {
* @var string $db_port - network port to connect to the database * @var string $db_port - network port to connect to the database
*/ */
public function get() { public function get() {
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) { $this->find();
include($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php"); if ($this->exists) {
} elseif (file_exists("/etc/fusionpbx/config.php")) { include($this->path);
include("/etc/fusionpbx/config.php");
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
include("/usr/local/etc/fusionpbx/config.php");
}
$this->db_type = $db_type; $this->db_type = $db_type;
$this->db_name = $db_name; $this->db_name = $db_name;
$this->db_username = $db_username; $this->db_username = $db_username;
@ -62,16 +60,33 @@ class config {
$this->db_path = $db_path; $this->db_path = $db_path;
$this->db_port = $db_port; $this->db_port = $db_port;
} }
}
}
/**
* determine if the config.php exists
* @var string $config_path - full path to the config.php file
*/
public function find() {
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) {
$this->config_path = $_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/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 $this->config_path;
}
/** /**
* Determine whether the config.php exists * Determine whether the config.php exists
*/ */
public function exists() { public function exists() {
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) { $this->find();
return true; if (strlen($this->config_path) > 0) {
} elseif (file_exists("/etc/fusionpbx/config.php")) {
return true;
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
return true; return true;
} }
else { else {
@ -81,8 +96,16 @@ class config {
} }
/* /*
$config = new config; $config = new config;
$config = $config->get;
$config_exists = $config->exists(); $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;
*/ */
?> ?>