Source for file DataBaseConfiguration.php

Documentation is available at DataBaseConfiguration.php

  1. <?php
  2. /*
  3. * This file is part of Sylar.
  4. *
  5. * Sylar is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Sylar is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with Sylar. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @copyright Copyright Sylar Development Team
  19. * @license http://www.gnu.org/licenses/ GNU Public License V2.0
  20. * @see https://launchpad.net/sylar/
  21. * @see http://www.giano-solutions.com
  22. */
  23.  
  24.  
  25. import('sylar.common.db.DataBaseManager');
  26.  
  27.  
  28.  
  29.  
  30. /**
  31. * Db Configuration
  32. * This class contains all informtation needed to connect to the database.
  33. * It's also used from DataBaseDriver to connect to Db.
  34. *
  35. * @package Sylar
  36. * @version 1.0
  37. * @since 27/mar/08
  38. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  39. * @copyright Sylar Development Team
  40. *
  41. * @see Sylar_DataBaseDriver
  42. */
  43. class Sylar_DataBaseConfiguration{
  44. private $sName;
  45. private $sDriver; // the same of Sylar_DataBaseManager
  46. private $sDescription;
  47.  
  48. private $sHost;
  49. private $sSchema;
  50. private $sUsername;
  51. private $sPassword;
  52. function __construct($sName, $aConfig=null){
  53. $this->setName($sName);
  54. if($aConfig){
  55. $this->fillConfigFromArray($aConfig);
  56. }
  57. }
  58.  
  59. function __destruct() {
  60. # nothing to do
  61. }
  62. // Setter and Getter
  63. public function setName($sName){
  64. $this->sName = $sName;
  65. }
  66. public function setDriver($sDriver){
  67. $this->sDriver = $sDriver;
  68. }
  69. public function setDescription($sDescription){
  70. $this->sDescription = $sDescription;
  71. }
  72. public function setHost($sHost){
  73. $this->sHost = $sHost;
  74. }
  75. public function setSchema($sSchema){
  76. $this->sSchema = $sSchema;
  77. }
  78. public function setUsername($sUsername){
  79. $this->sUsername = $sUsername;
  80. }
  81. public function setPassword($sPassword){
  82. $this->sPassword = $sPassword;
  83. }
  84. public function getName(){
  85. return $this->sName;
  86. }
  87. public function getDriver(){
  88. return $this->sDriver;
  89. }
  90. public function getDescription(){
  91. return $this->sDescription;
  92. }
  93. public function getHost(){
  94. return $this->sHost;
  95. }
  96. public function getSchema(){
  97. return $this->sSchema;
  98. }
  99. public function getUsername(){
  100. return $this->sUsername;
  101. }
  102. public function getPassword(){
  103. return $this->sPassword;
  104. }
  105. /**
  106. * Fill configuration
  107. * It fill all configuration data from an array with this field:
  108. * host
  109. * schema
  110. * username
  111. * password
  112. *
  113. * @return void
  114. * @param array $aConfig
  115. */
  116. public function fillConfigFromArray($aConfig){
  117. $this->setHost($aConfig["host"]);
  118. $this->setSchema($aConfig["schema"]);
  119. $this->setUsername($aConfig["username"]);
  120. $this->setPassword($aConfig["password"]);
  121. $this->setDriver($aConfig["driver"]);
  122. // in the future manage the other information like SID in Oracle ecc...
  123. // these informations depends on Driver Value
  124. }
  125. /**
  126. * Check the Db Configuration
  127. * It controls if the configuration is consistent.
  128. * It doesn't test the connection, it only check the params.
  129. *
  130. * @return boolean
  131. */
  132. public function checkConfiguration(){
  133. if(!$this->getHost() || strlen($this->getHost())==0 ){
  134. throw new ExceptionInSylar("Db Host undefined or empty", 1 );
  135. return false;
  136. }
  137. if(!$this->getSchema() || strlen($this->getSchema())==0 ){
  138. throw new ExceptionInSylar("Db Schema undefined or empty", 1 );
  139. return false;
  140. }
  141. if(!$this->getUsername() || strlen($this->getUsername())==0 ){
  142. throw new ExceptionInSylar("Db Username undefined or empty", 1 );
  143. return false;
  144. }
  145. if(!$this->getPassword()){
  146. throw new ExceptionInSylar("Db Password Undefined", 1 );
  147. return false;
  148. }
  149. if(!$this->getDriver() || strlen($this->getDriver()) ==0 ){
  150. throw new ExceptionInSylar("No Driver DB Defined", 1 );
  151. return false;
  152. }
  153. // Verify if the driver exists in the framework
  154. //
  155. $dbManager = new Sylar_DataBaseManager();
  156. if( !$dbManager->driverIsInstalled($this->getDriver()) ){
  157. throw new ExceptionInSylar("Request Db Driver Not Installed in Sylar", 1 );
  158. return false;
  159. }
  160. return true;
  161. }
  162. }
  163. ?>

Documentation generated on Thu, 24 Apr 2008 16:14:13 +0200 by phpDocumentor 1.3.0RC3