fusionpbx/resources/classes/config.php

111 lines
2.7 KiB
PHP
Raw Normal View History

2015-11-28 02:57:23 +01:00
<?php
/**
* destinations
*
* @method get config.php
2015-11-28 03:25:16 +01:00
* @method exists determin if the the config.php file exists
* @method exists determin if the the config.php file exists
2015-11-28 02:57:23 +01:00
*/
class config {
/**
2015-11-28 03:25:16 +01:00
* database variables and config path
2015-11-28 02:57:23 +01:00
*/
public $db_type;
public $db_name;
public $db_username;
public $db_password;
public $db_host;
public $db_path;
public $db_port;
2015-11-28 03:25:16 +01:00
public $config_path;
2015-11-28 02:57:23 +01:00
/**
* Called when the object is created
*/
public function __construct() {
//place holder
}
/**
* Called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
foreach ($this as $key => $value) {
unset($this->$key);
}
}
/**
* Determine whether the config.php exists
* @var string $db_type - type of database
* @var string $db_name - name of the database
* @var string $db_username - username to access the database
* @var string $db_password - password to access the database
* @var string $db_host - hostname of the database server
* @var string $db_path - path of the database file
* @var string $db_port - network port to connect to the database
*/
public function get() {
2015-11-28 03:25:16 +01:00
$this->find();
if ($this->exists) {
include($this->path);
$this->db_type = $db_type;
$this->db_name = $db_name;
$this->db_username = $db_username;
$this->db_password = $db_password;
$this->db_host = $db_host;
$this->db_path = $db_path;
$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() {
2015-11-28 02:57:23 +01:00
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) {
2015-11-28 03:25:16 +01:00
$this->config_path = $_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php";
2015-11-28 02:57:23 +01:00
} elseif (file_exists("/etc/fusionpbx/config.php")) {
2015-11-28 03:25:16 +01:00
$this->config_path = "/etc/fusionpbx/config.php";
2015-11-28 02:57:23 +01:00
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
2015-11-28 03:25:16 +01:00
$this->config_path = "/usr/local/etc/fusionpbx/config.php";
}
else {
$this->config_path = '';
2015-11-28 02:57:23 +01:00
}
2015-11-28 03:25:16 +01:00
return $this->config_path;
2015-11-28 02:57:23 +01:00
}
/**
* Determine whether the config.php exists
*/
public function exists() {
2015-11-28 03:25:16 +01:00
$this->find();
if (strlen($this->config_path) > 0) {
2015-11-28 02:57:23 +01:00
return true;
}
else {
return false;
}
}
}
/*
$config = new config;
$config_exists = $config->exists();
2015-11-28 03:25:16 +01:00
$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;
2015-11-28 02:57:23 +01:00
*/
?>