@@ -15,7 +15,7 @@ |
||
| 15 | 15 | $dbCredentials = require('database.php'); |
| 16 | 16 | $var = $arguments[0]; |
| 17 | 17 | |
| 18 | - if(array_key_exists($var, $dbCredentials)){ |
|
| 18 | + if (array_key_exists($var, $dbCredentials)) { |
|
| 19 | 19 | return $dbCredentials[$var]; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | public function __call($method, $parameters) |
| 28 | 28 | { |
| 29 | - if($method== 'asArray'){ |
|
| 29 | + if ($method == 'asArray') { |
|
| 30 | 30 | // $obj = new Utils(); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -50,16 +50,16 @@ |
||
| 50 | 50 | return $destination; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Turn the stadClass object to the type of calling Model |
|
| 55 | - * |
|
| 56 | - * @param String $destination |
|
| 57 | - * @param Object $sourceObject |
|
| 58 | - * @return Object $destination |
|
| 59 | - * |
|
| 60 | - * @author RN Kushwaha <[email protected]> |
|
| 61 | - * @since v0.0.5 |
|
| 62 | - */ |
|
| 53 | + /** |
|
| 54 | + * Turn the stadClass object to the type of calling Model |
|
| 55 | + * |
|
| 56 | + * @param String $destination |
|
| 57 | + * @param Object $sourceObject |
|
| 58 | + * @return Object $destination |
|
| 59 | + * |
|
| 60 | + * @author RN Kushwaha <[email protected]> |
|
| 61 | + * @since v0.0.5 |
|
| 62 | + */ |
|
| 63 | 63 | public function turnObjects($destination, $data) |
| 64 | 64 | { |
| 65 | 65 | $destination = new $destination(); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function turnObject($destination, $sourceObject) |
| 29 | 29 | { |
| 30 | 30 | $destination = new $destination(); |
| 31 | - if(is_object($sourceObject)){ |
|
| 31 | + if (is_object($sourceObject)) { |
|
| 32 | 32 | $sourceReflection = new \ReflectionObject($sourceObject); |
| 33 | 33 | $destinationReflection = new \ReflectionObject($destination); |
| 34 | 34 | $sourceProperties = $sourceReflection->getProperties(); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | if ($destinationReflection->hasProperty($name)) { |
| 42 | 42 | $propDest = $destinationReflection->getProperty($name); |
| 43 | 43 | $propDest->setAccessible(true); |
| 44 | - $propDest->setValue($destination,$value); |
|
| 44 | + $propDest->setValue($destination, $value); |
|
| 45 | 45 | } else { |
| 46 | 46 | $destination->$name = $value; |
| 47 | 47 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public function turnObjects($destination, $data) |
| 64 | 64 | { |
| 65 | 65 | $destination = new $destination(); |
| 66 | - if(count($data)){ |
|
| 66 | + if (count($data)) { |
|
| 67 | 67 | $destination->data = json_decode(json_encode($data, true)); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -17,48 +17,48 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class InsertQueryBuilder extends QueryBuilder |
| 19 | 19 | { |
| 20 | - public function buildInsert($table, $obj){ |
|
| 20 | + public function buildInsert($table, $obj) { |
|
| 21 | 21 | $qb = new QueryBuilder(); |
| 22 | 22 | $query = "INSERT INTO ".$table." ("; |
| 23 | - foreach($obj as $key => $val){ |
|
| 24 | - $query.= $qb->quote($key).", "; |
|
| 23 | + foreach ($obj as $key => $val) { |
|
| 24 | + $query .= $qb->quote($key).", "; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | $query = rtrim($query, ", "); |
| 28 | - $query.= ") VALUES "; |
|
| 28 | + $query .= ") VALUES "; |
|
| 29 | 29 | |
| 30 | 30 | return $query; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function buildInsertPlaceholder($rows){ |
|
| 33 | + public function buildInsertPlaceholder($rows) { |
|
| 34 | 34 | $ar = array(); |
| 35 | 35 | $query = "("; |
| 36 | 36 | |
| 37 | - foreach($rows as $key => $val){ |
|
| 37 | + foreach ($rows as $key => $val) { |
|
| 38 | 38 | $ar[$key] = $val; |
| 39 | - $query.= ":".$key.", "; |
|
| 39 | + $query .= ":".$key.", "; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $query = rtrim($query, ", "); |
| 43 | - $query.=") "; |
|
| 43 | + $query .= ") "; |
|
| 44 | 44 | |
| 45 | 45 | return ['query' => $query, 'array' => $ar]; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function buildInsertPlaceholders($rows){ |
|
| 48 | + public function buildInsertPlaceholders($rows) { |
|
| 49 | 49 | $bindAr = array(); |
| 50 | 50 | $query = ""; |
| 51 | 51 | |
| 52 | - foreach($rows as $i => $row){ |
|
| 53 | - $query.="("; |
|
| 54 | - foreach($row as $key => $val){ |
|
| 55 | - $param = ":" . $key . $i; |
|
| 56 | - $query.= $param.", "; |
|
| 52 | + foreach ($rows as $i => $row) { |
|
| 53 | + $query .= "("; |
|
| 54 | + foreach ($row as $key => $val) { |
|
| 55 | + $param = ":".$key.$i; |
|
| 56 | + $query .= $param.", "; |
|
| 57 | 57 | $bindAr[$param] = $val; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $query = rtrim($query, ", "); |
| 61 | - $query.="), "; |
|
| 61 | + $query .= "), "; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $query = rtrim($query, ", "); |
@@ -82,29 +82,29 @@ discard block |
||
| 82 | 82 | $dataToBuild = $rows; |
| 83 | 83 | $methodToCall = 'buildInsertPlaceholder'; |
| 84 | 84 | |
| 85 | - if(is_array($rows) && isset($rows[0]) && is_array($rows[0])){ |
|
| 85 | + if (is_array($rows) && isset($rows[0]) && is_array($rows[0])) { |
|
| 86 | 86 | $dataToBuild = $rows[0]; |
| 87 | 87 | $methodToCall = 'buildInsertPlaceholders'; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $query = $this->buildInsert($table, $dataToBuild); |
| 91 | 91 | $dataRet = $this->$methodToCall($rows); |
| 92 | - $query.= $dataRet['query']; |
|
| 92 | + $query .= $dataRet['query']; |
|
| 93 | 93 | $bindAr = $dataRet['array']; |
| 94 | 94 | |
| 95 | - try{ |
|
| 95 | + try { |
|
| 96 | 96 | $stmt = $db->prepare($qb->queryPrefix($query)); |
| 97 | 97 | |
| 98 | - if(is_array($rows) && isset($rows[0]) && is_array($rows[0])){ |
|
| 99 | - foreach($bindAr as $param => $val){ |
|
| 98 | + if (is_array($rows) && isset($rows[0]) && is_array($rows[0])) { |
|
| 99 | + foreach ($bindAr as $param => $val) { |
|
| 100 | 100 | $stmt->bindValue($param, $val); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $stmt->execute(); |
| 104 | - } else{ |
|
| 104 | + } else { |
|
| 105 | 105 | $stmt->execute($bindAr); |
| 106 | 106 | } |
| 107 | - } catch(Exception $e){ |
|
| 107 | + } catch (Exception $e) { |
|
| 108 | 108 | throw new Exception($e->getMessage()); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | private $qb; |
| 19 | 19 | |
| 20 | - public function __construct(){ |
|
| 20 | + public function __construct() { |
|
| 21 | 21 | $this->qb = new QueryBuilder(); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | foreach ($conditions as $where) { |
| 37 | 37 | $sign = '='; |
| 38 | - if(count($where)==3) { |
|
| 38 | + if (count($where) == 3) { |
|
| 39 | 39 | $sign = $where[1]; |
| 40 | 40 | } |
| 41 | 41 | if ($firstTime) { |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | class WhereQueryParser |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - protected function prepareArrayForWhere($bindKey, $bindVal = null){ |
|
| 16 | + protected function prepareArrayForWhere($bindKey, $bindVal = null) { |
|
| 17 | 17 | $ar = $conditionAr = array(); |
| 18 | 18 | // expecting a string like 'status = :status' |
| 19 | 19 | if ($this->checkWherePrepareUsed($bindKey)) { |
@@ -22,28 +22,28 @@ discard block |
||
| 22 | 22 | $this->qb = new QueryBuilder(); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function createQuery($row){ |
|
| 25 | + public function createQuery($row) { |
|
| 26 | 26 | $ar = []; |
| 27 | - if(isset($row) && isset($row->id) && $row->id > 0 ){ |
|
| 27 | + if (isset($row) && isset($row->id) && $row->id > 0) { |
|
| 28 | 28 | $query = "UPDATE ".$this->table." SET "; |
| 29 | - foreach($row as $key => $val){ |
|
| 29 | + foreach ($row as $key => $val) { |
|
| 30 | 30 | $ar[':'.$key] = $val; |
| 31 | - if($key == 'id') continue; |
|
| 32 | - $query.= $this->qb->quote($key)." =:".$key.","; |
|
| 31 | + if ($key == 'id') continue; |
|
| 32 | + $query .= $this->qb->quote($key)." =:".$key.","; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $query = rtrim($query, ","); |
| 36 | - $query.= " WHERE ".$this->qb->quote('id')."=:id"; |
|
| 36 | + $query .= " WHERE ".$this->qb->quote('id')."=:id"; |
|
| 37 | 37 | |
| 38 | 38 | return ['query' => $query, 'data' => $ar]; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $queryVal = ''; |
| 42 | 42 | $query = "INSERT INTO ".$this->table." ("; |
| 43 | - foreach($row as $key => $val){ |
|
| 44 | - $query.= $this->qb->quote($key).", "; |
|
| 43 | + foreach ($row as $key => $val) { |
|
| 44 | + $query .= $this->qb->quote($key).", "; |
|
| 45 | 45 | $ar[$key] = $val; |
| 46 | - $queryVal.= ":".$key.", "; |
|
| 46 | + $queryVal .= ":".$key.", "; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $query = rtrim($query, ", ").") VALUES (".$queryVal.rtrim($query, ", ").") "; |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | list($query, $data) = $this->createQuery($row); |
| 70 | 70 | |
| 71 | - try{ |
|
| 71 | + try { |
|
| 72 | 72 | $stmt = Connection::get()->prepare($this->qb->queryPrefix($query)); |
| 73 | 73 | $stmt->execute($data); |
| 74 | - } catch(Exception $e){ |
|
| 74 | + } catch (Exception $e) { |
|
| 75 | 75 | throw new Exception($e->getMessage()); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | public function where() |
| 140 | 140 | { |
| 141 | 141 | $args = func_get_args(); |
| 142 | - if(func_num_args()===2){ |
|
| 142 | + if (func_num_args() === 2) { |
|
| 143 | 143 | $this->where = array_merge($this->where, [[$args[0], '=', $args[1]]]); |
| 144 | - } elseif(func_num_args()===3){ |
|
| 144 | + } elseif (func_num_args() === 3) { |
|
| 145 | 145 | $this->where = array_merge($this->where, [[$args[0], $args[1], $args[2]]]); |
| 146 | - } else{ |
|
| 146 | + } else { |
|
| 147 | 147 | throw new Exception('Where parameter contains invalid number of parameters', 1); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | |
| 409 | 409 | $row = $this->first(); |
| 410 | 410 | |
| 411 | - if($row == null ){ |
|
| 411 | + if ($row == null) { |
|
| 412 | 412 | throw new Exception("The record does not exists!"); |
| 413 | 413 | } |
| 414 | 414 | |
@@ -437,9 +437,9 @@ discard block |
||
| 437 | 437 | $qb = new QueryBuilder(); |
| 438 | 438 | $query = "TRUNCATE ".$this->table; |
| 439 | 439 | |
| 440 | - try{ |
|
| 440 | + try { |
|
| 441 | 441 | Connection::get()->query($qb->queryPrefix($query)); |
| 442 | - } catch(Exception $e){ |
|
| 442 | + } catch (Exception $e) { |
|
| 443 | 443 | throw new Exception($e->getMessage()); |
| 444 | 444 | } |
| 445 | 445 | |
@@ -477,14 +477,14 @@ discard block |
||
| 477 | 477 | $query = "UPDATE ".$this->table." SET "; |
| 478 | 478 | $ar = array(); |
| 479 | 479 | |
| 480 | - foreach($row as $key => $val){ |
|
| 480 | + foreach ($row as $key => $val) { |
|
| 481 | 481 | $ar[':'.$key] = $val; |
| 482 | - $query.= $qb->quote($key)." =:".$key.","; |
|
| 482 | + $query .= $qb->quote($key)." =:".$key.","; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | $query = rtrim($query, ","); |
| 486 | 486 | |
| 487 | - try{ |
|
| 487 | + try { |
|
| 488 | 488 | $whereQuery = $wqb->buildAllWhereQuery( |
| 489 | 489 | $this->where, |
| 490 | 490 | $this->whereIn, |
@@ -492,11 +492,11 @@ discard block |
||
| 492 | 492 | $this->whereNull, |
| 493 | 493 | $this->whereNotNull |
| 494 | 494 | ); |
| 495 | - $query.= " ".join(" ", $whereQuery); |
|
| 495 | + $query .= " ".join(" ", $whereQuery); |
|
| 496 | 496 | $stmt = Connection::get()->prepare($qb->queryPrefix($query)); |
| 497 | 497 | $stmt->execute($ar); |
| 498 | 498 | $this->reset(); |
| 499 | - } catch(Exception $e){ |
|
| 499 | + } catch (Exception $e) { |
|
| 500 | 500 | throw new Exception($e->getMessage()); |
| 501 | 501 | } |
| 502 | 502 | |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | $wqb = new WhereQueryBuilder(); |
| 518 | 518 | $query = "DELETE FROM ".$this->table; |
| 519 | 519 | |
| 520 | - try{ |
|
| 520 | + try { |
|
| 521 | 521 | $whereQuery = $wqb->buildAllWhereQuery( |
| 522 | 522 | $this->where, |
| 523 | 523 | $this->whereIn, |
@@ -525,10 +525,10 @@ discard block |
||
| 525 | 525 | $this->whereNull, |
| 526 | 526 | $this->whereNotNull |
| 527 | 527 | ); |
| 528 | - $query.= " ".join(" ", $whereQuery); |
|
| 528 | + $query .= " ".join(" ", $whereQuery); |
|
| 529 | 529 | Connection::get()->query($qb->queryPrefix($query)); |
| 530 | 530 | $this->reset(); |
| 531 | - } catch(Exception $e){ |
|
| 531 | + } catch (Exception $e) { |
|
| 532 | 532 | throw new Exception($e->getMessage()); |
| 533 | 533 | } |
| 534 | 534 | |