@@ -35,23 +35,23 @@ |
||
| 35 | 35 | /** |
| 36 | 36 | * Initialise the module list by scanning the directory MODULE_PATH |
| 37 | 37 | */ |
| 38 | - public function init(){ |
|
| 38 | + public function init() { |
|
| 39 | 39 | $logger = self::getLogger(); |
| 40 | 40 | $logger->debug('Check if the application contains the modules ...'); |
| 41 | 41 | $moduleDir = opendir(MODULE_PATH); |
| 42 | - if (is_resource($moduleDir)){ |
|
| 43 | - while(($module = readdir($moduleDir)) !== false){ |
|
| 44 | - if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
| 42 | + if (is_resource($moduleDir)) { |
|
| 43 | + while (($module = readdir($moduleDir)) !== false) { |
|
| 44 | + if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
| 45 | 45 | self::$list[] = $module; |
| 46 | - } else{ |
|
| 47 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
| 46 | + } else { |
|
| 47 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | closedir($moduleDir); |
| 51 | 51 | } |
| 52 | 52 | ksort(self::$list); |
| 53 | 53 | |
| 54 | - if (! empty(self::$list)){ |
|
| 54 | + if (!empty(self::$list)) { |
|
| 55 | 55 | $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | $expire = get_config('csrf_expire', 60); |
| 39 | 39 | $keyExpire = 'csrf_expire'; |
| 40 | 40 | $currentTime = time(); |
| 41 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
| 41 | + if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) { |
|
| 42 | 42 | $logger->info('The CSRF token not yet expire just return it'); |
| 43 | 43 | return Session::get($key); |
| 44 | - } else{ |
|
| 44 | + } else { |
|
| 45 | 45 | $newTime = $currentTime + $expire; |
| 46 | 46 | $token = sha1(uniqid()) . sha1(uniqid()); |
| 47 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
| 47 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']'); |
|
| 48 | 48 | Session::set($keyExpire, $newTime); |
| 49 | 49 | Session::set($key, $token); |
| 50 | 50 | return Session::get($key); |
@@ -87,23 +87,23 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * This method is used to check the whitelist IP address access |
| 89 | 89 | */ |
| 90 | - public static function checkWhiteListIpAccess(){ |
|
| 90 | + public static function checkWhiteListIpAccess() { |
|
| 91 | 91 | $logger = self::getLogger(); |
| 92 | 92 | $logger->debug('Validation of the IP address access ...'); |
| 93 | 93 | $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
| 94 | 94 | $isEnable = get_config('white_list_ip_enable', false); |
| 95 | - if($isEnable){ |
|
| 95 | + if ($isEnable) { |
|
| 96 | 96 | $logger->info('Whitelist IP access is enabled in the configuration'); |
| 97 | 97 | $list = get_config('white_list_ip_addresses', array()); |
| 98 | - if(! empty($list)){ |
|
| 98 | + if (!empty($list)) { |
|
| 99 | 99 | //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
| 100 | 100 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
| 101 | 101 | $ip = get_ip(); |
| 102 | - if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){ |
|
| 102 | + if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) { |
|
| 103 | 103 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
| 104 | 104 | //wildcard to access all ip address |
| 105 | 105 | return; |
| 106 | - } else{ |
|
| 106 | + } else { |
|
| 107 | 107 | // go through all whitelisted ips |
| 108 | 108 | foreach ($list as $ipaddr) { |
| 109 | 109 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | show_error('Access to this application is not allowed'); |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | - } else{ |
|
| 131 | + } else { |
|
| 132 | 132 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class DatabaseQueryResult{ |
|
| 27 | + class DatabaseQueryResult { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The database query result |
| 31 | 31 | * @var mixed |
| 32 | 32 | */ |
| 33 | - private $result = null; |
|
| 33 | + private $result = null; |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return mixed |
| 58 | 58 | */ |
| 59 | - public function getResult(){ |
|
| 59 | + public function getResult() { |
|
| 60 | 60 | return $this->result; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return object DatabaseQueryResult |
| 68 | 68 | */ |
| 69 | - public function setResult($result){ |
|
| 69 | + public function setResult($result) { |
|
| 70 | 70 | $this->result = $result; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | - public function getNumRows(){ |
|
| 79 | + public function getNumRows() { |
|
| 80 | 80 | return $this->numRows; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return object DatabaseQueryResult |
| 88 | 88 | */ |
| 89 | - public function setNumRows($numRows){ |
|
| 89 | + public function setNumRows($numRows) { |
|
| 90 | 90 | $this->numRows = $numRows; |
| 91 | 91 | return $this; |
| 92 | 92 | } |
@@ -23,94 +23,94 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class DatabaseQueryBuilder{ |
|
| 26 | + class DatabaseQueryBuilder { |
|
| 27 | 27 | /** |
| 28 | 28 | * The SQL SELECT statment |
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - private $select = '*'; |
|
| 31 | + private $select = '*'; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * The SQL FROM statment |
| 35 | 35 | * @var string |
| 36 | 36 | */ |
| 37 | - private $from = null; |
|
| 37 | + private $from = null; |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * The SQL WHERE statment |
| 41 | 41 | * @var string |
| 42 | 42 | */ |
| 43 | - private $where = null; |
|
| 43 | + private $where = null; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * The SQL LIMIT statment |
| 47 | 47 | * @var string |
| 48 | 48 | */ |
| 49 | - private $limit = null; |
|
| 49 | + private $limit = null; |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The SQL JOIN statment |
| 53 | 53 | * @var string |
| 54 | 54 | */ |
| 55 | - private $join = null; |
|
| 55 | + private $join = null; |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The SQL ORDER BY statment |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - private $orderBy = null; |
|
| 61 | + private $orderBy = null; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * The SQL GROUP BY statment |
| 65 | 65 | * @var string |
| 66 | 66 | */ |
| 67 | - private $groupBy = null; |
|
| 67 | + private $groupBy = null; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The SQL HAVING statment |
| 71 | 71 | * @var string |
| 72 | 72 | */ |
| 73 | - private $having = null; |
|
| 73 | + private $having = null; |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * The full SQL query statment after build for each command |
| 77 | 77 | * @var string |
| 78 | 78 | */ |
| 79 | - private $query = null; |
|
| 79 | + private $query = null; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * The list of SQL valid operators |
| 83 | 83 | * @var array |
| 84 | 84 | */ |
| 85 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
| 85 | + private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>'); |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The prefix used in each database table |
| 90 | 90 | * @var string |
| 91 | 91 | */ |
| 92 | - private $prefix = null; |
|
| 92 | + private $prefix = null; |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * The PDO instance |
| 97 | 97 | * @var object |
| 98 | 98 | */ |
| 99 | - private $pdo = null; |
|
| 99 | + private $pdo = null; |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * The database driver name used |
| 103 | 103 | * @var string |
| 104 | 104 | */ |
| 105 | - private $driver = null; |
|
| 105 | + private $driver = null; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Construct new DatabaseQueryBuilder |
| 110 | 110 | * @param object $pdo the PDO object |
| 111 | 111 | */ |
| 112 | - public function __construct(PDO $pdo = null){ |
|
| 113 | - if (is_object($pdo)){ |
|
| 112 | + public function __construct(PDO $pdo = null) { |
|
| 113 | + if (is_object($pdo)) { |
|
| 114 | 114 | $this->setPdo($pdo); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * @param string|array $table the table name or array of table list |
| 121 | 121 | * @return object the current DatabaseQueryBuilder instance |
| 122 | 122 | */ |
| 123 | - public function from($table){ |
|
| 124 | - if (is_array($table)){ |
|
| 123 | + public function from($table) { |
|
| 124 | + if (is_array($table)) { |
|
| 125 | 125 | $froms = ''; |
| 126 | - foreach($table as $key){ |
|
| 126 | + foreach ($table as $key) { |
|
| 127 | 127 | $froms .= $this->getPrefix() . $key . ', '; |
| 128 | 128 | } |
| 129 | 129 | $this->from = rtrim($froms, ', '); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param string|array $fields the field name or array of field list |
| 139 | 139 | * @return object the current DatabaseQueryBuilder instance |
| 140 | 140 | */ |
| 141 | - public function select($fields){ |
|
| 141 | + public function select($fields) { |
|
| 142 | 142 | $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
| 143 | 143 | $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
| 144 | 144 | return $this; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param string $field the field name to distinct |
| 150 | 150 | * @return object the current DatabaseQueryBuilder instance |
| 151 | 151 | */ |
| 152 | - public function distinct($field){ |
|
| 152 | + public function distinct($field) { |
|
| 153 | 153 | $distinct = ' DISTINCT ' . $field; |
| 154 | 154 | $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
| 155 | 155 | return $this; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param string $name if is not null represent the alias used for this field in the result |
| 162 | 162 | * @return object the current DatabaseQueryBuilder instance |
| 163 | 163 | */ |
| 164 | - public function count($field = '*', $name = null){ |
|
| 164 | + public function count($field = '*', $name = null) { |
|
| 165 | 165 | return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @param string $name if is not null represent the alias used for this field in the result |
| 172 | 172 | * @return object the current DatabaseQueryBuilder instance |
| 173 | 173 | */ |
| 174 | - public function min($field, $name = null){ |
|
| 174 | + public function min($field, $name = null) { |
|
| 175 | 175 | return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string $name if is not null represent the alias used for this field in the result |
| 182 | 182 | * @return object the current DatabaseQueryBuilder instance |
| 183 | 183 | */ |
| 184 | - public function max($field, $name = null){ |
|
| 184 | + public function max($field, $name = null) { |
|
| 185 | 185 | return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @param string $name if is not null represent the alias used for this field in the result |
| 192 | 192 | * @return object the current DatabaseQueryBuilder instance |
| 193 | 193 | */ |
| 194 | - public function sum($field, $name = null){ |
|
| 194 | + public function sum($field, $name = null) { |
|
| 195 | 195 | return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param string $name if is not null represent the alias used for this field in the result |
| 202 | 202 | * @return object the current DatabaseQueryBuilder instance |
| 203 | 203 | */ |
| 204 | - public function avg($field, $name = null){ |
|
| 204 | + public function avg($field, $name = null) { |
|
| 205 | 205 | return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -215,17 +215,17 @@ discard block |
||
| 215 | 215 | * @param string $type the type of join (INNER, LEFT, RIGHT) |
| 216 | 216 | * @return object the current DatabaseQueryBuilder instance |
| 217 | 217 | */ |
| 218 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
| 218 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') { |
|
| 219 | 219 | $on = $field1; |
| 220 | 220 | $table = $this->getPrefix() . $table; |
| 221 | - if (! is_null($op)){ |
|
| 222 | - $on = (! in_array($op, $this->operatorList) |
|
| 221 | + if (!is_null($op)) { |
|
| 222 | + $on = (!in_array($op, $this->operatorList) |
|
| 223 | 223 | ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
| 224 | 224 | : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
| 225 | 225 | } |
| 226 | - if (empty($this->join)){ |
|
| 226 | + if (empty($this->join)) { |
|
| 227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 228 | - } else{ |
|
| 228 | + } else { |
|
| 229 | 229 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 230 | 230 | } |
| 231 | 231 | return $this; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @see DatabaseQueryBuilder::join() |
| 237 | 237 | * @return object the current DatabaseQueryBuilder instance |
| 238 | 238 | */ |
| 239 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 239 | + public function innerJoin($table, $field1, $op = null, $field2 = '') { |
|
| 240 | 240 | return $this->join($table, $field1, $op, $field2, 'INNER '); |
| 241 | 241 | } |
| 242 | 242 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * @see DatabaseQueryBuilder::join() |
| 246 | 246 | * @return object the current DatabaseQueryBuilder instance |
| 247 | 247 | */ |
| 248 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 248 | + public function leftJoin($table, $field1, $op = null, $field2 = '') { |
|
| 249 | 249 | return $this->join($table, $field1, $op, $field2, 'LEFT '); |
| 250 | 250 | } |
| 251 | 251 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @see DatabaseQueryBuilder::join() |
| 255 | 255 | * @return object the current DatabaseQueryBuilder instance |
| 256 | 256 | */ |
| 257 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 257 | + public function rightJoin($table, $field1, $op = null, $field2 = '') { |
|
| 258 | 258 | return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
| 259 | 259 | } |
| 260 | 260 | |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * @see DatabaseQueryBuilder::join() |
| 264 | 264 | * @return object the current DatabaseQueryBuilder instance |
| 265 | 265 | */ |
| 266 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 266 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 267 | 267 | return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @see DatabaseQueryBuilder::join() |
| 273 | 273 | * @return object the current DatabaseQueryBuilder instance |
| 274 | 274 | */ |
| 275 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 275 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 276 | 276 | return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @see DatabaseQueryBuilder::join() |
| 282 | 282 | * @return object the current DatabaseQueryBuilder instance |
| 283 | 283 | */ |
| 284 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 284 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 285 | 285 | return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
| 286 | 286 | } |
| 287 | 287 | |
@@ -291,13 +291,13 @@ discard block |
||
| 291 | 291 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 292 | 292 | * @return object the current DatabaseQueryBuilder instance |
| 293 | 293 | */ |
| 294 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
| 295 | - if (is_array($field)){ |
|
| 296 | - foreach($field as $f){ |
|
| 294 | + public function whereIsNull($field, $andOr = 'AND') { |
|
| 295 | + if (is_array($field)) { |
|
| 296 | + foreach ($field as $f) { |
|
| 297 | 297 | $this->whereIsNull($f, $andOr); |
| 298 | 298 | } |
| 299 | 299 | } else { |
| 300 | - $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 300 | + $this->setWhereStr($field . ' IS NULL ', $andOr); |
|
| 301 | 301 | } |
| 302 | 302 | return $this; |
| 303 | 303 | } |
@@ -308,13 +308,13 @@ discard block |
||
| 308 | 308 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 309 | 309 | * @return object the current DatabaseQueryBuilder instance |
| 310 | 310 | */ |
| 311 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
| 312 | - if (is_array($field)){ |
|
| 313 | - foreach($field as $f){ |
|
| 311 | + public function whereIsNotNull($field, $andOr = 'AND') { |
|
| 312 | + if (is_array($field)) { |
|
| 313 | + foreach ($field as $f) { |
|
| 314 | 314 | $this->whereIsNotNull($f, $andOr); |
| 315 | 315 | } |
| 316 | 316 | } else { |
| 317 | - $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 317 | + $this->setWhereStr($field . ' IS NOT NULL ', $andOr); |
|
| 318 | 318 | } |
| 319 | 319 | return $this; |
| 320 | 320 | } |
@@ -329,12 +329,12 @@ discard block |
||
| 329 | 329 | * @param boolean $escape whether to escape or not the $val |
| 330 | 330 | * @return object the current DatabaseQueryBuilder instance |
| 331 | 331 | */ |
| 332 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
| 332 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) { |
|
| 333 | 333 | $whereStr = ''; |
| 334 | - if (is_array($where)){ |
|
| 334 | + if (is_array($where)) { |
|
| 335 | 335 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 336 | - } else{ |
|
| 337 | - if (is_array($op)){ |
|
| 336 | + } else { |
|
| 337 | + if (is_array($op)) { |
|
| 338 | 338 | $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
| 339 | 339 | } else { |
| 340 | 340 | $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | * @see DatabaseQueryBuilder::where() |
| 350 | 350 | * @return object the current DatabaseQueryBuilder instance |
| 351 | 351 | */ |
| 352 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
| 352 | + public function orWhere($where, $op = null, $val = null, $escape = true) { |
|
| 353 | 353 | return $this->where($where, $op, $val, '', 'OR', $escape); |
| 354 | 354 | } |
| 355 | 355 | |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @see DatabaseQueryBuilder::where() |
| 360 | 360 | * @return object the current DatabaseQueryBuilder instance |
| 361 | 361 | */ |
| 362 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
| 362 | + public function notWhere($where, $op = null, $val = null, $escape = true) { |
|
| 363 | 363 | return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
| 364 | 364 | } |
| 365 | 365 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @see DatabaseQueryBuilder::where() |
| 369 | 369 | * @return object the current DatabaseQueryBuilder instance |
| 370 | 370 | */ |
| 371 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
| 371 | + public function orNotWhere($where, $op = null, $val = null, $escape = true) { |
|
| 372 | 372 | return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
| 373 | 373 | } |
| 374 | 374 | |
@@ -378,11 +378,11 @@ discard block |
||
| 378 | 378 | * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
| 379 | 379 | * @return object the current DatabaseQueryBuilder instance |
| 380 | 380 | */ |
| 381 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
| 382 | - if (empty($this->where)){ |
|
| 381 | + public function groupStart($type = '', $andOr = ' AND') { |
|
| 382 | + if (empty($this->where)) { |
|
| 383 | 383 | $this->where = $type . ' ('; |
| 384 | 384 | } else { |
| 385 | - if (substr(trim($this->where), -1) == '('){ |
|
| 385 | + if (substr(trim($this->where), -1) == '(') { |
|
| 386 | 386 | $this->where .= $type . ' ('; |
| 387 | 387 | } else { |
| 388 | 388 | $this->where .= $andOr . ' ' . $type . ' ('; |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | * @see DatabaseQueryBuilder::groupStart() |
| 397 | 397 | * @return object the current DatabaseQueryBuilder instance |
| 398 | 398 | */ |
| 399 | - public function notGroupStart(){ |
|
| 399 | + public function notGroupStart() { |
|
| 400 | 400 | return $this->groupStart('NOT'); |
| 401 | 401 | } |
| 402 | 402 | |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * @see DatabaseQueryBuilder::groupStart() |
| 406 | 406 | * @return object the current DatabaseQueryBuilder instance |
| 407 | 407 | */ |
| 408 | - public function orGroupStart(){ |
|
| 408 | + public function orGroupStart() { |
|
| 409 | 409 | return $this->groupStart('', ' OR'); |
| 410 | 410 | } |
| 411 | 411 | |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | * @see DatabaseQueryBuilder::groupStart() |
| 415 | 415 | * @return object the current DatabaseQueryBuilder instance |
| 416 | 416 | */ |
| 417 | - public function orNotGroupStart(){ |
|
| 417 | + public function orNotGroupStart() { |
|
| 418 | 418 | return $this->groupStart('NOT', ' OR'); |
| 419 | 419 | } |
| 420 | 420 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * Close the parenthesis for the grouped SQL |
| 423 | 423 | * @return object the current DatabaseQueryBuilder instance |
| 424 | 424 | */ |
| 425 | - public function groupEnd(){ |
|
| 425 | + public function groupEnd() { |
|
| 426 | 426 | $this->where .= ')'; |
| 427 | 427 | return $this; |
| 428 | 428 | } |
@@ -436,10 +436,10 @@ discard block |
||
| 436 | 436 | * @param boolean $escape whether to escape or not the values |
| 437 | 437 | * @return object the current DatabaseQueryBuilder instance |
| 438 | 438 | */ |
| 439 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
| 439 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) { |
|
| 440 | 440 | $_keys = array(); |
| 441 | - foreach ($keys as $k => $v){ |
|
| 442 | - if (is_null($v)){ |
|
| 441 | + foreach ($keys as $k => $v) { |
|
| 442 | + if (is_null($v)) { |
|
| 443 | 443 | $v = ''; |
| 444 | 444 | } |
| 445 | 445 | $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape)); |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * @see DatabaseQueryBuilder::in() |
| 456 | 456 | * @return object the current DatabaseQueryBuilder instance |
| 457 | 457 | */ |
| 458 | - public function notIn($field, array $keys, $escape = true){ |
|
| 458 | + public function notIn($field, array $keys, $escape = true) { |
|
| 459 | 459 | return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
| 460 | 460 | } |
| 461 | 461 | |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | * @see DatabaseQueryBuilder::in() |
| 465 | 465 | * @return object the current DatabaseQueryBuilder instance |
| 466 | 466 | */ |
| 467 | - public function orIn($field, array $keys, $escape = true){ |
|
| 467 | + public function orIn($field, array $keys, $escape = true) { |
|
| 468 | 468 | return $this->in($field, $keys, '', 'OR', $escape); |
| 469 | 469 | } |
| 470 | 470 | |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | * @see DatabaseQueryBuilder::in() |
| 474 | 474 | * @return object the current DatabaseQueryBuilder instance |
| 475 | 475 | */ |
| 476 | - public function orNotIn($field, array $keys, $escape = true){ |
|
| 476 | + public function orNotIn($field, array $keys, $escape = true) { |
|
| 477 | 477 | return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
| 478 | 478 | } |
| 479 | 479 | |
@@ -487,11 +487,11 @@ discard block |
||
| 487 | 487 | * @param boolean $escape whether to escape or not the values |
| 488 | 488 | * @return object the current DatabaseQueryBuilder instance |
| 489 | 489 | */ |
| 490 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
| 491 | - if (is_null($value1)){ |
|
| 490 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) { |
|
| 491 | + if (is_null($value1)) { |
|
| 492 | 492 | $value1 = ''; |
| 493 | 493 | } |
| 494 | - if (is_null($value2)){ |
|
| 494 | + if (is_null($value2)) { |
|
| 495 | 495 | $value2 = ''; |
| 496 | 496 | } |
| 497 | 497 | $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | * @see DatabaseQueryBuilder::between() |
| 505 | 505 | * @return object the current DatabaseQueryBuilder instance |
| 506 | 506 | */ |
| 507 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
| 507 | + public function notBetween($field, $value1, $value2, $escape = true) { |
|
| 508 | 508 | return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
| 509 | 509 | } |
| 510 | 510 | |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | * @see DatabaseQueryBuilder::between() |
| 514 | 514 | * @return object the current DatabaseQueryBuilder instance |
| 515 | 515 | */ |
| 516 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
| 516 | + public function orBetween($field, $value1, $value2, $escape = true) { |
|
| 517 | 517 | return $this->between($field, $value1, $value2, '', 'OR', $escape); |
| 518 | 518 | } |
| 519 | 519 | |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | * @see DatabaseQueryBuilder::between() |
| 523 | 523 | * @return object the current DatabaseQueryBuilder instance |
| 524 | 524 | */ |
| 525 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
| 525 | + public function orNotBetween($field, $value1, $value2, $escape = true) { |
|
| 526 | 526 | return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
| 527 | 527 | } |
| 528 | 528 | |
@@ -535,8 +535,8 @@ discard block |
||
| 535 | 535 | * @param boolean $escape whether to escape or not the values |
| 536 | 536 | * @return object the current DatabaseQueryBuilder instance |
| 537 | 537 | */ |
| 538 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
| 539 | - if (empty($data)){ |
|
| 538 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) { |
|
| 539 | + if (empty($data)) { |
|
| 540 | 540 | $data = ''; |
| 541 | 541 | } |
| 542 | 542 | $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | * @see DatabaseQueryBuilder::like() |
| 549 | 549 | * @return object the current DatabaseQueryBuilder instance |
| 550 | 550 | */ |
| 551 | - public function orLike($field, $data, $escape = true){ |
|
| 551 | + public function orLike($field, $data, $escape = true) { |
|
| 552 | 552 | return $this->like($field, $data, '', 'OR', $escape); |
| 553 | 553 | } |
| 554 | 554 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | * @see DatabaseQueryBuilder::like() |
| 558 | 558 | * @return object the current DatabaseQueryBuilder instance |
| 559 | 559 | */ |
| 560 | - public function notLike($field, $data, $escape = true){ |
|
| 560 | + public function notLike($field, $data, $escape = true) { |
|
| 561 | 561 | return $this->like($field, $data, 'NOT ', 'AND', $escape); |
| 562 | 562 | } |
| 563 | 563 | |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | * @see DatabaseQueryBuilder::like() |
| 567 | 567 | * @return object the current DatabaseQueryBuilder instance |
| 568 | 568 | */ |
| 569 | - public function orNotLike($field, $data, $escape = true){ |
|
| 569 | + public function orNotLike($field, $data, $escape = true) { |
|
| 570 | 570 | return $this->like($field, $data, 'NOT ', 'OR', $escape); |
| 571 | 571 | } |
| 572 | 572 | |
@@ -577,13 +577,13 @@ discard block |
||
| 577 | 577 | * @param int $limitEnd the limit count |
| 578 | 578 | * @return object the current DatabaseQueryBuilder instance |
| 579 | 579 | */ |
| 580 | - public function limit($limit, $limitEnd = null){ |
|
| 581 | - if (empty($limit)){ |
|
| 580 | + public function limit($limit, $limitEnd = null) { |
|
| 581 | + if (empty($limit)) { |
|
| 582 | 582 | $limit = 0; |
| 583 | 583 | } |
| 584 | - if (! is_null($limitEnd)){ |
|
| 584 | + if (!is_null($limitEnd)) { |
|
| 585 | 585 | $this->limit = $limit . ', ' . $limitEnd; |
| 586 | - } else{ |
|
| 586 | + } else { |
|
| 587 | 587 | $this->limit = $limit; |
| 588 | 588 | } |
| 589 | 589 | return $this; |
@@ -595,10 +595,10 @@ discard block |
||
| 595 | 595 | * @param string $orderDir the order direction (ASC or DESC) |
| 596 | 596 | * @return object the current DatabaseQueryBuilder instance |
| 597 | 597 | */ |
| 598 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
| 599 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 598 | + public function orderBy($orderBy, $orderDir = ' ASC') { |
|
| 599 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()') { |
|
| 600 | 600 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 601 | - } else{ |
|
| 601 | + } else { |
|
| 602 | 602 | $this->orderBy = empty($this->orderBy) |
| 603 | 603 | ? ($orderBy . ' ' . strtoupper($orderDir)) |
| 604 | 604 | : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
@@ -611,10 +611,10 @@ discard block |
||
| 611 | 611 | * @param string|array $field the field name used or array of field list |
| 612 | 612 | * @return object the current DatabaseQueryBuilder instance |
| 613 | 613 | */ |
| 614 | - public function groupBy($field){ |
|
| 615 | - if (is_array($field)){ |
|
| 614 | + public function groupBy($field) { |
|
| 615 | + if (is_array($field)) { |
|
| 616 | 616 | $this->groupBy = implode(', ', $field); |
| 617 | - } else{ |
|
| 617 | + } else { |
|
| 618 | 618 | $this->groupBy = $field; |
| 619 | 619 | } |
| 620 | 620 | return $this; |
@@ -628,16 +628,16 @@ discard block |
||
| 628 | 628 | * @param boolean $escape whether to escape or not the values |
| 629 | 629 | * @return object the current DatabaseQueryBuilder instance |
| 630 | 630 | */ |
| 631 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
| 632 | - if (is_array($op)){ |
|
| 631 | + public function having($field, $op = null, $val = null, $escape = true) { |
|
| 632 | + if (is_array($op)) { |
|
| 633 | 633 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 634 | - } else if (! in_array($op, $this->operatorList)){ |
|
| 635 | - if (is_null($op)){ |
|
| 634 | + } else if (!in_array($op, $this->operatorList)) { |
|
| 635 | + if (is_null($op)) { |
|
| 636 | 636 | $op = ''; |
| 637 | 637 | } |
| 638 | 638 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 639 | - } else{ |
|
| 640 | - if (is_null($val)){ |
|
| 639 | + } else { |
|
| 640 | + if (is_null($val)) { |
|
| 641 | 641 | $val = ''; |
| 642 | 642 | } |
| 643 | 643 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | * @param boolean $escape whether to escape or not the values |
| 652 | 652 | * @return object the current DatabaseQueryBuilder instance |
| 653 | 653 | */ |
| 654 | - public function insert($data = array(), $escape = true){ |
|
| 654 | + public function insert($data = array(), $escape = true) { |
|
| 655 | 655 | $columns = array_keys($data); |
| 656 | 656 | $column = implode(', ', $columns); |
| 657 | 657 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -666,22 +666,22 @@ discard block |
||
| 666 | 666 | * @param boolean $escape whether to escape or not the values |
| 667 | 667 | * @return object the current DatabaseQueryBuilder instance |
| 668 | 668 | */ |
| 669 | - public function update($data = array(), $escape = true){ |
|
| 669 | + public function update($data = array(), $escape = true) { |
|
| 670 | 670 | $query = 'UPDATE ' . $this->from . ' SET '; |
| 671 | 671 | $values = array(); |
| 672 | - foreach ($data as $column => $val){ |
|
| 672 | + foreach ($data as $column => $val) { |
|
| 673 | 673 | $values[] = $column . ' = ' . ($this->escape($val, $escape)); |
| 674 | 674 | } |
| 675 | 675 | $query .= implode(', ', $values); |
| 676 | - if (! empty($this->where)){ |
|
| 676 | + if (!empty($this->where)) { |
|
| 677 | 677 | $query .= ' WHERE ' . $this->where; |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - if (! empty($this->orderBy)){ |
|
| 680 | + if (!empty($this->orderBy)) { |
|
| 681 | 681 | $query .= ' ORDER BY ' . $this->orderBy; |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - if (! empty($this->limit)){ |
|
| 684 | + if (!empty($this->limit)) { |
|
| 685 | 685 | $query .= ' LIMIT ' . $this->limit; |
| 686 | 686 | } |
| 687 | 687 | $this->query = $query; |
@@ -692,22 +692,22 @@ discard block |
||
| 692 | 692 | * Delete the record in database |
| 693 | 693 | * @return object the current DatabaseQueryBuilder instance |
| 694 | 694 | */ |
| 695 | - public function delete(){ |
|
| 695 | + public function delete() { |
|
| 696 | 696 | $query = 'DELETE FROM ' . $this->from; |
| 697 | 697 | $isTruncate = $query; |
| 698 | - if (! empty($this->where)){ |
|
| 698 | + if (!empty($this->where)) { |
|
| 699 | 699 | $query .= ' WHERE ' . $this->where; |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - if (! empty($this->orderBy)){ |
|
| 702 | + if (!empty($this->orderBy)) { |
|
| 703 | 703 | $query .= ' ORDER BY ' . $this->orderBy; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - if (! empty($this->limit)){ |
|
| 706 | + if (!empty($this->limit)) { |
|
| 707 | 707 | $query .= ' LIMIT ' . $this->limit; |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | - if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 710 | + if ($isTruncate == $query && $this->driver != 'sqlite') { |
|
| 711 | 711 | $query = 'TRUNCATE TABLE ' . $this->from; |
| 712 | 712 | } |
| 713 | 713 | $this->query = $query; |
@@ -720,9 +720,9 @@ discard block |
||
| 720 | 720 | * @param boolean $escaped whether we can do escape of not |
| 721 | 721 | * @return mixed the data after escaped or the same data if not |
| 722 | 722 | */ |
| 723 | - public function escape($data, $escaped = true){ |
|
| 723 | + public function escape($data, $escaped = true) { |
|
| 724 | 724 | $data = trim($data); |
| 725 | - if($escaped){ |
|
| 725 | + if ($escaped) { |
|
| 726 | 726 | return $this->pdo->quote($data); |
| 727 | 727 | } |
| 728 | 728 | return $data; |
@@ -733,31 +733,31 @@ discard block |
||
| 733 | 733 | * Return the current SQL query string |
| 734 | 734 | * @return string |
| 735 | 735 | */ |
| 736 | - public function getQuery(){ |
|
| 736 | + public function getQuery() { |
|
| 737 | 737 | //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
| 738 | - if(empty($this->query)){ |
|
| 738 | + if (empty($this->query)) { |
|
| 739 | 739 | $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
| 740 | - if (! empty($this->join)){ |
|
| 740 | + if (!empty($this->join)) { |
|
| 741 | 741 | $query .= $this->join; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | - if (! empty($this->where)){ |
|
| 744 | + if (!empty($this->where)) { |
|
| 745 | 745 | $query .= ' WHERE ' . $this->where; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - if (! empty($this->groupBy)){ |
|
| 748 | + if (!empty($this->groupBy)) { |
|
| 749 | 749 | $query .= ' GROUP BY ' . $this->groupBy; |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - if (! empty($this->having)){ |
|
| 752 | + if (!empty($this->having)) { |
|
| 753 | 753 | $query .= ' HAVING ' . $this->having; |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | - if (! empty($this->orderBy)){ |
|
| 756 | + if (!empty($this->orderBy)) { |
|
| 757 | 757 | $query .= ' ORDER BY ' . $this->orderBy; |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - if (! empty($this->limit)){ |
|
| 760 | + if (!empty($this->limit)) { |
|
| 761 | 761 | $query .= ' LIMIT ' . $this->limit; |
| 762 | 762 | } |
| 763 | 763 | $this->query = $query; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | * Return the PDO instance |
| 771 | 771 | * @return object |
| 772 | 772 | */ |
| 773 | - public function getPdo(){ |
|
| 773 | + public function getPdo() { |
|
| 774 | 774 | return $this->pdo; |
| 775 | 775 | } |
| 776 | 776 | |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | * @param PDO $pdo the pdo object |
| 780 | 780 | * @return object DatabaseQueryBuilder |
| 781 | 781 | */ |
| 782 | - public function setPdo(PDO $pdo = null){ |
|
| 782 | + public function setPdo(PDO $pdo = null) { |
|
| 783 | 783 | $this->pdo = $pdo; |
| 784 | 784 | return $this; |
| 785 | 785 | } |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | * Return the database table prefix |
| 789 | 789 | * @return string |
| 790 | 790 | */ |
| 791 | - public function getPrefix(){ |
|
| 791 | + public function getPrefix() { |
|
| 792 | 792 | return $this->prefix; |
| 793 | 793 | } |
| 794 | 794 | |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | * @param string $prefix the new prefix |
| 798 | 798 | * @return object DatabaseQueryBuilder |
| 799 | 799 | */ |
| 800 | - public function setPrefix($prefix){ |
|
| 800 | + public function setPrefix($prefix) { |
|
| 801 | 801 | $this->prefix = $prefix; |
| 802 | 802 | return $this; |
| 803 | 803 | } |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | * Return the database driver |
| 807 | 807 | * @return string |
| 808 | 808 | */ |
| 809 | - public function getDriver(){ |
|
| 809 | + public function getDriver() { |
|
| 810 | 810 | return $this->driver; |
| 811 | 811 | } |
| 812 | 812 | |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | * @param string $driver the new driver |
| 816 | 816 | * @return object DatabaseQueryBuilder |
| 817 | 817 | */ |
| 818 | - public function setDriver($driver){ |
|
| 818 | + public function setDriver($driver) { |
|
| 819 | 819 | $this->driver = $driver; |
| 820 | 820 | return $this; |
| 821 | 821 | } |
@@ -824,7 +824,7 @@ discard block |
||
| 824 | 824 | * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
| 825 | 825 | * @return object the current DatabaseQueryBuilder instance |
| 826 | 826 | */ |
| 827 | - public function reset(){ |
|
| 827 | + public function reset() { |
|
| 828 | 828 | $this->select = '*'; |
| 829 | 829 | $this->from = null; |
| 830 | 830 | $this->where = null; |
@@ -843,12 +843,12 @@ discard block |
||
| 843 | 843 | * |
| 844 | 844 | * @return string |
| 845 | 845 | */ |
| 846 | - protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){ |
|
| 846 | + protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) { |
|
| 847 | 847 | $x = explode('?', $field); |
| 848 | 848 | $w = ''; |
| 849 | - foreach($x as $k => $v){ |
|
| 850 | - if (!empty($v)){ |
|
| 851 | - if (! isset($op[$k])){ |
|
| 849 | + foreach ($x as $k => $v) { |
|
| 850 | + if (!empty($v)) { |
|
| 851 | + if (!isset($op[$k])) { |
|
| 852 | 852 | $op[$k] = ''; |
| 853 | 853 | } |
| 854 | 854 | $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
@@ -864,15 +864,15 @@ discard block |
||
| 864 | 864 | * |
| 865 | 865 | * @return string |
| 866 | 866 | */ |
| 867 | - protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){ |
|
| 867 | + protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) { |
|
| 868 | 868 | $_where = array(); |
| 869 | - foreach ($where as $column => $data){ |
|
| 870 | - if (is_null($data)){ |
|
| 869 | + foreach ($where as $column => $data) { |
|
| 870 | + if (is_null($data)) { |
|
| 871 | 871 | $data = ''; |
| 872 | 872 | } |
| 873 | 873 | $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape)); |
| 874 | 874 | } |
| 875 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 875 | + $where = implode(' ' . $andOr . ' ', $_where); |
|
| 876 | 876 | return $where; |
| 877 | 877 | } |
| 878 | 878 | |
@@ -882,12 +882,12 @@ discard block |
||
| 882 | 882 | * |
| 883 | 883 | * @return string |
| 884 | 884 | */ |
| 885 | - protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){ |
|
| 885 | + protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) { |
|
| 886 | 886 | $x = explode('?', $where); |
| 887 | 887 | $w = ''; |
| 888 | - foreach($x as $k => $v){ |
|
| 889 | - if (! empty($v)){ |
|
| 890 | - if (isset($op[$k]) && is_null($op[$k])){ |
|
| 888 | + foreach ($x as $k => $v) { |
|
| 889 | + if (!empty($v)) { |
|
| 890 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
| 891 | 891 | $op[$k] = ''; |
| 892 | 892 | } |
| 893 | 893 | $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : ''); |
@@ -902,15 +902,15 @@ discard block |
||
| 902 | 902 | * |
| 903 | 903 | * @return string |
| 904 | 904 | */ |
| 905 | - protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){ |
|
| 905 | + protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) { |
|
| 906 | 906 | $w = ''; |
| 907 | - if (! in_array((string)$op, $this->operatorList)){ |
|
| 908 | - if (is_null($op)){ |
|
| 907 | + if (!in_array((string) $op, $this->operatorList)) { |
|
| 908 | + if (is_null($op)) { |
|
| 909 | 909 | $op = ''; |
| 910 | 910 | } |
| 911 | 911 | $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
| 912 | 912 | } else { |
| 913 | - if (is_null($val)){ |
|
| 913 | + if (is_null($val)) { |
|
| 914 | 914 | $val = ''; |
| 915 | 915 | } |
| 916 | 916 | $w = $type . $where . $op . ($this->escape($val, $escape)); |
@@ -923,14 +923,14 @@ discard block |
||
| 923 | 923 | * @param string $whereStr the WHERE clause string |
| 924 | 924 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 925 | 925 | */ |
| 926 | - protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 927 | - if (empty($this->where)){ |
|
| 926 | + protected function setWhereStr($whereStr, $andOr = 'AND') { |
|
| 927 | + if (empty($this->where)) { |
|
| 928 | 928 | $this->where = $whereStr; |
| 929 | 929 | } else { |
| 930 | - if (substr(trim($this->where), -1) == '('){ |
|
| 930 | + if (substr(trim($this->where), -1) == '(') { |
|
| 931 | 931 | $this->where = $this->where . ' ' . $whereStr; |
| 932 | 932 | } else { |
| 933 | - $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
|
| 933 | + $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr; |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | 936 | } |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | * @see DatabaseQueryBuilder::avg |
| 947 | 947 | * @return object |
| 948 | 948 | */ |
| 949 | - protected function select_min_max_sum_count_avg($clause, $field, $name = null){ |
|
| 949 | + protected function select_min_max_sum_count_avg($clause, $field, $name = null) { |
|
| 950 | 950 | $clause = strtoupper($clause); |
| 951 | 951 | $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 952 | 952 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class DatabaseQueryRunner extends BaseClass{ |
|
| 26 | + class DatabaseQueryRunner extends BaseClass { |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The last query result |
| 31 | 31 | * @var object |
| 32 | 32 | */ |
| 33 | - private $queryResult = null; |
|
| 33 | + private $queryResult = null; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * The benchmark instance |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * The SQL query statment to execute |
| 43 | 43 | * @var string |
| 44 | 44 | */ |
| 45 | - private $query = null; |
|
| 45 | + private $query = null; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Indicate if we need return result as list (boolean) |
| 49 | 49 | * or the data used to replace the placeholder (array) |
| 50 | 50 | * @var array|boolean |
| 51 | 51 | */ |
| 52 | - private $returnAsList = true; |
|
| 52 | + private $returnAsList = true; |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Indicate if we need return result as array or not |
| 57 | 57 | * @var boolean |
| 58 | 58 | */ |
| 59 | - private $returnAsArray = true; |
|
| 59 | + private $returnAsArray = true; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * The last PDOStatment instance |
| 63 | 63 | * @var object |
| 64 | 64 | */ |
| 65 | - private $pdoStatment = null; |
|
| 65 | + private $pdoStatment = null; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * The error returned for the last query |
| 69 | 69 | * @var string |
| 70 | 70 | */ |
| 71 | - private $error = null; |
|
| 71 | + private $error = null; |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * The PDO instance |
| 75 | 75 | * @var object |
| 76 | 76 | */ |
| 77 | - private $pdo = null; |
|
| 77 | + private $pdo = null; |
|
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * The database driver name used |
| 81 | 81 | * @var string |
| 82 | 82 | */ |
| 83 | - private $driver = null; |
|
| 83 | + private $driver = null; |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | * @param boolean $returnAsList if need return as list or just one row |
| 92 | 92 | * @param boolean $returnAsArray whether to return the result as array or not |
| 93 | 93 | */ |
| 94 | - public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){ |
|
| 94 | + public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) { |
|
| 95 | 95 | parent::__construct(); |
| 96 | - if (is_object($pdo)){ |
|
| 96 | + if (is_object($pdo)) { |
|
| 97 | 97 | $this->pdo = $pdo; |
| 98 | 98 | } |
| 99 | 99 | $this->query = $query; |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return object|void |
| 110 | 110 | */ |
| 111 | - public function execute(){ |
|
| 111 | + public function execute() { |
|
| 112 | 112 | //reset instance |
| 113 | 113 | $this->reset(); |
| 114 | 114 | |
| 115 | 115 | //for database query execution time |
| 116 | 116 | $benchmarkMarkerKey = $this->getBenchmarkKey(); |
| 117 | - if (! is_object($this->benchmarkInstance)){ |
|
| 117 | + if (!is_object($this->benchmarkInstance)) { |
|
| 118 | 118 | $this->benchmarkInstance = & class_loader('Benchmark'); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -130,18 +130,18 @@ discard block |
||
| 130 | 130 | 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')' |
| 131 | 131 | ); |
| 132 | 132 | //TODO use the configuration value for the high response time currently is 1 second |
| 133 | - if ($responseTime >= 1 ){ |
|
| 133 | + if ($responseTime >= 1) { |
|
| 134 | 134 | $this->logger->warning( |
| 135 | 135 | 'High response time while processing database query [' . $this->query . ']. |
| 136 | - The response time is [' .$responseTime. '] sec.' |
|
| 136 | + The response time is [' .$responseTime . '] sec.' |
|
| 137 | 137 | ); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ($this->pdoStatment !== false){ |
|
| 140 | + if ($this->pdoStatment !== false) { |
|
| 141 | 141 | $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false; |
| 142 | - if($isSqlSELECTQuery){ |
|
| 142 | + if ($isSqlSELECTQuery) { |
|
| 143 | 143 | $this->setResultForSelect(); |
| 144 | - } else{ |
|
| 144 | + } else { |
|
| 145 | 145 | $this->setResultForNonSelect(); |
| 146 | 146 | } |
| 147 | 147 | return $this->queryResult; |
@@ -153,26 +153,26 @@ discard block |
||
| 153 | 153 | * Return the result for SELECT query |
| 154 | 154 | * @see DatabaseQueryRunner::execute |
| 155 | 155 | */ |
| 156 | - protected function setResultForSelect(){ |
|
| 156 | + protected function setResultForSelect() { |
|
| 157 | 157 | //if need return all result like list of record |
| 158 | 158 | $result = null; |
| 159 | 159 | $numRows = 0; |
| 160 | 160 | $fetchMode = PDO::FETCH_OBJ; |
| 161 | - if($this->returnAsArray){ |
|
| 161 | + if ($this->returnAsArray) { |
|
| 162 | 162 | $fetchMode = PDO::FETCH_ASSOC; |
| 163 | 163 | } |
| 164 | - if ($this->returnAsList){ |
|
| 164 | + if ($this->returnAsList) { |
|
| 165 | 165 | $result = $this->pdoStatment->fetchAll($fetchMode); |
| 166 | - } else{ |
|
| 166 | + } else { |
|
| 167 | 167 | $result = $this->pdoStatment->fetch($fetchMode); |
| 168 | 168 | } |
| 169 | 169 | //Sqlite and pgsql always return 0 when using rowCount() |
| 170 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 170 | + if (in_array($this->driver, array('sqlite', 'pgsql'))) { |
|
| 171 | 171 | $numRows = count($result); |
| 172 | - } else{ |
|
| 172 | + } else { |
|
| 173 | 173 | $numRows = $this->pdoStatment->rowCount(); |
| 174 | 174 | } |
| 175 | - if(! is_object($this->queryResult)){ |
|
| 175 | + if (!is_object($this->queryResult)) { |
|
| 176 | 176 | $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
| 177 | 177 | } |
| 178 | 178 | $this->queryResult->setResult($result); |
@@ -183,19 +183,19 @@ discard block |
||
| 183 | 183 | * Return the result for non SELECT query |
| 184 | 184 | * @see DatabaseQueryRunner::execute |
| 185 | 185 | */ |
| 186 | - protected function setResultForNonSelect(){ |
|
| 186 | + protected function setResultForNonSelect() { |
|
| 187 | 187 | //Sqlite and pgsql always return 0 when using rowCount() |
| 188 | 188 | $result = false; |
| 189 | 189 | $numRows = 0; |
| 190 | - if (in_array($this->driver, array('sqlite', 'pgsql'))){ |
|
| 190 | + if (in_array($this->driver, array('sqlite', 'pgsql'))) { |
|
| 191 | 191 | $result = true; //to test the result for the query like UPDATE, INSERT, DELETE |
| 192 | 192 | $numRows = 1; //TODO use the correct method to get the exact affected row |
| 193 | - } else{ |
|
| 193 | + } else { |
|
| 194 | 194 | //to test the result for the query like UPDATE, INSERT, DELETE |
| 195 | 195 | $result = $this->pdoStatment->rowCount() >= 0; |
| 196 | 196 | $numRows = $this->pdoStatment->rowCount(); |
| 197 | 197 | } |
| 198 | - if(! is_object($this->queryResult)){ |
|
| 198 | + if (!is_object($this->queryResult)) { |
|
| 199 | 199 | $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database'); |
| 200 | 200 | } |
| 201 | 201 | $this->queryResult->setResult($result); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @return object DatabaseQueryResult |
| 228 | 228 | */ |
| 229 | - public function getQueryResult(){ |
|
| 229 | + public function getQueryResult() { |
|
| 230 | 230 | return $this->queryResult; |
| 231 | 231 | } |
| 232 | 232 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return object DatabaseQueryRunner |
| 238 | 238 | */ |
| 239 | - public function setQueryResult(DatabaseQueryResult $queryResult){ |
|
| 239 | + public function setQueryResult(DatabaseQueryResult $queryResult) { |
|
| 240 | 240 | $this->queryResult = $queryResult; |
| 241 | 241 | return $this; |
| 242 | 242 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * Return the current query SQL string |
| 246 | 246 | * @return string |
| 247 | 247 | */ |
| 248 | - public function getQuery(){ |
|
| 248 | + public function getQuery() { |
|
| 249 | 249 | return $this->query; |
| 250 | 250 | } |
| 251 | 251 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @param string $query the SQL query to set |
| 255 | 255 | * @return object DatabaseQueryRunner |
| 256 | 256 | */ |
| 257 | - public function setQuery($query){ |
|
| 257 | + public function setQuery($query) { |
|
| 258 | 258 | $this->query = $query; |
| 259 | 259 | return $this; |
| 260 | 260 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @param boolean $returnType |
| 265 | 265 | * @return object DatabaseQueryRunner |
| 266 | 266 | */ |
| 267 | - public function setReturnType($returnType){ |
|
| 267 | + public function setReturnType($returnType) { |
|
| 268 | 268 | $this->returnAsList = $returnType; |
| 269 | 269 | return $this; |
| 270 | 270 | } |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @param boolean $status the status if true will return as array |
| 275 | 275 | * @return object DatabaseQueryRunner |
| 276 | 276 | */ |
| 277 | - public function setReturnAsArray($status = true){ |
|
| 277 | + public function setReturnAsArray($status = true) { |
|
| 278 | 278 | $this->returnAsArray = $status; |
| 279 | 279 | return $this; |
| 280 | 280 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * Return the error for last query execution |
| 284 | 284 | * @return string |
| 285 | 285 | */ |
| 286 | - public function getQueryError(){ |
|
| 286 | + public function getQueryError() { |
|
| 287 | 287 | return $this->error; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * Return the PDO instance |
| 292 | 292 | * @return object |
| 293 | 293 | */ |
| 294 | - public function getPdo(){ |
|
| 294 | + public function getPdo() { |
|
| 295 | 295 | return $this->pdo; |
| 296 | 296 | } |
| 297 | 297 | |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * @param PDO $pdo the pdo object |
| 301 | 301 | * @return object DatabaseQueryRunner |
| 302 | 302 | */ |
| 303 | - public function setPdo(PDO $pdo = null){ |
|
| 303 | + public function setPdo(PDO $pdo = null) { |
|
| 304 | 304 | $this->pdo = $pdo; |
| 305 | 305 | return $this; |
| 306 | 306 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * Return the database driver |
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | - public function getDriver(){ |
|
| 312 | + public function getDriver() { |
|
| 313 | 313 | return $this->driver; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @param string $driver the new driver |
| 319 | 319 | * @return object DatabaseQueryRunner |
| 320 | 320 | */ |
| 321 | - public function setDriver($driver){ |
|
| 321 | + public function setDriver($driver) { |
|
| 322 | 322 | $this->driver = $driver; |
| 323 | 323 | return $this; |
| 324 | 324 | } |
@@ -328,14 +328,14 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @return string |
| 330 | 330 | */ |
| 331 | - protected function getBenchmarkKey(){ |
|
| 331 | + protected function getBenchmarkKey() { |
|
| 332 | 332 | return md5($this->query . $this->returnAsList . $this->returnAsArray); |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | 336 | * Set error for database query execution |
| 337 | 337 | */ |
| 338 | - protected function setQueryRunnerError(){ |
|
| 338 | + protected function setQueryRunnerError() { |
|
| 339 | 339 | $error = $this->pdo->errorInfo(); |
| 340 | 340 | $this->error = isset($error[2]) ? $error[2] : ''; |
| 341 | 341 | $this->logger->error('The database query execution got an error: ' . stringfy_vars($error)); |
@@ -347,11 +347,11 @@ discard block |
||
| 347 | 347 | * Set the Log instance using argument or create new instance |
| 348 | 348 | * @param object $logger the Log instance if not null |
| 349 | 349 | */ |
| 350 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
| 351 | - if ($logger !== null){ |
|
| 350 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
| 351 | + if ($logger !== null) { |
|
| 352 | 352 | $this->logger = $logger; |
| 353 | - } else{ |
|
| 354 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 353 | + } else { |
|
| 354 | + $this->logger = & class_loader('Log', 'classes'); |
|
| 355 | 355 | $this->logger->setLogger('Library::DatabaseQueryRunner'); |
| 356 | 356 | } |
| 357 | 357 | } |
@@ -23,92 +23,92 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class Database extends BaseClass{ |
|
| 26 | + class Database extends BaseClass { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The PDO instance |
| 30 | 30 | * @var object |
| 31 | 31 | */ |
| 32 | - private $pdo = null; |
|
| 32 | + private $pdo = null; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The database name used for the application |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - private $databaseName = null; |
|
| 38 | + private $databaseName = null; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * The number of rows returned by the last query |
| 42 | 42 | * @var int |
| 43 | 43 | */ |
| 44 | - private $numRows = 0; |
|
| 44 | + private $numRows = 0; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The last insert id for the primary key column that have auto increment or sequence |
| 48 | 48 | * @var mixed |
| 49 | 49 | */ |
| 50 | - private $insertId = null; |
|
| 50 | + private $insertId = null; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * The full SQL query statment after build for each command |
| 54 | 54 | * @var string |
| 55 | 55 | */ |
| 56 | - private $query = null; |
|
| 56 | + private $query = null; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * The result returned for the last query |
| 60 | 60 | * @var mixed |
| 61 | 61 | */ |
| 62 | - private $result = array(); |
|
| 62 | + private $result = array(); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * The cache default time to live in second. 0 means no need to use the cache feature |
| 66 | 66 | * @var int |
| 67 | 67 | */ |
| 68 | - private $cacheTtl = 0; |
|
| 68 | + private $cacheTtl = 0; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * The cache current time to live. 0 means no need to use the cache feature |
| 72 | 72 | * @var int |
| 73 | 73 | */ |
| 74 | - private $temporaryCacheTtl = 0; |
|
| 74 | + private $temporaryCacheTtl = 0; |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * The number of executed query for the current request |
| 78 | 78 | * @var int |
| 79 | 79 | */ |
| 80 | - private $queryCount = 0; |
|
| 80 | + private $queryCount = 0; |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * The default data to be used in the statments query INSERT, UPDATE |
| 84 | 84 | * @var array |
| 85 | 85 | */ |
| 86 | - private $data = array(); |
|
| 86 | + private $data = array(); |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The database configuration |
| 90 | 90 | * @var array |
| 91 | 91 | */ |
| 92 | - private $config = array(); |
|
| 92 | + private $config = array(); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * The cache instance |
| 96 | 96 | * @var object |
| 97 | 97 | */ |
| 98 | - private $cacheInstance = null; |
|
| 98 | + private $cacheInstance = null; |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * The DatabaseQueryBuilder instance |
| 103 | 103 | * @var object |
| 104 | 104 | */ |
| 105 | - protected $queryBuilder = null; |
|
| 105 | + protected $queryBuilder = null; |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * The DatabaseQueryRunner instance |
| 109 | 109 | * @var object |
| 110 | 110 | */ |
| 111 | - protected $queryRunner = null; |
|
| 111 | + protected $queryRunner = null; |
|
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | * This is used to connect to database |
| 137 | 137 | * @return bool |
| 138 | 138 | */ |
| 139 | - public function connect(){ |
|
| 139 | + public function connect() { |
|
| 140 | 140 | $config = $this->getDatabaseConfiguration(); |
| 141 | - if (! empty($config)){ |
|
| 142 | - try{ |
|
| 141 | + if (!empty($config)) { |
|
| 142 | + try { |
|
| 143 | 143 | $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']); |
| 144 | 144 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
| 145 | 145 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $this->updateQueryBuilderAndRunnerProperties(); |
| 150 | 150 | |
| 151 | 151 | return is_object($this->pdo); |
| 152 | - } catch (PDOException $e){ |
|
| 152 | + } catch (PDOException $e) { |
|
| 153 | 153 | $this->logger->fatal($e->getMessage()); |
| 154 | 154 | show_error('Cannot connect to Database.'); |
| 155 | 155 | return false; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * Return the number of rows returned by the current query |
| 164 | 164 | * @return int |
| 165 | 165 | */ |
| 166 | - public function numRows(){ |
|
| 166 | + public function numRows() { |
|
| 167 | 167 | return $this->numRows; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * Return the last insert id value |
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | - public function insertId(){ |
|
| 174 | + public function insertId() { |
|
| 175 | 175 | return $this->insertId; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | * If is string will determine the result type "array" or "object" |
| 183 | 183 | * @return mixed the query SQL string or the record result |
| 184 | 184 | */ |
| 185 | - public function get($returnSQLQueryOrResultType = false){ |
|
| 185 | + public function get($returnSQLQueryOrResultType = false) { |
|
| 186 | 186 | $this->queryBuilder->limit(1); |
| 187 | 187 | $query = $this->getAll(true); |
| 188 | - if ($returnSQLQueryOrResultType === true){ |
|
| 188 | + if ($returnSQLQueryOrResultType === true) { |
|
| 189 | 189 | return $query; |
| 190 | 190 | } else { |
| 191 | 191 | return $this->query($query, false, $returnSQLQueryOrResultType == 'array'); |
@@ -198,9 +198,9 @@ discard block |
||
| 198 | 198 | * If is string will determine the result type "array" or "object" |
| 199 | 199 | * @return mixed the query SQL string or the record result |
| 200 | 200 | */ |
| 201 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
| 201 | + public function getAll($returnSQLQueryOrResultType = false) { |
|
| 202 | 202 | $query = $this->queryBuilder->getQuery(); |
| 203 | - if ($returnSQLQueryOrResultType === true){ |
|
| 203 | + if ($returnSQLQueryOrResultType === true) { |
|
| 204 | 204 | return $query; |
| 205 | 205 | } |
| 206 | 206 | return $this->query($query, true, $returnSQLQueryOrResultType == 'array'); |
@@ -212,18 +212,18 @@ discard block |
||
| 212 | 212 | * @param boolean $escape whether to escape or not the values |
| 213 | 213 | * @return mixed the insert id of the new record or null |
| 214 | 214 | */ |
| 215 | - public function insert($data = array(), $escape = true){ |
|
| 216 | - if (empty($data) && ! empty($this->data)){ |
|
| 215 | + public function insert($data = array(), $escape = true) { |
|
| 216 | + if (empty($data) && !empty($this->data)) { |
|
| 217 | 217 | //as when using $this->setData() may be the data already escaped |
| 218 | 218 | $escape = false; |
| 219 | 219 | $data = $this->data; |
| 220 | 220 | } |
| 221 | 221 | $query = $this->queryBuilder->insert($data, $escape)->getQuery(); |
| 222 | 222 | $result = $this->query($query); |
| 223 | - if ($result){ |
|
| 223 | + if ($result) { |
|
| 224 | 224 | $this->insertId = $this->pdo->lastInsertId(); |
| 225 | 225 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
| 226 | - return ! ($this->insertId) ? true : $this->insertId; |
|
| 226 | + return !($this->insertId) ? true : $this->insertId; |
|
| 227 | 227 | } |
| 228 | 228 | return false; |
| 229 | 229 | } |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * @param boolean $escape whether to escape or not the values |
| 235 | 235 | * @return mixed the update status |
| 236 | 236 | */ |
| 237 | - public function update($data = array(), $escape = true){ |
|
| 238 | - if (empty($data) && ! empty($this->data)){ |
|
| 237 | + public function update($data = array(), $escape = true) { |
|
| 238 | + if (empty($data) && !empty($this->data)) { |
|
| 239 | 239 | //as when using $this->setData() may be the data already escaped |
| 240 | 240 | $escape = false; |
| 241 | 241 | $data = $this->data; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * Delete the record in database |
| 249 | 249 | * @return mixed the delete status |
| 250 | 250 | */ |
| 251 | - public function delete(){ |
|
| 251 | + public function delete() { |
|
| 252 | 252 | $query = $this->queryBuilder->delete()->getQuery(); |
| 253 | 253 | return $this->query($query); |
| 254 | 254 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @param integer $ttl the cache time to live in second |
| 259 | 259 | * @return object the current Database instance |
| 260 | 260 | */ |
| 261 | - public function setCache($ttl = 0){ |
|
| 261 | + public function setCache($ttl = 0) { |
|
| 262 | 262 | $this->cacheTtl = $ttl; |
| 263 | 263 | $this->temporaryCacheTtl = $ttl; |
| 264 | 264 | return $this; |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @param integer $ttl the cache time to live in second |
| 270 | 270 | * @return object the current Database instance |
| 271 | 271 | */ |
| 272 | - public function cached($ttl = 0){ |
|
| 272 | + public function cached($ttl = 0) { |
|
| 273 | 273 | $this->temporaryCacheTtl = $ttl; |
| 274 | 274 | return $this; |
| 275 | 275 | } |
@@ -281,9 +281,9 @@ discard block |
||
| 281 | 281 | * @return mixed the data after escaped or the same data if no |
| 282 | 282 | * need escaped |
| 283 | 283 | */ |
| 284 | - public function escape($data, $escaped = true){ |
|
| 284 | + public function escape($data, $escaped = true) { |
|
| 285 | 285 | $data = trim($data); |
| 286 | - if($escaped){ |
|
| 286 | + if ($escaped) { |
|
| 287 | 287 | return $this->pdo->quote($data); |
| 288 | 288 | } |
| 289 | 289 | return $data; |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * Return the number query executed count for the current request |
| 294 | 294 | * @return int |
| 295 | 295 | */ |
| 296 | - public function queryCount(){ |
|
| 296 | + public function queryCount() { |
|
| 297 | 297 | return $this->queryCount; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * Return the current query SQL string |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function getQuery(){ |
|
| 304 | + public function getQuery() { |
|
| 305 | 305 | return $this->query; |
| 306 | 306 | } |
| 307 | 307 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * Return the application database name |
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | - public function getDatabaseName(){ |
|
| 312 | + public function getDatabaseName() { |
|
| 313 | 313 | return $this->databaseName; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * Return the PDO instance |
| 318 | 318 | * @return object |
| 319 | 319 | */ |
| 320 | - public function getPdo(){ |
|
| 320 | + public function getPdo() { |
|
| 321 | 321 | return $this->pdo; |
| 322 | 322 | } |
| 323 | 323 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @param object $pdo the pdo object |
| 327 | 327 | * @return object Database |
| 328 | 328 | */ |
| 329 | - public function setPdo(PDO $pdo){ |
|
| 329 | + public function setPdo(PDO $pdo) { |
|
| 330 | 330 | $this->pdo = $pdo; |
| 331 | 331 | return $this; |
| 332 | 332 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * Return the cache instance |
| 336 | 336 | * @return CacheInterface |
| 337 | 337 | */ |
| 338 | - public function getCacheInstance(){ |
|
| 338 | + public function getCacheInstance() { |
|
| 339 | 339 | return $this->cacheInstance; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @param CacheInterface $cache the cache object |
| 345 | 345 | * @return object Database |
| 346 | 346 | */ |
| 347 | - public function setCacheInstance($cache){ |
|
| 347 | + public function setCacheInstance($cache) { |
|
| 348 | 348 | $this->cacheInstance = $cache; |
| 349 | 349 | return $this; |
| 350 | 350 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * Return the DatabaseQueryBuilder instance |
| 355 | 355 | * @return object DatabaseQueryBuilder |
| 356 | 356 | */ |
| 357 | - public function getQueryBuilder(){ |
|
| 357 | + public function getQueryBuilder() { |
|
| 358 | 358 | return $this->queryBuilder; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * Set the DatabaseQueryBuilder instance |
| 363 | 363 | * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object |
| 364 | 364 | */ |
| 365 | - public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){ |
|
| 365 | + public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) { |
|
| 366 | 366 | $this->queryBuilder = $queryBuilder; |
| 367 | 367 | return $this; |
| 368 | 368 | } |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * Return the DatabaseQueryRunner instance |
| 372 | 372 | * @return object DatabaseQueryRunner |
| 373 | 373 | */ |
| 374 | - public function getQueryRunner(){ |
|
| 374 | + public function getQueryRunner() { |
|
| 375 | 375 | return $this->queryRunner; |
| 376 | 376 | } |
| 377 | 377 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * Set the DatabaseQueryRunner instance |
| 380 | 380 | * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object |
| 381 | 381 | */ |
| 382 | - public function setQueryRunner(DatabaseQueryRunner $queryRunner){ |
|
| 382 | + public function setQueryRunner(DatabaseQueryRunner $queryRunner) { |
|
| 383 | 383 | $this->queryRunner = $queryRunner; |
| 384 | 384 | return $this; |
| 385 | 385 | } |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * Return the data to be used for insert, update, etc. |
| 389 | 389 | * @return array |
| 390 | 390 | */ |
| 391 | - public function getData(){ |
|
| 391 | + public function getData() { |
|
| 392 | 392 | return $this->data; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -399,9 +399,9 @@ discard block |
||
| 399 | 399 | * @param boolean $escape whether to escape or not the $value |
| 400 | 400 | * @return object the current Database instance |
| 401 | 401 | */ |
| 402 | - public function setData($key, $value = null, $escape = true){ |
|
| 403 | - if (is_array($key)){ |
|
| 404 | - foreach($key as $k => $v){ |
|
| 402 | + public function setData($key, $value = null, $escape = true) { |
|
| 403 | + if (is_array($key)) { |
|
| 404 | + foreach ($key as $k => $v) { |
|
| 405 | 405 | $this->setData($k, $v, $escape); |
| 406 | 406 | } |
| 407 | 407 | } else { |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @param boolean $returnAsArray return the result as array or not |
| 418 | 418 | * @return mixed the query result |
| 419 | 419 | */ |
| 420 | - public function query($query, $returnAsList = true, $returnAsArray = false){ |
|
| 420 | + public function query($query, $returnAsList = true, $returnAsArray = false) { |
|
| 421 | 421 | $this->reset(); |
| 422 | 422 | $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
| 423 | 423 | //If is the SELECT query |
@@ -438,12 +438,12 @@ discard block |
||
| 438 | 438 | //if can use cache feature for this query |
| 439 | 439 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
| 440 | 440 | |
| 441 | - if ($dbCacheStatus && $isSqlSELECTQuery){ |
|
| 441 | + if ($dbCacheStatus && $isSqlSELECTQuery) { |
|
| 442 | 442 | $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
| 443 | 443 | $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray); |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - if (!$cacheContent){ |
|
| 446 | + if (!$cacheContent) { |
|
| 447 | 447 | //count the number of query execution to server |
| 448 | 448 | $this->queryCount++; |
| 449 | 449 | |
@@ -452,19 +452,19 @@ discard block |
||
| 452 | 452 | ->setReturnAsArray($returnAsArray) |
| 453 | 453 | ->execute(); |
| 454 | 454 | |
| 455 | - if (!is_object($queryResult)){ |
|
| 455 | + if (!is_object($queryResult)) { |
|
| 456 | 456 | $this->result = false; |
| 457 | 457 | $this->numRows = 0; |
| 458 | 458 | return $this->result; |
| 459 | 459 | } |
| 460 | 460 | $this->result = $queryResult->getResult(); |
| 461 | 461 | $this->numRows = $queryResult->getNumRows(); |
| 462 | - if ($isSqlSELECTQuery && $dbCacheStatus){ |
|
| 462 | + if ($isSqlSELECTQuery && $dbCacheStatus) { |
|
| 463 | 463 | $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray); |
| 464 | 464 | $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire); |
| 465 | 465 | } |
| 466 | - } else if ($isSqlSELECTQuery){ |
|
| 467 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
| 466 | + } else if ($isSqlSELECTQuery) { |
|
| 467 | + $this->logger->info('The result for query [' . $this->query . '] already cached use it'); |
|
| 468 | 468 | $this->result = $cacheContent; |
| 469 | 469 | $this->numRows = count($this->result); |
| 470 | 470 | } |
@@ -478,9 +478,9 @@ discard block |
||
| 478 | 478 | * @param boolean $autoConnect whether to connect to database after set the configuration |
| 479 | 479 | * @return object Database |
| 480 | 480 | */ |
| 481 | - public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){ |
|
| 481 | + public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false) { |
|
| 482 | 482 | $db = array(); |
| 483 | - if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){ |
|
| 483 | + if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) { |
|
| 484 | 484 | //here don't use require_once because somewhere user can create database instance directly |
| 485 | 485 | require CONFIG_PATH . 'database.php'; |
| 486 | 486 | } |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | //determine the port using the hostname like localhost:3307 |
| 496 | 496 | //hostname will be "localhost", and port "3307" |
| 497 | 497 | $p = explode(':', $config['hostname']); |
| 498 | - if (count($p) >= 2){ |
|
| 498 | + if (count($p) >= 2) { |
|
| 499 | 499 | $config['hostname'] = $p[0]; |
| 500 | 500 | $config['port'] = $p[1]; |
| 501 | 501 | } |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | array('password' => string_hidden($this->config['password'])) |
| 510 | 510 | )) |
| 511 | 511 | ); |
| 512 | - if($autoConnect){ |
|
| 512 | + if ($autoConnect) { |
|
| 513 | 513 | //Now connect to the database |
| 514 | 514 | $this->connect(); |
| 515 | 515 | } |
@@ -520,14 +520,14 @@ discard block |
||
| 520 | 520 | * Return the database configuration |
| 521 | 521 | * @return array |
| 522 | 522 | */ |
| 523 | - public function getDatabaseConfiguration(){ |
|
| 523 | + public function getDatabaseConfiguration() { |
|
| 524 | 524 | return $this->config; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
| 528 | 528 | * Close the connexion |
| 529 | 529 | */ |
| 530 | - public function close(){ |
|
| 530 | + public function close() { |
|
| 531 | 531 | $this->pdo = null; |
| 532 | 532 | } |
| 533 | 533 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | * Return the database default configuration |
| 536 | 536 | * @return array |
| 537 | 537 | */ |
| 538 | - protected function getDatabaseDefaultConfiguration(){ |
|
| 538 | + protected function getDatabaseDefaultConfiguration() { |
|
| 539 | 539 | return array( |
| 540 | 540 | 'driver' => '', |
| 541 | 541 | 'username' => '', |
@@ -553,16 +553,16 @@ discard block |
||
| 553 | 553 | * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties |
| 554 | 554 | * @return void |
| 555 | 555 | */ |
| 556 | - protected function updateQueryBuilderAndRunnerProperties(){ |
|
| 556 | + protected function updateQueryBuilderAndRunnerProperties() { |
|
| 557 | 557 | //update queryBuilder with some properties needed |
| 558 | - if (is_object($this->queryBuilder)){ |
|
| 558 | + if (is_object($this->queryBuilder)) { |
|
| 559 | 559 | $this->queryBuilder->setDriver($this->config['driver']) |
| 560 | 560 | ->setPrefix($this->config['prefix']) |
| 561 | 561 | ->setPdo($this->pdo); |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | //update queryRunner with some properties needed |
| 565 | - if (is_object($this->queryRunner)){ |
|
| 565 | + if (is_object($this->queryRunner)) { |
|
| 566 | 566 | $this->queryRunner->setDriver($this->config['driver']) |
| 567 | 567 | ->setPdo($this->pdo); |
| 568 | 568 | } |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * This method is used to get the PDO DSN string using the configured driver |
| 574 | 574 | * @return string|null the DSN string or null if can not find it |
| 575 | 575 | */ |
| 576 | - protected function getDsnValueFromConfig(){ |
|
| 576 | + protected function getDsnValueFromConfig() { |
|
| 577 | 577 | $dsn = null; |
| 578 | 578 | $config = $this->getDatabaseConfiguration(); |
| 579 | - if (! empty($config)){ |
|
| 579 | + if (!empty($config)) { |
|
| 580 | 580 | $driver = $config['driver']; |
| 581 | 581 | $driverDsnMap = array( |
| 582 | 582 | 'mysql' => $this->getDsnValueForDriver('mysql'), |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | 'sqlite' => $this->getDsnValueForDriver('sqlite'), |
| 585 | 585 | 'oracle' => $this->getDsnValueForDriver('oracle') |
| 586 | 586 | ); |
| 587 | - if (isset($driverDsnMap[$driver])){ |
|
| 587 | + if (isset($driverDsnMap[$driver])) { |
|
| 588 | 588 | $dsn = $driverDsnMap[$driver]; |
| 589 | 589 | } |
| 590 | 590 | } |
@@ -596,17 +596,17 @@ discard block |
||
| 596 | 596 | * @param string $driver the driver name |
| 597 | 597 | * @return string|null the dsn name |
| 598 | 598 | */ |
| 599 | - protected function getDsnValueForDriver($driver){ |
|
| 599 | + protected function getDsnValueForDriver($driver) { |
|
| 600 | 600 | $dsn = ''; |
| 601 | 601 | $config = $this->getDatabaseConfiguration(); |
| 602 | - if (empty($config)){ |
|
| 602 | + if (empty($config)) { |
|
| 603 | 603 | return null; |
| 604 | 604 | } |
| 605 | 605 | switch ($driver) { |
| 606 | 606 | case 'mysql': |
| 607 | 607 | case 'pgsql': |
| 608 | 608 | $port = ''; |
| 609 | - if (! empty($config['port'])) { |
|
| 609 | + if (!empty($config['port'])) { |
|
| 610 | 610 | $port = 'port=' . $config['port'] . ';'; |
| 611 | 611 | } |
| 612 | 612 | $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database']; |
@@ -616,10 +616,10 @@ discard block |
||
| 616 | 616 | break; |
| 617 | 617 | case 'oracle': |
| 618 | 618 | $port = ''; |
| 619 | - if (! empty($config['port'])) { |
|
| 619 | + if (!empty($config['port'])) { |
|
| 620 | 620 | $port = ':' . $config['port']; |
| 621 | 621 | } |
| 622 | - $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 622 | + $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database']; |
|
| 623 | 623 | break; |
| 624 | 624 | } |
| 625 | 625 | return $dsn; |
@@ -631,9 +631,9 @@ discard block |
||
| 631 | 631 | * |
| 632 | 632 | * @return mixed |
| 633 | 633 | */ |
| 634 | - protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){ |
|
| 634 | + protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) { |
|
| 635 | 635 | $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray); |
| 636 | - if (! is_object($this->cacheInstance)){ |
|
| 636 | + if (!is_object($this->cacheInstance)) { |
|
| 637 | 637 | //can not call method with reference in argument |
| 638 | 638 | //like $this->setCacheInstance(& get_instance()->cache); |
| 639 | 639 | //use temporary variable |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | * @param mixed $result the query result to save |
| 651 | 651 | * @param int $expire the cache TTL |
| 652 | 652 | */ |
| 653 | - protected function setCacheContentForQuery($query, $key, $result, $expire){ |
|
| 654 | - $this->logger->info('Save the result for query [' .$query. '] into cache for future use'); |
|
| 655 | - if (! is_object($this->cacheInstance)){ |
|
| 653 | + protected function setCacheContentForQuery($query, $key, $result, $expire) { |
|
| 654 | + $this->logger->info('Save the result for query [' . $query . '] into cache for future use'); |
|
| 655 | + if (!is_object($this->cacheInstance)) { |
|
| 656 | 656 | //can not call method with reference in argument |
| 657 | 657 | //like $this->setCacheInstance(& get_instance()->cache); |
| 658 | 658 | //use temporary variable |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | * |
| 670 | 670 | * @return string |
| 671 | 671 | */ |
| 672 | - protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){ |
|
| 672 | + protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) { |
|
| 673 | 673 | return md5($query . $returnAsList . $returnAsArray); |
| 674 | 674 | } |
| 675 | 675 | |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | /** |
| 678 | 678 | * Reset the database class attributs to the initail values before each query. |
| 679 | 679 | */ |
| 680 | - private function reset(){ |
|
| 680 | + private function reset() { |
|
| 681 | 681 | //query builder reset |
| 682 | 682 | $this->queryBuilder->reset(); |
| 683 | 683 | $this->numRows = 0; |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | /** |
| 691 | 691 | * The class destructor |
| 692 | 692 | */ |
| 693 | - public function __destruct(){ |
|
| 693 | + public function __destruct() { |
|
| 694 | 694 | $this->pdo = null; |
| 695 | 695 | } |
| 696 | 696 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @param mixed $default the default value to use if can not find the session flash item in the list |
| 66 | 66 | * @return mixed the session flash value if exist or the default value |
| 67 | 67 | */ |
| 68 | - public static function getFlash($item, $default = null){ |
|
| 68 | + public static function getFlash($item, $default = null) { |
|
| 69 | 69 | $logger = self::getLogger(); |
| 70 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 70 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 71 | 71 | $return = array_key_exists($key, $_SESSION) ? |
| 72 | 72 | ($_SESSION[$key]) : $default; |
| 73 | - if(array_key_exists($key, $_SESSION)){ |
|
| 73 | + if (array_key_exists($key, $_SESSION)) { |
|
| 74 | 74 | unset($_SESSION[$key]); |
| 75 | - } else{ |
|
| 76 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
| 75 | + } else { |
|
| 76 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
| 77 | 77 | } |
| 78 | 78 | return $return; |
| 79 | 79 | } |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | * Clear the session item in the list |
| 103 | 103 | * @param string $item the session item name to be deleted |
| 104 | 104 | */ |
| 105 | - public static function clear($item){ |
|
| 105 | + public static function clear($item) { |
|
| 106 | 106 | $logger = self::getLogger(); |
| 107 | - if(array_key_exists($item, $_SESSION)){ |
|
| 108 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
| 107 | + if (array_key_exists($item, $_SESSION)) { |
|
| 108 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
| 109 | 109 | unset($_SESSION[$item]); |
| 110 | - } else{ |
|
| 111 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
| 110 | + } else { |
|
| 111 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | * Clear the session flash item in the list |
| 117 | 117 | * @param string $item the session flash item name to be deleted |
| 118 | 118 | */ |
| 119 | - public static function clearFlash($item){ |
|
| 119 | + public static function clearFlash($item) { |
|
| 120 | 120 | $logger = self::getLogger(); |
| 121 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
| 122 | - if(array_key_exists($key, $_SESSION)){ |
|
| 123 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
| 121 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
| 122 | + if (array_key_exists($key, $_SESSION)) { |
|
| 123 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
| 124 | 124 | unset($_SESSION[$item]); |
| 125 | - } else{ |
|
| 126 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
| 125 | + } else { |
|
| 126 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
@@ -44,25 +44,25 @@ |
||
| 44 | 44 | * @param string $path the link path or full URL |
| 45 | 45 | * @return string the full link URL |
| 46 | 46 | */ |
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 47 | + public static function site_url($path = '') { |
|
| 48 | + if (is_url($path)) { |
|
| 49 | 49 | return $path; |
| 50 | 50 | } |
| 51 | 51 | $path = rtrim($path, '/'); |
| 52 | 52 | $baseUrl = get_config('base_url'); |
| 53 | 53 | $frontController = get_config('front_controller'); |
| 54 | 54 | $url = $baseUrl; |
| 55 | - if($frontController){ |
|
| 55 | + if ($frontController) { |
|
| 56 | 56 | $url .= $frontController . '/'; |
| 57 | 57 | } |
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 58 | + if (($suffix = get_config('url_suffix')) && $path) { |
|
| 59 | + if (strpos($path, '?') !== false) { |
|
| 60 | 60 | $query = explode('?', $path); |
| 61 | 61 | $query[0] = str_ireplace($suffix, '', $query[0]); |
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | - } else{ |
|
| 65 | + } else { |
|
| 66 | 66 | $path .= $suffix; |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
| 29 | 29 | */ |
| 30 | - if ( !interface_exists('SessionHandlerInterface')){ |
|
| 30 | + if (!interface_exists('SessionHandlerInterface')) { |
|
| 31 | 31 | show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.'); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - class DBSessionHandler extends BaseClass implements SessionHandlerInterface{ |
|
| 34 | + class DBSessionHandler extends BaseClass implements SessionHandlerInterface { |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * The encryption method to use to encrypt session data in database |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * Create new instance of Database session handler |
| 80 | 80 | * @param object $modelInstance the model instance |
| 81 | 81 | */ |
| 82 | - public function __construct(DBSessionHandlerModel $modelInstance = null){ |
|
| 82 | + public function __construct(DBSessionHandlerModel $modelInstance = null) { |
|
| 83 | 83 | parent::__construct(); |
| 84 | 84 | |
| 85 | 85 | //Set Loader instance to use |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | $this->OBJ = & get_instance(); |
| 89 | 89 | |
| 90 | - if (is_object($modelInstance)){ |
|
| 90 | + if (is_object($modelInstance)) { |
|
| 91 | 91 | $this->setModelInstance($modelInstance); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * Set the session secret used to encrypt the data in database |
| 97 | 97 | * @param string $secret the base64 string secret |
| 98 | 98 | */ |
| 99 | - public function setSessionSecret($secret){ |
|
| 99 | + public function setSessionSecret($secret) { |
|
| 100 | 100 | $this->sessionSecret = $secret; |
| 101 | 101 | return $this; |
| 102 | 102 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * Return the session secret |
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | - public function getSessionSecret(){ |
|
| 108 | + public function getSessionSecret() { |
|
| 109 | 109 | return $this->sessionSecret; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * Set the initializer vector for openssl |
| 115 | 115 | * @param string $key the session secret used in base64 format |
| 116 | 116 | */ |
| 117 | - public function setInitializerVector($key){ |
|
| 117 | + public function setInitializerVector($key) { |
|
| 118 | 118 | $ivLength = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD); |
| 119 | 119 | $key = base64_decode($key); |
| 120 | 120 | $this->iv = substr(hash('sha256', $key), 0, $ivLength); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * Return the initializer vector |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public function getInitializerVector(){ |
|
| 128 | + public function getInitializerVector() { |
|
| 129 | 129 | return $this->iv; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | * @param string $sessionName the session name |
| 136 | 136 | * @return boolean |
| 137 | 137 | */ |
| 138 | - public function open($savePath, $sessionName){ |
|
| 138 | + public function open($savePath, $sessionName) { |
|
| 139 | 139 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
| 140 | 140 | //try to check if session secret is set before |
| 141 | 141 | $secret = $this->getSessionSecret(); |
| 142 | - if (empty($secret)){ |
|
| 142 | + if (empty($secret)) { |
|
| 143 | 143 | $secret = get_config('session_secret', null); |
| 144 | 144 | $this->setSessionSecret($secret); |
| 145 | 145 | } |
| 146 | 146 | $this->logger->info('Session secret: ' . $secret); |
| 147 | 147 | |
| 148 | - if (! is_object($this->modelInstance)){ |
|
| 148 | + if (!is_object($this->modelInstance)) { |
|
| 149 | 149 | $this->setModelInstanceFromSessionConfig(); |
| 150 | 150 | } |
| 151 | 151 | $this->setInitializerVector($secret); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | //set session tables columns |
| 154 | 154 | $this->sessionTableColumns = $this->modelInstance->getSessionTableColumns(); |
| 155 | 155 | |
| 156 | - if (empty($this->sessionTableColumns)){ |
|
| 156 | + if (empty($this->sessionTableColumns)) { |
|
| 157 | 157 | show_error('The session handler is "database" but the table columns not set'); |
| 158 | 158 | } |
| 159 | 159 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * Close the session |
| 170 | 170 | * @return boolean |
| 171 | 171 | */ |
| 172 | - public function close(){ |
|
| 172 | + public function close() { |
|
| 173 | 173 | $this->logger->debug('Closing database session handler'); |
| 174 | 174 | return true; |
| 175 | 175 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param string $sid the session id to use |
| 180 | 180 | * @return string the session data in serialiaze format |
| 181 | 181 | */ |
| 182 | - public function read($sid){ |
|
| 182 | + public function read($sid) { |
|
| 183 | 183 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
| 184 | 184 | $instance = $this->getModelInstance(); |
| 185 | 185 | $columns = $this->sessionTableColumns; |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $ip = get_ip(); |
| 190 | 190 | $host = @gethostbyaddr($ip) or null; |
| 191 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
| 191 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
| 192 | 192 | |
| 193 | 193 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
| 194 | - if ($data && isset($data->{$columns['sdata']})){ |
|
| 194 | + if ($data && isset($data->{$columns['sdata']})) { |
|
| 195 | 195 | //checking inactivity |
| 196 | 196 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
| 197 | - if ($data->{$columns['stime']} < $timeInactivity){ |
|
| 197 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
| 198 | 198 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
| 199 | 199 | $this->destroy($sid); |
| 200 | 200 | return null; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | * @param mixed $data the session data to save in serialize format |
| 212 | 212 | * @return boolean |
| 213 | 213 | */ |
| 214 | - public function write($sid, $data){ |
|
| 214 | + public function write($sid, $data) { |
|
| 215 | 215 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
| 216 | 216 | $instance = $this->getModelInstance(); |
| 217 | 217 | $columns = $this->sessionTableColumns; |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | $ip = get_ip(); |
| 223 | 223 | $keyValue = $instance->getKeyValue(); |
| 224 | 224 | $host = @gethostbyaddr($ip) or null; |
| 225 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
| 225 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
| 226 | 226 | $data = $this->encode($data); |
| 227 | 227 | $params = array( |
| 228 | 228 | $columns['sid'] => $sid, |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | ); |
| 236 | 236 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
| 237 | 237 | $exists = $instance->get($sid); |
| 238 | - if ($exists){ |
|
| 238 | + if ($exists) { |
|
| 239 | 239 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
| 240 | 240 | //update |
| 241 | 241 | unset($params[$columns['sid']]); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @param string $sid the session id value |
| 252 | 252 | * @return boolean |
| 253 | 253 | */ |
| 254 | - public function destroy($sid){ |
|
| 254 | + public function destroy($sid) { |
|
| 255 | 255 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
| 256 | 256 | $instance = $this->modelInstance; |
| 257 | 257 | $instance->delete($sid); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * @param integer $maxLifetime the max lifetime |
| 264 | 264 | * @return boolean |
| 265 | 265 | */ |
| 266 | - public function gc($maxLifetime){ |
|
| 266 | + public function gc($maxLifetime) { |
|
| 267 | 267 | $instance = $this->modelInstance; |
| 268 | 268 | $time = time() - $maxLifetime; |
| 269 | 269 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * @param mixed $data the session data to encode |
| 277 | 277 | * @return mixed the encoded session data |
| 278 | 278 | */ |
| 279 | - public function encode($data){ |
|
| 279 | + public function encode($data) { |
|
| 280 | 280 | $key = base64_decode($this->sessionSecret); |
| 281 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
| 281 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
| 282 | 282 | $output = base64_encode($dataEncrypted); |
| 283 | 283 | return $output; |
| 284 | 284 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @param mixed $data the data to decode |
| 290 | 290 | * @return mixed the decoded data |
| 291 | 291 | */ |
| 292 | - public function decode($data){ |
|
| 292 | + public function decode($data) { |
|
| 293 | 293 | $key = base64_decode($this->sessionSecret); |
| 294 | 294 | $data = base64_decode($data); |
| 295 | 295 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * set the loader instance for future use |
| 310 | 310 | * @param object Loader $loader the loader object |
| 311 | 311 | */ |
| 312 | - public function setLoader($loader){ |
|
| 312 | + public function setLoader($loader) { |
|
| 313 | 313 | $this->loader = $loader; |
| 314 | 314 | return $this; |
| 315 | 315 | } |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * set the model instance for future use |
| 327 | 327 | * @param DBSessionHandlerModel $modelInstance the model object |
| 328 | 328 | */ |
| 329 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
| 329 | + public function setModelInstance(DBSessionHandlerModel $modelInstance) { |
|
| 330 | 330 | $this->modelInstance = $modelInstance; |
| 331 | 331 | return $this; |
| 332 | 332 | } |
@@ -334,13 +334,13 @@ discard block |
||
| 334 | 334 | /** |
| 335 | 335 | * Set the model instance using the configuration for session |
| 336 | 336 | */ |
| 337 | - protected function setModelInstanceFromSessionConfig(){ |
|
| 337 | + protected function setModelInstanceFromSessionConfig() { |
|
| 338 | 338 | $modelName = get_config('session_save_path'); |
| 339 | 339 | $this->logger->info('The database session model: ' . $modelName); |
| 340 | 340 | $this->loader->model($modelName, 'dbsessionhandlerinstance'); |
| 341 | 341 | //@codeCoverageIgnoreStart |
| 342 | 342 | if (isset($this->OBJ->dbsessionhandlerinstance) |
| 343 | - && ! ($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) |
|
| 343 | + && !($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) |
|
| 344 | 344 | ) { |
| 345 | 345 | show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"'); |
| 346 | 346 | } |