config.php 3.3 KB

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