config.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * config
  4. *
  5. * @method get config.php
  6. * @method find find the path to the config.php file
  7. * @method exists determin if the the config.php file exists
  8. */
  9. class config {
  10. /**
  11. * database variables and config path
  12. */
  13. public $db_type;
  14. public $db_name;
  15. public $db_username;
  16. public $db_password;
  17. public $db_host;
  18. public $db_path;
  19. public $db_port;
  20. public $config_path;
  21. /**
  22. * Called when the object is created
  23. */
  24. public function __construct() {
  25. //place holder
  26. }
  27. /**
  28. * Called when there are no references to a particular object
  29. * unset the variables used in the class
  30. */
  31. public function __destruct() {
  32. foreach ($this as $key => $value) {
  33. unset($this->$key);
  34. }
  35. }
  36. /**
  37. * Determine whether the config.php exists
  38. * @var string $db_type - type of database
  39. * @var string $db_name - name of the database
  40. * @var string $db_username - username to access the database
  41. * @var string $db_password - password to access the database
  42. * @var string $db_host - hostname of the database server
  43. * @var string $db_path - path of the database file
  44. * @var string $db_port - network port to connect to the database
  45. */
  46. public function get() {
  47. $this->find();
  48. if ($this->exists()) {
  49. require $this->config_path;
  50. $this->db_type = $db_type;
  51. $this->db_name = $db_name;
  52. $this->db_username = $db_username;
  53. $this->db_password = $db_password;
  54. $this->db_host = $db_host;
  55. $this->db_path = $db_path;
  56. $this->db_port = $db_port;
  57. }
  58. }
  59. /**
  60. * Find the path to the config.php
  61. * @var string $config_path - full path to the config.php file
  62. */
  63. public function find() {
  64. //get the PROJECT PATH
  65. include "root.php";
  66. // find the file
  67. if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
  68. $this->config_path = $_SERVER["PROJECT_ROOT"]."/resources/config.php";
  69. } elseif (file_exists("/etc/fusionpbx/config.php")) {
  70. $this->config_path = "/etc/fusionpbx/config.php";
  71. } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
  72. $this->config_path = "/usr/local/etc/fusionpbx/config.php";
  73. }
  74. else {
  75. $this->config_path = '';
  76. }
  77. //return the path
  78. return $this->config_path;
  79. }
  80. /**
  81. * Determine whether the config.php exists
  82. */
  83. public function exists() {
  84. $this->find();
  85. if (strlen($this->config_path) > 0) {
  86. return true;
  87. }
  88. else {
  89. return false;
  90. }
  91. }
  92. }
  93. /*
  94. $config = new config;
  95. $config_exists = $config->exists();
  96. $config_path = $config->find();
  97. $config->get();
  98. $db_type = $config->db_type;
  99. $db_name = $config->db_name;
  100. $db_username = $config->db_username;
  101. $db_password = $config->db_password;
  102. $db_host = $config->db_host;
  103. $db_path = $config->db_path;
  104. $db_port = $config->db_port;
  105. echo "config_path: ".$config_path."\n";
  106. if ($config_exists) {
  107. echo "config_exists: true\n";
  108. } else {
  109. echo "config_exists: false\n";
  110. }
  111. echo "db_type: ".$db_type."\n";
  112. echo "db_name: ".$db_name."\n";
  113. echo "db_username: ".$db_username."\n";
  114. echo "db_password: ".$db_password."\n";
  115. echo "db_host: ".$db_host."\n";
  116. echo "db_path: ".$db_path."\n";
  117. echo "db_port: ".$db_port."\n";
  118. */
  119. ?>