@@ -2,14 +2,14 @@ |
||
2 | 2 | jRequire("PdoAdapterMysql.php"); |
3 | 3 | class PdoAdapterSqLiteMemory extends PdoAdapterMysql { |
4 | 4 | public $connection; |
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
5 | + public function __construct($_srv, $_db, $_usr, $_pass) { |
|
6 | 6 | try { |
7 | 7 | $this->connection = new PDO("sqlite::memory:"); |
8 | - } catch( Exception $e ) { |
|
8 | + } catch (Exception $e) { |
|
9 | 9 | throw new JException($e->getMessage()); |
10 | 10 | } |
11 | 11 | } |
12 | - public function newTable( $_sql ) { |
|
12 | + public function newTable($_sql) { |
|
13 | 13 | try { |
14 | 14 | $temp = $this->connection->exec($_sql); |
15 | 15 | } catch (Exception $e) { |
@@ -2,35 +2,35 @@ |
||
2 | 2 | jRequire("ConnectionInterface.php"); |
3 | 3 | class PdoAdapterMysql implements ConnectionAdapterInterface { |
4 | 4 | public $connection; |
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
5 | + public function __construct($_srv, $_db, $_usr, $_pass) { |
|
6 | 6 | try { |
7 | 7 | $connection = "mysql:host=$_srv;dbname=$_db"; |
8 | - $this->connection = new PDO( $connection, $_usr, $_pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"] ); |
|
9 | - } catch( Exception $e ) { |
|
8 | + $this->connection = new PDO($connection, $_usr, $_pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"]); |
|
9 | + } catch (Exception $e) { |
|
10 | 10 | throw new JException($e->getMessage()); |
11 | 11 | } |
12 | 12 | } |
13 | - public function query( $_query ) { |
|
13 | + public function query($_query) { |
|
14 | 14 | $this->stdQuery($_query); |
15 | 15 | return true; |
16 | 16 | } |
17 | - public function queryInsert( $_query ) { |
|
17 | + public function queryInsert($_query) { |
|
18 | 18 | $this->stdQuery($_query); |
19 | 19 | return $this->connection->lastInsertId(); |
20 | 20 | } |
21 | - public function queryFetch( $_query ) { |
|
21 | + public function queryFetch($_query) { |
|
22 | 22 | $temp = $this->stdQuery($_query); |
23 | 23 | return $temp->fetchAll(PDO::FETCH_ASSOC); |
24 | 24 | } |
25 | - public function queryArray( $_query ) { |
|
25 | + public function queryArray($_query) { |
|
26 | 26 | $temp = $this->stdQuery($_query); |
27 | 27 | return $temp->fetchAll(PDO::FETCH_COLUMN, 0); |
28 | 28 | } |
29 | - protected function stdQuery( $_query ) { |
|
29 | + protected function stdQuery($_query) { |
|
30 | 30 | $database = $this->connection; |
31 | 31 | $query = $database->prepare($_query); |
32 | 32 | $result = $query->execute(); |
33 | - if(!$result) |
|
33 | + if (!$result) |
|
34 | 34 | throw new JException(json_encode([ |
35 | 35 | "query" => $_query, |
36 | 36 | "error" => [ |
@@ -2,14 +2,14 @@ |
||
2 | 2 | jRequire("PdoAdapterMysql.php"); |
3 | 3 | class PdoAdapterSqLiteFile extends PdoAdapterMysql { |
4 | 4 | public $connection; |
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
5 | + public function __construct($_srv, $_db, $_usr, $_pass) { |
|
6 | 6 | try { |
7 | 7 | $this->connection = new PDO("sqlite:$_srv"); |
8 | - } catch( Exception $e ) { |
|
8 | + } catch (Exception $e) { |
|
9 | 9 | throw new JException($e->getMessage()); |
10 | 10 | } |
11 | 11 | } |
12 | - public function newTable( $_sql ) { |
|
12 | + public function newTable($_sql) { |
|
13 | 13 | try { |
14 | 14 | $temp = $this->connection->exec($_sql); |
15 | 15 | } catch (Exception $e) { |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | class Connection { |
4 | 4 | public $database; |
5 | 5 | public $info; |
6 | - public function __construct( $_object ) { |
|
7 | - if(!is_object($_object)) |
|
6 | + public function __construct($_object) { |
|
7 | + if (!is_object($_object)) |
|
8 | 8 | throw new JException("Parameter must be an object."); |
9 | 9 | $this->setConnection( |
10 | 10 | $_object->server, |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $this->getConnectionType($_object->engine) |
15 | 15 | ); |
16 | 16 | } |
17 | - protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
17 | + protected function setConnection($_srv, $_db, $_usr, $_pass, $_type) { |
|
18 | 18 | switch ($_type) { |
19 | 19 | case "mysqli": |
20 | 20 | $this->database = new MysqliAdapter($_srv, $_db, $_usr, $_pass); |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | "type" => $_type |
42 | 42 | ]; |
43 | 43 | } |
44 | - protected function getConnectionType( $_type ) { |
|
45 | - $array = (array)$_type; |
|
44 | + protected function getConnectionType($_type) { |
|
45 | + $array = (array) $_type; |
|
46 | 46 | foreach ($array as $key => $value) |
47 | - if($value) |
|
47 | + if ($value) |
|
48 | 48 | return $key; |
49 | 49 | return "default"; |
50 | 50 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | $this->connection = []; |
10 | 10 | $this->currentConnection = null; |
11 | 11 | } |
12 | - public function addConnection( $_path, $_name = "default" ) { |
|
13 | - if(!is_string($_path)) |
|
12 | + public function addConnection($_path, $_name = "default") { |
|
13 | + if (!is_string($_path)) |
|
14 | 14 | throw new JException("Parameter must be a string.", 1); |
15 | 15 | try { |
16 | 16 | $jConfig = new JConfig($_path); |
17 | - if($jConfig->enable) { |
|
17 | + if ($jConfig->enable) { |
|
18 | 18 | $connection = new Connection($jConfig); |
19 | 19 | $this->addConnectionMan($connection, $_name); |
20 | 20 | } |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | throw new JException($e->getMessage(), 1); |
23 | 23 | } |
24 | 24 | } |
25 | - public function addConnectionMan( $_connection, $_name = "default") { |
|
26 | - if(!is_object($_connection) || !is_a($_connection, "Connection")) |
|
25 | + public function addConnectionMan($_connection, $_name = "default") { |
|
26 | + if (!is_object($_connection) || !is_a($_connection, "Connection")) |
|
27 | 27 | throw new JException("Parameter must be a Connection object.", 1); |
28 | 28 | try { |
29 | 29 | $this->connection["$_name"] = $_connection; |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | throw new JException($e->getMessage(), 1); |
33 | 33 | } |
34 | 34 | } |
35 | - public function setConnection( $_name = "default" ) { |
|
36 | - if(!is_string($_name)) |
|
35 | + public function setConnection($_name = "default") { |
|
36 | + if (!is_string($_name)) |
|
37 | 37 | throw new JException("Parameter must be a string.", 1); |
38 | - if(!isset($this->connection["$_name"])) |
|
38 | + if (!isset($this->connection["$_name"])) |
|
39 | 39 | throw new JException("This connection name does not exist.", 1); |
40 | 40 | $this->currentConnection = $this->connection["$_name"]; |
41 | 41 | } |
42 | - public function query( $_query ) { |
|
43 | - if(!is_string($_query)) |
|
42 | + public function query($_query) { |
|
43 | + if (!is_string($_query)) |
|
44 | 44 | throw new JException("Parameter must be a string.", 1); |
45 | - if($this->currentConnection == null) |
|
45 | + if ($this->currentConnection == null) |
|
46 | 46 | throw new JException("No connection selected.", 1); |
47 | 47 | try { |
48 | 48 | $temp = $this->currentConnection->database->query($_query); |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | } |
52 | 52 | return $temp; |
53 | 53 | } |
54 | - public function queryInsert( $_query ) { |
|
55 | - if(!is_string($_query)) |
|
54 | + public function queryInsert($_query) { |
|
55 | + if (!is_string($_query)) |
|
56 | 56 | throw new JException("Parameter must be a string.", 1); |
57 | - if($this->currentConnection == null) |
|
57 | + if ($this->currentConnection == null) |
|
58 | 58 | throw new JException("No connection selected.", 1); |
59 | 59 | try { |
60 | 60 | $temp = $this->currentConnection->database->queryInsert($_query); |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | } |
64 | 64 | return $temp; |
65 | 65 | } |
66 | - public function queryFetch( $_query ) { |
|
67 | - if(!is_string($_query)) |
|
66 | + public function queryFetch($_query) { |
|
67 | + if (!is_string($_query)) |
|
68 | 68 | throw new JException("Parameter must be a string.", 1); |
69 | - if($this->currentConnection == null) |
|
69 | + if ($this->currentConnection == null) |
|
70 | 70 | throw new JException("No connection selected.", 1); |
71 | 71 | try { |
72 | 72 | $temp = $this->currentConnection->database->queryFetch($_query); |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | } |
76 | 76 | return $temp; |
77 | 77 | } |
78 | - public function queryArray( $_query ) { |
|
79 | - if(!is_string($_query)) |
|
78 | + public function queryArray($_query) { |
|
79 | + if (!is_string($_query)) |
|
80 | 80 | throw new JException("Parameter must be a string.", 1); |
81 | - if($this->currentConnection == null) |
|
81 | + if ($this->currentConnection == null) |
|
82 | 82 | throw new JException("No connection selected.", 1); |
83 | 83 | try { |
84 | 84 | $temp = $this->currentConnection->database->queryArray($_query); |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | } |
88 | 88 | return $temp; |
89 | 89 | } |
90 | - public function newTable( $_query ) { |
|
91 | - if(!is_string($_query)) |
|
90 | + public function newTable($_query) { |
|
91 | + if (!is_string($_query)) |
|
92 | 92 | throw new JException("Parameter must be a string.", 1); |
93 | - if($this->currentConnection == null) |
|
93 | + if ($this->currentConnection == null) |
|
94 | 94 | throw new JException("No connection selected.", 1); |
95 | 95 | try { |
96 | 96 | $temp = $this->currentConnection->database->newTable($_query); |
@@ -17,26 +17,26 @@ |
||
17 | 17 | $this->__queryConstruct(); |
18 | 18 | $this->__fileConstruct(); |
19 | 19 | } |
20 | - public function addModules( $_modules ) { |
|
21 | - if(!is_array($_modules)) |
|
20 | + public function addModules($_modules) { |
|
21 | + if (!is_array($_modules)) |
|
22 | 22 | throw new JException("Parameter must be an array."); |
23 | 23 | foreach ($_modules as $value) |
24 | 24 | $this->addModule($value); |
25 | 25 | } |
26 | - public function addModule( $_module ) { |
|
27 | - if(!is_object($_module)) |
|
26 | + public function addModule($_module) { |
|
27 | + if (!is_object($_module)) |
|
28 | 28 | throw new JException("Parameter must be a object."); |
29 | - if(! is_subclass_of ($_module, "Module")) |
|
29 | + if (!is_subclass_of($_module, "Module")) |
|
30 | 30 | throw new JException("Parameter must be a object inherited from Module object."); |
31 | 31 | $this->modules[$_module->name] = $_module; |
32 | - if($this->currentConnection) |
|
32 | + if ($this->currentConnection) |
|
33 | 33 | $this->modules[$_module->name]->addConnectionMan($this->currentConnection); |
34 | 34 | } |
35 | - public function addConnectionMan( $_connection, $_name = "default") { |
|
35 | + public function addConnectionMan($_connection, $_name = "default") { |
|
36 | 36 | try { |
37 | 37 | $this->__addConnectionMan($_connection, $_name); |
38 | 38 | foreach ($this->modules as &$module) |
39 | - if(isset($this->currentConnection)) |
|
39 | + if (isset($this->currentConnection)) |
|
40 | 40 | $module->addConnectionMan($this->currentConnection, $_name); |
41 | 41 | } catch (Exception $e) { |
42 | 42 | throw new JException($e->getMessage(), 1); |