@@ -1,108 +1,108 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - class DatabaseQueryBuilder{ |
|
| 27 | - /** |
|
| 28 | - * The SQL SELECT statment |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private $select = '*'; |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + class DatabaseQueryBuilder{ |
|
| 27 | + /** |
|
| 28 | + * The SQL SELECT statment |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private $select = '*'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The SQL FROM statment |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private $from = null; |
|
| 33 | + /** |
|
| 34 | + * The SQL FROM statment |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private $from = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * The SQL WHERE statment |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private $where = null; |
|
| 39 | + /** |
|
| 40 | + * The SQL WHERE statment |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private $where = null; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The SQL LIMIT statment |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - private $limit = null; |
|
| 45 | + /** |
|
| 46 | + * The SQL LIMIT statment |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + private $limit = null; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * The SQL JOIN statment |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - private $join = null; |
|
| 51 | + /** |
|
| 52 | + * The SQL JOIN statment |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + private $join = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * The SQL ORDER BY statment |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private $orderBy = null; |
|
| 57 | + /** |
|
| 58 | + * The SQL ORDER BY statment |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private $orderBy = null; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The SQL GROUP BY statment |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - private $groupBy = null; |
|
| 63 | + /** |
|
| 64 | + * The SQL GROUP BY statment |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + private $groupBy = null; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The SQL HAVING statment |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - private $having = null; |
|
| 69 | + /** |
|
| 70 | + * The SQL HAVING statment |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + private $having = null; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * The full SQL query statment after build for each command |
|
| 77 | - * @var string |
|
| 78 | - */ |
|
| 79 | - private $query = null; |
|
| 75 | + /** |
|
| 76 | + * The full SQL query statment after build for each command |
|
| 77 | + * @var string |
|
| 78 | + */ |
|
| 79 | + private $query = null; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * The list of SQL valid operators |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 81 | + /** |
|
| 82 | + * The list of SQL valid operators |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | 85 | private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The prefix used in each database table |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * The prefix used in each database table |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | 92 | private $prefix = null; |
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * The PDO instance |
|
| 97 | - * @var object |
|
| 98 | - */ |
|
| 96 | + * The PDO instance |
|
| 97 | + * @var object |
|
| 98 | + */ |
|
| 99 | 99 | private $pdo = null; |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * The database driver name used |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - private $driver = null; |
|
| 101 | + /** |
|
| 102 | + * The database driver name used |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + private $driver = null; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function __construct(PDO $pdo = null){ |
| 113 | 113 | if (is_object($pdo)){ |
| 114 | - $this->setPdo($pdo); |
|
| 114 | + $this->setPdo($pdo); |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | * @return object the current DatabaseQueryBuilder instance |
| 122 | 122 | */ |
| 123 | 123 | public function from($table){ |
| 124 | - if (is_array($table)){ |
|
| 124 | + if (is_array($table)){ |
|
| 125 | 125 | $froms = ''; |
| 126 | 126 | foreach($table as $key){ |
| 127 | - $froms .= $this->getPrefix() . $key . ', '; |
|
| 127 | + $froms .= $this->getPrefix() . $key . ', '; |
|
| 128 | 128 | } |
| 129 | 129 | $this->from = rtrim($froms, ', '); |
| 130 | - } else { |
|
| 130 | + } else { |
|
| 131 | 131 | $this->from = $this->getPrefix() . $table; |
| 132 | - } |
|
| 133 | - return $this; |
|
| 132 | + } |
|
| 133 | + return $this; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | * @return object the current DatabaseQueryBuilder instance |
| 140 | 140 | */ |
| 141 | 141 | public function select($fields){ |
| 142 | - $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
| 143 | - $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
|
| 144 | - return $this; |
|
| 142 | + $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
| 143 | + $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
|
| 144 | + return $this; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,19 +150,19 @@ discard block |
||
| 150 | 150 | * @return object the current DatabaseQueryBuilder instance |
| 151 | 151 | */ |
| 152 | 152 | public function distinct($field){ |
| 153 | - $distinct = ' DISTINCT ' . $field; |
|
| 154 | - $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
|
| 155 | - return $this; |
|
| 153 | + $distinct = ' DISTINCT ' . $field; |
|
| 154 | + $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
|
| 155 | + return $this; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Set the SQL function COUNT in SELECT statment |
|
| 160 | - * @param string $field the field name |
|
| 161 | - * @param string $name if is not null represent the alias used for this field in the result |
|
| 162 | - * @return object the current DatabaseQueryBuilder instance |
|
| 163 | - */ |
|
| 158 | + /** |
|
| 159 | + * Set the SQL function COUNT in SELECT statment |
|
| 160 | + * @param string $field the field name |
|
| 161 | + * @param string $name if is not null represent the alias used for this field in the result |
|
| 162 | + * @return object the current DatabaseQueryBuilder instance |
|
| 163 | + */ |
|
| 164 | 164 | public function count($field = '*', $name = null){ |
| 165 | - return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
|
| 165 | + return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return object the current DatabaseQueryBuilder instance |
| 173 | 173 | */ |
| 174 | 174 | public function min($field, $name = null){ |
| 175 | - return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
|
| 175 | + return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return object the current DatabaseQueryBuilder instance |
| 183 | 183 | */ |
| 184 | 184 | public function max($field, $name = null){ |
| 185 | - return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
|
| 185 | + return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @return object the current DatabaseQueryBuilder instance |
| 193 | 193 | */ |
| 194 | 194 | public function sum($field, $name = null){ |
| 195 | - return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
|
| 195 | + return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return object the current DatabaseQueryBuilder instance |
| 203 | 203 | */ |
| 204 | 204 | public function avg($field, $name = null){ |
| 205 | - return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
|
| 205 | + return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -216,20 +216,20 @@ discard block |
||
| 216 | 216 | * @return object the current DatabaseQueryBuilder instance |
| 217 | 217 | */ |
| 218 | 218 | public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
| 219 | - $on = $field1; |
|
| 220 | - $table = $this->getPrefix() . $table; |
|
| 221 | - if (! is_null($op)){ |
|
| 219 | + $on = $field1; |
|
| 220 | + $table = $this->getPrefix() . $table; |
|
| 221 | + if (! is_null($op)){ |
|
| 222 | 222 | $on = (! in_array($op, $this->operatorList) |
| 223 | - ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
|
| 224 | - : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
|
| 225 | - } |
|
| 226 | - if (empty($this->join)){ |
|
| 223 | + ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
|
| 224 | + : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
|
| 225 | + } |
|
| 226 | + if (empty($this->join)){ |
|
| 227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 228 | - } |
|
| 229 | - else{ |
|
| 228 | + } |
|
| 229 | + else{ |
|
| 230 | 230 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 231 | - } |
|
| 232 | - return $this; |
|
| 231 | + } |
|
| 232 | + return $this; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @return object the current DatabaseQueryBuilder instance |
| 239 | 239 | */ |
| 240 | 240 | public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
| 241 | - return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
| 241 | + return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -247,16 +247,16 @@ discard block |
||
| 247 | 247 | * @return object the current DatabaseQueryBuilder instance |
| 248 | 248 | */ |
| 249 | 249 | public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
| 250 | - return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
| 251 | - } |
|
| 250 | + return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 253 | + /** |
|
| 254 | 254 | * Set the SQL RIGHT JOIN statment |
| 255 | 255 | * @see DatabaseQueryBuilder::join() |
| 256 | 256 | * @return object the current DatabaseQueryBuilder instance |
| 257 | 257 | */ |
| 258 | 258 | public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
| 259 | - return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
| 259 | + return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @return object the current DatabaseQueryBuilder instance |
| 266 | 266 | */ |
| 267 | 267 | public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 268 | - return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
| 268 | + return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @return object the current DatabaseQueryBuilder instance |
| 275 | 275 | */ |
| 276 | 276 | public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 277 | - return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
| 277 | + return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return object the current DatabaseQueryBuilder instance |
| 284 | 284 | */ |
| 285 | 285 | public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
| 286 | - return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
| 286 | + return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * @return object the current DatabaseQueryBuilder instance |
| 294 | 294 | */ |
| 295 | 295 | public function whereIsNull($field, $andOr = 'AND'){ |
| 296 | - if (is_array($field)){ |
|
| 296 | + if (is_array($field)){ |
|
| 297 | 297 | foreach($field as $f){ |
| 298 | - $this->whereIsNull($f, $andOr); |
|
| 298 | + $this->whereIsNull($f, $andOr); |
|
| 299 | 299 | } |
| 300 | - } else { |
|
| 301 | - $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 302 | - } |
|
| 303 | - return $this; |
|
| 300 | + } else { |
|
| 301 | + $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 302 | + } |
|
| 303 | + return $this; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | * @return object the current DatabaseQueryBuilder instance |
| 311 | 311 | */ |
| 312 | 312 | public function whereIsNotNull($field, $andOr = 'AND'){ |
| 313 | - if (is_array($field)){ |
|
| 313 | + if (is_array($field)){ |
|
| 314 | 314 | foreach($field as $f){ |
| 315 | - $this->whereIsNotNull($f, $andOr); |
|
| 315 | + $this->whereIsNotNull($f, $andOr); |
|
| 316 | + } |
|
| 317 | + } else { |
|
| 318 | + $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 316 | 319 | } |
| 317 | - } else { |
|
| 318 | - $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 319 | - } |
|
| 320 | - return $this; |
|
| 320 | + return $this; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | * @return object the current DatabaseQueryBuilder instance |
| 332 | 332 | */ |
| 333 | 333 | public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
| 334 | - $whereStr = ''; |
|
| 335 | - if (is_array($where)){ |
|
| 334 | + $whereStr = ''; |
|
| 335 | + if (is_array($where)){ |
|
| 336 | 336 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 337 | - } |
|
| 338 | - else{ |
|
| 337 | + } |
|
| 338 | + else{ |
|
| 339 | 339 | if (is_array($op)){ |
| 340 | - $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
| 340 | + $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
|
| 341 | 341 | } else { |
| 342 | - $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
|
| 342 | + $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
|
| 343 | + } |
|
| 343 | 344 | } |
| 344 | - } |
|
| 345 | - $this->setWhereStr($whereStr, $andOr); |
|
| 346 | - return $this; |
|
| 345 | + $this->setWhereStr($whereStr, $andOr); |
|
| 346 | + return $this; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @return object the current DatabaseQueryBuilder instance |
| 353 | 353 | */ |
| 354 | 354 | public function orWhere($where, $op = null, $val = null, $escape = true){ |
| 355 | - return $this->where($where, $op, $val, '', 'OR', $escape); |
|
| 355 | + return $this->where($where, $op, $val, '', 'OR', $escape); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @return object the current DatabaseQueryBuilder instance |
| 363 | 363 | */ |
| 364 | 364 | public function notWhere($where, $op = null, $val = null, $escape = true){ |
| 365 | - return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
| 365 | + return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @return object the current DatabaseQueryBuilder instance |
| 372 | 372 | */ |
| 373 | 373 | public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
| 374 | - return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
| 374 | + return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -381,16 +381,16 @@ discard block |
||
| 381 | 381 | * @return object the current DatabaseQueryBuilder instance |
| 382 | 382 | */ |
| 383 | 383 | public function groupStart($type = '', $andOr = ' AND'){ |
| 384 | - if (empty($this->where)){ |
|
| 384 | + if (empty($this->where)){ |
|
| 385 | 385 | $this->where = $type . ' ('; |
| 386 | - } else { |
|
| 387 | - if (substr(trim($this->where), -1) == '('){ |
|
| 386 | + } else { |
|
| 387 | + if (substr(trim($this->where), -1) == '('){ |
|
| 388 | 388 | $this->where .= $type . ' ('; |
| 389 | - } else { |
|
| 390 | - $this->where .= $andOr . ' ' . $type . ' ('; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - return $this; |
|
| 389 | + } else { |
|
| 390 | + $this->where .= $andOr . ' ' . $type . ' ('; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + return $this; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return object the current DatabaseQueryBuilder instance |
| 400 | 400 | */ |
| 401 | 401 | public function notGroupStart(){ |
| 402 | - return $this->groupStart('NOT'); |
|
| 402 | + return $this->groupStart('NOT'); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -408,16 +408,16 @@ discard block |
||
| 408 | 408 | * @return object the current DatabaseQueryBuilder instance |
| 409 | 409 | */ |
| 410 | 410 | public function orGroupStart(){ |
| 411 | - return $this->groupStart('', ' OR'); |
|
| 411 | + return $this->groupStart('', ' OR'); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
| 416 | - * @see DatabaseQueryBuilder::groupStart() |
|
| 417 | - * @return object the current DatabaseQueryBuilder instance |
|
| 418 | - */ |
|
| 414 | + /** |
|
| 415 | + * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
| 416 | + * @see DatabaseQueryBuilder::groupStart() |
|
| 417 | + * @return object the current DatabaseQueryBuilder instance |
|
| 418 | + */ |
|
| 419 | 419 | public function orNotGroupStart(){ |
| 420 | - return $this->groupStart('NOT', ' OR'); |
|
| 420 | + return $this->groupStart('NOT', ' OR'); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | * @return object the current DatabaseQueryBuilder instance |
| 426 | 426 | */ |
| 427 | 427 | public function groupEnd(){ |
| 428 | - $this->where .= ')'; |
|
| 429 | - return $this; |
|
| 428 | + $this->where .= ')'; |
|
| 429 | + return $this; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @return object the current DatabaseQueryBuilder instance |
| 440 | 440 | */ |
| 441 | 441 | public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
| 442 | - $_keys = array(); |
|
| 443 | - foreach ($keys as $k => $v){ |
|
| 442 | + $_keys = array(); |
|
| 443 | + foreach ($keys as $k => $v){ |
|
| 444 | 444 | if (is_null($v)){ |
| 445 | - $v = ''; |
|
| 445 | + $v = ''; |
|
| 446 | 446 | } |
| 447 | 447 | $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape)); |
| 448 | - } |
|
| 449 | - $keys = implode(', ', $_keys); |
|
| 450 | - $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')'; |
|
| 451 | - $this->setWhereStr($whereStr, $andOr); |
|
| 452 | - return $this; |
|
| 448 | + } |
|
| 449 | + $keys = implode(', ', $_keys); |
|
| 450 | + $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')'; |
|
| 451 | + $this->setWhereStr($whereStr, $andOr); |
|
| 452 | + return $this; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * @return object the current DatabaseQueryBuilder instance |
| 459 | 459 | */ |
| 460 | 460 | public function notIn($field, array $keys, $escape = true){ |
| 461 | - return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
| 461 | + return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @return object the current DatabaseQueryBuilder instance |
| 468 | 468 | */ |
| 469 | 469 | public function orIn($field, array $keys, $escape = true){ |
| 470 | - return $this->in($field, $keys, '', 'OR', $escape); |
|
| 470 | + return $this->in($field, $keys, '', 'OR', $escape); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | * @return object the current DatabaseQueryBuilder instance |
| 477 | 477 | */ |
| 478 | 478 | public function orNotIn($field, array $keys, $escape = true){ |
| 479 | - return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
| 479 | + return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | * @return object the current DatabaseQueryBuilder instance |
| 491 | 491 | */ |
| 492 | 492 | public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
| 493 | - if (is_null($value1)){ |
|
| 493 | + if (is_null($value1)){ |
|
| 494 | 494 | $value1 = ''; |
| 495 | - } |
|
| 496 | - if (is_null($value2)){ |
|
| 495 | + } |
|
| 496 | + if (is_null($value2)){ |
|
| 497 | 497 | $value2 = ''; |
| 498 | - } |
|
| 499 | - $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
|
| 500 | - $this->setWhereStr($whereStr, $andOr); |
|
| 501 | - return $this; |
|
| 498 | + } |
|
| 499 | + $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
|
| 500 | + $this->setWhereStr($whereStr, $andOr); |
|
| 501 | + return $this; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | * @return object the current DatabaseQueryBuilder instance |
| 508 | 508 | */ |
| 509 | 509 | public function notBetween($field, $value1, $value2, $escape = true){ |
| 510 | - return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
| 510 | + return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @return object the current DatabaseQueryBuilder instance |
| 517 | 517 | */ |
| 518 | 518 | public function orBetween($field, $value1, $value2, $escape = true){ |
| 519 | - return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
| 519 | + return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @return object the current DatabaseQueryBuilder instance |
| 526 | 526 | */ |
| 527 | 527 | public function orNotBetween($field, $value1, $value2, $escape = true){ |
| 528 | - return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
| 528 | + return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -538,11 +538,11 @@ discard block |
||
| 538 | 538 | * @return object the current DatabaseQueryBuilder instance |
| 539 | 539 | */ |
| 540 | 540 | public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
| 541 | - if (empty($data)){ |
|
| 541 | + if (empty($data)){ |
|
| 542 | 542 | $data = ''; |
| 543 | - } |
|
| 544 | - $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
|
| 545 | - return $this; |
|
| 543 | + } |
|
| 544 | + $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
|
| 545 | + return $this; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | * @return object the current DatabaseQueryBuilder instance |
| 552 | 552 | */ |
| 553 | 553 | public function orLike($field, $data, $escape = true){ |
| 554 | - return $this->like($field, $data, '', 'OR', $escape); |
|
| 554 | + return $this->like($field, $data, '', 'OR', $escape); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | * @return object the current DatabaseQueryBuilder instance |
| 561 | 561 | */ |
| 562 | 562 | public function notLike($field, $data, $escape = true){ |
| 563 | - return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
| 563 | + return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @return object the current DatabaseQueryBuilder instance |
| 570 | 570 | */ |
| 571 | 571 | public function orNotLike($field, $data, $escape = true){ |
| 572 | - return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
| 572 | + return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -580,16 +580,16 @@ discard block |
||
| 580 | 580 | * @return object the current DatabaseQueryBuilder instance |
| 581 | 581 | */ |
| 582 | 582 | public function limit($limit, $limitEnd = null){ |
| 583 | - if (empty($limit)){ |
|
| 583 | + if (empty($limit)){ |
|
| 584 | 584 | $limit = 0; |
| 585 | - } |
|
| 586 | - if (! is_null($limitEnd)){ |
|
| 585 | + } |
|
| 586 | + if (! is_null($limitEnd)){ |
|
| 587 | 587 | $this->limit = $limit . ', ' . $limitEnd; |
| 588 | - } |
|
| 589 | - else{ |
|
| 588 | + } |
|
| 589 | + else{ |
|
| 590 | 590 | $this->limit = $limit; |
| 591 | - } |
|
| 592 | - return $this; |
|
| 591 | + } |
|
| 592 | + return $this; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -599,15 +599,15 @@ discard block |
||
| 599 | 599 | * @return object the current DatabaseQueryBuilder instance |
| 600 | 600 | */ |
| 601 | 601 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
| 602 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 602 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 603 | 603 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 604 | - } |
|
| 605 | - else{ |
|
| 604 | + } |
|
| 605 | + else{ |
|
| 606 | 606 | $this->orderBy = empty($this->orderBy) |
| 607 | - ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
| 608 | - : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 609 | - } |
|
| 610 | - return $this; |
|
| 607 | + ? ($orderBy . ' ' . strtoupper($orderDir)) |
|
| 608 | + : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
| 609 | + } |
|
| 610 | + return $this; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -616,13 +616,13 @@ discard block |
||
| 616 | 616 | * @return object the current DatabaseQueryBuilder instance |
| 617 | 617 | */ |
| 618 | 618 | public function groupBy($field){ |
| 619 | - if (is_array($field)){ |
|
| 619 | + if (is_array($field)){ |
|
| 620 | 620 | $this->groupBy = implode(', ', $field); |
| 621 | - } |
|
| 622 | - else{ |
|
| 621 | + } |
|
| 622 | + else{ |
|
| 623 | 623 | $this->groupBy = $field; |
| 624 | - } |
|
| 625 | - return $this; |
|
| 624 | + } |
|
| 625 | + return $this; |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -634,22 +634,22 @@ discard block |
||
| 634 | 634 | * @return object the current DatabaseQueryBuilder instance |
| 635 | 635 | */ |
| 636 | 636 | public function having($field, $op = null, $val = null, $escape = true){ |
| 637 | - if (is_array($op)){ |
|
| 637 | + if (is_array($op)){ |
|
| 638 | 638 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 639 | - } |
|
| 640 | - else if (! in_array($op, $this->operatorList)){ |
|
| 639 | + } |
|
| 640 | + else if (! in_array($op, $this->operatorList)){ |
|
| 641 | 641 | if (is_null($op)){ |
| 642 | - $op = ''; |
|
| 642 | + $op = ''; |
|
| 643 | 643 | } |
| 644 | 644 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 645 | - } |
|
| 646 | - else{ |
|
| 645 | + } |
|
| 646 | + else{ |
|
| 647 | 647 | if (is_null($val)){ |
| 648 | - $val = ''; |
|
| 648 | + $val = ''; |
|
| 649 | 649 | } |
| 650 | 650 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
| 651 | - } |
|
| 652 | - return $this; |
|
| 651 | + } |
|
| 652 | + return $this; |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -659,12 +659,12 @@ discard block |
||
| 659 | 659 | * @return object the current DatabaseQueryBuilder instance |
| 660 | 660 | */ |
| 661 | 661 | public function insert($data = array(), $escape = true){ |
| 662 | - $columns = array_keys($data); |
|
| 663 | - $column = implode(', ', $columns); |
|
| 664 | - $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
| 662 | + $columns = array_keys($data); |
|
| 663 | + $column = implode(', ', $columns); |
|
| 664 | + $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
| 665 | 665 | |
| 666 | - $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
| 667 | - return $this; |
|
| 666 | + $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
| 667 | + return $this; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | /** |
@@ -674,25 +674,25 @@ discard block |
||
| 674 | 674 | * @return object the current DatabaseQueryBuilder instance |
| 675 | 675 | */ |
| 676 | 676 | public function update($data = array(), $escape = true){ |
| 677 | - $query = 'UPDATE ' . $this->from . ' SET '; |
|
| 678 | - $values = array(); |
|
| 679 | - foreach ($data as $column => $val){ |
|
| 677 | + $query = 'UPDATE ' . $this->from . ' SET '; |
|
| 678 | + $values = array(); |
|
| 679 | + foreach ($data as $column => $val){ |
|
| 680 | 680 | $values[] = $column . ' = ' . ($this->escape($val, $escape)); |
| 681 | - } |
|
| 682 | - $query .= implode(', ', $values); |
|
| 683 | - if (! empty($this->where)){ |
|
| 681 | + } |
|
| 682 | + $query .= implode(', ', $values); |
|
| 683 | + if (! empty($this->where)){ |
|
| 684 | 684 | $query .= ' WHERE ' . $this->where; |
| 685 | - } |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - if (! empty($this->orderBy)){ |
|
| 687 | + if (! empty($this->orderBy)){ |
|
| 688 | 688 | $query .= ' ORDER BY ' . $this->orderBy; |
| 689 | - } |
|
| 689 | + } |
|
| 690 | 690 | |
| 691 | - if (! empty($this->limit)){ |
|
| 691 | + if (! empty($this->limit)){ |
|
| 692 | 692 | $query .= ' LIMIT ' . $this->limit; |
| 693 | - } |
|
| 694 | - $this->query = $query; |
|
| 695 | - return $this; |
|
| 693 | + } |
|
| 694 | + $this->query = $query; |
|
| 695 | + return $this; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -700,25 +700,25 @@ discard block |
||
| 700 | 700 | * @return object the current DatabaseQueryBuilder instance |
| 701 | 701 | */ |
| 702 | 702 | public function delete(){ |
| 703 | - $query = 'DELETE FROM ' . $this->from; |
|
| 704 | - $isTruncate = $query; |
|
| 705 | - if (! empty($this->where)){ |
|
| 706 | - $query .= ' WHERE ' . $this->where; |
|
| 707 | - } |
|
| 703 | + $query = 'DELETE FROM ' . $this->from; |
|
| 704 | + $isTruncate = $query; |
|
| 705 | + if (! empty($this->where)){ |
|
| 706 | + $query .= ' WHERE ' . $this->where; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - if (! empty($this->orderBy)){ |
|
| 710 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
| 711 | - } |
|
| 709 | + if (! empty($this->orderBy)){ |
|
| 710 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - if (! empty($this->limit)){ |
|
| 714 | - $query .= ' LIMIT ' . $this->limit; |
|
| 715 | - } |
|
| 713 | + if (! empty($this->limit)){ |
|
| 714 | + $query .= ' LIMIT ' . $this->limit; |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 718 | - $query = 'TRUNCATE TABLE ' . $this->from; |
|
| 719 | - } |
|
| 720 | - $this->query = $query; |
|
| 721 | - return $this; |
|
| 717 | + if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 718 | + $query = 'TRUNCATE TABLE ' . $this->from; |
|
| 719 | + } |
|
| 720 | + $this->query = $query; |
|
| 721 | + return $this; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -728,11 +728,11 @@ discard block |
||
| 728 | 728 | * @return mixed the data after escaped or the same data if not |
| 729 | 729 | */ |
| 730 | 730 | public function escape($data, $escaped = true){ |
| 731 | - $data = trim($data); |
|
| 732 | - if($escaped){ |
|
| 731 | + $data = trim($data); |
|
| 732 | + if($escaped){ |
|
| 733 | 733 | return $this->pdo->quote($data); |
| 734 | - } |
|
| 735 | - return $data; |
|
| 734 | + } |
|
| 735 | + return $data; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
@@ -741,126 +741,126 @@ discard block |
||
| 741 | 741 | * @return string |
| 742 | 742 | */ |
| 743 | 743 | public function getQuery(){ |
| 744 | - //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
|
| 745 | - if(empty($this->query)){ |
|
| 746 | - $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
| 747 | - if (! empty($this->join)){ |
|
| 748 | - $query .= $this->join; |
|
| 749 | - } |
|
| 744 | + //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
|
| 745 | + if(empty($this->query)){ |
|
| 746 | + $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
| 747 | + if (! empty($this->join)){ |
|
| 748 | + $query .= $this->join; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - if (! empty($this->where)){ |
|
| 752 | - $query .= ' WHERE ' . $this->where; |
|
| 753 | - } |
|
| 751 | + if (! empty($this->where)){ |
|
| 752 | + $query .= ' WHERE ' . $this->where; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - if (! empty($this->groupBy)){ |
|
| 756 | - $query .= ' GROUP BY ' . $this->groupBy; |
|
| 757 | - } |
|
| 755 | + if (! empty($this->groupBy)){ |
|
| 756 | + $query .= ' GROUP BY ' . $this->groupBy; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - if (! empty($this->having)){ |
|
| 760 | - $query .= ' HAVING ' . $this->having; |
|
| 761 | - } |
|
| 759 | + if (! empty($this->having)){ |
|
| 760 | + $query .= ' HAVING ' . $this->having; |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - if (! empty($this->orderBy)){ |
|
| 764 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
| 765 | - } |
|
| 763 | + if (! empty($this->orderBy)){ |
|
| 764 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - if (! empty($this->limit)){ |
|
| 768 | - $query .= ' LIMIT ' . $this->limit; |
|
| 769 | - } |
|
| 770 | - $this->query = $query; |
|
| 771 | - } |
|
| 772 | - return $this->query; |
|
| 767 | + if (! empty($this->limit)){ |
|
| 768 | + $query .= ' LIMIT ' . $this->limit; |
|
| 769 | + } |
|
| 770 | + $this->query = $query; |
|
| 771 | + } |
|
| 772 | + return $this->query; |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
| 776 | - /** |
|
| 777 | - * Return the PDO instance |
|
| 778 | - * @return object |
|
| 779 | - */ |
|
| 776 | + /** |
|
| 777 | + * Return the PDO instance |
|
| 778 | + * @return object |
|
| 779 | + */ |
|
| 780 | 780 | public function getPdo(){ |
| 781 | - return $this->pdo; |
|
| 781 | + return $this->pdo; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
| 785 | 785 | * Set the PDO instance |
| 786 | 786 | * @param PDO $pdo the pdo object |
| 787 | - * @return object DatabaseQueryBuilder |
|
| 787 | + * @return object DatabaseQueryBuilder |
|
| 788 | 788 | */ |
| 789 | 789 | public function setPdo(PDO $pdo = null){ |
| 790 | - $this->pdo = $pdo; |
|
| 791 | - return $this; |
|
| 790 | + $this->pdo = $pdo; |
|
| 791 | + return $this; |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | - /** |
|
| 795 | - * Return the database table prefix |
|
| 796 | - * @return string |
|
| 797 | - */ |
|
| 794 | + /** |
|
| 795 | + * Return the database table prefix |
|
| 796 | + * @return string |
|
| 797 | + */ |
|
| 798 | 798 | public function getPrefix(){ |
| 799 | - return $this->prefix; |
|
| 799 | + return $this->prefix; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | 803 | * Set the database table prefix |
| 804 | 804 | * @param string $prefix the new prefix |
| 805 | - * @return object DatabaseQueryBuilder |
|
| 805 | + * @return object DatabaseQueryBuilder |
|
| 806 | 806 | */ |
| 807 | 807 | public function setPrefix($prefix){ |
| 808 | - $this->prefix = $prefix; |
|
| 809 | - return $this; |
|
| 808 | + $this->prefix = $prefix; |
|
| 809 | + return $this; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - /** |
|
| 813 | - * Return the database driver |
|
| 814 | - * @return string |
|
| 815 | - */ |
|
| 812 | + /** |
|
| 813 | + * Return the database driver |
|
| 814 | + * @return string |
|
| 815 | + */ |
|
| 816 | 816 | public function getDriver(){ |
| 817 | - return $this->driver; |
|
| 817 | + return $this->driver; |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
| 821 | 821 | * Set the database driver |
| 822 | 822 | * @param string $driver the new driver |
| 823 | - * @return object DatabaseQueryBuilder |
|
| 823 | + * @return object DatabaseQueryBuilder |
|
| 824 | 824 | */ |
| 825 | 825 | public function setDriver($driver){ |
| 826 | - $this->driver = $driver; |
|
| 827 | - return $this; |
|
| 826 | + $this->driver = $driver; |
|
| 827 | + return $this; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - /** |
|
| 831 | - * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
|
| 832 | - * @return object the current DatabaseQueryBuilder instance |
|
| 833 | - */ |
|
| 830 | + /** |
|
| 831 | + * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
|
| 832 | + * @return object the current DatabaseQueryBuilder instance |
|
| 833 | + */ |
|
| 834 | 834 | public function reset(){ |
| 835 | - $this->select = '*'; |
|
| 836 | - $this->from = null; |
|
| 837 | - $this->where = null; |
|
| 838 | - $this->limit = null; |
|
| 839 | - $this->orderBy = null; |
|
| 840 | - $this->groupBy = null; |
|
| 841 | - $this->having = null; |
|
| 842 | - $this->join = null; |
|
| 843 | - $this->query = null; |
|
| 844 | - return $this; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Get the SQL HAVING clause when operator argument is an array |
|
| 849 | - * @see DatabaseQueryBuilder::having |
|
| 850 | - * |
|
| 851 | - * @return string |
|
| 852 | - */ |
|
| 835 | + $this->select = '*'; |
|
| 836 | + $this->from = null; |
|
| 837 | + $this->where = null; |
|
| 838 | + $this->limit = null; |
|
| 839 | + $this->orderBy = null; |
|
| 840 | + $this->groupBy = null; |
|
| 841 | + $this->having = null; |
|
| 842 | + $this->join = null; |
|
| 843 | + $this->query = null; |
|
| 844 | + return $this; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Get the SQL HAVING clause when operator argument is an array |
|
| 849 | + * @see DatabaseQueryBuilder::having |
|
| 850 | + * |
|
| 851 | + * @return string |
|
| 852 | + */ |
|
| 853 | 853 | protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){ |
| 854 | 854 | $x = explode('?', $field); |
| 855 | 855 | $w = ''; |
| 856 | 856 | foreach($x as $k => $v){ |
| 857 | - if (!empty($v)){ |
|
| 857 | + if (!empty($v)){ |
|
| 858 | 858 | if (! isset($op[$k])){ |
| 859 | - $op[$k] = ''; |
|
| 859 | + $op[$k] = ''; |
|
| 860 | + } |
|
| 861 | + $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
|
| 862 | + } |
|
| 860 | 863 | } |
| 861 | - $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | 864 | return $w; |
| 865 | 865 | } |
| 866 | 866 | |
@@ -872,35 +872,35 @@ discard block |
||
| 872 | 872 | * @return string |
| 873 | 873 | */ |
| 874 | 874 | protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){ |
| 875 | - $_where = array(); |
|
| 876 | - foreach ($where as $column => $data){ |
|
| 875 | + $_where = array(); |
|
| 876 | + foreach ($where as $column => $data){ |
|
| 877 | 877 | if (is_null($data)){ |
| 878 | - $data = ''; |
|
| 878 | + $data = ''; |
|
| 879 | 879 | } |
| 880 | 880 | $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape)); |
| 881 | - } |
|
| 882 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 883 | - return $where; |
|
| 881 | + } |
|
| 882 | + $where = implode(' '.$andOr.' ', $_where); |
|
| 883 | + return $where; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - /** |
|
| 887 | - * Get the SQL WHERE clause when operator argument is an array |
|
| 888 | - * @see DatabaseQueryBuilder::where |
|
| 889 | - * |
|
| 890 | - * @return string |
|
| 891 | - */ |
|
| 886 | + /** |
|
| 887 | + * Get the SQL WHERE clause when operator argument is an array |
|
| 888 | + * @see DatabaseQueryBuilder::where |
|
| 889 | + * |
|
| 890 | + * @return string |
|
| 891 | + */ |
|
| 892 | 892 | protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){ |
| 893 | - $x = explode('?', $where); |
|
| 894 | - $w = ''; |
|
| 895 | - foreach($x as $k => $v){ |
|
| 893 | + $x = explode('?', $where); |
|
| 894 | + $w = ''; |
|
| 895 | + foreach($x as $k => $v){ |
|
| 896 | 896 | if (! empty($v)){ |
| 897 | 897 | if (isset($op[$k]) && is_null($op[$k])){ |
| 898 | - $op[$k] = ''; |
|
| 898 | + $op[$k] = ''; |
|
| 899 | 899 | } |
| 900 | 900 | $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : ''); |
| 901 | 901 | } |
| 902 | - } |
|
| 903 | - return $w; |
|
| 902 | + } |
|
| 903 | + return $w; |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -910,53 +910,53 @@ discard block |
||
| 910 | 910 | * @return string |
| 911 | 911 | */ |
| 912 | 912 | protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){ |
| 913 | - $w = ''; |
|
| 914 | - if (! in_array((string)$op, $this->operatorList)){ |
|
| 915 | - if (is_null($op)){ |
|
| 913 | + $w = ''; |
|
| 914 | + if (! in_array((string)$op, $this->operatorList)){ |
|
| 915 | + if (is_null($op)){ |
|
| 916 | 916 | $op = ''; |
| 917 | - } |
|
| 918 | - $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
|
| 917 | + } |
|
| 918 | + $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
|
| 919 | 919 | } else { |
| 920 | - if (is_null($val)){ |
|
| 920 | + if (is_null($val)){ |
|
| 921 | 921 | $val = ''; |
| 922 | - } |
|
| 923 | - $w = $type . $where . $op . ($this->escape($val, $escape)); |
|
| 922 | + } |
|
| 923 | + $w = $type . $where . $op . ($this->escape($val, $escape)); |
|
| 924 | 924 | } |
| 925 | 925 | return $w; |
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Set the $this->where property |
|
| 930 | - * @param string $whereStr the WHERE clause string |
|
| 931 | - * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
| 932 | - */ |
|
| 933 | - protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Set the $this->where property |
|
| 930 | + * @param string $whereStr the WHERE clause string |
|
| 931 | + * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
| 932 | + */ |
|
| 933 | + protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 934 | 934 | if (empty($this->where)){ |
| 935 | - $this->where = $whereStr; |
|
| 935 | + $this->where = $whereStr; |
|
| 936 | 936 | } else { |
| 937 | - if (substr(trim($this->where), -1) == '('){ |
|
| 937 | + if (substr(trim($this->where), -1) == '('){ |
|
| 938 | 938 | $this->where = $this->where . ' ' . $whereStr; |
| 939 | - } else { |
|
| 939 | + } else { |
|
| 940 | 940 | $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
| 941 | - } |
|
| 941 | + } |
|
| 942 | + } |
|
| 942 | 943 | } |
| 943 | - } |
|
| 944 | 944 | |
| 945 | 945 | |
| 946 | - /** |
|
| 947 | - * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG |
|
| 948 | - * @param string $clause the clause type like MIN, MAX, etc. |
|
| 949 | - * @see DatabaseQueryBuilder::min |
|
| 950 | - * @see DatabaseQueryBuilder::max |
|
| 951 | - * @see DatabaseQueryBuilder::sum |
|
| 952 | - * @see DatabaseQueryBuilder::count |
|
| 953 | - * @see DatabaseQueryBuilder::avg |
|
| 954 | - * @return object |
|
| 955 | - */ |
|
| 946 | + /** |
|
| 947 | + * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG |
|
| 948 | + * @param string $clause the clause type like MIN, MAX, etc. |
|
| 949 | + * @see DatabaseQueryBuilder::min |
|
| 950 | + * @see DatabaseQueryBuilder::max |
|
| 951 | + * @see DatabaseQueryBuilder::sum |
|
| 952 | + * @see DatabaseQueryBuilder::count |
|
| 953 | + * @see DatabaseQueryBuilder::avg |
|
| 954 | + * @return object |
|
| 955 | + */ |
|
| 956 | 956 | protected function select_min_max_sum_count_avg($clause, $field, $name = null){ |
| 957 | - $clause = strtoupper($clause); |
|
| 958 | - $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
| 959 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
| 960 | - return $this; |
|
| 957 | + $clause = strtoupper($clause); |
|
| 958 | + $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
| 959 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
| 960 | + return $this; |
|
| 961 | 961 | } |
| 962 | 962 | } |
@@ -1,337 +1,337 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework created using the concept of codeigniter with bootstrap twitter |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This file contains the main configuration of your application |
|
| 29 | - * web address, front controller, error logging, session parameters, CSRF, Cache, |
|
| 30 | - * Whitelist IP access, etc. |
|
| 31 | - */ |
|
| 27 | + /** |
|
| 28 | + * This file contains the main configuration of your application |
|
| 29 | + * web address, front controller, error logging, session parameters, CSRF, Cache, |
|
| 30 | + * Whitelist IP access, etc. |
|
| 31 | + */ |
|
| 32 | 32 | |
| 33 | - /*+---------------------------------------------------------------+ |
|
| 33 | + /*+---------------------------------------------------------------+ |
|
| 34 | 34 | * Basic configuration section |
| 35 | 35 | +------------------------------------------------------------------+ |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The web address of your application. |
|
| 40 | - * |
|
| 41 | - * The address of your application or website terminated by a slash. |
|
| 42 | - * You can use a domain name or IP address, for example: |
|
| 43 | - * |
|
| 44 | - * $config['base_url'] = 'http://www.mysite.com'; |
|
| 45 | - * or |
|
| 46 | - * $config['base_url'] = 'http://198.15.25.12'; |
|
| 47 | - * |
|
| 48 | - * If this value is empty, we try to determine it automatically by using |
|
| 49 | - * the server variables "SERVER_ADDR" or "SCRIPT_NAME", |
|
| 50 | - * we recommend that you specify this value for a server in production this may reduce the performance of your application. |
|
| 51 | - */ |
|
| 52 | - $config['base_url'] = ''; |
|
| 38 | + /** |
|
| 39 | + * The web address of your application. |
|
| 40 | + * |
|
| 41 | + * The address of your application or website terminated by a slash. |
|
| 42 | + * You can use a domain name or IP address, for example: |
|
| 43 | + * |
|
| 44 | + * $config['base_url'] = 'http://www.mysite.com'; |
|
| 45 | + * or |
|
| 46 | + * $config['base_url'] = 'http://198.15.25.12'; |
|
| 47 | + * |
|
| 48 | + * If this value is empty, we try to determine it automatically by using |
|
| 49 | + * the server variables "SERVER_ADDR" or "SCRIPT_NAME", |
|
| 50 | + * we recommend that you specify this value for a server in production this may reduce the performance of your application. |
|
| 51 | + */ |
|
| 52 | + $config['base_url'] = ''; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The front controller |
|
| 56 | - * |
|
| 57 | - * This represents the name of the file called by the application during the loading |
|
| 58 | - * process generally the file "index.php". |
|
| 59 | - * If your webserver supports the url rewrite module, then you can leave this value empty. |
|
| 60 | - * You will find a sample file to hide this file in the url inside the root folder of your |
|
| 61 | - * application "htaccess.txt" for the apache web server just rename it to ".htaccess" |
|
| 62 | - * |
|
| 63 | - * Without the rewrite module url enabled, leave this value to "index.php", in this case your urls look like: |
|
| 64 | - * |
|
| 65 | - * http://www.yoursite.com/index.php/controller/method |
|
| 66 | - * |
|
| 67 | - * otherwise if the module is available and activated you can put this value empty and your urls look like: |
|
| 68 | - * |
|
| 69 | - * http://www.yoursite.com/controller/method |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - $config['front_controller'] = 'index.php'; |
|
| 54 | + /** |
|
| 55 | + * The front controller |
|
| 56 | + * |
|
| 57 | + * This represents the name of the file called by the application during the loading |
|
| 58 | + * process generally the file "index.php". |
|
| 59 | + * If your webserver supports the url rewrite module, then you can leave this value empty. |
|
| 60 | + * You will find a sample file to hide this file in the url inside the root folder of your |
|
| 61 | + * application "htaccess.txt" for the apache web server just rename it to ".htaccess" |
|
| 62 | + * |
|
| 63 | + * Without the rewrite module url enabled, leave this value to "index.php", in this case your urls look like: |
|
| 64 | + * |
|
| 65 | + * http://www.yoursite.com/index.php/controller/method |
|
| 66 | + * |
|
| 67 | + * otherwise if the module is available and activated you can put this value empty and your urls look like: |
|
| 68 | + * |
|
| 69 | + * http://www.yoursite.com/controller/method |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + $config['front_controller'] = 'index.php'; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Url suffix |
|
| 76 | - */ |
|
| 77 | - $config['url_suffix'] = ''; |
|
| 74 | + /** |
|
| 75 | + * Url suffix |
|
| 76 | + */ |
|
| 77 | + $config['url_suffix'] = ''; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * site charset |
|
| 81 | - */ |
|
| 82 | - $config['charset'] = 'UTF-8'; |
|
| 79 | + /** |
|
| 80 | + * site charset |
|
| 81 | + */ |
|
| 82 | + $config['charset'] = 'UTF-8'; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Compress the output before send to browser |
|
| 86 | - * |
|
| 87 | - * Enables Gzip output compression for faster page loads. When enabled, |
|
| 88 | - * the Response class will test whether your server supports Gzip. |
|
| 89 | - * Even if it does, however, not all browsers support compression |
|
| 90 | - * so enable only if you are reasonably sure your visitors can handle it. |
|
| 91 | - * |
|
| 92 | - * This is only used if "zlib.output_compression" is turned off in your php configuration. |
|
| 93 | - * Please do not use it together with httpd-level output compression. |
|
| 94 | - * |
|
| 95 | - * IMPORTANT NOTE: If you are getting a blank page when compression is enabled it |
|
| 96 | - * means you are prematurely outputting something to your browser. It could |
|
| 97 | - * even be a line of whitespace at the end of one of your scripts. For |
|
| 98 | - * compression to work, nothing can be sent before the output buffer is called |
|
| 99 | - * by the Response class. Do not 'echo' any values with compression enabled. |
|
| 100 | - */ |
|
| 101 | - $config['compress_output'] = false; |
|
| 84 | + /** |
|
| 85 | + * Compress the output before send to browser |
|
| 86 | + * |
|
| 87 | + * Enables Gzip output compression for faster page loads. When enabled, |
|
| 88 | + * the Response class will test whether your server supports Gzip. |
|
| 89 | + * Even if it does, however, not all browsers support compression |
|
| 90 | + * so enable only if you are reasonably sure your visitors can handle it. |
|
| 91 | + * |
|
| 92 | + * This is only used if "zlib.output_compression" is turned off in your php configuration. |
|
| 93 | + * Please do not use it together with httpd-level output compression. |
|
| 94 | + * |
|
| 95 | + * IMPORTANT NOTE: If you are getting a blank page when compression is enabled it |
|
| 96 | + * means you are prematurely outputting something to your browser. It could |
|
| 97 | + * even be a line of whitespace at the end of one of your scripts. For |
|
| 98 | + * compression to work, nothing can be sent before the output buffer is called |
|
| 99 | + * by the Response class. Do not 'echo' any values with compression enabled. |
|
| 100 | + */ |
|
| 101 | + $config['compress_output'] = false; |
|
| 102 | 102 | |
| 103 | - /*+---------------------------------------------------------------+ |
|
| 103 | + /*+---------------------------------------------------------------+ |
|
| 104 | 104 | * Language configuration section |
| 105 | 105 | +------------------------------------------------------------------+ |
| 106 | 106 | */ |
| 107 | - /** |
|
| 108 | - * list of available supported language |
|
| 109 | - * array( |
|
| 110 | - * 'lang_key' => 'human readable' |
|
| 111 | - * ) |
|
| 112 | - */ |
|
| 113 | - $config['languages'] = array('en' => 'english'); |
|
| 107 | + /** |
|
| 108 | + * list of available supported language |
|
| 109 | + * array( |
|
| 110 | + * 'lang_key' => 'human readable' |
|
| 111 | + * ) |
|
| 112 | + */ |
|
| 113 | + $config['languages'] = array('en' => 'english'); |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * the default language to use if can not find the client language |
|
| 117 | - * need match with the array key of the supported languages |
|
| 118 | - */ |
|
| 119 | - $config['default_language'] = 'en'; //en = english, fr = french |
|
| 115 | + /** |
|
| 116 | + * the default language to use if can not find the client language |
|
| 117 | + * need match with the array key of the supported languages |
|
| 118 | + */ |
|
| 119 | + $config['default_language'] = 'en'; //en = english, fr = french |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * the name of cookie used to store the client language |
|
| 123 | - */ |
|
| 124 | - $config['language_cookie_name'] = 'cookie_lang'; |
|
| 121 | + /** |
|
| 122 | + * the name of cookie used to store the client language |
|
| 123 | + */ |
|
| 124 | + $config['language_cookie_name'] = 'cookie_lang'; |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /*+---------------------------------------------------------------+ |
|
| 127 | + /*+---------------------------------------------------------------+ |
|
| 128 | 128 | * Logs configuration section |
| 129 | 129 | +------------------------------------------------------------------+ |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * The log level |
|
| 134 | - * |
|
| 135 | - * The valid level are: OFF, NONE, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, ALL |
|
| 136 | - * |
|
| 137 | - * 'OFF' or 'NONE' = do not save log |
|
| 138 | - * 'FATAL' = enable log for fatal level and above (FATAL) |
|
| 139 | - * 'ERROR' = enable log for error level and above (ERROR, FATAL) |
|
| 140 | - * 'WARNING' or WARN = enable log for warning level and above (WARNING, ERROR, FATAL) |
|
| 141 | - * 'INFO' = enable log for info level and above (INFO, WARNING, ERROR, FATAL) |
|
| 142 | - * 'DEBUG' = enable log for debug level and above (DEBUG, INFO, WARNING, ERROR, FATAL) |
|
| 143 | - * 'ALL' = enable log for all level |
|
| 144 | - * |
|
| 145 | - * The default value is NONE if the config value is: null, '', 0, false |
|
| 146 | - * |
|
| 147 | - * Note: in production environment it's recommand to set the log level to 'WARNING' if not in small |
|
| 148 | - * of time the log file size will increase very fast and will cost the application performance |
|
| 149 | - * and also the filesystem usage of your server. |
|
| 150 | - */ |
|
| 151 | - $config['log_level'] = 'NONE'; |
|
| 132 | + /** |
|
| 133 | + * The log level |
|
| 134 | + * |
|
| 135 | + * The valid level are: OFF, NONE, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, ALL |
|
| 136 | + * |
|
| 137 | + * 'OFF' or 'NONE' = do not save log |
|
| 138 | + * 'FATAL' = enable log for fatal level and above (FATAL) |
|
| 139 | + * 'ERROR' = enable log for error level and above (ERROR, FATAL) |
|
| 140 | + * 'WARNING' or WARN = enable log for warning level and above (WARNING, ERROR, FATAL) |
|
| 141 | + * 'INFO' = enable log for info level and above (INFO, WARNING, ERROR, FATAL) |
|
| 142 | + * 'DEBUG' = enable log for debug level and above (DEBUG, INFO, WARNING, ERROR, FATAL) |
|
| 143 | + * 'ALL' = enable log for all level |
|
| 144 | + * |
|
| 145 | + * The default value is NONE if the config value is: null, '', 0, false |
|
| 146 | + * |
|
| 147 | + * Note: in production environment it's recommand to set the log level to 'WARNING' if not in small |
|
| 148 | + * of time the log file size will increase very fast and will cost the application performance |
|
| 149 | + * and also the filesystem usage of your server. |
|
| 150 | + */ |
|
| 151 | + $config['log_level'] = 'NONE'; |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * The path to log directory |
|
| 156 | - * |
|
| 157 | - * The path that the log data will be saved ending with de "/" or "\", leave empty if you |
|
| 158 | - * want use the default configuration |
|
| 159 | - * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 160 | - * else the default value will be used i.e the constant LOG_PATH |
|
| 161 | - * for security raison this directory must be outside of the document root of your |
|
| 162 | - * website. |
|
| 163 | - */ |
|
| 164 | - $config['log_save_path'] = ''; |
|
| 154 | + /** |
|
| 155 | + * The path to log directory |
|
| 156 | + * |
|
| 157 | + * The path that the log data will be saved ending with de "/" or "\", leave empty if you |
|
| 158 | + * want use the default configuration |
|
| 159 | + * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 160 | + * else the default value will be used i.e the constant LOG_PATH |
|
| 161 | + * for security raison this directory must be outside of the document root of your |
|
| 162 | + * website. |
|
| 163 | + */ |
|
| 164 | + $config['log_save_path'] = ''; |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * The logger name to use for the log |
|
| 168 | - * |
|
| 169 | - * If this config is set so means only log message with this or these logger(s) will be saved |
|
| 170 | - * |
|
| 171 | - * Example: |
|
| 172 | - * $config['log_logger_name'] = array('MY_LOGGER1', 'MY_LOGGER2'); //only log message with MY_LOGGER1 or MY_LOGGER2 will be saved in file. |
|
| 173 | - */ |
|
| 174 | - $config['log_logger_name'] = array(); |
|
| 166 | + /** |
|
| 167 | + * The logger name to use for the log |
|
| 168 | + * |
|
| 169 | + * If this config is set so means only log message with this or these logger(s) will be saved |
|
| 170 | + * |
|
| 171 | + * Example: |
|
| 172 | + * $config['log_logger_name'] = array('MY_LOGGER1', 'MY_LOGGER2'); //only log message with MY_LOGGER1 or MY_LOGGER2 will be saved in file. |
|
| 173 | + */ |
|
| 174 | + $config['log_logger_name'] = array(); |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /*+---------------------------------------------------------------+ |
|
| 177 | + /*+---------------------------------------------------------------+ |
|
| 178 | 178 | * Session configuration section |
| 179 | 179 | +------------------------------------------------------------------+ |
| 180 | 180 | */ |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * The session name |
|
| 184 | - * |
|
| 185 | - * By default is PHPSESSID. this must be alpha-numerical characters |
|
| 186 | - */ |
|
| 187 | - $config['session_name'] = 'PHPSESSID'; |
|
| 182 | + /** |
|
| 183 | + * The session name |
|
| 184 | + * |
|
| 185 | + * By default is PHPSESSID. this must be alpha-numerical characters |
|
| 186 | + */ |
|
| 187 | + $config['session_name'] = 'PHPSESSID'; |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Session save path |
|
| 191 | - * |
|
| 192 | - * The path that the session data will be saved, leave empty if you |
|
| 193 | - * want use the default configuration in the php.ini |
|
| 194 | - * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 195 | - * for security raison this directory must be outside of the document root of your |
|
| 196 | - * website. |
|
| 197 | - * Note: if the session handler is "database" the session_save_path is the model name to use |
|
| 198 | - */ |
|
| 199 | - $config['session_save_path'] = ''; |
|
| 189 | + /** |
|
| 190 | + * Session save path |
|
| 191 | + * |
|
| 192 | + * The path that the session data will be saved, leave empty if you |
|
| 193 | + * want use the default configuration in the php.ini |
|
| 194 | + * warning : if set, this directory must exist and will be writable and owned by the web server |
|
| 195 | + * for security raison this directory must be outside of the document root of your |
|
| 196 | + * website. |
|
| 197 | + * Note: if the session handler is "database" the session_save_path is the model name to use |
|
| 198 | + */ |
|
| 199 | + $config['session_save_path'] = ''; |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Session handler |
|
| 203 | - * |
|
| 204 | - * The session handler that we will use to manage the session. |
|
| 205 | - * currently the possible values are "files", "database". |
|
| 206 | - */ |
|
| 207 | - $config['session_handler'] = 'files'; |
|
| 201 | + /** |
|
| 202 | + * Session handler |
|
| 203 | + * |
|
| 204 | + * The session handler that we will use to manage the session. |
|
| 205 | + * currently the possible values are "files", "database". |
|
| 206 | + */ |
|
| 207 | + $config['session_handler'] = 'files'; |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Session secret |
|
| 211 | - * |
|
| 212 | - * This is used to hash the session data if the config "session_handler" is set to "database" |
|
| 213 | - * warning : do not change this value until you already set |
|
| 214 | - * for security raison use the very complicated value include $%)@^&^\''\'\' |
|
| 215 | - * NOTE: this value is an base64 so you need use the tool that generate it, like |
|
| 216 | - * PHP function base64_encode() |
|
| 217 | - */ |
|
| 218 | - $config['session_secret'] = ''; |
|
| 209 | + /** |
|
| 210 | + * Session secret |
|
| 211 | + * |
|
| 212 | + * This is used to hash the session data if the config "session_handler" is set to "database" |
|
| 213 | + * warning : do not change this value until you already set |
|
| 214 | + * for security raison use the very complicated value include $%)@^&^\''\'\' |
|
| 215 | + * NOTE: this value is an base64 so you need use the tool that generate it, like |
|
| 216 | + * PHP function base64_encode() |
|
| 217 | + */ |
|
| 218 | + $config['session_secret'] = ''; |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * number of second that consider the session already expire |
|
| 222 | - */ |
|
| 223 | - $config['session_inactivity_time'] = 600; //in second |
|
| 220 | + /** |
|
| 221 | + * number of second that consider the session already expire |
|
| 222 | + */ |
|
| 223 | + $config['session_inactivity_time'] = 600; //in second |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Session cookie lifetime |
|
| 227 | - * |
|
| 228 | - * The cookie lifetime that the session will be dropped in seconds, leave 0 if you want |
|
| 229 | - * the cookie expire after the browser is closed |
|
| 230 | - */ |
|
| 231 | - $config['session_cookie_lifetime'] = 0; |
|
| 225 | + /** |
|
| 226 | + * Session cookie lifetime |
|
| 227 | + * |
|
| 228 | + * The cookie lifetime that the session will be dropped in seconds, leave 0 if you want |
|
| 229 | + * the cookie expire after the browser is closed |
|
| 230 | + */ |
|
| 231 | + $config['session_cookie_lifetime'] = 0; |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Session cookie path |
|
| 235 | - * |
|
| 236 | - * The path to your website that the cookie is available "/" means all path is available |
|
| 237 | - * example : /mysubdirectory => available in http://www.mysite.com/mysubdirectory |
|
| 238 | - */ |
|
| 239 | - $config['session_cookie_path'] = '/'; |
|
| 233 | + /** |
|
| 234 | + * Session cookie path |
|
| 235 | + * |
|
| 236 | + * The path to your website that the cookie is available "/" means all path is available |
|
| 237 | + * example : /mysubdirectory => available in http://www.mysite.com/mysubdirectory |
|
| 238 | + */ |
|
| 239 | + $config['session_cookie_path'] = '/'; |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Session cookie domain |
|
| 243 | - * |
|
| 244 | - * The domain of your website that the cookie is available if you want the cookie is available |
|
| 245 | - * in all your subdomain use this dot before the domain name for example ".mysite.com". |
|
| 246 | - * leave empty if you want use the default configuration |
|
| 247 | - */ |
|
| 248 | - $config['session_cookie_domain'] = ''; |
|
| 241 | + /** |
|
| 242 | + * Session cookie domain |
|
| 243 | + * |
|
| 244 | + * The domain of your website that the cookie is available if you want the cookie is available |
|
| 245 | + * in all your subdomain use this dot before the domain name for example ".mysite.com". |
|
| 246 | + * leave empty if you want use the default configuration |
|
| 247 | + */ |
|
| 248 | + $config['session_cookie_domain'] = ''; |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * Session cookie secure |
|
| 252 | - * |
|
| 253 | - * If your website use SSL i.e https, you set "true" for this configuration, so the cookie |
|
| 254 | - * is available only if the website use the secure connection else set this value to "false" |
|
| 255 | - */ |
|
| 256 | - $config['session_cookie_secure'] = false; |
|
| 250 | + /** |
|
| 251 | + * Session cookie secure |
|
| 252 | + * |
|
| 253 | + * If your website use SSL i.e https, you set "true" for this configuration, so the cookie |
|
| 254 | + * is available only if the website use the secure connection else set this value to "false" |
|
| 255 | + */ |
|
| 256 | + $config['session_cookie_secure'] = false; |
|
| 257 | 257 | |
| 258 | 258 | |
| 259 | - /*+---------------------------------------------------------------+ |
|
| 259 | + /*+---------------------------------------------------------------+ |
|
| 260 | 260 | * CSRF configuration section |
| 261 | 261 | +------------------------------------------------------------------+ |
| 262 | 262 | */ |
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * CSRF status |
|
| 266 | - * |
|
| 267 | - * if you would to use the CSRF (that we recommand you), set this key to true |
|
| 268 | - */ |
|
| 269 | - $config['csrf_enable'] = false; |
|
| 264 | + /** |
|
| 265 | + * CSRF status |
|
| 266 | + * |
|
| 267 | + * if you would to use the CSRF (that we recommand you), set this key to true |
|
| 268 | + */ |
|
| 269 | + $config['csrf_enable'] = false; |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * CSRF key |
|
| 273 | - * |
|
| 274 | - * the key used to store the csrf data |
|
| 275 | - */ |
|
| 276 | - $config['csrf_key'] = 'csrf_key'; |
|
| 271 | + /** |
|
| 272 | + * CSRF key |
|
| 273 | + * |
|
| 274 | + * the key used to store the csrf data |
|
| 275 | + */ |
|
| 276 | + $config['csrf_key'] = 'csrf_key'; |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * CSRF expire |
|
| 280 | - * |
|
| 281 | - * expire time in seconds of the CSRF data |
|
| 282 | - */ |
|
| 283 | - $config['csrf_expire'] = 120; |
|
| 278 | + /** |
|
| 279 | + * CSRF expire |
|
| 280 | + * |
|
| 281 | + * expire time in seconds of the CSRF data |
|
| 282 | + */ |
|
| 283 | + $config['csrf_expire'] = 120; |
|
| 284 | 284 | |
| 285 | 285 | |
| 286 | - /*+---------------------------------------------------------------+ |
|
| 286 | + /*+---------------------------------------------------------------+ |
|
| 287 | 287 | * Cache configuration section |
| 288 | 288 | +------------------------------------------------------------------+ |
| 289 | 289 | */ |
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Cache status |
|
| 293 | - * |
|
| 294 | - * If you would to use the cache functionnality set this value to true |
|
| 295 | - */ |
|
| 296 | - $config['cache_enable'] = false; |
|
| 291 | + /** |
|
| 292 | + * Cache status |
|
| 293 | + * |
|
| 294 | + * If you would to use the cache functionnality set this value to true |
|
| 295 | + */ |
|
| 296 | + $config['cache_enable'] = false; |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Cache Time To Live |
|
| 300 | - * |
|
| 301 | - * expire time in seconds of the cache data |
|
| 302 | - */ |
|
| 303 | - $config['cache_ttl'] = 120; //in second |
|
| 298 | + /** |
|
| 299 | + * Cache Time To Live |
|
| 300 | + * |
|
| 301 | + * expire time in seconds of the cache data |
|
| 302 | + */ |
|
| 303 | + $config['cache_ttl'] = 120; //in second |
|
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Cache handler class |
|
| 307 | - * |
|
| 308 | - * The cache handler class inside (CORE_CLASSES_CACHE_PATH, LIBRARY_PATH) directories that implements |
|
| 309 | - * the interface "CacheInterface" that we will use to manage the cache. |
|
| 310 | - * currently the possible values are "FileCache", "ApcCache". |
|
| 311 | - */ |
|
| 312 | - $config['cache_handler'] = 'FileCache'; |
|
| 305 | + /** |
|
| 306 | + * Cache handler class |
|
| 307 | + * |
|
| 308 | + * The cache handler class inside (CORE_CLASSES_CACHE_PATH, LIBRARY_PATH) directories that implements |
|
| 309 | + * the interface "CacheInterface" that we will use to manage the cache. |
|
| 310 | + * currently the possible values are "FileCache", "ApcCache". |
|
| 311 | + */ |
|
| 312 | + $config['cache_handler'] = 'FileCache'; |
|
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /*+---------------------------------------------------------------+ |
|
| 315 | + /*+---------------------------------------------------------------+ |
|
| 316 | 316 | * White list IP access configuration section |
| 317 | 317 | +------------------------------------------------------------------+ |
| 318 | 318 | */ |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * White list ip status |
|
| 322 | - * |
|
| 323 | - * if you would to use the white list ip access, set this key to true |
|
| 324 | - */ |
|
| 325 | - $config['white_list_ip_enable'] = false; |
|
| 320 | + /** |
|
| 321 | + * White list ip status |
|
| 322 | + * |
|
| 323 | + * if you would to use the white list ip access, set this key to true |
|
| 324 | + */ |
|
| 325 | + $config['white_list_ip_enable'] = false; |
|
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * White listed ip addresses |
|
| 329 | - * |
|
| 330 | - * add the allowed ip address list to access this application. |
|
| 331 | - * You can use the wildcard address |
|
| 332 | - * @example: '18.90.09.*', '10.*.*.*', '*' |
|
| 333 | - * |
|
| 334 | - */ |
|
| 335 | - $config['white_list_ip_addresses'] = array('127.0.0.1', '::1'); |
|
| 327 | + /** |
|
| 328 | + * White listed ip addresses |
|
| 329 | + * |
|
| 330 | + * add the allowed ip address list to access this application. |
|
| 331 | + * You can use the wildcard address |
|
| 332 | + * @example: '18.90.09.*', '10.*.*.*', '*' |
|
| 333 | + * |
|
| 334 | + */ |
|
| 335 | + $config['white_list_ip_addresses'] = array('127.0.0.1', '::1'); |
|
| 336 | 336 | |
| 337 | - |
|
| 338 | 337 | \ No newline at end of file |
| 338 | + |
|
| 339 | 339 | \ No newline at end of file |
@@ -1,267 +1,267 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** |
|
| 3 | - * TNH Framework |
|
| 4 | - * |
|
| 5 | - * A simple PHP framework using HMVC architecture |
|
| 6 | - * |
|
| 7 | - * This content is released under the GNU GPL License (GPL) |
|
| 8 | - * |
|
| 9 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | - * |
|
| 11 | - * This program is free software; you can redistribute it and/or |
|
| 12 | - * modify it under the terms of the GNU General Public License |
|
| 13 | - * as published by the Free Software Foundation; either version 3 |
|
| 14 | - * of the License, or (at your option) any later version. |
|
| 15 | - * |
|
| 16 | - * This program is distributed in the hope that it will be useful, |
|
| 17 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | - * GNU General Public License for more details. |
|
| 20 | - * |
|
| 21 | - * You should have received a copy of the GNU General Public License |
|
| 22 | - * along with this program; if not, write to the Free Software |
|
| 23 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | - */ |
|
| 2 | + /** |
|
| 3 | + * TNH Framework |
|
| 4 | + * |
|
| 5 | + * A simple PHP framework using HMVC architecture |
|
| 6 | + * |
|
| 7 | + * This content is released under the GNU GPL License (GPL) |
|
| 8 | + * |
|
| 9 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 10 | + * |
|
| 11 | + * This program is free software; you can redistribute it and/or |
|
| 12 | + * modify it under the terms of the GNU General Public License |
|
| 13 | + * as published by the Free Software Foundation; either version 3 |
|
| 14 | + * of the License, or (at your option) any later version. |
|
| 15 | + * |
|
| 16 | + * This program is distributed in the hope that it will be useful, |
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 | + * GNU General Public License for more details. |
|
| 20 | + * |
|
| 21 | + * You should have received a copy of the GNU General Public License |
|
| 22 | + * along with this program; if not, write to the Free Software |
|
| 23 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 24 | + */ |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * the directory separator, under windows it is \ and unix, linux / |
|
| 28 | - */ |
|
| 29 | - define('DS', DIRECTORY_SEPARATOR); |
|
| 26 | + /** |
|
| 27 | + * the directory separator, under windows it is \ and unix, linux / |
|
| 28 | + */ |
|
| 29 | + define('DS', DIRECTORY_SEPARATOR); |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The root directory of the application. |
|
| 33 | - * |
|
| 34 | - * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 35 | - */ |
|
| 36 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 31 | + /** |
|
| 32 | + * The root directory of the application. |
|
| 33 | + * |
|
| 34 | + * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
| 35 | + */ |
|
| 36 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The path to the directory. |
|
| 40 | - * |
|
| 41 | - * That contains your static files (javascript, css, images, etc.) |
|
| 42 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 43 | - */ |
|
| 44 | - define('ASSETS_PATH', 'assets/'); |
|
| 38 | + /** |
|
| 39 | + * The path to the directory. |
|
| 40 | + * |
|
| 41 | + * That contains your static files (javascript, css, images, etc.) |
|
| 42 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
| 43 | + */ |
|
| 44 | + define('ASSETS_PATH', 'assets/'); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * The path to the directory of your cache files. |
|
| 48 | - * |
|
| 49 | - * This feature is available currently for database and views. |
|
| 50 | - */ |
|
| 51 | - define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 46 | + /** |
|
| 47 | + * The path to the directory of your cache files. |
|
| 48 | + * |
|
| 49 | + * This feature is available currently for database and views. |
|
| 50 | + */ |
|
| 51 | + define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The path to the application directory. |
|
| 55 | - * |
|
| 56 | - * It contains your most often used files that is to say which contains your files of the application, |
|
| 57 | - * in MVC architecture (controllers, models, views). |
|
| 58 | - */ |
|
| 59 | - define('APPS_PATH', ROOT_PATH . 'classes' . DS); |
|
| 53 | + /** |
|
| 54 | + * The path to the application directory. |
|
| 55 | + * |
|
| 56 | + * It contains your most often used files that is to say which contains your files of the application, |
|
| 57 | + * in MVC architecture (controllers, models, views). |
|
| 58 | + */ |
|
| 59 | + define('APPS_PATH', ROOT_PATH . 'classes' . DS); |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * The path to the controller directory of your application. |
|
| 63 | - * |
|
| 64 | - * If you already know the MVC architecture you know what a controller means; |
|
| 65 | - * it is he who makes the business logic of your application in general. |
|
| 66 | - */ |
|
| 67 | - define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 61 | + /** |
|
| 62 | + * The path to the controller directory of your application. |
|
| 63 | + * |
|
| 64 | + * If you already know the MVC architecture you know what a controller means; |
|
| 65 | + * it is he who makes the business logic of your application in general. |
|
| 66 | + */ |
|
| 67 | + define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The path to the directory of your model classes of your application. |
|
| 71 | - * |
|
| 72 | - * If you already know the MVC architecture you know what a model means; |
|
| 73 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 74 | - */ |
|
| 75 | - define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 69 | + /** |
|
| 70 | + * The path to the directory of your model classes of your application. |
|
| 71 | + * |
|
| 72 | + * If you already know the MVC architecture you know what a model means; |
|
| 73 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
| 74 | + */ |
|
| 75 | + define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The path to the directory of your views. |
|
| 79 | - * |
|
| 80 | - * If you already know the MVC architecture you know what a view means, |
|
| 81 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
| 82 | - * everything displayed in the browser interface, etc. |
|
| 83 | - */ |
|
| 84 | - define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 77 | + /** |
|
| 78 | + * The path to the directory of your views. |
|
| 79 | + * |
|
| 80 | + * If you already know the MVC architecture you know what a view means, |
|
| 81 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
| 82 | + * everything displayed in the browser interface, etc. |
|
| 83 | + */ |
|
| 84 | + define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * The path to the configuration directory. |
|
| 88 | - * |
|
| 89 | - * That contains most of the configuration files for your |
|
| 90 | - * application (database, class loading file, functions, etc.) |
|
| 91 | - */ |
|
| 92 | - define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 86 | + /** |
|
| 87 | + * The path to the configuration directory. |
|
| 88 | + * |
|
| 89 | + * That contains most of the configuration files for your |
|
| 90 | + * application (database, class loading file, functions, etc.) |
|
| 91 | + */ |
|
| 92 | + define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * The core directory |
|
| 96 | - * |
|
| 97 | - * It is recommended to put this folder out of the web directory of your server and |
|
| 98 | - * you should not change its content because in case of update you could lose the modified files. |
|
| 99 | - */ |
|
| 100 | - define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 94 | + /** |
|
| 95 | + * The core directory |
|
| 96 | + * |
|
| 97 | + * It is recommended to put this folder out of the web directory of your server and |
|
| 98 | + * you should not change its content because in case of update you could lose the modified files. |
|
| 99 | + */ |
|
| 100 | + define('CORE_PATH', ROOT_PATH . 'core' . DS); |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * The path to the directory of core classes that used by the system. |
|
| 104 | - * |
|
| 105 | - * It contains PHP classes that are used by the framework internally. |
|
| 106 | - */ |
|
| 107 | - define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 102 | + /** |
|
| 103 | + * The path to the directory of core classes that used by the system. |
|
| 104 | + * |
|
| 105 | + * It contains PHP classes that are used by the framework internally. |
|
| 106 | + */ |
|
| 107 | + define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * The path to the directory of core classes for the cache used by the system. |
|
| 111 | - * |
|
| 112 | - * It contains PHP classes for the cache drivers. |
|
| 113 | - */ |
|
| 114 | - define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 109 | + /** |
|
| 110 | + * The path to the directory of core classes for the cache used by the system. |
|
| 111 | + * |
|
| 112 | + * It contains PHP classes for the cache drivers. |
|
| 113 | + */ |
|
| 114 | + define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
|
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * The path to the directory of core classes for the database used by the system. |
|
| 118 | - * |
|
| 119 | - * It contains PHP classes for the database library, drivers, etc. |
|
| 120 | - */ |
|
| 121 | - define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 117 | + * The path to the directory of core classes for the database used by the system. |
|
| 118 | + * |
|
| 119 | + * It contains PHP classes for the database library, drivers, etc. |
|
| 120 | + */ |
|
| 121 | + define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * The path to the directory of core classes for the model used by the system. |
|
| 125 | - * |
|
| 126 | - * It contains PHP classes for the models. |
|
| 127 | - */ |
|
| 128 | - define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 123 | + /** |
|
| 124 | + * The path to the directory of core classes for the model used by the system. |
|
| 125 | + * |
|
| 126 | + * It contains PHP classes for the models. |
|
| 127 | + */ |
|
| 128 | + define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * The path to the directory of functions or helper systems. |
|
| 132 | - * |
|
| 133 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 134 | - */ |
|
| 135 | - define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 130 | + /** |
|
| 131 | + * The path to the directory of functions or helper systems. |
|
| 132 | + * |
|
| 133 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
| 134 | + */ |
|
| 135 | + define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * The path to the core directory of languages files. |
|
| 139 | - * |
|
| 140 | - */ |
|
| 141 | - define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 137 | + /** |
|
| 138 | + * The path to the core directory of languages files. |
|
| 139 | + * |
|
| 140 | + */ |
|
| 141 | + define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * The path to the system library directory. |
|
| 145 | - * |
|
| 146 | - * Which contains the libraries most often used in your web application, as for the |
|
| 147 | - * core directory it is advisable to put it out of the root directory of your application. |
|
| 148 | - */ |
|
| 149 | - define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 143 | + /** |
|
| 144 | + * The path to the system library directory. |
|
| 145 | + * |
|
| 146 | + * Which contains the libraries most often used in your web application, as for the |
|
| 147 | + * core directory it is advisable to put it out of the root directory of your application. |
|
| 148 | + */ |
|
| 149 | + define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * The path to the system view directory. |
|
| 153 | - * |
|
| 154 | - * That contains the views used for the system, such as error messages, and so on. |
|
| 155 | - */ |
|
| 156 | - define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 151 | + /** |
|
| 152 | + * The path to the system view directory. |
|
| 153 | + * |
|
| 154 | + * That contains the views used for the system, such as error messages, and so on. |
|
| 155 | + */ |
|
| 156 | + define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * The path to the directory of your PHP personal functions or helper. |
|
| 160 | - * |
|
| 161 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 162 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 163 | - * because if you update the system you may lose them. |
|
| 164 | - */ |
|
| 165 | - define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 158 | + /** |
|
| 159 | + * The path to the directory of your PHP personal functions or helper. |
|
| 160 | + * |
|
| 161 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
| 162 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
| 163 | + * because if you update the system you may lose them. |
|
| 164 | + */ |
|
| 165 | + define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * The path to the app directory of personal language. |
|
| 169 | - * |
|
| 170 | - * This feature is not yet available. |
|
| 171 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
| 172 | - */ |
|
| 173 | - define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 167 | + /** |
|
| 168 | + * The path to the app directory of personal language. |
|
| 169 | + * |
|
| 170 | + * This feature is not yet available. |
|
| 171 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
| 172 | + */ |
|
| 173 | + define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * The path to the directory of your personal libraries |
|
| 177 | - * |
|
| 178 | - * It contains your PHP classes, package, etc. |
|
| 179 | - * Note: you should not put your personal libraries in the system library directory, |
|
| 180 | - * because it is recalled in case of updating the system you might have surprises. |
|
| 181 | - */ |
|
| 182 | - define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 175 | + /** |
|
| 176 | + * The path to the directory of your personal libraries |
|
| 177 | + * |
|
| 178 | + * It contains your PHP classes, package, etc. |
|
| 179 | + * Note: you should not put your personal libraries in the system library directory, |
|
| 180 | + * because it is recalled in case of updating the system you might have surprises. |
|
| 181 | + */ |
|
| 182 | + define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * The path to the directory that contains the log files. |
|
| 186 | - * |
|
| 187 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 188 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 189 | - * details see the documentation of your web server. |
|
| 190 | - * Example for Unix or linux with apache web server: |
|
| 191 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 192 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 193 | - */ |
|
| 194 | - define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 184 | + /** |
|
| 185 | + * The path to the directory that contains the log files. |
|
| 186 | + * |
|
| 187 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
| 188 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
| 189 | + * details see the documentation of your web server. |
|
| 190 | + * Example for Unix or linux with apache web server: |
|
| 191 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
| 192 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
| 193 | + */ |
|
| 194 | + define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * The path to the modules directory. |
|
| 198 | - * |
|
| 199 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 200 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
| 201 | - */ |
|
| 202 | - define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
| 196 | + /** |
|
| 197 | + * The path to the modules directory. |
|
| 198 | + * |
|
| 199 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
| 200 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
| 201 | + */ |
|
| 202 | + define('MODULE_PATH', ROOT_PATH . 'modules' . DS); |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * The path to the directory of sources external to your application. |
|
| 206 | - * |
|
| 207 | - * If you have already used "composer" you know what that means. |
|
| 208 | - */ |
|
| 209 | - define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 204 | + /** |
|
| 205 | + * The path to the directory of sources external to your application. |
|
| 206 | + * |
|
| 207 | + * If you have already used "composer" you know what that means. |
|
| 208 | + */ |
|
| 209 | + define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * The front controller of your application. |
|
| 213 | - * |
|
| 214 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 215 | - * your application by using the rewrite module URL of your web server . |
|
| 216 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 217 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 218 | - */ |
|
| 219 | - define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 211 | + /** |
|
| 212 | + * The front controller of your application. |
|
| 213 | + * |
|
| 214 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
| 215 | + * your application by using the rewrite module URL of your web server . |
|
| 216 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
| 217 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
| 218 | + */ |
|
| 219 | + define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Check if user run the application under CLI |
|
| 223 | - */ |
|
| 224 | - define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 221 | + /** |
|
| 222 | + * Check if user run the application under CLI |
|
| 223 | + */ |
|
| 224 | + define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * The environment of your application (production, test, development). |
|
| 228 | - * |
|
| 229 | - * if your application is still in development you use the value "development" |
|
| 230 | - * so you will have the display of the error messages, etc. |
|
| 231 | - * Once you finish the development of your application that is to put it online |
|
| 232 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 233 | - * the loading of the system, will be fast. |
|
| 234 | - */ |
|
| 235 | - define('ENVIRONMENT', 'development'); |
|
| 226 | + /** |
|
| 227 | + * The environment of your application (production, test, development). |
|
| 228 | + * |
|
| 229 | + * if your application is still in development you use the value "development" |
|
| 230 | + * so you will have the display of the error messages, etc. |
|
| 231 | + * Once you finish the development of your application that is to put it online |
|
| 232 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
| 233 | + * the loading of the system, will be fast. |
|
| 234 | + */ |
|
| 235 | + define('ENVIRONMENT', 'development'); |
|
| 236 | 236 | |
| 237 | - /* ---------------------------------------------------------------------------------- */ |
|
| 238 | - /////////////////////////////////////////////////////////////////////////////////////// |
|
| 239 | - /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
| 240 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 237 | + /* ---------------------------------------------------------------------------------- */ |
|
| 238 | + /////////////////////////////////////////////////////////////////////////////////////// |
|
| 239 | + /******************** DO NOT CHANGE THE LINES BELOW *********************************/ |
|
| 240 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 241 | 241 | |
| 242 | - switch (ENVIRONMENT) { |
|
| 243 | - case 'development': |
|
| 244 | - error_reporting(-1); |
|
| 245 | - ini_set('display_errors', 1); |
|
| 246 | - break; |
|
| 247 | - case 'testing': |
|
| 248 | - case 'production': |
|
| 249 | - ini_set('display_errors', 0); |
|
| 250 | - if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
| 251 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 252 | - } |
|
| 253 | - else{ |
|
| 254 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 255 | - } |
|
| 256 | - break; |
|
| 257 | - default: |
|
| 258 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 259 | - echo 'The application environment is not set correctly.'; |
|
| 260 | - exit(1); |
|
| 261 | - } |
|
| 242 | + switch (ENVIRONMENT) { |
|
| 243 | + case 'development': |
|
| 244 | + error_reporting(-1); |
|
| 245 | + ini_set('display_errors', 1); |
|
| 246 | + break; |
|
| 247 | + case 'testing': |
|
| 248 | + case 'production': |
|
| 249 | + ini_set('display_errors', 0); |
|
| 250 | + if (version_compare(PHP_VERSION, '5.3', '>=')) { |
|
| 251 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 252 | + } |
|
| 253 | + else{ |
|
| 254 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 255 | + } |
|
| 256 | + break; |
|
| 257 | + default: |
|
| 258 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 259 | + echo 'The application environment is not set correctly.'; |
|
| 260 | + exit(1); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * let's go. |
|
| 265 | - * Everything is OK now we launch our application. |
|
| 266 | - */ |
|
| 267 | - require_once CORE_PATH . 'bootstrap.php'; |
|
| 268 | 263 | \ No newline at end of file |
| 264 | + /** |
|
| 265 | + * let's go. |
|
| 266 | + * Everything is OK now we launch our application. |
|
| 267 | + */ |
|
| 268 | + require_once CORE_PATH . 'bootstrap.php'; |
|
| 269 | 269 | \ No newline at end of file |
@@ -1,32 +1,32 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | class Pagination{ |
| 28 | 28 | |
| 29 | - /** |
|
| 29 | + /** |
|
| 30 | 30 | * The list of loaded config |
| 31 | 31 | * @var array |
| 32 | 32 | */ |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | if (empty($config) || ! is_array($config)){ |
| 50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 51 | 51 | } |
| 52 | - else{ |
|
| 53 | - $config = array_merge($config, $overwriteConfig); |
|
| 54 | - $this->config = $config; |
|
| 52 | + else{ |
|
| 53 | + $config = array_merge($config, $overwriteConfig); |
|
| 54 | + $this->config = $config; |
|
| 55 | 55 | //put it gobally |
| 56 | - Config::setAll($config); |
|
| 57 | - unset($config); |
|
| 58 | - } |
|
| 56 | + Config::setAll($config); |
|
| 57 | + unset($config); |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | else{ |
| 61 | 61 | show_error('Unable to find the pagination configuration file'); |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | return $this->paginationQueryString; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Set the value of the pagination query string |
|
| 97 | - * @param string $paginationQueryString the new value |
|
| 98 | - * @return object |
|
| 99 | - */ |
|
| 95 | + /** |
|
| 96 | + * Set the value of the pagination query string |
|
| 97 | + * @param string $paginationQueryString the new value |
|
| 98 | + * @return object |
|
| 99 | + */ |
|
| 100 | 100 | public function setPaginationQueryString($paginationQueryString){ |
| 101 | 101 | $this->paginationQueryString = $paginationQueryString; |
| 102 | 102 | return $this; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $queryString = Url::queryString(); |
| 114 | 114 | $currentUrl = Url::current(); |
| 115 | 115 | $query = ''; |
| 116 | - if ($queryString == ''){ |
|
| 116 | + if ($queryString == ''){ |
|
| 117 | 117 | $query = '?' . $pageQueryName . '='; |
| 118 | 118 | } |
| 119 | 119 | else{ |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function getLink($totalRows, $currentPageNumber){ |
| 148 | 148 | $numberOfLink = $this->config['nb_link']; |
| 149 | - $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
| 149 | + $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
| 150 | 150 | if (empty($this->paginationQueryString)){ |
| 151 | 151 | //determine the pagination query string value |
| 152 | 152 | $this->determinePaginationQueryStringValue(); |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | $numberOfRowPerPage = (int) $numberOfRowPerPage; |
| 160 | 160 | |
| 161 | 161 | if ($currentPageNumber <= 0){ |
| 162 | - $currentPageNumber = 1; |
|
| 163 | - } |
|
| 162 | + $currentPageNumber = 1; |
|
| 163 | + } |
|
| 164 | 164 | if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) { |
| 165 | 165 | return $navbar; |
| 166 | 166 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
| 186 | 186 | } |
| 187 | 187 | else if ($currentPageNumber == $numberOfPage){ |
| 188 | - $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
|
| 188 | + $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
|
| 189 | 189 | } |
| 190 | 190 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
| 191 | 191 | return $navbar; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | $navbar .= $this->config['next_open'] |
| 256 | - . '<a href="' . $query . ($currentPageNumber + 1) . '">' |
|
| 257 | - . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
| 256 | + . '<a href="' . $query . ($currentPageNumber + 1) . '">' |
|
| 257 | + . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
| 258 | 258 | return $navbar; |
| 259 | 259 | } |
| 260 | 260 | |
@@ -1,343 +1,343 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - class Html{ |
|
| 27 | + class Html{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Generate the html anchor link |
|
| 31 | - * @param string $link the href attribute value |
|
| 32 | - * @param string $anchor the displayed anchor |
|
| 33 | - * @param array $attributes the additional attributes to be added |
|
| 34 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 35 | - * |
|
| 36 | - * @return string|void the anchor link generated html if $return is true or display it if not |
|
| 37 | - */ |
|
| 38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
| 39 | - $link = Url::site_url($link); |
|
| 40 | - if(! $anchor){ |
|
| 41 | - $anchor = $link; |
|
| 42 | - } |
|
| 43 | - $str = null; |
|
| 44 | - $str .= '<a href = "'.$link.'"'; |
|
| 45 | - $str .= attributes_to_string($attributes); |
|
| 46 | - $str .= '>'; |
|
| 47 | - $str .= $anchor; |
|
| 48 | - $str .= '</a>'; |
|
| 29 | + /** |
|
| 30 | + * Generate the html anchor link |
|
| 31 | + * @param string $link the href attribute value |
|
| 32 | + * @param string $anchor the displayed anchor |
|
| 33 | + * @param array $attributes the additional attributes to be added |
|
| 34 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 35 | + * |
|
| 36 | + * @return string|void the anchor link generated html if $return is true or display it if not |
|
| 37 | + */ |
|
| 38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
| 39 | + $link = Url::site_url($link); |
|
| 40 | + if(! $anchor){ |
|
| 41 | + $anchor = $link; |
|
| 42 | + } |
|
| 43 | + $str = null; |
|
| 44 | + $str .= '<a href = "'.$link.'"'; |
|
| 45 | + $str .= attributes_to_string($attributes); |
|
| 46 | + $str .= '>'; |
|
| 47 | + $str .= $anchor; |
|
| 48 | + $str .= '</a>'; |
|
| 49 | 49 | |
| 50 | - if($return){ |
|
| 51 | - return $str; |
|
| 52 | - } |
|
| 53 | - echo $str; |
|
| 54 | - } |
|
| 50 | + if($return){ |
|
| 51 | + return $str; |
|
| 52 | + } |
|
| 53 | + echo $str; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Generate an mailto anchor link |
|
| 58 | - * @param string $link the email address |
|
| 59 | - * @param string $anchor the displayed value of the link |
|
| 60 | - * @param array $attributes the additional attributes to be added |
|
| 61 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 62 | - * |
|
| 63 | - * @return string|void the generated html for mailto link if $return is true or display it if not |
|
| 64 | - */ |
|
| 65 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
| 66 | - if(! $anchor){ |
|
| 67 | - $anchor = $link; |
|
| 68 | - } |
|
| 69 | - $str = null; |
|
| 70 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
| 71 | - $str .= attributes_to_string($attributes); |
|
| 72 | - $str .= '>'; |
|
| 73 | - $str .= $anchor; |
|
| 74 | - $str .= '</a>'; |
|
| 56 | + /** |
|
| 57 | + * Generate an mailto anchor link |
|
| 58 | + * @param string $link the email address |
|
| 59 | + * @param string $anchor the displayed value of the link |
|
| 60 | + * @param array $attributes the additional attributes to be added |
|
| 61 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 62 | + * |
|
| 63 | + * @return string|void the generated html for mailto link if $return is true or display it if not |
|
| 64 | + */ |
|
| 65 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
| 66 | + if(! $anchor){ |
|
| 67 | + $anchor = $link; |
|
| 68 | + } |
|
| 69 | + $str = null; |
|
| 70 | + $str .= '<a href = "mailto:'.$link.'"'; |
|
| 71 | + $str .= attributes_to_string($attributes); |
|
| 72 | + $str .= '>'; |
|
| 73 | + $str .= $anchor; |
|
| 74 | + $str .= '</a>'; |
|
| 75 | 75 | |
| 76 | - if($return){ |
|
| 77 | - return $str; |
|
| 78 | - } |
|
| 79 | - echo $str; |
|
| 80 | - } |
|
| 76 | + if($return){ |
|
| 77 | + return $str; |
|
| 78 | + } |
|
| 79 | + echo $str; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Generate the html "br" tag |
|
| 84 | - * @param integer $nb the number of generated "<br />" tag |
|
| 85 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 86 | - * |
|
| 87 | - * @return string|void the generated "br" html if $return is true or display it if not |
|
| 88 | - */ |
|
| 89 | - public static function br($nb = 1, $return = true){ |
|
| 90 | - $nb = (int) $nb; |
|
| 91 | - $str = null; |
|
| 92 | - for ($i = 1; $i <= $nb; $i++) { |
|
| 93 | - $str .= '<br />'; |
|
| 94 | - } |
|
| 82 | + /** |
|
| 83 | + * Generate the html "br" tag |
|
| 84 | + * @param integer $nb the number of generated "<br />" tag |
|
| 85 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 86 | + * |
|
| 87 | + * @return string|void the generated "br" html if $return is true or display it if not |
|
| 88 | + */ |
|
| 89 | + public static function br($nb = 1, $return = true){ |
|
| 90 | + $nb = (int) $nb; |
|
| 91 | + $str = null; |
|
| 92 | + for ($i = 1; $i <= $nb; $i++) { |
|
| 93 | + $str .= '<br />'; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - if($return){ |
|
| 97 | - return $str; |
|
| 98 | - } |
|
| 99 | - echo $str; |
|
| 100 | - } |
|
| 96 | + if($return){ |
|
| 97 | + return $str; |
|
| 98 | + } |
|
| 99 | + echo $str; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Generate the html content for tag "hr" |
|
| 104 | - * @param integer $nb the number of generated "<hr />" tag |
|
| 105 | - * @param array $attributes the tag attributes |
|
| 106 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 107 | - * |
|
| 108 | - * @return string|void the generated "hr" html if $return is true or display it if not. |
|
| 109 | - */ |
|
| 110 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
| 111 | - $nb = (int) $nb; |
|
| 112 | - $str = null; |
|
| 113 | - for ($i = 1; $i <= $nb; $i++) { |
|
| 114 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
| 115 | - } |
|
| 116 | - if($return){ |
|
| 117 | - return $str; |
|
| 118 | - } |
|
| 119 | - echo $str; |
|
| 120 | - } |
|
| 102 | + /** |
|
| 103 | + * Generate the html content for tag "hr" |
|
| 104 | + * @param integer $nb the number of generated "<hr />" tag |
|
| 105 | + * @param array $attributes the tag attributes |
|
| 106 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 107 | + * |
|
| 108 | + * @return string|void the generated "hr" html if $return is true or display it if not. |
|
| 109 | + */ |
|
| 110 | + public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
| 111 | + $nb = (int) $nb; |
|
| 112 | + $str = null; |
|
| 113 | + for ($i = 1; $i <= $nb; $i++) { |
|
| 114 | + $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
| 115 | + } |
|
| 116 | + if($return){ |
|
| 117 | + return $str; |
|
| 118 | + } |
|
| 119 | + echo $str; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Generate the html content for tag like h1, h2, h3, h4, h5 and h6 |
|
| 124 | - * @param integer $type the tag type 1 mean h1, 2 h2, etc, |
|
| 125 | - * @param string $text the display text |
|
| 126 | - * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>" |
|
| 127 | - * @param array $attributes the tag attributes |
|
| 128 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 129 | - * |
|
| 130 | - * @return string|void the generated header html if $return is true or display it if not. |
|
| 131 | - */ |
|
| 132 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
| 133 | - $nb = (int) $nb; |
|
| 134 | - $type = (int) $type; |
|
| 135 | - $str = null; |
|
| 136 | - for ($i = 1; $i <= $nb; $i++) { |
|
| 137 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
| 138 | - } |
|
| 139 | - if($return){ |
|
| 140 | - return $str; |
|
| 141 | - } |
|
| 142 | - echo $str; |
|
| 143 | - } |
|
| 122 | + /** |
|
| 123 | + * Generate the html content for tag like h1, h2, h3, h4, h5 and h6 |
|
| 124 | + * @param integer $type the tag type 1 mean h1, 2 h2, etc, |
|
| 125 | + * @param string $text the display text |
|
| 126 | + * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>" |
|
| 127 | + * @param array $attributes the tag attributes |
|
| 128 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 129 | + * |
|
| 130 | + * @return string|void the generated header html if $return is true or display it if not. |
|
| 131 | + */ |
|
| 132 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
| 133 | + $nb = (int) $nb; |
|
| 134 | + $type = (int) $type; |
|
| 135 | + $str = null; |
|
| 136 | + for ($i = 1; $i <= $nb; $i++) { |
|
| 137 | + $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
| 138 | + } |
|
| 139 | + if($return){ |
|
| 140 | + return $str; |
|
| 141 | + } |
|
| 142 | + echo $str; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Generate the html "ul" tag |
|
| 147 | - * @param array $data the data to use for each "li" tag |
|
| 148 | - * @param array $attributes the "ul" properties attribute use the array index below for each tag: |
|
| 149 | - * for ul "ul", for li "li". |
|
| 150 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 151 | - * |
|
| 152 | - * @return string|void the generated "ul" html if $return is true or display it if not. |
|
| 153 | - */ |
|
| 154 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
| 155 | - if($return){ |
|
| 156 | - return self::buildUlOl($data, $attributes, true, 'ul'); |
|
| 157 | - } |
|
| 158 | - self::buildUlOl($data, $attributes, false, 'ul'); |
|
| 159 | - } |
|
| 145 | + /** |
|
| 146 | + * Generate the html "ul" tag |
|
| 147 | + * @param array $data the data to use for each "li" tag |
|
| 148 | + * @param array $attributes the "ul" properties attribute use the array index below for each tag: |
|
| 149 | + * for ul "ul", for li "li". |
|
| 150 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 151 | + * |
|
| 152 | + * @return string|void the generated "ul" html if $return is true or display it if not. |
|
| 153 | + */ |
|
| 154 | + public static function ul($data = array(), $attributes = array(), $return = true){ |
|
| 155 | + if($return){ |
|
| 156 | + return self::buildUlOl($data, $attributes, true, 'ul'); |
|
| 157 | + } |
|
| 158 | + self::buildUlOl($data, $attributes, false, 'ul'); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Generate the html "ol" tag |
|
| 163 | - * @param array $data the data to use for each "li" tag |
|
| 164 | - * @param array $attributes the "ol" properties attribute use the array index below for each tag: |
|
| 165 | - * for ol "ol", for li "li". |
|
| 166 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 167 | - * @return string|void the generated "ol" html if $return is true or display it if not. |
|
| 168 | - */ |
|
| 169 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
| 170 | - if($return){ |
|
| 171 | - return self::buildUlOl($data, $attributes, true, 'ol'); |
|
| 172 | - } |
|
| 173 | - self::buildUlOl($data, $attributes, false, 'ol'); |
|
| 174 | - } |
|
| 161 | + /** |
|
| 162 | + * Generate the html "ol" tag |
|
| 163 | + * @param array $data the data to use for each "li" tag |
|
| 164 | + * @param array $attributes the "ol" properties attribute use the array index below for each tag: |
|
| 165 | + * for ol "ol", for li "li". |
|
| 166 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 167 | + * @return string|void the generated "ol" html if $return is true or display it if not. |
|
| 168 | + */ |
|
| 169 | + public static function ol($data = array(), $attributes = array(), $return = true){ |
|
| 170 | + if($return){ |
|
| 171 | + return self::buildUlOl($data, $attributes, true, 'ol'); |
|
| 172 | + } |
|
| 173 | + self::buildUlOl($data, $attributes, false, 'ol'); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Generate the html "table" tag |
|
| 179 | - * @param array $headers the table headers to use between (<thead>) |
|
| 180 | - * @param array $body the table body values between (<tbody>) |
|
| 181 | - * @param array $attributes the table properties attribute use the array index below for each tag: |
|
| 182 | - * for table "table", for thead "thead", for thead tr "thead_tr", |
|
| 183 | - * for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot", |
|
| 184 | - * for tfoot tr "tfoot_tr", for tfoot th "tfoot_th". |
|
| 185 | - * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values |
|
| 186 | - * @param boolean $return whether need return the generated html or just display it directly |
|
| 187 | - * @return string|void the generated "table" html if $return is true or display it if not. |
|
| 188 | - */ |
|
| 189 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
| 190 | - $headers = (array) $headers; |
|
| 191 | - $body = (array) $body; |
|
| 192 | - $str = null; |
|
| 193 | - $tableAttributes = ''; |
|
| 194 | - if(! empty($attributes['table'])){ |
|
| 195 | - $tableAttributes = ' ' . attributes_to_string($attributes['table']); |
|
| 196 | - } |
|
| 197 | - $str .= '<table' . $tableAttributes . '>'; |
|
| 198 | - $str .= self::buildTableHeader($headers, $attributes); |
|
| 199 | - $str .= self::buildTableBody($body, $attributes); |
|
| 177 | + /** |
|
| 178 | + * Generate the html "table" tag |
|
| 179 | + * @param array $headers the table headers to use between (<thead>) |
|
| 180 | + * @param array $body the table body values between (<tbody>) |
|
| 181 | + * @param array $attributes the table properties attribute use the array index below for each tag: |
|
| 182 | + * for table "table", for thead "thead", for thead tr "thead_tr", |
|
| 183 | + * for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot", |
|
| 184 | + * for tfoot tr "tfoot_tr", for tfoot th "tfoot_th". |
|
| 185 | + * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values |
|
| 186 | + * @param boolean $return whether need return the generated html or just display it directly |
|
| 187 | + * @return string|void the generated "table" html if $return is true or display it if not. |
|
| 188 | + */ |
|
| 189 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
| 190 | + $headers = (array) $headers; |
|
| 191 | + $body = (array) $body; |
|
| 192 | + $str = null; |
|
| 193 | + $tableAttributes = ''; |
|
| 194 | + if(! empty($attributes['table'])){ |
|
| 195 | + $tableAttributes = ' ' . attributes_to_string($attributes['table']); |
|
| 196 | + } |
|
| 197 | + $str .= '<table' . $tableAttributes . '>'; |
|
| 198 | + $str .= self::buildTableHeader($headers, $attributes); |
|
| 199 | + $str .= self::buildTableBody($body, $attributes); |
|
| 200 | 200 | |
| 201 | - if($use_footer){ |
|
| 202 | - $str .= self::buildTableFooter($headers, $attributes); |
|
| 203 | - } |
|
| 204 | - $str .= '</table>'; |
|
| 205 | - if($return){ |
|
| 206 | - return $str; |
|
| 207 | - } |
|
| 208 | - echo $str; |
|
| 209 | - } |
|
| 201 | + if($use_footer){ |
|
| 202 | + $str .= self::buildTableFooter($headers, $attributes); |
|
| 203 | + } |
|
| 204 | + $str .= '</table>'; |
|
| 205 | + if($return){ |
|
| 206 | + return $str; |
|
| 207 | + } |
|
| 208 | + echo $str; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * This method is used to build the header of the html table |
|
| 213 | - * @see Html::table |
|
| 214 | - * @return string|null |
|
| 215 | - */ |
|
| 216 | - protected static function buildTableHeader(array $headers, $attributes = array()){ |
|
| 217 | - $str = null; |
|
| 218 | - $theadAttributes = ''; |
|
| 219 | - if(! empty($attributes['thead'])){ |
|
| 220 | - $theadAttributes = ' ' . attributes_to_string($attributes['thead']); |
|
| 221 | - } |
|
| 222 | - $theadtrAttributes = ''; |
|
| 223 | - if(! empty($attributes['thead_tr'])){ |
|
| 224 | - $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']); |
|
| 225 | - } |
|
| 226 | - $thAttributes = ''; |
|
| 227 | - if(! empty($attributes['thead_th'])){ |
|
| 228 | - $thAttributes = ' ' . attributes_to_string($attributes['thead_th']); |
|
| 229 | - } |
|
| 230 | - $str .= '<thead' . $theadAttributes .'>'; |
|
| 231 | - $str .= '<tr' . $theadtrAttributes .'>'; |
|
| 232 | - foreach ($headers as $value) { |
|
| 233 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
| 234 | - } |
|
| 235 | - $str .= '</tr>'; |
|
| 236 | - $str .= '</thead>'; |
|
| 237 | - return $str; |
|
| 238 | - } |
|
| 211 | + /** |
|
| 212 | + * This method is used to build the header of the html table |
|
| 213 | + * @see Html::table |
|
| 214 | + * @return string|null |
|
| 215 | + */ |
|
| 216 | + protected static function buildTableHeader(array $headers, $attributes = array()){ |
|
| 217 | + $str = null; |
|
| 218 | + $theadAttributes = ''; |
|
| 219 | + if(! empty($attributes['thead'])){ |
|
| 220 | + $theadAttributes = ' ' . attributes_to_string($attributes['thead']); |
|
| 221 | + } |
|
| 222 | + $theadtrAttributes = ''; |
|
| 223 | + if(! empty($attributes['thead_tr'])){ |
|
| 224 | + $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']); |
|
| 225 | + } |
|
| 226 | + $thAttributes = ''; |
|
| 227 | + if(! empty($attributes['thead_th'])){ |
|
| 228 | + $thAttributes = ' ' . attributes_to_string($attributes['thead_th']); |
|
| 229 | + } |
|
| 230 | + $str .= '<thead' . $theadAttributes .'>'; |
|
| 231 | + $str .= '<tr' . $theadtrAttributes .'>'; |
|
| 232 | + foreach ($headers as $value) { |
|
| 233 | + $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
| 234 | + } |
|
| 235 | + $str .= '</tr>'; |
|
| 236 | + $str .= '</thead>'; |
|
| 237 | + return $str; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * This method is used to build the body of the html table |
|
| 242 | - * @see Html::table |
|
| 243 | - * @return string|null |
|
| 244 | - */ |
|
| 245 | - protected static function buildTableBody(array $body, $attributes = array()){ |
|
| 246 | - $str = null; |
|
| 247 | - $tbodyAttributes = ''; |
|
| 248 | - if(! empty($attributes['tbody'])){ |
|
| 249 | - $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']); |
|
| 250 | - } |
|
| 251 | - $tbodytrAttributes = ''; |
|
| 252 | - if(! empty($attributes['tbody_tr'])){ |
|
| 253 | - $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']); |
|
| 254 | - } |
|
| 255 | - $tbodytdAttributes = ''; |
|
| 256 | - if(! empty($attributes['tbody_td'])){ |
|
| 257 | - $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']); |
|
| 258 | - } |
|
| 259 | - $str .= '<tbody' . $tbodyAttributes .'>'; |
|
| 260 | - $str .= self::buildTableBodyContent($body, $tbodytrAttributes, $tbodytdAttributes); |
|
| 261 | - $str .= '</tbody>'; |
|
| 262 | - return $str; |
|
| 263 | - } |
|
| 240 | + /** |
|
| 241 | + * This method is used to build the body of the html table |
|
| 242 | + * @see Html::table |
|
| 243 | + * @return string|null |
|
| 244 | + */ |
|
| 245 | + protected static function buildTableBody(array $body, $attributes = array()){ |
|
| 246 | + $str = null; |
|
| 247 | + $tbodyAttributes = ''; |
|
| 248 | + if(! empty($attributes['tbody'])){ |
|
| 249 | + $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']); |
|
| 250 | + } |
|
| 251 | + $tbodytrAttributes = ''; |
|
| 252 | + if(! empty($attributes['tbody_tr'])){ |
|
| 253 | + $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']); |
|
| 254 | + } |
|
| 255 | + $tbodytdAttributes = ''; |
|
| 256 | + if(! empty($attributes['tbody_td'])){ |
|
| 257 | + $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']); |
|
| 258 | + } |
|
| 259 | + $str .= '<tbody' . $tbodyAttributes .'>'; |
|
| 260 | + $str .= self::buildTableBodyContent($body, $tbodytrAttributes, $tbodytdAttributes); |
|
| 261 | + $str .= '</tbody>'; |
|
| 262 | + return $str; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * This method is used to build the body content of the html table |
|
| 267 | - * @param array $body the table body data |
|
| 268 | - * @param string $tbodytrAttributes the html attributes for each tr in tbody |
|
| 269 | - * @param string $tbodytdAttributes the html attributes for each td in tbody |
|
| 270 | - * @return string |
|
| 271 | - */ |
|
| 272 | - protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes){ |
|
| 273 | - $str = null; |
|
| 274 | - foreach ($body as $row) { |
|
| 275 | - if(is_array($row)){ |
|
| 276 | - $str .= '<tr' . $tbodytrAttributes .'>'; |
|
| 277 | - foreach ($row as $value) { |
|
| 278 | - $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>'; |
|
| 279 | - } |
|
| 280 | - $str .= '</tr>'; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - return $str; |
|
| 284 | - } |
|
| 265 | + /** |
|
| 266 | + * This method is used to build the body content of the html table |
|
| 267 | + * @param array $body the table body data |
|
| 268 | + * @param string $tbodytrAttributes the html attributes for each tr in tbody |
|
| 269 | + * @param string $tbodytdAttributes the html attributes for each td in tbody |
|
| 270 | + * @return string |
|
| 271 | + */ |
|
| 272 | + protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes){ |
|
| 273 | + $str = null; |
|
| 274 | + foreach ($body as $row) { |
|
| 275 | + if(is_array($row)){ |
|
| 276 | + $str .= '<tr' . $tbodytrAttributes .'>'; |
|
| 277 | + foreach ($row as $value) { |
|
| 278 | + $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>'; |
|
| 279 | + } |
|
| 280 | + $str .= '</tr>'; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + return $str; |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * This method is used to build the footer of the html table |
|
| 288 | - * @see Html::table |
|
| 289 | - * @return string|null |
|
| 290 | - */ |
|
| 291 | - protected static function buildTableFooter(array $footers, $attributes = array()){ |
|
| 292 | - $str = null; |
|
| 293 | - $tfootAttributes = ''; |
|
| 294 | - if(! empty($attributes['tfoot'])){ |
|
| 295 | - $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']); |
|
| 296 | - } |
|
| 297 | - $tfoottrAttributes = ''; |
|
| 298 | - if(! empty($attributes['tfoot_tr'])){ |
|
| 299 | - $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']); |
|
| 300 | - } |
|
| 301 | - $thAttributes = ''; |
|
| 302 | - if(! empty($attributes['tfoot_th'])){ |
|
| 303 | - $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']); |
|
| 304 | - } |
|
| 305 | - $str .= '<tfoot' . $tfootAttributes .'>'; |
|
| 306 | - $str .= '<tr' . $tfoottrAttributes .'>'; |
|
| 307 | - foreach ($footers as $value) { |
|
| 308 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
| 309 | - } |
|
| 310 | - $str .= '</tr>'; |
|
| 311 | - $str .= '</tfoot>'; |
|
| 312 | - return $str; |
|
| 313 | - } |
|
| 286 | + /** |
|
| 287 | + * This method is used to build the footer of the html table |
|
| 288 | + * @see Html::table |
|
| 289 | + * @return string|null |
|
| 290 | + */ |
|
| 291 | + protected static function buildTableFooter(array $footers, $attributes = array()){ |
|
| 292 | + $str = null; |
|
| 293 | + $tfootAttributes = ''; |
|
| 294 | + if(! empty($attributes['tfoot'])){ |
|
| 295 | + $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']); |
|
| 296 | + } |
|
| 297 | + $tfoottrAttributes = ''; |
|
| 298 | + if(! empty($attributes['tfoot_tr'])){ |
|
| 299 | + $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']); |
|
| 300 | + } |
|
| 301 | + $thAttributes = ''; |
|
| 302 | + if(! empty($attributes['tfoot_th'])){ |
|
| 303 | + $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']); |
|
| 304 | + } |
|
| 305 | + $str .= '<tfoot' . $tfootAttributes .'>'; |
|
| 306 | + $str .= '<tr' . $tfoottrAttributes .'>'; |
|
| 307 | + foreach ($footers as $value) { |
|
| 308 | + $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
| 309 | + } |
|
| 310 | + $str .= '</tr>'; |
|
| 311 | + $str .= '</tfoot>'; |
|
| 312 | + return $str; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Return the HTML content for ol or ul tags |
|
| 317 | - * @see Html::ol |
|
| 318 | - * @see Html::ul |
|
| 319 | - * @param string $olul the type 'ol' or 'ul' |
|
| 320 | - * @return void|string |
|
| 321 | - */ |
|
| 322 | - protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul'){ |
|
| 323 | - $data = (array) $data; |
|
| 324 | - $str = null; |
|
| 325 | - $olulAttributes = ''; |
|
| 326 | - if(! empty($attributes[$olul])){ |
|
| 327 | - $olulAttributes = ' ' . attributes_to_string($attributes[$olul]); |
|
| 328 | - } |
|
| 329 | - $liAttributes = ''; |
|
| 330 | - if(! empty($attributes['li'])){ |
|
| 331 | - $liAttributes = ' ' . attributes_to_string($attributes['li']); |
|
| 332 | - } |
|
| 333 | - $str .= '<' . $olul . $olulAttributes . '>'; |
|
| 334 | - foreach ($data as $row) { |
|
| 335 | - $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
| 336 | - } |
|
| 337 | - $str .= '</' . $olul . '>'; |
|
| 338 | - if($return){ |
|
| 339 | - return $str; |
|
| 340 | - } |
|
| 341 | - echo $str; |
|
| 342 | - } |
|
| 343 | - } |
|
| 315 | + /** |
|
| 316 | + * Return the HTML content for ol or ul tags |
|
| 317 | + * @see Html::ol |
|
| 318 | + * @see Html::ul |
|
| 319 | + * @param string $olul the type 'ol' or 'ul' |
|
| 320 | + * @return void|string |
|
| 321 | + */ |
|
| 322 | + protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul'){ |
|
| 323 | + $data = (array) $data; |
|
| 324 | + $str = null; |
|
| 325 | + $olulAttributes = ''; |
|
| 326 | + if(! empty($attributes[$olul])){ |
|
| 327 | + $olulAttributes = ' ' . attributes_to_string($attributes[$olul]); |
|
| 328 | + } |
|
| 329 | + $liAttributes = ''; |
|
| 330 | + if(! empty($attributes['li'])){ |
|
| 331 | + $liAttributes = ' ' . attributes_to_string($attributes['li']); |
|
| 332 | + } |
|
| 333 | + $str .= '<' . $olul . $olulAttributes . '>'; |
|
| 334 | + foreach ($data as $row) { |
|
| 335 | + $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
| 336 | + } |
|
| 337 | + $str .= '</' . $olul . '>'; |
|
| 338 | + if($return){ |
|
| 339 | + return $str; |
|
| 340 | + } |
|
| 341 | + echo $str; |
|
| 342 | + } |
|
| 343 | + } |
|
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 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 | 26 | |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | protected $_temporary_return_type = NULL; |
| 121 | 121 | |
| 122 | 122 | |
| 123 | - /** |
|
| 123 | + /** |
|
| 124 | 124 | The database cache time |
| 125 | - */ |
|
| 126 | - protected $dbCacheTime = 0; |
|
| 125 | + */ |
|
| 126 | + protected $dbCacheTime = 0; |
|
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * Instance of the Loader class |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | else{ |
| 153 | 153 | $obj = & get_instance(); |
| 154 | - if (isset($obj->database) && is_object($obj->database)){ |
|
| 154 | + if (isset($obj->database) && is_object($obj->database)){ |
|
| 155 | 155 | /** |
| 156 | - * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
|
| 157 | - * to prevent duplication |
|
| 158 | - */ |
|
| 159 | - $this->setDatabaseInstance(clone $obj->database); |
|
| 156 | + * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
|
| 157 | + * to prevent duplication |
|
| 158 | + */ |
|
| 159 | + $this->setDatabaseInstance(clone $obj->database); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function get($primary_value) |
| 176 | 176 | { |
| 177 | - return $this->get_by($this->primary_key, $primary_value); |
|
| 177 | + return $this->get_by($this->primary_key, $primary_value); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | { |
| 190 | 190 | $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
| 191 | 191 | } |
| 192 | - $this->_set_where($where); |
|
| 192 | + $this->_set_where($where); |
|
| 193 | 193 | |
| 194 | 194 | $this->trigger('before_get'); |
| 195 | - $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
| 195 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
| 196 | 196 | $this->getQueryBuilder()->from($this->_table); |
| 197 | - $row = $this->_database->get($type); |
|
| 197 | + $row = $this->_database->get($type); |
|
| 198 | 198 | $this->_temporary_return_type = $this->return_type; |
| 199 | 199 | $row = $this->trigger('after_get', $row); |
| 200 | 200 | $this->_with = array(); |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | { |
| 232 | 232 | $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
| 233 | 233 | } |
| 234 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
| 234 | + $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
| 235 | 235 | $this->getQueryBuilder()->from($this->_table); |
| 236 | - $result = $this->_database->getAll($type); |
|
| 236 | + $result = $this->_database->getAll($type); |
|
| 237 | 237 | $this->_temporary_return_type = $this->return_type; |
| 238 | 238 | |
| 239 | 239 | foreach ($result as $key => &$row) |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | /** |
| 248 | 248 | * Insert a new row into the table. $data should be an associative array |
| 249 | 249 | * of data to be inserted. Returns newly created ID. |
| 250 | - * @see Database::insert |
|
| 250 | + * @see Database::insert |
|
| 251 | 251 | */ |
| 252 | 252 | public function insert($data = array(), $skip_validation = FALSE, $escape = true) |
| 253 | 253 | { |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | { |
| 261 | 261 | $data = $this->trigger('before_create', $data); |
| 262 | 262 | $this->getQueryBuilder()->from($this->_table); |
| 263 | - $this->_database->insert($data, $escape); |
|
| 263 | + $this->_database->insert($data, $escape); |
|
| 264 | 264 | $insert_id = $this->_database->insertId(); |
| 265 | 265 | $this->trigger('after_create', $insert_id); |
| 266 | - //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 267 | - return ! $insert_id ? true : $insert_id; |
|
| 266 | + //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
|
| 267 | + return ! $insert_id ? true : $insert_id; |
|
| 268 | 268 | } |
| 269 | 269 | else |
| 270 | 270 | { |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | { |
| 325 | 325 | $this->getQueryBuilder()->in($this->primary_key, $primary_values) |
| 326 | 326 | ->from($this->_table); |
| 327 | - $result = $this->_database->update($data, $escape); |
|
| 327 | + $result = $this->_database->update($data, $escape); |
|
| 328 | 328 | $this->trigger('after_update', array($data, $result)); |
| 329 | 329 | return $result; |
| 330 | 330 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | { |
| 357 | 357 | $this->_set_where($args); |
| 358 | 358 | $this->getQueryBuilder()->from($this->_table); |
| 359 | - $result = $this->_database->update($data); |
|
| 359 | + $result = $this->_database->update($data); |
|
| 360 | 360 | $this->trigger('after_update', array($data, $result)); |
| 361 | 361 | return $result; |
| 362 | 362 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | { |
| 371 | 371 | $data = $this->trigger('before_update', $data); |
| 372 | 372 | $this->getQueryBuilder()->from($this->_table); |
| 373 | - $result = $this->_database->update($data, $escape); |
|
| 373 | + $result = $this->_database->update($data, $escape); |
|
| 374 | 374 | $this->trigger('after_update', array($data, $result)); |
| 375 | 375 | return $result; |
| 376 | 376 | } |
@@ -382,16 +382,16 @@ discard block |
||
| 382 | 382 | { |
| 383 | 383 | $this->trigger('before_delete', $id); |
| 384 | 384 | $this->getQueryBuilder()->where($this->primary_key, $id); |
| 385 | - $result = false; |
|
| 385 | + $result = false; |
|
| 386 | 386 | if ($this->soft_delete) |
| 387 | 387 | { |
| 388 | 388 | $this->getQueryBuilder()->from($this->_table); |
| 389 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 389 | + $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 390 | 390 | } |
| 391 | 391 | else |
| 392 | 392 | { |
| 393 | 393 | $this->getQueryBuilder()->from($this->_table); |
| 394 | - $result = $this->_database->delete(); |
|
| 394 | + $result = $this->_database->delete(); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | $this->trigger('after_delete', $result); |
@@ -404,18 +404,18 @@ discard block |
||
| 404 | 404 | public function delete_by() |
| 405 | 405 | { |
| 406 | 406 | $where = func_get_args(); |
| 407 | - $where = $this->trigger('before_delete', $where); |
|
| 407 | + $where = $this->trigger('before_delete', $where); |
|
| 408 | 408 | $this->_set_where($where); |
| 409 | - $result = false; |
|
| 409 | + $result = false; |
|
| 410 | 410 | if ($this->soft_delete) |
| 411 | 411 | { |
| 412 | 412 | $this->getQueryBuilder()->from($this->_table); |
| 413 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 413 | + $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 414 | 414 | } |
| 415 | 415 | else |
| 416 | 416 | { |
| 417 | 417 | $this->getQueryBuilder()->from($this->_table); |
| 418 | - $result = $this->_database->delete(); |
|
| 418 | + $result = $this->_database->delete(); |
|
| 419 | 419 | } |
| 420 | 420 | $this->trigger('after_delete', $result); |
| 421 | 421 | return $result; |
@@ -428,16 +428,16 @@ discard block |
||
| 428 | 428 | { |
| 429 | 429 | $primary_values = $this->trigger('before_delete', $primary_values); |
| 430 | 430 | $this->getQueryBuilder()->in($this->primary_key, $primary_values); |
| 431 | - $result = false; |
|
| 431 | + $result = false; |
|
| 432 | 432 | if ($this->soft_delete) |
| 433 | 433 | { |
| 434 | 434 | $this->getQueryBuilder()->from($this->_table); |
| 435 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 435 | + $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
| 436 | 436 | } |
| 437 | 437 | else |
| 438 | 438 | { |
| 439 | 439 | $this->getQueryBuilder()->from($this->_table); |
| 440 | - $result = $this->_database->delete(); |
|
| 440 | + $result = $this->_database->delete(); |
|
| 441 | 441 | } |
| 442 | 442 | $this->trigger('after_delete', $result); |
| 443 | 443 | return $result; |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function truncate() |
| 451 | 451 | { |
| 452 | - $this->getQueryBuilder()->from($this->_table); |
|
| 453 | - $result = $this->_database->delete(); |
|
| 452 | + $this->getQueryBuilder()->from($this->_table); |
|
| 453 | + $result = $this->_database->delete(); |
|
| 454 | 454 | return $result; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -468,14 +468,14 @@ discard block |
||
| 468 | 468 | return $this; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Relationship |
|
| 473 | - */ |
|
| 471 | + /** |
|
| 472 | + * Relationship |
|
| 473 | + */ |
|
| 474 | 474 | public function relate($row) |
| 475 | 475 | { |
| 476 | - if (empty($row)) |
|
| 476 | + if (empty($row)) |
|
| 477 | 477 | { |
| 478 | - return $row; |
|
| 478 | + return $row; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | $row = $this->relateBelongsTo($row); |
@@ -508,9 +508,9 @@ discard block |
||
| 508 | 508 | $this->getQueryBuilder()->where($this->soft_delete_key, FALSE); |
| 509 | 509 | } |
| 510 | 510 | $this->getQueryBuilder() |
| 511 | - ->select(array($key, $value)) |
|
| 512 | - ->from($this->_table); |
|
| 513 | - $result = $this->_database->getAll(); |
|
| 511 | + ->select(array($key, $value)) |
|
| 512 | + ->from($this->_table); |
|
| 513 | + $result = $this->_database->getAll(); |
|
| 514 | 514 | $options = array(); |
| 515 | 515 | foreach ($result as $row) |
| 516 | 516 | { |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | $where = func_get_args(); |
| 533 | 533 | $this->_set_where($where); |
| 534 | 534 | $this->getQueryBuilder()->from($this->_table); |
| 535 | - $this->_database->getAll(); |
|
| 535 | + $this->_database->getAll(); |
|
| 536 | 536 | return $this->_database->numRows(); |
| 537 | 537 | } |
| 538 | 538 | |
@@ -545,20 +545,20 @@ discard block |
||
| 545 | 545 | { |
| 546 | 546 | $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
| 547 | 547 | } |
| 548 | - $this->getQueryBuilder()->from($this->_table); |
|
| 549 | - $this->_database->getAll(); |
|
| 548 | + $this->getQueryBuilder()->from($this->_table); |
|
| 549 | + $this->_database->getAll(); |
|
| 550 | 550 | return $this->_database->numRows(); |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Enabled cache temporary |
|
| 555 | - */ |
|
| 556 | - public function cached($ttl = 0){ |
|
| 557 | - if ($ttl > 0){ |
|
| 558 | - $this->_database = $this->_database->cached($ttl); |
|
| 559 | - } |
|
| 560 | - return $this; |
|
| 561 | - } |
|
| 553 | + /** |
|
| 554 | + * Enabled cache temporary |
|
| 555 | + */ |
|
| 556 | + public function cached($ttl = 0){ |
|
| 557 | + if ($ttl > 0){ |
|
| 558 | + $this->_database = $this->_database->cached($ttl); |
|
| 559 | + } |
|
| 560 | + return $this; |
|
| 561 | + } |
|
| 562 | 562 | |
| 563 | 563 | /** |
| 564 | 564 | * Tell the class to skip the insert validation |
@@ -582,10 +582,10 @@ discard block |
||
| 582 | 582 | */ |
| 583 | 583 | public function get_next_id() |
| 584 | 584 | { |
| 585 | - $this->getQueryBuilder()->select('AUTO_INCREMENT') |
|
| 586 | - ->from('information_schema.TABLES') |
|
| 587 | - ->where('TABLE_NAME', $this->_table) |
|
| 588 | - ->where('TABLE_SCHEMA', $this->_database->getDatabaseName()); |
|
| 585 | + $this->getQueryBuilder()->select('AUTO_INCREMENT') |
|
| 586 | + ->from('information_schema.TABLES') |
|
| 587 | + ->where('TABLE_NAME', $this->_table) |
|
| 588 | + ->where('TABLE_SCHEMA', $this->_database->getDatabaseName()); |
|
| 589 | 589 | return (int) $this->_database->get()->AUTO_INCREMENT; |
| 590 | 590 | } |
| 591 | 591 | |
@@ -708,24 +708,24 @@ discard block |
||
| 708 | 708 | { |
| 709 | 709 | if (is_object($row)) |
| 710 | 710 | { |
| 711 | - if (isset($row->$attr)){ |
|
| 712 | - unset($row->$attr); |
|
| 713 | - } |
|
| 711 | + if (isset($row->$attr)){ |
|
| 712 | + unset($row->$attr); |
|
| 713 | + } |
|
| 714 | 714 | } |
| 715 | 715 | else |
| 716 | 716 | { |
| 717 | - if (isset($row[$attr])){ |
|
| 718 | - unset($row[$attr]); |
|
| 719 | - } |
|
| 717 | + if (isset($row[$attr])){ |
|
| 718 | + unset($row[$attr]); |
|
| 719 | + } |
|
| 720 | 720 | } |
| 721 | 721 | } |
| 722 | 722 | return $row; |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | - /** |
|
| 726 | - * Return the database instance |
|
| 727 | - * @return Database the database instance |
|
| 728 | - */ |
|
| 725 | + /** |
|
| 726 | + * Return the database instance |
|
| 727 | + * @return Database the database instance |
|
| 728 | + */ |
|
| 729 | 729 | public function getDatabaseInstance(){ |
| 730 | 730 | return $this->_database; |
| 731 | 731 | } |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * set the Database instance for future use |
| 735 | 735 | * @param Database $db the database object |
| 736 | 736 | */ |
| 737 | - public function setDatabaseInstance($db){ |
|
| 737 | + public function setDatabaseInstance($db){ |
|
| 738 | 738 | $this->_database = $db; |
| 739 | 739 | if ($this->dbCacheTime > 0){ |
| 740 | 740 | $this->_database->setCache($this->dbCacheTime); |
@@ -753,14 +753,14 @@ discard block |
||
| 753 | 753 | /** |
| 754 | 754 | * Set the loader instance for future use |
| 755 | 755 | * @param Loader $loader the loader object |
| 756 | - * @return object |
|
| 756 | + * @return object |
|
| 757 | 757 | */ |
| 758 | - public function setLoader($loader){ |
|
| 758 | + public function setLoader($loader){ |
|
| 759 | 759 | $this->loaderInstance = $loader; |
| 760 | 760 | return $this; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - /** |
|
| 763 | + /** |
|
| 764 | 764 | * Return the queryBuilder instance this is the shortcut to database queryBuilder |
| 765 | 765 | * @return object the DatabaseQueryBuilder instance |
| 766 | 766 | */ |
@@ -771,9 +771,9 @@ discard block |
||
| 771 | 771 | /** |
| 772 | 772 | * Set the DatabaseQueryBuilder instance for future use |
| 773 | 773 | * @param object $queryBuilder the DatabaseQueryBuilder object |
| 774 | - * @return object |
|
| 774 | + * @return object |
|
| 775 | 775 | */ |
| 776 | - public function setQueryBuilder($queryBuilder){ |
|
| 776 | + public function setQueryBuilder($queryBuilder){ |
|
| 777 | 777 | $this->_database->setQueryBuilder($queryBuilder); |
| 778 | 778 | return $this; |
| 779 | 779 | } |
@@ -790,9 +790,9 @@ discard block |
||
| 790 | 790 | /** |
| 791 | 791 | * Set the form validation instance for future use |
| 792 | 792 | * @param FormValidation $fv the form validation object |
| 793 | - * @return object |
|
| 793 | + * @return object |
|
| 794 | 794 | */ |
| 795 | - public function setFormValidation($fv){ |
|
| 795 | + public function setFormValidation($fv){ |
|
| 796 | 796 | $this->formValidationInstance = $fv; |
| 797 | 797 | return $this; |
| 798 | 798 | } |
@@ -833,12 +833,12 @@ discard block |
||
| 833 | 833 | * INTERNAL METHODS |
| 834 | 834 | * ------------------------------------------------------------ */ |
| 835 | 835 | |
| 836 | - /** |
|
| 837 | - * relate for the relation "belongs_to" |
|
| 838 | - * @return mixed |
|
| 839 | - */ |
|
| 840 | - protected function relateBelongsTo($row){ |
|
| 841 | - foreach ($this->belongs_to as $key => $value) |
|
| 836 | + /** |
|
| 837 | + * relate for the relation "belongs_to" |
|
| 838 | + * @return mixed |
|
| 839 | + */ |
|
| 840 | + protected function relateBelongsTo($row){ |
|
| 841 | + foreach ($this->belongs_to as $key => $value) |
|
| 842 | 842 | { |
| 843 | 843 | if (is_string($value)) |
| 844 | 844 | { |
@@ -869,15 +869,15 @@ discard block |
||
| 869 | 869 | } |
| 870 | 870 | } |
| 871 | 871 | } |
| 872 | - return $row; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * relate for the relation "has_many" |
|
| 877 | - * @return mixed |
|
| 878 | - */ |
|
| 879 | - protected function relateHasMany($row){ |
|
| 880 | - foreach ($this->has_many as $key => $value) |
|
| 872 | + return $row; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * relate for the relation "has_many" |
|
| 877 | + * @return mixed |
|
| 878 | + */ |
|
| 879 | + protected function relateHasMany($row){ |
|
| 880 | + foreach ($this->has_many as $key => $value) |
|
| 881 | 881 | { |
| 882 | 882 | if (is_string($value)) |
| 883 | 883 | { |
@@ -908,8 +908,8 @@ discard block |
||
| 908 | 908 | } |
| 909 | 909 | } |
| 910 | 910 | } |
| 911 | - return $row; |
|
| 912 | - } |
|
| 911 | + return $row; |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | 914 | /** |
| 915 | 915 | * Trigger an event and call its observers. Pass through the event name |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | } |
| 946 | 946 | $fv = $this->formValidationInstance; |
| 947 | 947 | if (! is_object($fv)){ |
| 948 | - Loader::library('FormValidation'); |
|
| 948 | + Loader::library('FormValidation'); |
|
| 949 | 949 | $fv = $this->formvalidation; |
| 950 | 950 | $this->setFormValidation($fv); |
| 951 | 951 | } |
@@ -960,30 +960,30 @@ discard block |
||
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | |
| 963 | - /** |
|
| 964 | - * Set WHERE parameters, when is array |
|
| 965 | - * @param array $params |
|
| 966 | - */ |
|
| 967 | - protected function _set_where_array(array $params){ |
|
| 968 | - foreach ($params as $field => $filter) |
|
| 969 | - { |
|
| 970 | - if (is_array($filter)) |
|
| 971 | - { |
|
| 972 | - $this->getQueryBuilder()->in($field, $filter); |
|
| 973 | - } |
|
| 974 | - else |
|
| 975 | - { |
|
| 976 | - if (is_int($field)) |
|
| 977 | - { |
|
| 978 | - $this->getQueryBuilder()->where($filter); |
|
| 979 | - } |
|
| 980 | - else |
|
| 981 | - { |
|
| 982 | - $this->getQueryBuilder()->where($field, $filter); |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - } |
|
| 963 | + /** |
|
| 964 | + * Set WHERE parameters, when is array |
|
| 965 | + * @param array $params |
|
| 966 | + */ |
|
| 967 | + protected function _set_where_array(array $params){ |
|
| 968 | + foreach ($params as $field => $filter) |
|
| 969 | + { |
|
| 970 | + if (is_array($filter)) |
|
| 971 | + { |
|
| 972 | + $this->getQueryBuilder()->in($field, $filter); |
|
| 973 | + } |
|
| 974 | + else |
|
| 975 | + { |
|
| 976 | + if (is_int($field)) |
|
| 977 | + { |
|
| 978 | + $this->getQueryBuilder()->where($filter); |
|
| 979 | + } |
|
| 980 | + else |
|
| 981 | + { |
|
| 982 | + $this->getQueryBuilder()->where($field, $filter); |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | 987 | |
| 988 | 988 | |
| 989 | 989 | /** |
@@ -999,8 +999,8 @@ discard block |
||
| 999 | 999 | { |
| 1000 | 1000 | $this->getQueryBuilder()->where($params[0]); |
| 1001 | 1001 | } |
| 1002 | - else if (count($params) == 2) |
|
| 1003 | - { |
|
| 1002 | + else if (count($params) == 2) |
|
| 1003 | + { |
|
| 1004 | 1004 | if (is_array($params[1])) |
| 1005 | 1005 | { |
| 1006 | 1006 | $this->getQueryBuilder()->in($params[0], $params[1]); |
@@ -1009,11 +1009,11 @@ discard block |
||
| 1009 | 1009 | { |
| 1010 | 1010 | $this->getQueryBuilder()->where($params[0], $params[1]); |
| 1011 | 1011 | } |
| 1012 | - } |
|
| 1013 | - else if (count($params) == 3) |
|
| 1014 | - { |
|
| 1015 | - $this->getQueryBuilder()->where($params[0], $params[1], $params[2]); |
|
| 1016 | - } |
|
| 1012 | + } |
|
| 1013 | + else if (count($params) == 3) |
|
| 1014 | + { |
|
| 1015 | + $this->getQueryBuilder()->where($params[0], $params[1], $params[2]); |
|
| 1016 | + } |
|
| 1017 | 1017 | else |
| 1018 | 1018 | { |
| 1019 | 1019 | if (is_array($params[1])) |
@@ -1029,7 +1029,7 @@ discard block |
||
| 1029 | 1029 | |
| 1030 | 1030 | /** |
| 1031 | 1031 | Shortcut to controller |
| 1032 | - */ |
|
| 1032 | + */ |
|
| 1033 | 1033 | public function __get($key){ |
| 1034 | 1034 | return get_instance()->{$key}; |
| 1035 | 1035 | } |
@@ -1,578 +1,578 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file common.php |
|
| 29 | - * |
|
| 30 | - * Contains most of the commons functions used by the system |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @filesource |
|
| 39 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file common.php |
|
| 29 | + * |
|
| 30 | + * Contains most of the commons functions used by the system |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @filesource |
|
| 39 | + */ |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * This function is the class loader helper is used if the library "Loader" not yet loaded |
|
| 44 | - * he load the class once |
|
| 45 | - * @param string $class the class name to be loaded |
|
| 46 | - * @param string $dir the directory where to find the class |
|
| 47 | - * @param mixed $params the parameter to pass as argument to the constructor of the class |
|
| 48 | - * @codeCoverageIgnore |
|
| 49 | - * |
|
| 50 | - * @return object the instance of the loaded class |
|
| 51 | - */ |
|
| 52 | - function & class_loader($class, $dir = 'libraries', $params = null){ |
|
| 53 | - //put the first letter of class to upper case |
|
| 54 | - $class = ucfirst($class); |
|
| 55 | - static $classes = array(); |
|
| 56 | - if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 57 | - return $classes[$class]; |
|
| 58 | - } |
|
| 59 | - $found = false; |
|
| 60 | - foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
|
| 61 | - $file = $path . $dir . '/' . $class . '.php'; |
|
| 62 | - if (file_exists($file)){ |
|
| 63 | - if (class_exists($class, false) === false){ |
|
| 64 | - require_once $file; |
|
| 65 | - } |
|
| 66 | - //already found |
|
| 67 | - $found = true; |
|
| 68 | - break; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - if (! $found){ |
|
| 72 | - //can't use show_error() at this time because some dependencies not yet loaded |
|
| 73 | - set_http_status_header(503); |
|
| 74 | - echo 'Cannot find the class [' . $class . ']'; |
|
| 75 | - die(); |
|
| 76 | - } |
|
| 42 | + /** |
|
| 43 | + * This function is the class loader helper is used if the library "Loader" not yet loaded |
|
| 44 | + * he load the class once |
|
| 45 | + * @param string $class the class name to be loaded |
|
| 46 | + * @param string $dir the directory where to find the class |
|
| 47 | + * @param mixed $params the parameter to pass as argument to the constructor of the class |
|
| 48 | + * @codeCoverageIgnore |
|
| 49 | + * |
|
| 50 | + * @return object the instance of the loaded class |
|
| 51 | + */ |
|
| 52 | + function & class_loader($class, $dir = 'libraries', $params = null){ |
|
| 53 | + //put the first letter of class to upper case |
|
| 54 | + $class = ucfirst($class); |
|
| 55 | + static $classes = array(); |
|
| 56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
| 57 | + return $classes[$class]; |
|
| 58 | + } |
|
| 59 | + $found = false; |
|
| 60 | + foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
|
| 61 | + $file = $path . $dir . '/' . $class . '.php'; |
|
| 62 | + if (file_exists($file)){ |
|
| 63 | + if (class_exists($class, false) === false){ |
|
| 64 | + require_once $file; |
|
| 65 | + } |
|
| 66 | + //already found |
|
| 67 | + $found = true; |
|
| 68 | + break; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + if (! $found){ |
|
| 72 | + //can't use show_error() at this time because some dependencies not yet loaded |
|
| 73 | + set_http_status_header(503); |
|
| 74 | + echo 'Cannot find the class [' . $class . ']'; |
|
| 75 | + die(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /* |
|
| 78 | + /* |
|
| 79 | 79 | TODO use the best method to get the Log instance |
| 80 | 80 | */ |
| 81 | - if ($class == 'Log'){ |
|
| 82 | - //can't use the instruction like "return new Log()" |
|
| 83 | - //because we need return the reference instance of the loaded class. |
|
| 84 | - $log = new Log(); |
|
| 85 | - return $log; |
|
| 86 | - } |
|
| 87 | - //track of loaded classes |
|
| 88 | - class_loaded($class); |
|
| 81 | + if ($class == 'Log'){ |
|
| 82 | + //can't use the instruction like "return new Log()" |
|
| 83 | + //because we need return the reference instance of the loaded class. |
|
| 84 | + $log = new Log(); |
|
| 85 | + return $log; |
|
| 86 | + } |
|
| 87 | + //track of loaded classes |
|
| 88 | + class_loaded($class); |
|
| 89 | 89 | |
| 90 | - //record the class instance |
|
| 91 | - $classes[$class] = isset($params) ? new $class($params) : new $class(); |
|
| 90 | + //record the class instance |
|
| 91 | + $classes[$class] = isset($params) ? new $class($params) : new $class(); |
|
| 92 | 92 | |
| 93 | - return $classes[$class]; |
|
| 94 | - } |
|
| 93 | + return $classes[$class]; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * This function is the helper to record the loaded classes |
|
| 98 | - * @param string $class the loaded class name |
|
| 99 | - * @codeCoverageIgnore |
|
| 100 | - * |
|
| 101 | - * @return array the list of the loaded classes |
|
| 102 | - */ |
|
| 103 | - function & class_loaded($class = null){ |
|
| 104 | - static $list = array(); |
|
| 105 | - if ($class !== null){ |
|
| 106 | - $list[strtolower($class)] = $class; |
|
| 107 | - } |
|
| 108 | - return $list; |
|
| 109 | - } |
|
| 96 | + /** |
|
| 97 | + * This function is the helper to record the loaded classes |
|
| 98 | + * @param string $class the loaded class name |
|
| 99 | + * @codeCoverageIgnore |
|
| 100 | + * |
|
| 101 | + * @return array the list of the loaded classes |
|
| 102 | + */ |
|
| 103 | + function & class_loaded($class = null){ |
|
| 104 | + static $list = array(); |
|
| 105 | + if ($class !== null){ |
|
| 106 | + $list[strtolower($class)] = $class; |
|
| 107 | + } |
|
| 108 | + return $list; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * This function is used to load the configurations in the case the "Config" library not yet loaded |
|
| 113 | - * @param array $overwrite_values if need overwrite the existing configuration |
|
| 114 | - * @codeCoverageIgnore |
|
| 115 | - * |
|
| 116 | - * @return array the configurations values |
|
| 117 | - */ |
|
| 118 | - function & load_configurations(array $overwrite_values = array()){ |
|
| 119 | - static $config; |
|
| 120 | - if (empty($config)){ |
|
| 121 | - $file = CONFIG_PATH . 'config.php'; |
|
| 122 | - $found = false; |
|
| 123 | - if (file_exists($file)){ |
|
| 124 | - require_once $file; |
|
| 125 | - $found = true; |
|
| 126 | - } |
|
| 127 | - if (! $found){ |
|
| 128 | - set_http_status_header(503); |
|
| 129 | - echo 'Unable to find the configuration file [' . $file . ']'; |
|
| 130 | - die(); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - foreach ($overwrite_values as $key => $value) { |
|
| 134 | - $config[$key] = $value; |
|
| 135 | - } |
|
| 136 | - return $config; |
|
| 137 | - } |
|
| 111 | + /** |
|
| 112 | + * This function is used to load the configurations in the case the "Config" library not yet loaded |
|
| 113 | + * @param array $overwrite_values if need overwrite the existing configuration |
|
| 114 | + * @codeCoverageIgnore |
|
| 115 | + * |
|
| 116 | + * @return array the configurations values |
|
| 117 | + */ |
|
| 118 | + function & load_configurations(array $overwrite_values = array()){ |
|
| 119 | + static $config; |
|
| 120 | + if (empty($config)){ |
|
| 121 | + $file = CONFIG_PATH . 'config.php'; |
|
| 122 | + $found = false; |
|
| 123 | + if (file_exists($file)){ |
|
| 124 | + require_once $file; |
|
| 125 | + $found = true; |
|
| 126 | + } |
|
| 127 | + if (! $found){ |
|
| 128 | + set_http_status_header(503); |
|
| 129 | + echo 'Unable to find the configuration file [' . $file . ']'; |
|
| 130 | + die(); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + foreach ($overwrite_values as $key => $value) { |
|
| 134 | + $config[$key] = $value; |
|
| 135 | + } |
|
| 136 | + return $config; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * This function is the helper to get the config value in case the "Config" library not yet loaded |
|
| 141 | - * @param string $key the config item to get the vale |
|
| 142 | - * @param mixed $default the default value to return if can't find the config item in the configuration |
|
| 143 | - * @test |
|
| 144 | - * |
|
| 145 | - * @return mixed the config value |
|
| 146 | - */ |
|
| 147 | - function get_config($key, $default = null){ |
|
| 148 | - static $cfg; |
|
| 149 | - if (empty($cfg)){ |
|
| 150 | - $cfg[0] = & load_configurations(); |
|
| 151 | - } |
|
| 152 | - return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
|
| 153 | - } |
|
| 139 | + /** |
|
| 140 | + * This function is the helper to get the config value in case the "Config" library not yet loaded |
|
| 141 | + * @param string $key the config item to get the vale |
|
| 142 | + * @param mixed $default the default value to return if can't find the config item in the configuration |
|
| 143 | + * @test |
|
| 144 | + * |
|
| 145 | + * @return mixed the config value |
|
| 146 | + */ |
|
| 147 | + function get_config($key, $default = null){ |
|
| 148 | + static $cfg; |
|
| 149 | + if (empty($cfg)){ |
|
| 150 | + $cfg[0] = & load_configurations(); |
|
| 151 | + } |
|
| 152 | + return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * This function is a helper to logging message |
|
| 157 | - * @param string $level the log level "ERROR", "DEBUG", "INFO", etc. |
|
| 158 | - * @param string $message the log message to be saved |
|
| 159 | - * @param string $logger the logger to use if is set |
|
| 160 | - * |
|
| 161 | - * @codeCoverageIgnore |
|
| 162 | - */ |
|
| 163 | - function save_to_log($level, $message, $logger = null){ |
|
| 164 | - $log =& class_loader('Log', 'classes'); |
|
| 165 | - if ($logger){ |
|
| 166 | - $log->setLogger($logger); |
|
| 167 | - } |
|
| 168 | - $log->writeLog($message, $level); |
|
| 169 | - } |
|
| 155 | + /** |
|
| 156 | + * This function is a helper to logging message |
|
| 157 | + * @param string $level the log level "ERROR", "DEBUG", "INFO", etc. |
|
| 158 | + * @param string $message the log message to be saved |
|
| 159 | + * @param string $logger the logger to use if is set |
|
| 160 | + * |
|
| 161 | + * @codeCoverageIgnore |
|
| 162 | + */ |
|
| 163 | + function save_to_log($level, $message, $logger = null){ |
|
| 164 | + $log =& class_loader('Log', 'classes'); |
|
| 165 | + if ($logger){ |
|
| 166 | + $log->setLogger($logger); |
|
| 167 | + } |
|
| 168 | + $log->writeLog($message, $level); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Set the HTTP status header |
|
| 173 | - * @param integer $code the HTTP status code |
|
| 174 | - * @param string $text the HTTP status text |
|
| 175 | - * |
|
| 176 | - * @codeCoverageIgnore |
|
| 177 | - */ |
|
| 178 | - function set_http_status_header($code = 200, $text = null){ |
|
| 179 | - if (empty($text)){ |
|
| 180 | - $http_status = array( |
|
| 181 | - 100 => 'Continue', |
|
| 182 | - 101 => 'Switching Protocols', |
|
| 183 | - 200 => 'OK', |
|
| 184 | - 201 => 'Created', |
|
| 185 | - 202 => 'Accepted', |
|
| 186 | - 203 => 'Non-Authoritative Information', |
|
| 187 | - 204 => 'No Content', |
|
| 188 | - 205 => 'Reset Content', |
|
| 189 | - 206 => 'Partial Content', |
|
| 190 | - 300 => 'Multiple Choices', |
|
| 191 | - 301 => 'Moved Permanently', |
|
| 192 | - 302 => 'Found', |
|
| 193 | - 303 => 'See Other', |
|
| 194 | - 304 => 'Not Modified', |
|
| 195 | - 305 => 'Use Proxy', |
|
| 196 | - 307 => 'Temporary Redirect', |
|
| 197 | - 400 => 'Bad Request', |
|
| 198 | - 401 => 'Unauthorized', |
|
| 199 | - 402 => 'Payment Required', |
|
| 200 | - 403 => 'Forbidden', |
|
| 201 | - 404 => 'Not Found', |
|
| 202 | - 405 => 'Method Not Allowed', |
|
| 203 | - 406 => 'Not Acceptable', |
|
| 204 | - 407 => 'Proxy Authentication Required', |
|
| 205 | - 408 => 'Request Timeout', |
|
| 206 | - 409 => 'Conflict', |
|
| 207 | - 410 => 'Gone', |
|
| 208 | - 411 => 'Length Required', |
|
| 209 | - 412 => 'Precondition Failed', |
|
| 210 | - 413 => 'Request Entity Too Large', |
|
| 211 | - 414 => 'Request-URI Too Long', |
|
| 212 | - 415 => 'Unsupported Media Type', |
|
| 213 | - 416 => 'Requested Range Not Satisfiable', |
|
| 214 | - 417 => 'Expectation Failed', |
|
| 215 | - 418 => 'I\'m a teapot', |
|
| 216 | - 500 => 'Internal Server Error', |
|
| 217 | - 501 => 'Not Implemented', |
|
| 218 | - 502 => 'Bad Gateway', |
|
| 219 | - 503 => 'Service Unavailable', |
|
| 220 | - 504 => 'Gateway Timeout', |
|
| 221 | - 505 => 'HTTP Version Not Supported', |
|
| 222 | - ); |
|
| 223 | - if (isset($http_status[$code])){ |
|
| 224 | - $text = $http_status[$code]; |
|
| 225 | - } |
|
| 226 | - else{ |
|
| 227 | - show_error('No HTTP status text found for your code please check it.'); |
|
| 228 | - } |
|
| 229 | - } |
|
| 171 | + /** |
|
| 172 | + * Set the HTTP status header |
|
| 173 | + * @param integer $code the HTTP status code |
|
| 174 | + * @param string $text the HTTP status text |
|
| 175 | + * |
|
| 176 | + * @codeCoverageIgnore |
|
| 177 | + */ |
|
| 178 | + function set_http_status_header($code = 200, $text = null){ |
|
| 179 | + if (empty($text)){ |
|
| 180 | + $http_status = array( |
|
| 181 | + 100 => 'Continue', |
|
| 182 | + 101 => 'Switching Protocols', |
|
| 183 | + 200 => 'OK', |
|
| 184 | + 201 => 'Created', |
|
| 185 | + 202 => 'Accepted', |
|
| 186 | + 203 => 'Non-Authoritative Information', |
|
| 187 | + 204 => 'No Content', |
|
| 188 | + 205 => 'Reset Content', |
|
| 189 | + 206 => 'Partial Content', |
|
| 190 | + 300 => 'Multiple Choices', |
|
| 191 | + 301 => 'Moved Permanently', |
|
| 192 | + 302 => 'Found', |
|
| 193 | + 303 => 'See Other', |
|
| 194 | + 304 => 'Not Modified', |
|
| 195 | + 305 => 'Use Proxy', |
|
| 196 | + 307 => 'Temporary Redirect', |
|
| 197 | + 400 => 'Bad Request', |
|
| 198 | + 401 => 'Unauthorized', |
|
| 199 | + 402 => 'Payment Required', |
|
| 200 | + 403 => 'Forbidden', |
|
| 201 | + 404 => 'Not Found', |
|
| 202 | + 405 => 'Method Not Allowed', |
|
| 203 | + 406 => 'Not Acceptable', |
|
| 204 | + 407 => 'Proxy Authentication Required', |
|
| 205 | + 408 => 'Request Timeout', |
|
| 206 | + 409 => 'Conflict', |
|
| 207 | + 410 => 'Gone', |
|
| 208 | + 411 => 'Length Required', |
|
| 209 | + 412 => 'Precondition Failed', |
|
| 210 | + 413 => 'Request Entity Too Large', |
|
| 211 | + 414 => 'Request-URI Too Long', |
|
| 212 | + 415 => 'Unsupported Media Type', |
|
| 213 | + 416 => 'Requested Range Not Satisfiable', |
|
| 214 | + 417 => 'Expectation Failed', |
|
| 215 | + 418 => 'I\'m a teapot', |
|
| 216 | + 500 => 'Internal Server Error', |
|
| 217 | + 501 => 'Not Implemented', |
|
| 218 | + 502 => 'Bad Gateway', |
|
| 219 | + 503 => 'Service Unavailable', |
|
| 220 | + 504 => 'Gateway Timeout', |
|
| 221 | + 505 => 'HTTP Version Not Supported', |
|
| 222 | + ); |
|
| 223 | + if (isset($http_status[$code])){ |
|
| 224 | + $text = $http_status[$code]; |
|
| 225 | + } |
|
| 226 | + else{ |
|
| 227 | + show_error('No HTTP status text found for your code please check it.'); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
| 232 | - header('Status: ' . $code . ' ' . $text, TRUE); |
|
| 233 | - } |
|
| 234 | - else{ |
|
| 235 | - $proto = 'HTTP/1.1'; |
|
| 236 | - if(isset($_SERVER['SERVER_PROTOCOL'])){ |
|
| 237 | - $proto = $_SERVER['SERVER_PROTOCOL']; |
|
| 238 | - } |
|
| 239 | - header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
|
| 240 | - } |
|
| 241 | - } |
|
| 231 | + if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
| 232 | + header('Status: ' . $code . ' ' . $text, TRUE); |
|
| 233 | + } |
|
| 234 | + else{ |
|
| 235 | + $proto = 'HTTP/1.1'; |
|
| 236 | + if(isset($_SERVER['SERVER_PROTOCOL'])){ |
|
| 237 | + $proto = $_SERVER['SERVER_PROTOCOL']; |
|
| 238 | + } |
|
| 239 | + header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * This function displays an error message to the user and ends the execution of the script. |
|
| 245 | - * |
|
| 246 | - * @param string $msg the message to display |
|
| 247 | - * @param string $title the message title: "error", "info", "warning", etc. |
|
| 248 | - * @param boolean $logging either to save error in log |
|
| 249 | - * |
|
| 250 | - * @codeCoverageIgnore |
|
| 251 | - */ |
|
| 252 | - function show_error($msg, $title = 'error', $logging = true){ |
|
| 253 | - $title = strtoupper($title); |
|
| 254 | - $data = array(); |
|
| 255 | - $data['error'] = $msg; |
|
| 256 | - $data['title'] = $title; |
|
| 257 | - if ($logging){ |
|
| 258 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 259 | - } |
|
| 260 | - $response = & class_loader('Response', 'classes'); |
|
| 261 | - $response->sendError($data); |
|
| 262 | - die(); |
|
| 263 | - } |
|
| 243 | + /** |
|
| 244 | + * This function displays an error message to the user and ends the execution of the script. |
|
| 245 | + * |
|
| 246 | + * @param string $msg the message to display |
|
| 247 | + * @param string $title the message title: "error", "info", "warning", etc. |
|
| 248 | + * @param boolean $logging either to save error in log |
|
| 249 | + * |
|
| 250 | + * @codeCoverageIgnore |
|
| 251 | + */ |
|
| 252 | + function show_error($msg, $title = 'error', $logging = true){ |
|
| 253 | + $title = strtoupper($title); |
|
| 254 | + $data = array(); |
|
| 255 | + $data['error'] = $msg; |
|
| 256 | + $data['title'] = $title; |
|
| 257 | + if ($logging){ |
|
| 258 | + save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
| 259 | + } |
|
| 260 | + $response = & class_loader('Response', 'classes'); |
|
| 261 | + $response->sendError($data); |
|
| 262 | + die(); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Check whether the protocol used is "https" or not |
|
| 267 | - * That is, the web server is configured to use a secure connection. |
|
| 268 | - * @codeCoverageIgnore |
|
| 269 | - * |
|
| 270 | - * @return boolean true if the web server uses the https protocol, false if not. |
|
| 271 | - */ |
|
| 272 | - function is_https(){ |
|
| 273 | - /* |
|
| 265 | + /** |
|
| 266 | + * Check whether the protocol used is "https" or not |
|
| 267 | + * That is, the web server is configured to use a secure connection. |
|
| 268 | + * @codeCoverageIgnore |
|
| 269 | + * |
|
| 270 | + * @return boolean true if the web server uses the https protocol, false if not. |
|
| 271 | + */ |
|
| 272 | + function is_https(){ |
|
| 273 | + /* |
|
| 274 | 274 | * some servers pass the "HTTPS" parameter in the server variable, |
| 275 | 275 | * if is the case, check if the value is "on", "true", "1". |
| 276 | 276 | */ |
| 277 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
| 278 | - return true; |
|
| 279 | - } |
|
| 280 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 281 | - return true; |
|
| 282 | - } |
|
| 283 | - if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 284 | - return true; |
|
| 285 | - } |
|
| 286 | - return false; |
|
| 287 | - } |
|
| 277 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
| 278 | + return true; |
|
| 279 | + } |
|
| 280 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
| 281 | + return true; |
|
| 282 | + } |
|
| 283 | + if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
| 284 | + return true; |
|
| 285 | + } |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * This function is used to check the URL format of the given string argument. |
|
| 291 | - * The address is valid if the protocol is http, https, ftp, etc. |
|
| 292 | - * |
|
| 293 | - * @param string $url the URL address to check |
|
| 294 | - * @test |
|
| 295 | - * |
|
| 296 | - * @return boolean true if is a valid URL address or false. |
|
| 297 | - */ |
|
| 298 | - function is_url($url){ |
|
| 299 | - return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
|
| 300 | - } |
|
| 289 | + /** |
|
| 290 | + * This function is used to check the URL format of the given string argument. |
|
| 291 | + * The address is valid if the protocol is http, https, ftp, etc. |
|
| 292 | + * |
|
| 293 | + * @param string $url the URL address to check |
|
| 294 | + * @test |
|
| 295 | + * |
|
| 296 | + * @return boolean true if is a valid URL address or false. |
|
| 297 | + */ |
|
| 298 | + function is_url($url){ |
|
| 299 | + return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Function defined to load controller |
|
| 304 | - * |
|
| 305 | - * @param string $controllerClass the controller class name to be loaded |
|
| 306 | - * @codeCoverageIgnore |
|
| 307 | - */ |
|
| 308 | - function autoload_controller($controllerClass){ |
|
| 309 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
| 310 | - require_once $path; |
|
| 311 | - } |
|
| 312 | - } |
|
| 302 | + /** |
|
| 303 | + * Function defined to load controller |
|
| 304 | + * |
|
| 305 | + * @param string $controllerClass the controller class name to be loaded |
|
| 306 | + * @codeCoverageIgnore |
|
| 307 | + */ |
|
| 308 | + function autoload_controller($controllerClass){ |
|
| 309 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
| 310 | + require_once $path; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Function defined for handling PHP exception error message, |
|
| 316 | - * it displays an error message using the function "show_error" |
|
| 317 | - * |
|
| 318 | - * @param object $ex instance of the "Exception" class or a derived class |
|
| 319 | - * @codeCoverageIgnore |
|
| 320 | - * |
|
| 321 | - * @return boolean |
|
| 322 | - */ |
|
| 323 | - function php_exception_handler($ex){ |
|
| 324 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 325 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 326 | - } |
|
| 327 | - else{ |
|
| 328 | - save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
|
| 329 | - } |
|
| 330 | - return true; |
|
| 331 | - } |
|
| 314 | + /** |
|
| 315 | + * Function defined for handling PHP exception error message, |
|
| 316 | + * it displays an error message using the function "show_error" |
|
| 317 | + * |
|
| 318 | + * @param object $ex instance of the "Exception" class or a derived class |
|
| 319 | + * @codeCoverageIgnore |
|
| 320 | + * |
|
| 321 | + * @return boolean |
|
| 322 | + */ |
|
| 323 | + function php_exception_handler($ex){ |
|
| 324 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 325 | + show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
| 326 | + } |
|
| 327 | + else{ |
|
| 328 | + save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
|
| 329 | + } |
|
| 330 | + return true; |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Function defined for PHP error message handling |
|
| 335 | - * |
|
| 336 | - * @param int $errno the type of error for example: E_USER_ERROR, E_USER_WARNING, etc. |
|
| 337 | - * @param string $errstr the error message |
|
| 338 | - * @param string $errfile the file where the error occurred |
|
| 339 | - * @param int $errline the line number where the error occurred |
|
| 340 | - * @codeCoverageIgnore |
|
| 341 | - * |
|
| 342 | - * @return boolean |
|
| 343 | - */ |
|
| 344 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 345 | - $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
|
| 346 | - if ($isError){ |
|
| 347 | - set_http_status_header(500); |
|
| 348 | - } |
|
| 349 | - if (! (error_reporting() & $errno)) { |
|
| 350 | - save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
|
| 351 | - return; |
|
| 352 | - } |
|
| 353 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 354 | - $errorType = 'error'; |
|
| 355 | - switch ($errno) { |
|
| 356 | - case E_USER_WARNING: |
|
| 357 | - $errorType = 'warning'; |
|
| 358 | - break; |
|
| 359 | - case E_USER_NOTICE: |
|
| 360 | - $errorType = 'notice'; |
|
| 361 | - break; |
|
| 362 | - } |
|
| 363 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 364 | - } |
|
| 365 | - if ($isError){ |
|
| 366 | - die(); |
|
| 367 | - } |
|
| 368 | - return true; |
|
| 369 | - } |
|
| 333 | + /** |
|
| 334 | + * Function defined for PHP error message handling |
|
| 335 | + * |
|
| 336 | + * @param int $errno the type of error for example: E_USER_ERROR, E_USER_WARNING, etc. |
|
| 337 | + * @param string $errstr the error message |
|
| 338 | + * @param string $errfile the file where the error occurred |
|
| 339 | + * @param int $errline the line number where the error occurred |
|
| 340 | + * @codeCoverageIgnore |
|
| 341 | + * |
|
| 342 | + * @return boolean |
|
| 343 | + */ |
|
| 344 | + function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
| 345 | + $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
|
| 346 | + if ($isError){ |
|
| 347 | + set_http_status_header(500); |
|
| 348 | + } |
|
| 349 | + if (! (error_reporting() & $errno)) { |
|
| 350 | + save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
|
| 351 | + return; |
|
| 352 | + } |
|
| 353 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
| 354 | + $errorType = 'error'; |
|
| 355 | + switch ($errno) { |
|
| 356 | + case E_USER_WARNING: |
|
| 357 | + $errorType = 'warning'; |
|
| 358 | + break; |
|
| 359 | + case E_USER_NOTICE: |
|
| 360 | + $errorType = 'notice'; |
|
| 361 | + break; |
|
| 362 | + } |
|
| 363 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
| 364 | + } |
|
| 365 | + if ($isError){ |
|
| 366 | + die(); |
|
| 367 | + } |
|
| 368 | + return true; |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - /** |
|
| 372 | - * This function is used to run in shutdown situation of the script |
|
| 373 | - * @codeCoverageIgnore |
|
| 374 | - */ |
|
| 375 | - function php_shudown_handler(){ |
|
| 376 | - $lastError = error_get_last(); |
|
| 377 | - if (isset($lastError) && |
|
| 378 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
| 379 | - php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
|
| 380 | - } |
|
| 381 | - } |
|
| 371 | + /** |
|
| 372 | + * This function is used to run in shutdown situation of the script |
|
| 373 | + * @codeCoverageIgnore |
|
| 374 | + */ |
|
| 375 | + function php_shudown_handler(){ |
|
| 376 | + $lastError = error_get_last(); |
|
| 377 | + if (isset($lastError) && |
|
| 378 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
| 379 | + php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | 383 | |
| 384 | - /** |
|
| 385 | - * Convert array attributes to string |
|
| 386 | - * |
|
| 387 | - * This function converts an associative array into HTML attributes. |
|
| 388 | - * For example : |
|
| 389 | - * $a = array('name' => 'Foo', 'type' => 'text'); => produces the following string: |
|
| 390 | - * name = "Foo" type = "text" |
|
| 391 | - * |
|
| 392 | - * @param array $attributes associative array to convert to a string attribute. |
|
| 393 | - * |
|
| 394 | - * @return string string of the HTML attribute. |
|
| 395 | - */ |
|
| 396 | - function attributes_to_string(array $attributes){ |
|
| 397 | - $str = ' '; |
|
| 398 | - //we check that the array passed as an argument is not empty. |
|
| 399 | - if (! empty($attributes)){ |
|
| 400 | - foreach($attributes as $key => $value){ |
|
| 401 | - $key = trim(htmlspecialchars($key)); |
|
| 402 | - $value = trim(htmlspecialchars($value)); |
|
| 403 | - /* |
|
| 384 | + /** |
|
| 385 | + * Convert array attributes to string |
|
| 386 | + * |
|
| 387 | + * This function converts an associative array into HTML attributes. |
|
| 388 | + * For example : |
|
| 389 | + * $a = array('name' => 'Foo', 'type' => 'text'); => produces the following string: |
|
| 390 | + * name = "Foo" type = "text" |
|
| 391 | + * |
|
| 392 | + * @param array $attributes associative array to convert to a string attribute. |
|
| 393 | + * |
|
| 394 | + * @return string string of the HTML attribute. |
|
| 395 | + */ |
|
| 396 | + function attributes_to_string(array $attributes){ |
|
| 397 | + $str = ' '; |
|
| 398 | + //we check that the array passed as an argument is not empty. |
|
| 399 | + if (! empty($attributes)){ |
|
| 400 | + foreach($attributes as $key => $value){ |
|
| 401 | + $key = trim(htmlspecialchars($key)); |
|
| 402 | + $value = trim(htmlspecialchars($value)); |
|
| 403 | + /* |
|
| 404 | 404 | * To predict the case where the string to convert contains the character " |
| 405 | 405 | * we check if this is the case we add a slash to solve this problem. |
| 406 | 406 | * For example: |
| 407 | 407 | * $attr = array('placeholder' => 'I am a "puple"') |
| 408 | 408 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
| 409 | 409 | */ |
| 410 | - if ($value && strpos('"', $value) !== false){ |
|
| 411 | - $value = addslashes($value); |
|
| 412 | - } |
|
| 413 | - $str .= $key.' = "'.$value.'" '; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - //remove the space after using rtrim() |
|
| 417 | - return rtrim($str); |
|
| 418 | - } |
|
| 410 | + if ($value && strpos('"', $value) !== false){ |
|
| 411 | + $value = addslashes($value); |
|
| 412 | + } |
|
| 413 | + $str .= $key.' = "'.$value.'" '; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + //remove the space after using rtrim() |
|
| 417 | + return rtrim($str); |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Function to stringfy PHP variable, useful in debug situation |
|
| 423 | - * |
|
| 424 | - * @param mixed $var the variable to stringfy |
|
| 425 | - * @codeCoverageIgnore |
|
| 426 | - * |
|
| 427 | - * @return string the stringfy value |
|
| 428 | - */ |
|
| 429 | - function stringfy_vars($var){ |
|
| 430 | - return print_r($var, true); |
|
| 431 | - } |
|
| 421 | + /** |
|
| 422 | + * Function to stringfy PHP variable, useful in debug situation |
|
| 423 | + * |
|
| 424 | + * @param mixed $var the variable to stringfy |
|
| 425 | + * @codeCoverageIgnore |
|
| 426 | + * |
|
| 427 | + * @return string the stringfy value |
|
| 428 | + */ |
|
| 429 | + function stringfy_vars($var){ |
|
| 430 | + return print_r($var, true); |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | - /** |
|
| 434 | - * Clean the user input |
|
| 435 | - * @param mixed $str the value to clean |
|
| 436 | - * @test |
|
| 437 | - * |
|
| 438 | - * @return mixed the sanitize value |
|
| 439 | - */ |
|
| 440 | - function clean_input($str){ |
|
| 441 | - if (is_array($str)){ |
|
| 442 | - $str = array_map('clean_input', $str); |
|
| 443 | - } |
|
| 444 | - else if (is_object($str)){ |
|
| 445 | - $obj = $str; |
|
| 446 | - foreach ($str as $var => $value) { |
|
| 447 | - $obj->$var = clean_input($value); |
|
| 448 | - } |
|
| 449 | - $str = $obj; |
|
| 450 | - } |
|
| 451 | - else{ |
|
| 452 | - $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
|
| 453 | - } |
|
| 454 | - return $str; |
|
| 455 | - } |
|
| 433 | + /** |
|
| 434 | + * Clean the user input |
|
| 435 | + * @param mixed $str the value to clean |
|
| 436 | + * @test |
|
| 437 | + * |
|
| 438 | + * @return mixed the sanitize value |
|
| 439 | + */ |
|
| 440 | + function clean_input($str){ |
|
| 441 | + if (is_array($str)){ |
|
| 442 | + $str = array_map('clean_input', $str); |
|
| 443 | + } |
|
| 444 | + else if (is_object($str)){ |
|
| 445 | + $obj = $str; |
|
| 446 | + foreach ($str as $var => $value) { |
|
| 447 | + $obj->$var = clean_input($value); |
|
| 448 | + } |
|
| 449 | + $str = $obj; |
|
| 450 | + } |
|
| 451 | + else{ |
|
| 452 | + $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
|
| 453 | + } |
|
| 454 | + return $str; |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * This function is used to hidden some part of the given string. Helpful if you need hide some confidential |
|
| 459 | - * Information like credit card number, password, etc. |
|
| 460 | - * |
|
| 461 | - * @param string $str the string you want to hide some part |
|
| 462 | - * @param int $startCount the length of non hidden for the beginning char |
|
| 463 | - * @param int $endCount the length of non hidden for the ending char |
|
| 464 | - * @param string $hiddenChar the char used to hide the given string |
|
| 465 | - * @test |
|
| 466 | - * |
|
| 467 | - * @return string the string with the hidden part. |
|
| 468 | - */ |
|
| 469 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 470 | - //get the string length |
|
| 471 | - $len = strlen($str); |
|
| 472 | - //if str is empty |
|
| 473 | - if ($len <= 0){ |
|
| 474 | - return str_repeat($hiddenChar, 6); |
|
| 475 | - } |
|
| 476 | - //if the length is less than startCount and endCount |
|
| 477 | - //or the startCount and endCount length is 0 |
|
| 478 | - //or startCount is negative or endCount is negative |
|
| 479 | - //return the full string hidden |
|
| 457 | + /** |
|
| 458 | + * This function is used to hidden some part of the given string. Helpful if you need hide some confidential |
|
| 459 | + * Information like credit card number, password, etc. |
|
| 460 | + * |
|
| 461 | + * @param string $str the string you want to hide some part |
|
| 462 | + * @param int $startCount the length of non hidden for the beginning char |
|
| 463 | + * @param int $endCount the length of non hidden for the ending char |
|
| 464 | + * @param string $hiddenChar the char used to hide the given string |
|
| 465 | + * @test |
|
| 466 | + * |
|
| 467 | + * @return string the string with the hidden part. |
|
| 468 | + */ |
|
| 469 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
| 470 | + //get the string length |
|
| 471 | + $len = strlen($str); |
|
| 472 | + //if str is empty |
|
| 473 | + if ($len <= 0){ |
|
| 474 | + return str_repeat($hiddenChar, 6); |
|
| 475 | + } |
|
| 476 | + //if the length is less than startCount and endCount |
|
| 477 | + //or the startCount and endCount length is 0 |
|
| 478 | + //or startCount is negative or endCount is negative |
|
| 479 | + //return the full string hidden |
|
| 480 | 480 | |
| 481 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 482 | - return str_repeat($hiddenChar, $len); |
|
| 483 | - } |
|
| 484 | - //the start non hidden string |
|
| 485 | - $startNonHiddenStr = substr($str, 0, $startCount); |
|
| 486 | - //the end non hidden string |
|
| 487 | - $endNonHiddenStr = null; |
|
| 488 | - if ($endCount > 0){ |
|
| 489 | - $endNonHiddenStr = substr($str, - $endCount); |
|
| 490 | - } |
|
| 491 | - //the hidden string |
|
| 492 | - $hiddenStr = str_repeat($hiddenChar, $len - ($startCount + $endCount)); |
|
| 481 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
| 482 | + return str_repeat($hiddenChar, $len); |
|
| 483 | + } |
|
| 484 | + //the start non hidden string |
|
| 485 | + $startNonHiddenStr = substr($str, 0, $startCount); |
|
| 486 | + //the end non hidden string |
|
| 487 | + $endNonHiddenStr = null; |
|
| 488 | + if ($endCount > 0){ |
|
| 489 | + $endNonHiddenStr = substr($str, - $endCount); |
|
| 490 | + } |
|
| 491 | + //the hidden string |
|
| 492 | + $hiddenStr = str_repeat($hiddenChar, $len - ($startCount + $endCount)); |
|
| 493 | 493 | |
| 494 | - return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
|
| 495 | - } |
|
| 494 | + return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | - /** |
|
| 498 | - * This function is used to set the initial session config regarding the configuration |
|
| 499 | - * @codeCoverageIgnore |
|
| 500 | - */ |
|
| 501 | - function set_session_config(){ |
|
| 502 | - //$_SESSION is not available on cli mode |
|
| 503 | - if (! IS_CLI){ |
|
| 504 | - $logger =& class_loader('Log', 'classes'); |
|
| 505 | - $logger->setLogger('PHPSession'); |
|
| 506 | - //set session params |
|
| 507 | - $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
|
| 508 | - $sessionName = get_config('session_name'); |
|
| 509 | - if ($sessionName){ |
|
| 510 | - session_name($sessionName); |
|
| 511 | - } |
|
| 512 | - $logger->info('Session handler: ' . $sessionHandler); |
|
| 513 | - $logger->info('Session name: ' . $sessionName); |
|
| 497 | + /** |
|
| 498 | + * This function is used to set the initial session config regarding the configuration |
|
| 499 | + * @codeCoverageIgnore |
|
| 500 | + */ |
|
| 501 | + function set_session_config(){ |
|
| 502 | + //$_SESSION is not available on cli mode |
|
| 503 | + if (! IS_CLI){ |
|
| 504 | + $logger =& class_loader('Log', 'classes'); |
|
| 505 | + $logger->setLogger('PHPSession'); |
|
| 506 | + //set session params |
|
| 507 | + $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
|
| 508 | + $sessionName = get_config('session_name'); |
|
| 509 | + if ($sessionName){ |
|
| 510 | + session_name($sessionName); |
|
| 511 | + } |
|
| 512 | + $logger->info('Session handler: ' . $sessionHandler); |
|
| 513 | + $logger->info('Session name: ' . $sessionName); |
|
| 514 | 514 | |
| 515 | - if ($sessionHandler == 'files'){ |
|
| 516 | - $sessionSavePath = get_config('session_save_path'); |
|
| 517 | - if ($sessionSavePath){ |
|
| 518 | - if (! is_dir($sessionSavePath)){ |
|
| 519 | - mkdir($sessionSavePath, 1773); |
|
| 520 | - } |
|
| 521 | - session_save_path($sessionSavePath); |
|
| 522 | - $logger->info('Session save path: ' . $sessionSavePath); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - else if ($sessionHandler == 'database'){ |
|
| 526 | - //load database session handle library |
|
| 527 | - //Database Session handler Model |
|
| 528 | - require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
|
| 515 | + if ($sessionHandler == 'files'){ |
|
| 516 | + $sessionSavePath = get_config('session_save_path'); |
|
| 517 | + if ($sessionSavePath){ |
|
| 518 | + if (! is_dir($sessionSavePath)){ |
|
| 519 | + mkdir($sessionSavePath, 1773); |
|
| 520 | + } |
|
| 521 | + session_save_path($sessionSavePath); |
|
| 522 | + $logger->info('Session save path: ' . $sessionSavePath); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + else if ($sessionHandler == 'database'){ |
|
| 526 | + //load database session handle library |
|
| 527 | + //Database Session handler Model |
|
| 528 | + require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
|
| 529 | 529 | |
| 530 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
| 531 | - session_set_save_handler($DBS, true); |
|
| 532 | - $logger->info('session save path: ' . get_config('session_save_path')); |
|
| 533 | - } |
|
| 534 | - else{ |
|
| 535 | - show_error('Invalid session handler configuration'); |
|
| 536 | - } |
|
| 537 | - $lifetime = get_config('session_cookie_lifetime', 0); |
|
| 538 | - $path = get_config('session_cookie_path', '/'); |
|
| 539 | - $domain = get_config('session_cookie_domain', ''); |
|
| 540 | - $secure = get_config('session_cookie_secure', false); |
|
| 541 | - session_set_cookie_params( |
|
| 542 | - $lifetime, |
|
| 543 | - $path, |
|
| 544 | - $domain, |
|
| 545 | - $secure, |
|
| 546 | - $httponly = true /*for security for access to cookie via javascript or XSS attack*/ |
|
| 547 | - ); |
|
| 548 | - //to prevent attack of Session Fixation |
|
| 549 | - //thank to https://www.phparch.com/2018/01/php-sessions-in-depth/ |
|
| 550 | - ini_set('session.use_strict_mode ', 1); |
|
| 551 | - ini_set('session.use_only_cookies', 1); |
|
| 552 | - ini_set('session.use_trans_sid ', 0); |
|
| 530 | + $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
| 531 | + session_set_save_handler($DBS, true); |
|
| 532 | + $logger->info('session save path: ' . get_config('session_save_path')); |
|
| 533 | + } |
|
| 534 | + else{ |
|
| 535 | + show_error('Invalid session handler configuration'); |
|
| 536 | + } |
|
| 537 | + $lifetime = get_config('session_cookie_lifetime', 0); |
|
| 538 | + $path = get_config('session_cookie_path', '/'); |
|
| 539 | + $domain = get_config('session_cookie_domain', ''); |
|
| 540 | + $secure = get_config('session_cookie_secure', false); |
|
| 541 | + session_set_cookie_params( |
|
| 542 | + $lifetime, |
|
| 543 | + $path, |
|
| 544 | + $domain, |
|
| 545 | + $secure, |
|
| 546 | + $httponly = true /*for security for access to cookie via javascript or XSS attack*/ |
|
| 547 | + ); |
|
| 548 | + //to prevent attack of Session Fixation |
|
| 549 | + //thank to https://www.phparch.com/2018/01/php-sessions-in-depth/ |
|
| 550 | + ini_set('session.use_strict_mode ', 1); |
|
| 551 | + ini_set('session.use_only_cookies', 1); |
|
| 552 | + ini_set('session.use_trans_sid ', 0); |
|
| 553 | 553 | |
| 554 | - $logger->info('Session lifetime: ' . $lifetime); |
|
| 555 | - $logger->info('Session cookie path: ' . $path); |
|
| 556 | - $logger->info('Session domain: ' . $domain); |
|
| 557 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
| 554 | + $logger->info('Session lifetime: ' . $lifetime); |
|
| 555 | + $logger->info('Session cookie path: ' . $path); |
|
| 556 | + $logger->info('Session domain: ' . $domain); |
|
| 557 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
| 558 | 558 | |
| 559 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
| 560 | - $logger->info('Session not yet start, start it now'); |
|
| 561 | - session_start(); |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - } |
|
| 559 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
| 560 | + $logger->info('Session not yet start, start it now'); |
|
| 561 | + session_start(); |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | 565 | |
| 566 | - /** |
|
| 567 | - * This function is very useful, it allows to recover the instance of the global controller. |
|
| 568 | - * Note this function always returns the address of the super instance. |
|
| 569 | - * For example : |
|
| 570 | - * $obj = & get_instance(); |
|
| 571 | - * |
|
| 572 | - * @codeCoverageIgnore |
|
| 573 | - * |
|
| 574 | - * @return object the instance of the "Controller" class |
|
| 575 | - */ |
|
| 576 | - function & get_instance(){ |
|
| 577 | - return Controller::get_instance(); |
|
| 578 | - } |
|
| 566 | + /** |
|
| 567 | + * This function is very useful, it allows to recover the instance of the global controller. |
|
| 568 | + * Note this function always returns the address of the super instance. |
|
| 569 | + * For example : |
|
| 570 | + * $obj = & get_instance(); |
|
| 571 | + * |
|
| 572 | + * @codeCoverageIgnore |
|
| 573 | + * |
|
| 574 | + * @return object the instance of the "Controller" class |
|
| 575 | + */ |
|
| 576 | + function & get_instance(){ |
|
| 577 | + return Controller::get_instance(); |
|
| 578 | + } |
|
@@ -1,322 +1,322 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Form{ |
|
| 28 | + class Form{ |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Generate the form opened tag |
|
| 32 | - * @param string $path the form action path |
|
| 33 | - * @param array $attributes the additional form attributes |
|
| 34 | - * @param string $method the form method like 'GET', 'POST' |
|
| 35 | - * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | - * @return string the generated form html |
|
| 37 | - */ |
|
| 38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | - if($path){ |
|
| 40 | - $path = Url::site_url($path); |
|
| 41 | - } |
|
| 42 | - $method = strtoupper($method); |
|
| 43 | - $str = null; |
|
| 44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | - if(! empty($enctype)){ |
|
| 46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | - } |
|
| 48 | - if(! isset($attributes['accept-charset'])){ |
|
| 49 | - $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | - } |
|
| 51 | - $str .= attributes_to_string($attributes); |
|
| 52 | - $str .= '>'; |
|
| 53 | - //if CSRF is enabled in the configuration |
|
| 54 | - if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 55 | - $csrfValue = Security::generateCSRF(); |
|
| 56 | - $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 57 | - $str .= static::hidden($csrfName, $csrfValue); |
|
| 58 | - } |
|
| 59 | - return $str; |
|
| 60 | - } |
|
| 30 | + /** |
|
| 31 | + * Generate the form opened tag |
|
| 32 | + * @param string $path the form action path |
|
| 33 | + * @param array $attributes the additional form attributes |
|
| 34 | + * @param string $method the form method like 'GET', 'POST' |
|
| 35 | + * @param string $enctype the form enctype like "multipart/form-data" |
|
| 36 | + * @return string the generated form html |
|
| 37 | + */ |
|
| 38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
| 39 | + if($path){ |
|
| 40 | + $path = Url::site_url($path); |
|
| 41 | + } |
|
| 42 | + $method = strtoupper($method); |
|
| 43 | + $str = null; |
|
| 44 | + $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
| 45 | + if(! empty($enctype)){ |
|
| 46 | + $str .= ' enctype = "'.$enctype.'" '; |
|
| 47 | + } |
|
| 48 | + if(! isset($attributes['accept-charset'])){ |
|
| 49 | + $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
|
| 50 | + } |
|
| 51 | + $str .= attributes_to_string($attributes); |
|
| 52 | + $str .= '>'; |
|
| 53 | + //if CSRF is enabled in the configuration |
|
| 54 | + if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
| 55 | + $csrfValue = Security::generateCSRF(); |
|
| 56 | + $csrfName = get_config('csrf_key', 'csrf_key'); |
|
| 57 | + $str .= static::hidden($csrfName, $csrfValue); |
|
| 58 | + } |
|
| 59 | + return $str; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Generate the form opened tag for multipart like to send a file |
|
| 64 | - * @see Form::open() for more details |
|
| 65 | - * @return string the generated multipart form html |
|
| 66 | - */ |
|
| 67 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 68 | - return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * Generate the form opened tag for multipart like to send a file |
|
| 64 | + * @see Form::open() for more details |
|
| 65 | + * @return string the generated multipart form html |
|
| 66 | + */ |
|
| 67 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
| 68 | + return self::open($path, $attributes, $method, 'multipart/form-data'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Generate the form close |
|
| 73 | - * @return string the form close html |
|
| 74 | - */ |
|
| 75 | - public static function close(){ |
|
| 76 | - return '</form>'; |
|
| 77 | - } |
|
| 71 | + /** |
|
| 72 | + * Generate the form close |
|
| 73 | + * @return string the form close html |
|
| 74 | + */ |
|
| 75 | + public static function close(){ |
|
| 76 | + return '</form>'; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Generate the form fieldset & legend |
|
| 81 | - * @param string $legend the legend tag value |
|
| 82 | - * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 83 | - * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 84 | - * @return string the generated fieldset value |
|
| 85 | - */ |
|
| 86 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 87 | - $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 88 | - if($legend){ |
|
| 89 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 90 | - } |
|
| 91 | - return $str; |
|
| 92 | - } |
|
| 79 | + /** |
|
| 80 | + * Generate the form fieldset & legend |
|
| 81 | + * @param string $legend the legend tag value |
|
| 82 | + * @param array $fieldsetAttributes the fieldset additional HTML attributes |
|
| 83 | + * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
|
| 84 | + * @return string the generated fieldset value |
|
| 85 | + */ |
|
| 86 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
| 87 | + $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
|
| 88 | + if($legend){ |
|
| 89 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
| 90 | + } |
|
| 91 | + return $str; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Generate the fieldset close tag |
|
| 96 | - * @return string the generated html for fieldset close |
|
| 97 | - */ |
|
| 98 | - public static function fieldsetClose(){ |
|
| 99 | - return '</fieldset>'; |
|
| 100 | - } |
|
| 94 | + /** |
|
| 95 | + * Generate the fieldset close tag |
|
| 96 | + * @return string the generated html for fieldset close |
|
| 97 | + */ |
|
| 98 | + public static function fieldsetClose(){ |
|
| 99 | + return '</fieldset>'; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Get the error message for the given form field name. |
|
| 104 | - * This use the form validation information to get the error information. |
|
| 105 | - * @param string $name the form field name |
|
| 106 | - * @return string the error message if exists and null if not |
|
| 107 | - */ |
|
| 108 | - public static function error($name){ |
|
| 109 | - $return = null; |
|
| 110 | - $obj = & get_instance(); |
|
| 111 | - if(isset($obj->formvalidation)){ |
|
| 112 | - $errors = $obj->formvalidation->returnErrors(); |
|
| 113 | - if(isset($errors[$name])){ |
|
| 114 | - list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 115 | - $return = $errorStart . $errors[$name] . $errorEnd; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - return $return; |
|
| 119 | - } |
|
| 102 | + /** |
|
| 103 | + * Get the error message for the given form field name. |
|
| 104 | + * This use the form validation information to get the error information. |
|
| 105 | + * @param string $name the form field name |
|
| 106 | + * @return string the error message if exists and null if not |
|
| 107 | + */ |
|
| 108 | + public static function error($name){ |
|
| 109 | + $return = null; |
|
| 110 | + $obj = & get_instance(); |
|
| 111 | + if(isset($obj->formvalidation)){ |
|
| 112 | + $errors = $obj->formvalidation->returnErrors(); |
|
| 113 | + if(isset($errors[$name])){ |
|
| 114 | + list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
|
| 115 | + $return = $errorStart . $errors[$name] . $errorEnd; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + return $return; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Get the form field value |
|
| 123 | - * @param string $name the form field name |
|
| 124 | - * @param mixed $default the default value if can not found the given form field name |
|
| 125 | - * @return mixed the form field value if is set, otherwise return the default value. |
|
| 126 | - */ |
|
| 127 | - public static function value($name, $default = null){ |
|
| 128 | - $value = get_instance()->request->query($name); |
|
| 129 | - if(strlen($value) > 0){ |
|
| 130 | - return $value; |
|
| 131 | - } |
|
| 132 | - return $default; |
|
| 133 | - } |
|
| 121 | + /** |
|
| 122 | + * Get the form field value |
|
| 123 | + * @param string $name the form field name |
|
| 124 | + * @param mixed $default the default value if can not found the given form field name |
|
| 125 | + * @return mixed the form field value if is set, otherwise return the default value. |
|
| 126 | + */ |
|
| 127 | + public static function value($name, $default = null){ |
|
| 128 | + $value = get_instance()->request->query($name); |
|
| 129 | + if(strlen($value) > 0){ |
|
| 130 | + return $value; |
|
| 131 | + } |
|
| 132 | + return $default; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Generate the form label html content |
|
| 137 | - * @param string $label the title of the label |
|
| 138 | - * @param string $for the value of the label "for" attribute |
|
| 139 | - * @param array $attributes the additional attributes to be added |
|
| 140 | - * @return string the generated label html content |
|
| 141 | - */ |
|
| 142 | - public static function label($label, $for = '', array $attributes = array()){ |
|
| 143 | - $str = '<label'; |
|
| 144 | - if($for){ |
|
| 145 | - $str .= ' for = "'.$for.'"'; |
|
| 146 | - } |
|
| 147 | - $str .= attributes_to_string($attributes); |
|
| 148 | - $str .= '>'; |
|
| 149 | - $str .= $label.'</label>'; |
|
| 150 | - return $str; |
|
| 151 | - } |
|
| 135 | + /** |
|
| 136 | + * Generate the form label html content |
|
| 137 | + * @param string $label the title of the label |
|
| 138 | + * @param string $for the value of the label "for" attribute |
|
| 139 | + * @param array $attributes the additional attributes to be added |
|
| 140 | + * @return string the generated label html content |
|
| 141 | + */ |
|
| 142 | + public static function label($label, $for = '', array $attributes = array()){ |
|
| 143 | + $str = '<label'; |
|
| 144 | + if($for){ |
|
| 145 | + $str .= ' for = "'.$for.'"'; |
|
| 146 | + } |
|
| 147 | + $str .= attributes_to_string($attributes); |
|
| 148 | + $str .= '>'; |
|
| 149 | + $str .= $label.'</label>'; |
|
| 150 | + return $str; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Generate the form field for input like "text", "email", "password", etc. |
|
| 155 | - * @param string $name the form field name |
|
| 156 | - * @param mixed $value the form field value to be set |
|
| 157 | - * @param array $attributes the additional attributes to be added in the form input |
|
| 158 | - * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 159 | - * @return string the generated form field html content for the input |
|
| 160 | - */ |
|
| 161 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 162 | - $str = null; |
|
| 163 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 164 | - $str .= attributes_to_string($attributes); |
|
| 165 | - $str .= '/>'; |
|
| 166 | - return $str; |
|
| 167 | - } |
|
| 153 | + /** |
|
| 154 | + * Generate the form field for input like "text", "email", "password", etc. |
|
| 155 | + * @param string $name the form field name |
|
| 156 | + * @param mixed $value the form field value to be set |
|
| 157 | + * @param array $attributes the additional attributes to be added in the form input |
|
| 158 | + * @param string $type the type of the form field (password, text, submit, button, etc.) |
|
| 159 | + * @return string the generated form field html content for the input |
|
| 160 | + */ |
|
| 161 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
| 162 | + $str = null; |
|
| 163 | + $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
| 164 | + $str .= attributes_to_string($attributes); |
|
| 165 | + $str .= '/>'; |
|
| 166 | + return $str; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Generate the form field for "text" |
|
| 171 | - * @see Form::input() for more details |
|
| 172 | - */ |
|
| 173 | - public static function text($name, $value = null, array $attributes = array()){ |
|
| 174 | - return self::input($name, $value, $attributes, 'text'); |
|
| 175 | - } |
|
| 169 | + /** |
|
| 170 | + * Generate the form field for "text" |
|
| 171 | + * @see Form::input() for more details |
|
| 172 | + */ |
|
| 173 | + public static function text($name, $value = null, array $attributes = array()){ |
|
| 174 | + return self::input($name, $value, $attributes, 'text'); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Generate the form field for "password" |
|
| 179 | - * @see Form::input() for more details |
|
| 180 | - */ |
|
| 181 | - public static function password($name, $value = null, array $attributes = array()){ |
|
| 182 | - return self::input($name, $value, $attributes, 'password'); |
|
| 183 | - } |
|
| 177 | + /** |
|
| 178 | + * Generate the form field for "password" |
|
| 179 | + * @see Form::input() for more details |
|
| 180 | + */ |
|
| 181 | + public static function password($name, $value = null, array $attributes = array()){ |
|
| 182 | + return self::input($name, $value, $attributes, 'password'); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * Generate the form field for "radio" |
|
| 187 | - * @see Form::input() for more details |
|
| 188 | - */ |
|
| 189 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 190 | - if($checked){ |
|
| 191 | - $attributes['checked'] = true; |
|
| 192 | - } |
|
| 193 | - return self::input($name, $value, $attributes, 'radio'); |
|
| 194 | - } |
|
| 185 | + /** |
|
| 186 | + * Generate the form field for "radio" |
|
| 187 | + * @see Form::input() for more details |
|
| 188 | + */ |
|
| 189 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 190 | + if($checked){ |
|
| 191 | + $attributes['checked'] = true; |
|
| 192 | + } |
|
| 193 | + return self::input($name, $value, $attributes, 'radio'); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Generate the form field for "checkbox" |
|
| 198 | - * @see Form::input() for more details |
|
| 199 | - */ |
|
| 200 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 201 | - if($checked){ |
|
| 202 | - $attributes['checked'] = true; |
|
| 203 | - } |
|
| 204 | - return self::input($name, $value, $attributes, 'checkbox'); |
|
| 205 | - } |
|
| 196 | + /** |
|
| 197 | + * Generate the form field for "checkbox" |
|
| 198 | + * @see Form::input() for more details |
|
| 199 | + */ |
|
| 200 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
| 201 | + if($checked){ |
|
| 202 | + $attributes['checked'] = true; |
|
| 203 | + } |
|
| 204 | + return self::input($name, $value, $attributes, 'checkbox'); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Generate the form field for "number" |
|
| 209 | - * @see Form::input() for more details |
|
| 210 | - */ |
|
| 211 | - public static function number($name, $value = null, array $attributes = array()){ |
|
| 212 | - return self::input($name, $value, $attributes, 'number'); |
|
| 213 | - } |
|
| 207 | + /** |
|
| 208 | + * Generate the form field for "number" |
|
| 209 | + * @see Form::input() for more details |
|
| 210 | + */ |
|
| 211 | + public static function number($name, $value = null, array $attributes = array()){ |
|
| 212 | + return self::input($name, $value, $attributes, 'number'); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Generate the form field for "phone" |
|
| 217 | - * @see Form::input() for more details |
|
| 218 | - */ |
|
| 219 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
| 220 | - return self::input($name, $value, $attributes, 'phone'); |
|
| 221 | - } |
|
| 215 | + /** |
|
| 216 | + * Generate the form field for "phone" |
|
| 217 | + * @see Form::input() for more details |
|
| 218 | + */ |
|
| 219 | + public static function phone($name, $value = null, array $attributes = array()){ |
|
| 220 | + return self::input($name, $value, $attributes, 'phone'); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Generate the form field for "email" |
|
| 225 | - * @see Form::input() for more details |
|
| 226 | - */ |
|
| 227 | - public static function email($name, $value = null, array $attributes = array()){ |
|
| 228 | - return self::input($name, $value, $attributes, 'email'); |
|
| 229 | - } |
|
| 223 | + /** |
|
| 224 | + * Generate the form field for "email" |
|
| 225 | + * @see Form::input() for more details |
|
| 226 | + */ |
|
| 227 | + public static function email($name, $value = null, array $attributes = array()){ |
|
| 228 | + return self::input($name, $value, $attributes, 'email'); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - /** |
|
| 232 | - * Generate the form field for "search" |
|
| 233 | - * @see Form::input() for more details |
|
| 234 | - */ |
|
| 235 | - public static function search($name, $value = null, array $attributes = array()){ |
|
| 236 | - return self::input($name, $value, $attributes, 'search'); |
|
| 237 | - } |
|
| 231 | + /** |
|
| 232 | + * Generate the form field for "search" |
|
| 233 | + * @see Form::input() for more details |
|
| 234 | + */ |
|
| 235 | + public static function search($name, $value = null, array $attributes = array()){ |
|
| 236 | + return self::input($name, $value, $attributes, 'search'); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Generate the form field for "hidden" |
|
| 241 | - * @see Form::input() for more details |
|
| 242 | - */ |
|
| 243 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 244 | - return self::input($name, $value, $attributes, 'hidden'); |
|
| 245 | - } |
|
| 239 | + /** |
|
| 240 | + * Generate the form field for "hidden" |
|
| 241 | + * @see Form::input() for more details |
|
| 242 | + */ |
|
| 243 | + public static function hidden($name, $value = null, array $attributes = array()){ |
|
| 244 | + return self::input($name, $value, $attributes, 'hidden'); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Generate the form field for "file" |
|
| 249 | - * @see Form::input() for more details |
|
| 250 | - */ |
|
| 251 | - public static function file($name, array $attributes = array()){ |
|
| 252 | - return self::input($name, null, $attributes, 'file'); |
|
| 253 | - } |
|
| 247 | + /** |
|
| 248 | + * Generate the form field for "file" |
|
| 249 | + * @see Form::input() for more details |
|
| 250 | + */ |
|
| 251 | + public static function file($name, array $attributes = array()){ |
|
| 252 | + return self::input($name, null, $attributes, 'file'); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Generate the form field for "button" |
|
| 257 | - * @see Form::input() for more details |
|
| 258 | - */ |
|
| 259 | - public static function button($name, $value = null, array $attributes = array()){ |
|
| 260 | - return self::input($name, $value, $attributes, 'button'); |
|
| 261 | - } |
|
| 255 | + /** |
|
| 256 | + * Generate the form field for "button" |
|
| 257 | + * @see Form::input() for more details |
|
| 258 | + */ |
|
| 259 | + public static function button($name, $value = null, array $attributes = array()){ |
|
| 260 | + return self::input($name, $value, $attributes, 'button'); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Generate the form field for "reset" |
|
| 265 | - * @see Form::input() for more details |
|
| 266 | - */ |
|
| 267 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
| 268 | - return self::input($name, $value, $attributes, 'reset'); |
|
| 269 | - } |
|
| 263 | + /** |
|
| 264 | + * Generate the form field for "reset" |
|
| 265 | + * @see Form::input() for more details |
|
| 266 | + */ |
|
| 267 | + public static function reset($name, $value = null, array $attributes = array()){ |
|
| 268 | + return self::input($name, $value, $attributes, 'reset'); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Generate the form field for "submit" |
|
| 273 | - * @see Form::input() for more details |
|
| 274 | - */ |
|
| 275 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
| 276 | - return self::input($name, $value, $attributes, 'submit'); |
|
| 277 | - } |
|
| 271 | + /** |
|
| 272 | + * Generate the form field for "submit" |
|
| 273 | + * @see Form::input() for more details |
|
| 274 | + */ |
|
| 275 | + public static function submit($name, $value = null, array $attributes = array()){ |
|
| 276 | + return self::input($name, $value, $attributes, 'submit'); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Generate the form field for textarea |
|
| 281 | - * @param string $name the name of the textarea field |
|
| 282 | - * @param string $value the textarea field value |
|
| 283 | - * @param array $attributes the additional attributes to be added |
|
| 284 | - * @return string the generated textarea form html content |
|
| 285 | - */ |
|
| 286 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 287 | - $str = null; |
|
| 288 | - $str .= '<textarea name = "'.$name.'"'; |
|
| 289 | - $str .= attributes_to_string($attributes); |
|
| 290 | - $str .= '>'; |
|
| 291 | - $str .= $value.'</textarea>'; |
|
| 292 | - return $str; |
|
| 293 | - } |
|
| 279 | + /** |
|
| 280 | + * Generate the form field for textarea |
|
| 281 | + * @param string $name the name of the textarea field |
|
| 282 | + * @param string $value the textarea field value |
|
| 283 | + * @param array $attributes the additional attributes to be added |
|
| 284 | + * @return string the generated textarea form html content |
|
| 285 | + */ |
|
| 286 | + public static function textarea($name, $value = '', array $attributes = array()){ |
|
| 287 | + $str = null; |
|
| 288 | + $str .= '<textarea name = "'.$name.'"'; |
|
| 289 | + $str .= attributes_to_string($attributes); |
|
| 290 | + $str .= '>'; |
|
| 291 | + $str .= $value.'</textarea>'; |
|
| 292 | + return $str; |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Generate the form field for select |
|
| 297 | - * @param string $name the name of the form field |
|
| 298 | - * @param mixed|array $values the values used to populate the "option" tags |
|
| 299 | - * @param mixed $selected the selected value in the option list |
|
| 300 | - * @param array $attributes the additional attribute to be added |
|
| 301 | - * @return string the generated form field html content for select |
|
| 302 | - */ |
|
| 303 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 304 | - if(! is_array($values)){ |
|
| 305 | - $values = array('' => $values); |
|
| 306 | - } |
|
| 307 | - $str = null; |
|
| 308 | - $str .= '<select name = "'.$name.'"'; |
|
| 309 | - $str .= attributes_to_string($attributes); |
|
| 310 | - $str .= '>'; |
|
| 311 | - foreach($values as $key => $val){ |
|
| 312 | - $select = ''; |
|
| 313 | - if($key == $selected){ |
|
| 314 | - $select = 'selected'; |
|
| 315 | - } |
|
| 316 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 317 | - } |
|
| 318 | - $str .= '</select>'; |
|
| 319 | - return $str; |
|
| 320 | - } |
|
| 295 | + /** |
|
| 296 | + * Generate the form field for select |
|
| 297 | + * @param string $name the name of the form field |
|
| 298 | + * @param mixed|array $values the values used to populate the "option" tags |
|
| 299 | + * @param mixed $selected the selected value in the option list |
|
| 300 | + * @param array $attributes the additional attribute to be added |
|
| 301 | + * @return string the generated form field html content for select |
|
| 302 | + */ |
|
| 303 | + public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
| 304 | + if(! is_array($values)){ |
|
| 305 | + $values = array('' => $values); |
|
| 306 | + } |
|
| 307 | + $str = null; |
|
| 308 | + $str .= '<select name = "'.$name.'"'; |
|
| 309 | + $str .= attributes_to_string($attributes); |
|
| 310 | + $str .= '>'; |
|
| 311 | + foreach($values as $key => $val){ |
|
| 312 | + $select = ''; |
|
| 313 | + if($key == $selected){ |
|
| 314 | + $select = 'selected'; |
|
| 315 | + } |
|
| 316 | + $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
| 317 | + } |
|
| 318 | + $str .= '</select>'; |
|
| 319 | + return $str; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - } |
|
| 322 | + } |
|
@@ -1,207 +1,207 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @file bootstrap.php |
|
| 29 | - * |
|
| 30 | - * Contains the loading process: loading of constants, common functions, libraries |
|
| 31 | - * configurations, etc |
|
| 32 | - * verification of the environment and the routing of the request. |
|
| 33 | - * |
|
| 34 | - * @package core |
|
| 35 | - * @author Tony NGUEREZA |
|
| 36 | - * @copyright Copyright (c) 2017 |
|
| 37 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 38 | - * @link http://www.iacademy.cf |
|
| 39 | - * @version 1.0.0 |
|
| 40 | - * @filesource |
|
| 41 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @file bootstrap.php |
|
| 29 | + * |
|
| 30 | + * Contains the loading process: loading of constants, common functions, libraries |
|
| 31 | + * configurations, etc |
|
| 32 | + * verification of the environment and the routing of the request. |
|
| 33 | + * |
|
| 34 | + * @package core |
|
| 35 | + * @author Tony NGUEREZA |
|
| 36 | + * @copyright Copyright (c) 2017 |
|
| 37 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 38 | + * @link http://www.iacademy.cf |
|
| 39 | + * @version 1.0.0 |
|
| 40 | + * @filesource |
|
| 41 | + */ |
|
| 42 | 42 | |
| 43 | - //if the application is running in CLI mode $_SESSION global variable is not available |
|
| 44 | - if(IS_CLI){ |
|
| 45 | - $_SESSION = array(); |
|
| 46 | - } |
|
| 43 | + //if the application is running in CLI mode $_SESSION global variable is not available |
|
| 44 | + if(IS_CLI){ |
|
| 45 | + $_SESSION = array(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * inclusion of global constants of the environment that contain : name of the framework, |
|
| 50 | - * version, release date, version of PHP required, etc. |
|
| 51 | - */ |
|
| 52 | - require_once CORE_PATH . 'constants.php'; |
|
| 48 | + /** |
|
| 49 | + * inclusion of global constants of the environment that contain : name of the framework, |
|
| 50 | + * version, release date, version of PHP required, etc. |
|
| 51 | + */ |
|
| 52 | + require_once CORE_PATH . 'constants.php'; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * include file containing commons functions used in the framework such: show_error, |
|
| 56 | - * php_exception_handler, php_error_handler, get_instance, etc. |
|
| 57 | - */ |
|
| 58 | - require_once CORE_PATH . 'common.php'; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Include of the file containing the BaseClass |
|
| 62 | - */ |
|
| 63 | - require_once CORE_CLASSES_PATH . 'BaseClass.php'; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Include of the file containing the BaseClass |
|
| 67 | - */ |
|
| 68 | - require_once CORE_CLASSES_PATH . 'BaseStaticClass.php'; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * The Benchmark class |
|
| 72 | - */ |
|
| 73 | - $BENCHMARK =& class_loader('Benchmark'); |
|
| 54 | + /** |
|
| 55 | + * include file containing commons functions used in the framework such: show_error, |
|
| 56 | + * php_exception_handler, php_error_handler, get_instance, etc. |
|
| 57 | + */ |
|
| 58 | + require_once CORE_PATH . 'common.php'; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Include of the file containing the BaseClass |
|
| 62 | + */ |
|
| 63 | + require_once CORE_CLASSES_PATH . 'BaseClass.php'; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Include of the file containing the BaseClass |
|
| 67 | + */ |
|
| 68 | + require_once CORE_CLASSES_PATH . 'BaseStaticClass.php'; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * The Benchmark class |
|
| 72 | + */ |
|
| 73 | + $BENCHMARK =& class_loader('Benchmark'); |
|
| 74 | 74 | |
| 75 | - $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 75 | + $BENCHMARK->mark('APP_EXECUTION_START'); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * instance of the Log class |
|
| 79 | - */ |
|
| 77 | + /** |
|
| 78 | + * instance of the Log class |
|
| 79 | + */ |
|
| 80 | 80 | $LOGGER =& class_loader('Log', 'classes'); |
| 81 | 81 | |
| 82 | 82 | $LOGGER->setLogger('ApplicationBootstrap'); |
| 83 | 83 | |
| 84 | 84 | $LOGGER->debug('Checking PHP version ...'); |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Verification of the PHP environment: minimum and maximum version |
|
| 88 | - */ |
|
| 89 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 90 | - show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
| 91 | - } |
|
| 92 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 93 | - show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
| 94 | - } |
|
| 95 | - $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Setting of the PHP error message handling function |
|
| 99 | - */ |
|
| 100 | - set_error_handler('php_error_handler'); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Setting of the PHP error exception handling function |
|
| 104 | - */ |
|
| 105 | - set_exception_handler('php_exception_handler'); |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Setting of the PHP shutdown handling function |
|
| 109 | - */ |
|
| 110 | - register_shutdown_function('php_shudown_handler'); |
|
| 86 | + /** |
|
| 87 | + * Verification of the PHP environment: minimum and maximum version |
|
| 88 | + */ |
|
| 89 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
| 90 | + show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
| 91 | + } |
|
| 92 | + else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
| 93 | + show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
| 94 | + } |
|
| 95 | + $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Setting of the PHP error message handling function |
|
| 99 | + */ |
|
| 100 | + set_error_handler('php_error_handler'); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Setting of the PHP error exception handling function |
|
| 104 | + */ |
|
| 105 | + set_exception_handler('php_exception_handler'); |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Setting of the PHP shutdown handling function |
|
| 109 | + */ |
|
| 110 | + register_shutdown_function('php_shudown_handler'); |
|
| 111 | 111 | |
| 112 | - //if user have some composer packages |
|
| 113 | - $LOGGER->debug('Check for composer autoload'); |
|
| 114 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 115 | - $LOGGER->info('The composer autoload file exists include it'); |
|
| 116 | - require_once VENDOR_PATH . 'autoload.php'; |
|
| 117 | - } |
|
| 118 | - else{ |
|
| 119 | - $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 120 | - } |
|
| 112 | + //if user have some composer packages |
|
| 113 | + $LOGGER->debug('Check for composer autoload'); |
|
| 114 | + if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 115 | + $LOGGER->info('The composer autoload file exists include it'); |
|
| 116 | + require_once VENDOR_PATH . 'autoload.php'; |
|
| 117 | + } |
|
| 118 | + else{ |
|
| 119 | + $LOGGER->info('The composer autoload file does not exist skipping'); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $LOGGER->debug('Begin to load the required resources'); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Load the EventInfo class file |
|
| 126 | - */ |
|
| 127 | - require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 131 | - /** |
|
| 132 | - * Load configurations and using the |
|
| 133 | - * static method "init()" to initialize the Config class . |
|
| 134 | - */ |
|
| 135 | - $CONFIG =& class_loader('Config', 'classes'); |
|
| 136 | - $CONFIG->init(); |
|
| 137 | - $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 138 | - |
|
| 139 | - $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 140 | - /** |
|
| 141 | - * Load modules and using the |
|
| 142 | - * static method "init()" to initialize the Module class. |
|
| 143 | - */ |
|
| 144 | - $MODULE =& class_loader('Module', 'classes'); |
|
| 145 | - $MODULE->init(); |
|
| 146 | - $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 147 | - |
|
| 148 | - $LOGGER->debug('Loading Base Controller ...'); |
|
| 149 | - /** |
|
| 150 | - * Include of the file containing the Base Controller class |
|
| 151 | - */ |
|
| 152 | - require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 153 | - $LOGGER->info('Base Controller loaded successfully'); |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Register controllers autoload function |
|
| 157 | - */ |
|
| 158 | - spl_autoload_register('autoload_controller'); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Loading Security class |
|
| 162 | - */ |
|
| 163 | - $SECURITY =& class_loader('Security', 'classes'); |
|
| 164 | - $SECURITY->checkWhiteListIpAccess(); |
|
| 122 | + $LOGGER->debug('Begin to load the required resources'); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Load the EventInfo class file |
|
| 126 | + */ |
|
| 127 | + require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + $BENCHMARK->mark('CONFIG_INIT_START'); |
|
| 131 | + /** |
|
| 132 | + * Load configurations and using the |
|
| 133 | + * static method "init()" to initialize the Config class . |
|
| 134 | + */ |
|
| 135 | + $CONFIG =& class_loader('Config', 'classes'); |
|
| 136 | + $CONFIG->init(); |
|
| 137 | + $BENCHMARK->mark('CONFIG_INIT_END'); |
|
| 138 | + |
|
| 139 | + $BENCHMARK->mark('MODULE_INIT_START'); |
|
| 140 | + /** |
|
| 141 | + * Load modules and using the |
|
| 142 | + * static method "init()" to initialize the Module class. |
|
| 143 | + */ |
|
| 144 | + $MODULE =& class_loader('Module', 'classes'); |
|
| 145 | + $MODULE->init(); |
|
| 146 | + $BENCHMARK->mark('MODULE_INIT_END'); |
|
| 147 | + |
|
| 148 | + $LOGGER->debug('Loading Base Controller ...'); |
|
| 149 | + /** |
|
| 150 | + * Include of the file containing the Base Controller class |
|
| 151 | + */ |
|
| 152 | + require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
| 153 | + $LOGGER->info('Base Controller loaded successfully'); |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Register controllers autoload function |
|
| 157 | + */ |
|
| 158 | + spl_autoload_register('autoload_controller'); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Loading Security class |
|
| 162 | + */ |
|
| 163 | + $SECURITY =& class_loader('Security', 'classes'); |
|
| 164 | + $SECURITY->checkWhiteListIpAccess(); |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Loading Url class |
|
| 168 | - */ |
|
| 169 | - $URL =& class_loader('Url', 'classes'); |
|
| 166 | + /** |
|
| 167 | + * Loading Url class |
|
| 168 | + */ |
|
| 169 | + $URL =& class_loader('Url', 'classes'); |
|
| 170 | 170 | |
| 171 | - if(get_config('cache_enable', false)){ |
|
| 172 | - /** |
|
| 173 | - * Load Cache interface file |
|
| 174 | - */ |
|
| 175 | - require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 176 | - $cacheHandler = get_config('cache_handler'); |
|
| 177 | - if(! $cacheHandler){ |
|
| 178 | - show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 179 | - } |
|
| 180 | - $CACHE = null; |
|
| 181 | - //first check if the cache handler is the system driver |
|
| 182 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 183 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 184 | - } |
|
| 185 | - else{ |
|
| 186 | - //it's not a system driver use user library |
|
| 187 | - $CACHE =& class_loader($cacheHandler); |
|
| 188 | - } |
|
| 189 | - //check if the page already cached |
|
| 190 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 191 | - $RESPONSE = & class_loader('Response', 'classes'); |
|
| 192 | - if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } |
|
| 171 | + if(get_config('cache_enable', false)){ |
|
| 172 | + /** |
|
| 173 | + * Load Cache interface file |
|
| 174 | + */ |
|
| 175 | + require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
| 176 | + $cacheHandler = get_config('cache_handler'); |
|
| 177 | + if(! $cacheHandler){ |
|
| 178 | + show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
| 179 | + } |
|
| 180 | + $CACHE = null; |
|
| 181 | + //first check if the cache handler is the system driver |
|
| 182 | + if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
| 183 | + $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
| 184 | + } |
|
| 185 | + else{ |
|
| 186 | + //it's not a system driver use user library |
|
| 187 | + $CACHE =& class_loader($cacheHandler); |
|
| 188 | + } |
|
| 189 | + //check if the page already cached |
|
| 190 | + if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
| 191 | + $RESPONSE = & class_loader('Response', 'classes'); |
|
| 192 | + if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - //load model class |
|
| 199 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 198 | + //load model class |
|
| 199 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
| 200 | 200 | |
| 201 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 202 | - /** |
|
| 203 | - * Routing |
|
| 204 | - * instantiation of the "Router" class and request processing. |
|
| 205 | - */ |
|
| 206 | - $ROUTER = & class_loader('Router', 'classes'); |
|
| 207 | - $ROUTER->processRequest(); |
|
| 201 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
| 202 | + /** |
|
| 203 | + * Routing |
|
| 204 | + * instantiation of the "Router" class and request processing. |
|
| 205 | + */ |
|
| 206 | + $ROUTER = & class_loader('Router', 'classes'); |
|
| 207 | + $ROUTER->processRequest(); |
|