@@ -3,6 +3,10 @@ |
||
| 3 | 3 | class Connection { |
| 4 | 4 | public $database; |
| 5 | 5 | public $info; |
| 6 | + |
|
| 7 | + /** |
|
| 8 | + * @param JConfig $_object |
|
| 9 | + */ |
|
| 6 | 10 | public function __construct( $_object ) { |
| 7 | 11 | if(!is_object($_object)) |
| 8 | 12 | throw new JException("Parameter must be an object."); |
@@ -4,8 +4,9 @@ discard block |
||
| 4 | 4 | public $database; |
| 5 | 5 | public $info; |
| 6 | 6 | public function __construct( $_object ) { |
| 7 | - if(!is_object($_object)) |
|
| 8 | - throw new JException("Parameter must be an object."); |
|
| 7 | + if(!is_object($_object)) { |
|
| 8 | + throw new JException("Parameter must be an object."); |
|
| 9 | + } |
|
| 9 | 10 | $this->setConnection( |
| 10 | 11 | $_object->server, |
| 11 | 12 | $_object->database, |
@@ -40,9 +41,10 @@ discard block |
||
| 40 | 41 | } |
| 41 | 42 | protected function getConnectionType( $_type ) { |
| 42 | 43 | $array = (array)$_type; |
| 43 | - foreach ($array as $key => $value) |
|
| 44 | - if($value) |
|
| 44 | + foreach ($array as $key => $value) { |
|
| 45 | + if($value) |
|
| 45 | 46 | return $key; |
| 47 | + } |
|
| 46 | 48 | return "pdo"; |
| 47 | 49 | } |
| 48 | 50 | } |
@@ -10,8 +10,9 @@ discard block |
||
| 10 | 10 | $this->currentConnection = null; |
| 11 | 11 | } |
| 12 | 12 | public function addConnection( $_path, $_name = "default" ) { |
| 13 | - if(!is_string($_path)) |
|
| 14 | - throw new JException("Parameter must be a string.", 1); |
|
| 13 | + if(!is_string($_path)) { |
|
| 14 | + throw new JException("Parameter must be a string.", 1); |
|
| 15 | + } |
|
| 15 | 16 | try { |
| 16 | 17 | $jConfig = new JConfig($_path); |
| 17 | 18 | if($jConfig->enable) { |
@@ -23,28 +24,33 @@ discard block |
||
| 23 | 24 | } |
| 24 | 25 | } |
| 25 | 26 | public function addConnectionMan( $_connection, $_name = "default") { |
| 26 | - if(!is_object($_connection) || !is_a($_connection, "Connection")) |
|
| 27 | - throw new JException("Parameter must be a Connection object.", 1); |
|
| 27 | + if(!is_object($_connection) || !is_a($_connection, "Connection")) { |
|
| 28 | + throw new JException("Parameter must be a Connection object.", 1); |
|
| 29 | + } |
|
| 28 | 30 | try { |
| 29 | 31 | $this->connection["$_name"] = $_connection; |
| 30 | 32 | $this->currentConnection = $_connection; |
| 31 | - foreach ($this->modules as &$module) |
|
| 32 | - if(isset($this->currentConnection)) |
|
| 33 | + foreach ($this->modules as &$module) { |
|
| 34 | + if(isset($this->currentConnection)) |
|
| 33 | 35 | $module->addConnectionMan($this->currentConnection, $_name); |
| 36 | + } |
|
| 34 | 37 | } catch (Exception $e) { |
| 35 | 38 | throw new JException($e->getMessage(), 1); |
| 36 | 39 | } |
| 37 | 40 | } |
| 38 | 41 | public function setConnection( $_name = "default" ) { |
| 39 | - if(!is_string($_name)) |
|
| 40 | - throw new JException("Parameter must be a string.", 1); |
|
| 41 | - if(!isset($this->connection["$_name"])) |
|
| 42 | - throw new JException("This connection name does not exist.", 1); |
|
| 42 | + if(!is_string($_name)) { |
|
| 43 | + throw new JException("Parameter must be a string.", 1); |
|
| 44 | + } |
|
| 45 | + if(!isset($this->connection["$_name"])) { |
|
| 46 | + throw new JException("This connection name does not exist.", 1); |
|
| 47 | + } |
|
| 43 | 48 | $this->currentConnection = $this->connection["$_name"]; |
| 44 | 49 | } |
| 45 | 50 | public function query( $_query ) { |
| 46 | - if(!is_string($_query)) |
|
| 47 | - throw new JException("Parameter must be a string.", 1); |
|
| 51 | + if(!is_string($_query)) { |
|
| 52 | + throw new JException("Parameter must be a string.", 1); |
|
| 53 | + } |
|
| 48 | 54 | try { |
| 49 | 55 | $temp = $this->currentConnection->database->query($_query); |
| 50 | 56 | } catch (Exception $e) { |
@@ -53,8 +59,9 @@ discard block |
||
| 53 | 59 | return $temp; |
| 54 | 60 | } |
| 55 | 61 | public function queryInsert( $_query ) { |
| 56 | - if(!is_string($_query)) |
|
| 57 | - throw new JException("Parameter must be a string.", 1); |
|
| 62 | + if(!is_string($_query)) { |
|
| 63 | + throw new JException("Parameter must be a string.", 1); |
|
| 64 | + } |
|
| 58 | 65 | try { |
| 59 | 66 | $temp = $this->currentConnection->database->queryInsert($_query); |
| 60 | 67 | } catch (Exception $e) { |
@@ -63,8 +70,9 @@ discard block |
||
| 63 | 70 | return $temp; |
| 64 | 71 | } |
| 65 | 72 | public function queryFetch( $_query ) { |
| 66 | - if(!is_string($_query)) |
|
| 67 | - throw new JException("Parameter must be a string.", 1); |
|
| 73 | + if(!is_string($_query)) { |
|
| 74 | + throw new JException("Parameter must be a string.", 1); |
|
| 75 | + } |
|
| 68 | 76 | try { |
| 69 | 77 | $temp = $this->currentConnection->database->queryFetch($_query); |
| 70 | 78 | } catch (Exception $e) { |
@@ -73,8 +81,9 @@ discard block |
||
| 73 | 81 | return $temp; |
| 74 | 82 | } |
| 75 | 83 | public function queryArray( $_query ) { |
| 76 | - if(!is_string($_query)) |
|
| 77 | - throw new JException("Parameter must be a string.", 1); |
|
| 84 | + if(!is_string($_query)) { |
|
| 85 | + throw new JException("Parameter must be a string.", 1); |
|
| 86 | + } |
|
| 78 | 87 | try { |
| 79 | 88 | $temp = $this->currentConnection->database->queryArray($_query); |
| 80 | 89 | } catch (Exception $e) { |
@@ -83,8 +92,9 @@ discard block |
||
| 83 | 92 | return $temp; |
| 84 | 93 | } |
| 85 | 94 | public function newTable( $_query ) { |
| 86 | - if(!is_string($_query)) |
|
| 87 | - throw new JException("Parameter must be a string.", 1); |
|
| 95 | + if(!is_string($_query)) { |
|
| 96 | + throw new JException("Parameter must be a string.", 1); |
|
| 97 | + } |
|
| 88 | 98 | try { |
| 89 | 99 | $temp = $this->currentConnection->database->newTable($_query); |
| 90 | 100 | } catch (Exception $e) { |