@@ -128,8 +128,7 @@ discard block |
||
| 128 | 128 | $logger->info('Delete config item ['.$item.']'); |
| 129 | 129 | unset(self::$config[$item]); |
| 130 | 130 | return true; |
| 131 | - } |
|
| 132 | - else{ |
|
| 131 | + } else{ |
|
| 133 | 132 | $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
| 134 | 133 | return false; |
| 135 | 134 | } |
@@ -156,15 +155,13 @@ discard block |
||
| 156 | 155 | //check if the server is running under IPv6 |
| 157 | 156 | if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
| 158 | 157 | $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
| 159 | - } |
|
| 160 | - else{ |
|
| 158 | + } else{ |
|
| 161 | 159 | $baseUrl = $_SERVER['SERVER_ADDR']; |
| 162 | 160 | } |
| 163 | 161 | $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
| 164 | 162 | $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
| 165 | 163 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
| 166 | - } |
|
| 167 | - else{ |
|
| 164 | + } else{ |
|
| 168 | 165 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
| 169 | 166 | $baseUrl = 'http://localhost/'; |
| 170 | 167 | } |
@@ -59,8 +59,7 @@ discard block |
||
| 59 | 59 | if(! isset($this->listeners[$eventName])){ |
| 60 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
| 61 | 61 | $this->listeners[$eventName] = array(); |
| 62 | - } |
|
| 63 | - else{ |
|
| 62 | + } else{ |
|
| 64 | 63 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
| 65 | 64 | } |
| 66 | 65 | $this->listeners[$eventName][] = $listener; |
@@ -78,12 +77,10 @@ discard block |
||
| 78 | 77 | if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
| 79 | 78 | $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
| 80 | 79 | unset($this->listeners[$eventName][$index]); |
| 81 | - } |
|
| 82 | - else{ |
|
| 80 | + } else{ |
|
| 83 | 81 | $this->logger->info('Cannot found this listener in the event listener list'); |
| 84 | 82 | } |
| 85 | - } |
|
| 86 | - else{ |
|
| 83 | + } else{ |
|
| 87 | 84 | $this->logger->info('This event does not have this listener ignore remove'); |
| 88 | 85 | } |
| 89 | 86 | } |
@@ -98,8 +95,7 @@ discard block |
||
| 98 | 95 | if($eventName !== null && isset($this->listeners[$eventName])){ |
| 99 | 96 | $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event'); |
| 100 | 97 | unset($this->listeners[$eventName]); |
| 101 | - } |
|
| 102 | - else{ |
|
| 98 | + } else{ |
|
| 103 | 99 | $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener'); |
| 104 | 100 | $this->listeners = array(); |
| 105 | 101 | } |
@@ -132,8 +128,7 @@ discard block |
||
| 132 | 128 | if($event->returnBack){ |
| 133 | 129 | $this->logger->info('This event need return back, return the result for future use'); |
| 134 | 130 | return $this->dispatchToListerners($event); |
| 135 | - } |
|
| 136 | - else{ |
|
| 131 | + } else{ |
|
| 137 | 132 | $this->logger->info('This event no need return back the result, just dispatch it'); |
| 138 | 133 | $this->dispatchToListerners($event); |
| 139 | 134 | } |
@@ -153,8 +148,7 @@ discard block |
||
| 153 | 148 | return $event; |
| 154 | 149 | } |
| 155 | 150 | return; |
| 156 | - } |
|
| 157 | - else{ |
|
| 151 | + } else{ |
|
| 158 | 152 | $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
| 159 | 153 | } |
| 160 | 154 | foreach($list as $listener){ |
@@ -162,12 +156,10 @@ discard block |
||
| 162 | 156 | $returnedEvent = call_user_func_array($listener, array($event)); |
| 163 | 157 | if($returnedEvent instanceof EventInfo){ |
| 164 | 158 | $event = $returnedEvent; |
| 165 | - } |
|
| 166 | - else{ |
|
| 159 | + } else{ |
|
| 167 | 160 | show_error('This event [' .$event->name. '] need you return the event object after processing'); |
| 168 | 161 | } |
| 169 | - } |
|
| 170 | - else{ |
|
| 162 | + } else{ |
|
| 171 | 163 | call_user_func_array($listener, array($event)); |
| 172 | 164 | } |
| 173 | 165 | if($event->stop){ |
@@ -204,14 +204,12 @@ discard block |
||
| 204 | 204 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
| 205 | 205 | $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
| 206 | 206 | return true; |
| 207 | - } |
|
| 208 | - catch (PDOException $e){ |
|
| 207 | + } catch (PDOException $e){ |
|
| 209 | 208 | $this->logger->fatal($e->getMessage()); |
| 210 | 209 | show_error('Cannot connect to Database.'); |
| 211 | 210 | return false; |
| 212 | 211 | } |
| 213 | - } |
|
| 214 | - else{ |
|
| 212 | + } else{ |
|
| 215 | 213 | show_error('Database configuration is not set.'); |
| 216 | 214 | return false; |
| 217 | 215 | } |
@@ -229,8 +227,7 @@ discard block |
||
| 229 | 227 | $froms .= $this->prefix . $key . ', '; |
| 230 | 228 | } |
| 231 | 229 | $this->from = rtrim($froms, ', '); |
| 232 | - } |
|
| 233 | - else{ |
|
| 230 | + } else{ |
|
| 234 | 231 | $this->from = $this->prefix . $table; |
| 235 | 232 | } |
| 236 | 233 | return $this; |
@@ -336,8 +333,7 @@ discard block |
||
| 336 | 333 | } |
| 337 | 334 | if (empty($this->join)){ |
| 338 | 335 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 339 | - } |
|
| 340 | - else{ |
|
| 336 | + } else{ |
|
| 341 | 337 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 342 | 338 | } |
| 343 | 339 | return $this; |
@@ -408,12 +404,10 @@ discard block |
||
| 408 | 404 | foreach($field as $f){ |
| 409 | 405 | $this->whereIsNull($f, $andOr); |
| 410 | 406 | } |
| 411 | - } |
|
| 412 | - else{ |
|
| 407 | + } else{ |
|
| 413 | 408 | if (! $this->where){ |
| 414 | 409 | $this->where = $field.' IS NULL '; |
| 415 | - } |
|
| 416 | - else{ |
|
| 410 | + } else{ |
|
| 417 | 411 | $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
| 418 | 412 | } |
| 419 | 413 | } |
@@ -431,12 +425,10 @@ discard block |
||
| 431 | 425 | foreach($field as $f){ |
| 432 | 426 | $this->whereIsNotNull($f, $andOr); |
| 433 | 427 | } |
| 434 | - } |
|
| 435 | - else{ |
|
| 428 | + } else{ |
|
| 436 | 429 | if (! $this->where){ |
| 437 | 430 | $this->where = $field.' IS NOT NULL '; |
| 438 | - } |
|
| 439 | - else{ |
|
| 431 | + } else{ |
|
| 440 | 432 | $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
| 441 | 433 | } |
| 442 | 434 | } |
@@ -494,8 +486,7 @@ discard block |
||
| 494 | 486 | $op = ''; |
| 495 | 487 | } |
| 496 | 488 | $w = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
| 497 | - } |
|
| 498 | - else{ |
|
| 489 | + } else{ |
|
| 499 | 490 | if(is_null($val)){ |
| 500 | 491 | $val = ''; |
| 501 | 492 | } |
@@ -512,12 +503,10 @@ discard block |
||
| 512 | 503 | protected function setWhereStr($whereStr, $andOr = 'AND'){ |
| 513 | 504 | if (empty($this->where)){ |
| 514 | 505 | $this->where = $whereStr; |
| 515 | - } |
|
| 516 | - else{ |
|
| 506 | + } else{ |
|
| 517 | 507 | if(substr($this->where, -1) == '('){ |
| 518 | 508 | $this->where = $this->where . ' ' . $whereStr; |
| 519 | - } |
|
| 520 | - else{ |
|
| 509 | + } else{ |
|
| 521 | 510 | $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
| 522 | 511 | } |
| 523 | 512 | } |
@@ -537,8 +526,7 @@ discard block |
||
| 537 | 526 | $whereStr = ''; |
| 538 | 527 | if (is_array($where)){ |
| 539 | 528 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 540 | - } |
|
| 541 | - else{ |
|
| 529 | + } else{ |
|
| 542 | 530 | if(is_array($op)){ |
| 543 | 531 | $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
| 544 | 532 | } else { |
@@ -586,12 +574,10 @@ discard block |
||
| 586 | 574 | public function groupStart($type = '', $andOr = ' AND'){ |
| 587 | 575 | if (empty($this->where)){ |
| 588 | 576 | $this->where = $type . ' ('; |
| 589 | - } |
|
| 590 | - else{ |
|
| 577 | + } else{ |
|
| 591 | 578 | if(substr($this->where, -1) == '('){ |
| 592 | 579 | $this->where .= $type . ' ('; |
| 593 | - } |
|
| 594 | - else{ |
|
| 580 | + } else{ |
|
| 595 | 581 | $this->where .= $andOr . ' ' . $type . ' ('; |
| 596 | 582 | } |
| 597 | 583 | } |
@@ -749,12 +735,10 @@ discard block |
||
| 749 | 735 | $like = $escape ? $this->escape($data) : $data; |
| 750 | 736 | if (empty($this->where)){ |
| 751 | 737 | $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
| 752 | - } |
|
| 753 | - else{ |
|
| 738 | + } else{ |
|
| 754 | 739 | if(substr($this->where, -1) == '('){ |
| 755 | 740 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
| 756 | - } |
|
| 757 | - else{ |
|
| 741 | + } else{ |
|
| 758 | 742 | $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
| 759 | 743 | } |
| 760 | 744 | } |
@@ -801,8 +785,7 @@ discard block |
||
| 801 | 785 | } |
| 802 | 786 | if (! is_null($limitEnd)){ |
| 803 | 787 | $this->limit = $limit . ', ' . $limitEnd; |
| 804 | - } |
|
| 805 | - else{ |
|
| 788 | + } else{ |
|
| 806 | 789 | $this->limit = $limit; |
| 807 | 790 | } |
| 808 | 791 | return $this; |
@@ -817,12 +800,10 @@ discard block |
||
| 817 | 800 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
| 818 | 801 | if (! empty($orderDir)){ |
| 819 | 802 | $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
| 820 | - } |
|
| 821 | - else{ |
|
| 803 | + } else{ |
|
| 822 | 804 | if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
| 823 | 805 | $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 824 | - } |
|
| 825 | - else{ |
|
| 806 | + } else{ |
|
| 826 | 807 | $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
| 827 | 808 | } |
| 828 | 809 | } |
@@ -837,8 +818,7 @@ discard block |
||
| 837 | 818 | public function groupBy($field){ |
| 838 | 819 | if(is_array($field)){ |
| 839 | 820 | $this->groupBy = implode(', ', $field); |
| 840 | - } |
|
| 841 | - else{ |
|
| 821 | + } else{ |
|
| 842 | 822 | $this->groupBy = $field; |
| 843 | 823 | } |
| 844 | 824 | return $this; |
@@ -865,14 +845,12 @@ discard block |
||
| 865 | 845 | } |
| 866 | 846 | } |
| 867 | 847 | $this->having = $w; |
| 868 | - } |
|
| 869 | - else if (! in_array($op, $this->operatorList)){ |
|
| 848 | + } else if (! in_array($op, $this->operatorList)){ |
|
| 870 | 849 | if(is_null($op)){ |
| 871 | 850 | $op = ''; |
| 872 | 851 | } |
| 873 | 852 | $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
| 874 | - } |
|
| 875 | - else{ |
|
| 853 | + } else{ |
|
| 876 | 854 | if(is_null($val)){ |
| 877 | 855 | $val = ''; |
| 878 | 856 | } |
@@ -917,8 +895,7 @@ discard block |
||
| 917 | 895 | $query = $this->getAll(true); |
| 918 | 896 | if($returnSQLQueryOrResultType === true){ |
| 919 | 897 | return $query; |
| 920 | - } |
|
| 921 | - else{ |
|
| 898 | + } else{ |
|
| 922 | 899 | return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
| 923 | 900 | } |
| 924 | 901 | } |
@@ -957,8 +934,7 @@ discard block |
||
| 957 | 934 | |
| 958 | 935 | if($returnSQLQueryOrResultType === true){ |
| 959 | 936 | return $query; |
| 960 | - } |
|
| 961 | - else{ |
|
| 937 | + } else{ |
|
| 962 | 938 | return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
| 963 | 939 | } |
| 964 | 940 | } |
@@ -976,8 +952,7 @@ discard block |
||
| 976 | 952 | $columns = array_keys($this->getData()); |
| 977 | 953 | $column = implode(',', $columns); |
| 978 | 954 | $val = implode(', ', $this->getData()); |
| 979 | - } |
|
| 980 | - else{ |
|
| 955 | + } else{ |
|
| 981 | 956 | $columns = array_keys($data); |
| 982 | 957 | $column = implode(',', $columns); |
| 983 | 958 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -992,8 +967,7 @@ discard block |
||
| 992 | 967 | } |
| 993 | 968 | $this->insertId = $this->pdo->lastInsertId(); |
| 994 | 969 | return $this->insertId(); |
| 995 | - } |
|
| 996 | - else{ |
|
| 970 | + } else{ |
|
| 997 | 971 | return false; |
| 998 | 972 | } |
| 999 | 973 | } |
@@ -1011,8 +985,7 @@ discard block |
||
| 1011 | 985 | foreach ($this->getData() as $column => $val){ |
| 1012 | 986 | $values[] = $column . ' = ' . $val; |
| 1013 | 987 | } |
| 1014 | - } |
|
| 1015 | - else{ |
|
| 988 | + } else{ |
|
| 1016 | 989 | foreach ($data as $column => $val){ |
| 1017 | 990 | $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
| 1018 | 991 | } |
@@ -1106,14 +1079,12 @@ discard block |
||
| 1106 | 1079 | $cacheKey = md5($query . $all . $array); |
| 1107 | 1080 | if(is_object($this->cacheInstance)){ |
| 1108 | 1081 | $cacheInstance = $this->cacheInstance; |
| 1109 | - } |
|
| 1110 | - else{ |
|
| 1082 | + } else{ |
|
| 1111 | 1083 | $obj = & get_instance(); |
| 1112 | 1084 | $cacheInstance = $obj->cache; |
| 1113 | 1085 | } |
| 1114 | 1086 | $cacheContent = $cacheInstance->get($cacheKey); |
| 1115 | - } |
|
| 1116 | - else{ |
|
| 1087 | + } else{ |
|
| 1117 | 1088 | $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database'); |
| 1118 | 1089 | } |
| 1119 | 1090 | |
@@ -1127,8 +1098,7 @@ discard block |
||
| 1127 | 1098 | $bench = null; |
| 1128 | 1099 | if(is_object($this->benchmarkInstance)){ |
| 1129 | 1100 | $bench = $this->benchmarkInstance; |
| 1130 | - } |
|
| 1131 | - else{ |
|
| 1101 | + } else{ |
|
| 1132 | 1102 | $obj = & get_instance(); |
| 1133 | 1103 | $bench = $obj->benchmark; |
| 1134 | 1104 | } |
@@ -1146,15 +1116,13 @@ discard block |
||
| 1146 | 1116 | //if need return all result like list of record |
| 1147 | 1117 | if ($all){ |
| 1148 | 1118 | $this->result = ($array === false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
| 1149 | - } |
|
| 1150 | - else{ |
|
| 1119 | + } else{ |
|
| 1151 | 1120 | $this->result = ($array === false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
| 1152 | 1121 | } |
| 1153 | 1122 | //Sqlite and pgsql always return 0 when using rowCount() |
| 1154 | 1123 | if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){ |
| 1155 | 1124 | $this->numRows = count($this->result); |
| 1156 | - } |
|
| 1157 | - else{ |
|
| 1125 | + } else{ |
|
| 1158 | 1126 | $this->numRows = $sqlQuery->rowCount(); |
| 1159 | 1127 | } |
| 1160 | 1128 | |
@@ -1162,23 +1130,20 @@ discard block |
||
| 1162 | 1130 | $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
| 1163 | 1131 | $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
| 1164 | 1132 | } |
| 1165 | - } |
|
| 1166 | - else{ |
|
| 1133 | + } else{ |
|
| 1167 | 1134 | $error = $this->pdo->errorInfo(); |
| 1168 | 1135 | $this->error = isset($error[2]) ? $error[2] : ''; |
| 1169 | 1136 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
| 1170 | 1137 | $this->error(); |
| 1171 | 1138 | } |
| 1172 | - } |
|
| 1173 | - else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
| 1139 | + } else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
| 1174 | 1140 | $queryStr = $this->pdo->query($this->query); |
| 1175 | 1141 | if($queryStr){ |
| 1176 | 1142 | //Sqlite and pgsql always return 0 when using rowCount() |
| 1177 | 1143 | if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){ |
| 1178 | 1144 | $this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE |
| 1179 | 1145 | $this->numRows = 1; |
| 1180 | - } |
|
| 1181 | - else{ |
|
| 1146 | + } else{ |
|
| 1182 | 1147 | $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
| 1183 | 1148 | $this->numRows = $queryStr->rowCount(); |
| 1184 | 1149 | } |
@@ -1189,8 +1154,7 @@ discard block |
||
| 1189 | 1154 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
| 1190 | 1155 | $this->error(); |
| 1191 | 1156 | } |
| 1192 | - } |
|
| 1193 | - else{ |
|
| 1157 | + } else{ |
|
| 1194 | 1158 | $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
| 1195 | 1159 | $this->result = $cacheContent; |
| 1196 | 1160 | $this->numRows = count($this->result); |
@@ -1382,8 +1346,7 @@ discard block |
||
| 1382 | 1346 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
| 1383 | 1347 | if($logger !== null){ |
| 1384 | 1348 | $this->logger = $logger; |
| 1385 | - } |
|
| 1386 | - else{ |
|
| 1349 | + } else{ |
|
| 1387 | 1350 | $this->logger =& class_loader('Log', 'classes'); |
| 1388 | 1351 | $this->logger->setLogger('Library::Database'); |
| 1389 | 1352 | } |
@@ -115,8 +115,7 @@ |
||
| 115 | 115 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
| 116 | 116 | if($logger !== null){ |
| 117 | 117 | $this->logger = $logger; |
| 118 | - } |
|
| 119 | - else{ |
|
| 118 | + } else{ |
|
| 120 | 119 | $this->logger =& class_loader('Log', 'classes'); |
| 121 | 120 | $this->logger->setLogger('MainController'); |
| 122 | 121 | } |