@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | 3 | /** |
4 | 4 | * TNH Framework |
5 | 5 | * |
@@ -22,163 +22,163 @@ 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 | class Database{ |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * The PDO instance |
30 | 30 | * @var object |
31 | - */ |
|
32 | - private $pdo = null; |
|
31 | + */ |
|
32 | + private $pdo = null; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * The database name used for the application |
36 | 36 | * @var string |
37 | - */ |
|
37 | + */ |
|
38 | 38 | private $databaseName = null; |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * The SQL SELECT statment |
42 | 42 | * @var string |
43 | - */ |
|
43 | + */ |
|
44 | 44 | private $select = '*'; |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * The SQL FROM statment |
48 | 48 | * @var string |
49 | - */ |
|
50 | - private $from = null; |
|
49 | + */ |
|
50 | + private $from = null; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * The SQL WHERE statment |
54 | 54 | * @var string |
55 | - */ |
|
56 | - private $where = null; |
|
55 | + */ |
|
56 | + private $where = null; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * The SQL LIMIT statment |
60 | 60 | * @var string |
61 | - */ |
|
62 | - private $limit = null; |
|
61 | + */ |
|
62 | + private $limit = null; |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * The SQL JOIN statment |
66 | 66 | * @var string |
67 | - */ |
|
68 | - private $join = null; |
|
67 | + */ |
|
68 | + private $join = null; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * The SQL ORDER BY statment |
72 | 72 | * @var string |
73 | - */ |
|
74 | - private $orderBy = null; |
|
73 | + */ |
|
74 | + private $orderBy = null; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * The SQL GROUP BY statment |
78 | 78 | * @var string |
79 | - */ |
|
80 | - private $groupBy = null; |
|
79 | + */ |
|
80 | + private $groupBy = null; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * The SQL HAVING statment |
84 | 84 | * @var string |
85 | - */ |
|
86 | - private $having = null; |
|
85 | + */ |
|
86 | + private $having = null; |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * The number of rows returned by the last query |
90 | 90 | * @var int |
91 | - */ |
|
92 | - private $numRows = 0; |
|
91 | + */ |
|
92 | + private $numRows = 0; |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * The last insert id for the primary key column that have auto increment or sequence |
96 | 96 | * @var mixed |
97 | - */ |
|
98 | - private $insertId = null; |
|
97 | + */ |
|
98 | + private $insertId = null; |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * The full SQL query statment after build for each command |
102 | 102 | * @var string |
103 | - */ |
|
104 | - private $query = null; |
|
103 | + */ |
|
104 | + private $query = null; |
|
105 | 105 | |
106 | 106 | /** |
107 | 107 | * The error returned for the last query |
108 | 108 | * @var string |
109 | - */ |
|
110 | - private $error = null; |
|
109 | + */ |
|
110 | + private $error = null; |
|
111 | 111 | |
112 | 112 | /** |
113 | 113 | * The result returned for the last query |
114 | 114 | * @var mixed |
115 | - */ |
|
116 | - private $result = array(); |
|
115 | + */ |
|
116 | + private $result = array(); |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * The prefix used in each database table |
120 | 120 | * @var string |
121 | - */ |
|
122 | - private $prefix = null; |
|
121 | + */ |
|
122 | + private $prefix = null; |
|
123 | 123 | |
124 | 124 | /** |
125 | 125 | * The list of SQL valid operators |
126 | 126 | * @var array |
127 | - */ |
|
128 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
127 | + */ |
|
128 | + private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * The cache default time to live in second. 0 means no need to use the cache feature |
132 | 132 | * @var int |
133 | - */ |
|
133 | + */ |
|
134 | 134 | private $cacheTtl = 0; |
135 | 135 | |
136 | 136 | /** |
137 | 137 | * The cache current time to live. 0 means no need to use the cache feature |
138 | 138 | * @var int |
139 | - */ |
|
140 | - private $temporaryCacheTtl = 0; |
|
139 | + */ |
|
140 | + private $temporaryCacheTtl = 0; |
|
141 | 141 | |
142 | 142 | /** |
143 | 143 | * The number of executed query for the current request |
144 | 144 | * @var int |
145 | - */ |
|
146 | - private $queryCount = 0; |
|
145 | + */ |
|
146 | + private $queryCount = 0; |
|
147 | 147 | |
148 | 148 | /** |
149 | 149 | * The default data to be used in the statments query INSERT, UPDATE |
150 | 150 | * @var array |
151 | - */ |
|
152 | - private $data = array(); |
|
151 | + */ |
|
152 | + private $data = array(); |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * The database configuration |
156 | 156 | * @var array |
157 | - */ |
|
158 | - private static $config = array(); |
|
157 | + */ |
|
158 | + private static $config = array(); |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * The logger instance |
162 | 162 | * @var Log |
163 | 163 | */ |
164 | - private $logger = null; |
|
165 | - |
|
166 | - /** |
|
167 | - * Construct new database |
|
168 | - * @param array $overwriteConfig the config to overwrite with the config set in database.php |
|
169 | - */ |
|
170 | - public function __construct($overwriteConfig = array()){ |
|
171 | - /** |
|
172 | - * instance of the Log class |
|
173 | - */ |
|
174 | - $this->logger =& class_loader('Log', 'classes'); |
|
175 | - $this->logger->setLogger('Library::Database'); |
|
176 | - |
|
177 | - if(file_exists(CONFIG_PATH . 'database.php')){ |
|
178 | - //here don't use require_once because somewhere user can create database instance directly |
|
179 | - require CONFIG_PATH . 'database.php'; |
|
180 | - if(empty($db) || !is_array($db)){ |
|
181 | - show_error('No database configuration found in database.php'); |
|
164 | + private $logger = null; |
|
165 | + |
|
166 | + /** |
|
167 | + * Construct new database |
|
168 | + * @param array $overwriteConfig the config to overwrite with the config set in database.php |
|
169 | + */ |
|
170 | + public function __construct($overwriteConfig = array()){ |
|
171 | + /** |
|
172 | + * instance of the Log class |
|
173 | + */ |
|
174 | + $this->logger =& class_loader('Log', 'classes'); |
|
175 | + $this->logger->setLogger('Library::Database'); |
|
176 | + |
|
177 | + if(file_exists(CONFIG_PATH . 'database.php')){ |
|
178 | + //here don't use require_once because somewhere user can create database instance directly |
|
179 | + require CONFIG_PATH . 'database.php'; |
|
180 | + if(empty($db) || !is_array($db)){ |
|
181 | + show_error('No database configuration found in database.php'); |
|
182 | 182 | } |
183 | 183 | else{ |
184 | 184 | if(! empty($overwriteConfig)){ |
@@ -223,955 +223,955 @@ discard block |
||
223 | 223 | $this->temporaryCacheTtl = $this->cacheTtl; |
224 | 224 | $this->logger->info('The database configuration are listed below: ' . stringfy_vars(array_merge($config, array('password' => string_hidden($config['password']))))); |
225 | 225 | } |
226 | - } |
|
227 | - else{ |
|
228 | - show_error('Unable to find database configuration'); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Set the SQL FROM statment |
|
234 | - * @param string|array $table the table name or array of table list |
|
235 | - * @return object the current Database instance |
|
236 | - */ |
|
237 | - public function from($table){ |
|
238 | - if(is_array($table)){ |
|
239 | - $froms = ''; |
|
240 | - foreach($table as $key){ |
|
241 | - $froms .= $this->prefix . $key . ', '; |
|
242 | - } |
|
243 | - $this->from = rtrim($froms, ', '); |
|
244 | - } |
|
245 | - else{ |
|
246 | - $this->from = $this->prefix . $table; |
|
247 | - } |
|
248 | - return $this; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Set the SQL SELECT statment |
|
253 | - * @param string|array $fields the field name or array of field list |
|
254 | - * @return object the current Database instance |
|
255 | - */ |
|
256 | - public function select($fields){ |
|
257 | - $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
258 | - $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select); |
|
259 | - return $this; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Set the SQL SELECT DISTINCT statment |
|
264 | - * @param string $field the field name to distinct |
|
265 | - * @return object the current Database instance |
|
266 | - */ |
|
267 | - public function distinct($field){ |
|
268 | - $distinct = ' DISTINCT ' . $field; |
|
269 | - $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct); |
|
270 | - |
|
271 | - return $this; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Set the SQL function MAX in SELECT statment |
|
276 | - * @param string $field the field name |
|
277 | - * @param string $name if is not null represent the alias used for this field in the result |
|
278 | - * @return object the current Database instance |
|
279 | - */ |
|
280 | - public function max($field, $name = null){ |
|
281 | - $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
282 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
283 | - return $this; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Set the SQL function MIN in SELECT statment |
|
288 | - * @param string $field the field name |
|
289 | - * @param string $name if is not null represent the alias used for this field in the result |
|
290 | - * @return object the current Database instance |
|
291 | - */ |
|
292 | - public function min($field, $name = null){ |
|
293 | - $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
294 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
295 | - return $this; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Set the SQL function SUM in SELECT statment |
|
300 | - * @param string $field the field name |
|
301 | - * @param string $name if is not null represent the alias used for this field in the result |
|
302 | - * @return object the current Database instance |
|
303 | - */ |
|
304 | - public function sum($field, $name = null){ |
|
305 | - $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
306 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
307 | - return $this; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Set the SQL function COUNT in SELECT statment |
|
312 | - * @param string $field the field name |
|
313 | - * @param string $name if is not null represent the alias used for this field in the result |
|
314 | - * @return object the current Database instance |
|
315 | - */ |
|
316 | - public function count($field = '*', $name = null){ |
|
317 | - $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
318 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
319 | - return $this; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Set the SQL function AVG in SELECT statment |
|
324 | - * @param string $field the field name |
|
325 | - * @param string $name if is not null represent the alias used for this field in the result |
|
326 | - * @return object the current Database instance |
|
327 | - */ |
|
328 | - public function avg($field, $name = null){ |
|
329 | - $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
330 | - $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
331 | - return $this; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Set the SQL JOIN statment |
|
336 | - * @param string $table the join table name |
|
337 | - * @param string $field1 the first field for join conditions |
|
338 | - * @param string $op the join condition operator. If is null the default will be "=" |
|
339 | - * @param string $field2 the second field for join conditions |
|
340 | - * @param string $type the type of join (INNER, LEFT, RIGHT) |
|
341 | - * @return object the current Database instance |
|
342 | - */ |
|
343 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
344 | - $on = $field1; |
|
345 | - $table = $this->prefix . $table; |
|
346 | - if(! is_null($op)){ |
|
347 | - $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
348 | - } |
|
349 | - if (is_null($this->join)){ |
|
350 | - $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
|
351 | - } |
|
352 | - else{ |
|
353 | - $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
|
354 | - } |
|
355 | - return $this; |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Set the SQL INNER JOIN statment |
|
360 | - * @see Database::join() |
|
361 | - * @return object the current Database instance |
|
362 | - */ |
|
363 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
364 | - return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Set the SQL LEFT JOIN statment |
|
369 | - * @see Database::join() |
|
370 | - * @return object the current Database instance |
|
371 | - */ |
|
372 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
373 | - return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
226 | + } |
|
227 | + else{ |
|
228 | + show_error('Unable to find database configuration'); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Set the SQL FROM statment |
|
234 | + * @param string|array $table the table name or array of table list |
|
235 | + * @return object the current Database instance |
|
236 | + */ |
|
237 | + public function from($table){ |
|
238 | + if(is_array($table)){ |
|
239 | + $froms = ''; |
|
240 | + foreach($table as $key){ |
|
241 | + $froms .= $this->prefix . $key . ', '; |
|
242 | + } |
|
243 | + $this->from = rtrim($froms, ', '); |
|
244 | + } |
|
245 | + else{ |
|
246 | + $this->from = $this->prefix . $table; |
|
247 | + } |
|
248 | + return $this; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Set the SQL SELECT statment |
|
253 | + * @param string|array $fields the field name or array of field list |
|
254 | + * @return object the current Database instance |
|
255 | + */ |
|
256 | + public function select($fields){ |
|
257 | + $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
|
258 | + $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select); |
|
259 | + return $this; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Set the SQL SELECT DISTINCT statment |
|
264 | + * @param string $field the field name to distinct |
|
265 | + * @return object the current Database instance |
|
266 | + */ |
|
267 | + public function distinct($field){ |
|
268 | + $distinct = ' DISTINCT ' . $field; |
|
269 | + $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct); |
|
270 | + |
|
271 | + return $this; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Set the SQL function MAX in SELECT statment |
|
276 | + * @param string $field the field name |
|
277 | + * @param string $name if is not null represent the alias used for this field in the result |
|
278 | + * @return object the current Database instance |
|
279 | + */ |
|
280 | + public function max($field, $name = null){ |
|
281 | + $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
282 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
283 | + return $this; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Set the SQL function MIN in SELECT statment |
|
288 | + * @param string $field the field name |
|
289 | + * @param string $name if is not null represent the alias used for this field in the result |
|
290 | + * @return object the current Database instance |
|
291 | + */ |
|
292 | + public function min($field, $name = null){ |
|
293 | + $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
294 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
295 | + return $this; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Set the SQL function SUM in SELECT statment |
|
300 | + * @param string $field the field name |
|
301 | + * @param string $name if is not null represent the alias used for this field in the result |
|
302 | + * @return object the current Database instance |
|
303 | + */ |
|
304 | + public function sum($field, $name = null){ |
|
305 | + $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
306 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
307 | + return $this; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Set the SQL function COUNT in SELECT statment |
|
312 | + * @param string $field the field name |
|
313 | + * @param string $name if is not null represent the alias used for this field in the result |
|
314 | + * @return object the current Database instance |
|
315 | + */ |
|
316 | + public function count($field = '*', $name = null){ |
|
317 | + $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
318 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
319 | + return $this; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Set the SQL function AVG in SELECT statment |
|
324 | + * @param string $field the field name |
|
325 | + * @param string $name if is not null represent the alias used for this field in the result |
|
326 | + * @return object the current Database instance |
|
327 | + */ |
|
328 | + public function avg($field, $name = null){ |
|
329 | + $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
|
330 | + $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
|
331 | + return $this; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Set the SQL JOIN statment |
|
336 | + * @param string $table the join table name |
|
337 | + * @param string $field1 the first field for join conditions |
|
338 | + * @param string $op the join condition operator. If is null the default will be "=" |
|
339 | + * @param string $field2 the second field for join conditions |
|
340 | + * @param string $type the type of join (INNER, LEFT, RIGHT) |
|
341 | + * @return object the current Database instance |
|
342 | + */ |
|
343 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
344 | + $on = $field1; |
|
345 | + $table = $this->prefix . $table; |
|
346 | + if(! is_null($op)){ |
|
347 | + $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
348 | + } |
|
349 | + if (is_null($this->join)){ |
|
350 | + $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
|
351 | + } |
|
352 | + else{ |
|
353 | + $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
|
354 | + } |
|
355 | + return $this; |
|
374 | 356 | } |
375 | 357 | |
376 | 358 | /** |
377 | - * Set the SQL RIGHT JOIN statment |
|
378 | - * @see Database::join() |
|
379 | - * @return object the current Database instance |
|
380 | - */ |
|
381 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
382 | - return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Set the SQL FULL OUTER JOIN statment |
|
387 | - * @see Database::join() |
|
388 | - * @return object the current Database instance |
|
389 | - */ |
|
390 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
391 | - return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Set the SQL LEFT OUTER JOIN statment |
|
396 | - * @see Database::join() |
|
397 | - * @return object the current Database instance |
|
398 | - */ |
|
399 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
400 | - return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Set the SQL RIGHT OUTER JOIN statment |
|
405 | - * @see Database::join() |
|
406 | - * @return object the current Database instance |
|
407 | - */ |
|
408 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
409 | - return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Set the SQL WHERE CLAUSE for IS NULL |
|
414 | - * @param string|array $field the field name or array of field list |
|
415 | - * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
416 | - * @return object the current Database instance |
|
417 | - */ |
|
418 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
419 | - if(is_array($field)){ |
|
420 | - foreach($field as $f){ |
|
421 | - $this->whereIsNull($f, $andOr); |
|
422 | - } |
|
423 | - } |
|
424 | - else{ |
|
425 | - if (! $this->where){ |
|
426 | - $this->where = $field.' IS NULL '; |
|
427 | - } |
|
428 | - else{ |
|
429 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
|
430 | - } |
|
431 | - } |
|
432 | - return $this; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * Set the SQL WHERE CLAUSE for IS NOT NULL |
|
437 | - * @param string|array $field the field name or array of field list |
|
438 | - * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
439 | - * @return object the current Database instance |
|
440 | - */ |
|
441 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
442 | - if(is_array($field)){ |
|
443 | - foreach($field as $f){ |
|
444 | - $this->whereIsNotNull($f, $andOr); |
|
445 | - } |
|
446 | - } |
|
447 | - else{ |
|
448 | - if (! $this->where){ |
|
449 | - $this->where = $field.' IS NOT NULL '; |
|
450 | - } |
|
451 | - else{ |
|
452 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
|
453 | - } |
|
454 | - } |
|
455 | - return $this; |
|
456 | - } |
|
359 | + * Set the SQL INNER JOIN statment |
|
360 | + * @see Database::join() |
|
361 | + * @return object the current Database instance |
|
362 | + */ |
|
363 | + public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
364 | + return $this->join($table, $field1, $op, $field2, 'INNER '); |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Set the SQL LEFT JOIN statment |
|
369 | + * @see Database::join() |
|
370 | + * @return object the current Database instance |
|
371 | + */ |
|
372 | + public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
373 | + return $this->join($table, $field1, $op, $field2, 'LEFT '); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Set the SQL RIGHT JOIN statment |
|
378 | + * @see Database::join() |
|
379 | + * @return object the current Database instance |
|
380 | + */ |
|
381 | + public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
382 | + return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Set the SQL FULL OUTER JOIN statment |
|
387 | + * @see Database::join() |
|
388 | + * @return object the current Database instance |
|
389 | + */ |
|
390 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
391 | + return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Set the SQL LEFT OUTER JOIN statment |
|
396 | + * @see Database::join() |
|
397 | + * @return object the current Database instance |
|
398 | + */ |
|
399 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
400 | + return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Set the SQL RIGHT OUTER JOIN statment |
|
405 | + * @see Database::join() |
|
406 | + * @return object the current Database instance |
|
407 | + */ |
|
408 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
409 | + return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Set the SQL WHERE CLAUSE for IS NULL |
|
414 | + * @param string|array $field the field name or array of field list |
|
415 | + * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
416 | + * @return object the current Database instance |
|
417 | + */ |
|
418 | + public function whereIsNull($field, $andOr = 'AND'){ |
|
419 | + if(is_array($field)){ |
|
420 | + foreach($field as $f){ |
|
421 | + $this->whereIsNull($f, $andOr); |
|
422 | + } |
|
423 | + } |
|
424 | + else{ |
|
425 | + if (! $this->where){ |
|
426 | + $this->where = $field.' IS NULL '; |
|
427 | + } |
|
428 | + else{ |
|
429 | + $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
|
430 | + } |
|
431 | + } |
|
432 | + return $this; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * Set the SQL WHERE CLAUSE for IS NOT NULL |
|
437 | + * @param string|array $field the field name or array of field list |
|
438 | + * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
439 | + * @return object the current Database instance |
|
440 | + */ |
|
441 | + public function whereIsNotNull($field, $andOr = 'AND'){ |
|
442 | + if(is_array($field)){ |
|
443 | + foreach($field as $f){ |
|
444 | + $this->whereIsNotNull($f, $andOr); |
|
445 | + } |
|
446 | + } |
|
447 | + else{ |
|
448 | + if (! $this->where){ |
|
449 | + $this->where = $field.' IS NOT NULL '; |
|
450 | + } |
|
451 | + else{ |
|
452 | + $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
|
453 | + } |
|
454 | + } |
|
455 | + return $this; |
|
456 | + } |
|
457 | 457 | |
458 | - /** |
|
459 | - * Set the SQL WHERE CLAUSE statment |
|
460 | - * @param string|array $where the where field or array of field list |
|
461 | - * @param string $op the condition operator. If is null the default will be "=" |
|
462 | - * @param mixed $val the where value |
|
463 | - * @param string $type the type used for this where clause (NOT, etc.) |
|
464 | - * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
465 | - * @param boolean $escape whether to escape or not the $val |
|
466 | - * @return object the current Database instance |
|
467 | - */ |
|
468 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
469 | - if (is_array($where)){ |
|
470 | - $_where = array(); |
|
471 | - foreach ($where as $column => $data){ |
|
472 | - if(is_null($data)){ |
|
473 | - $data = ''; |
|
474 | - } |
|
475 | - $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data); |
|
476 | - } |
|
477 | - $where = implode(' '.$andOr.' ', $_where); |
|
478 | - } |
|
479 | - else{ |
|
480 | - if(is_array($op)){ |
|
481 | - $x = explode('?', $where); |
|
482 | - $w = ''; |
|
483 | - foreach($x as $k => $v){ |
|
484 | - if(! empty($v)){ |
|
485 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
486 | - $op[$k] = ''; |
|
487 | - } |
|
488 | - $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
|
489 | - } |
|
490 | - } |
|
491 | - $where = $w; |
|
492 | - } |
|
493 | - else if (! in_array((string)$op, $this->operatorList)){ |
|
494 | - if(is_null($op)){ |
|
495 | - $op = ''; |
|
496 | - } |
|
497 | - $where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
|
498 | - } |
|
499 | - else{ |
|
500 | - if(is_null($val)){ |
|
501 | - $val = ''; |
|
502 | - } |
|
503 | - $where = $type . $where . $op . ($escape ? $this->escape($val) : $val); |
|
504 | - } |
|
505 | - } |
|
506 | - if (is_null($this->where)){ |
|
507 | - $this->where = $where; |
|
508 | - } |
|
509 | - else{ |
|
510 | - if(substr($this->where, -1) == '('){ |
|
511 | - $this->where = $this->where . ' ' . $where; |
|
512 | - } |
|
513 | - else{ |
|
514 | - $this->where = $this->where . ' '.$andOr.' ' . $where; |
|
515 | - } |
|
516 | - } |
|
517 | - return $this; |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Set the SQL WHERE CLAUSE statment using OR |
|
522 | - * @see Database::where() |
|
523 | - * @return object the current Database instance |
|
524 | - */ |
|
525 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
526 | - return $this->where($where, $op, $val, '', 'OR', $escape); |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * Set the SQL WHERE CLAUSE statment using AND and NOT |
|
532 | - * @see Database::where() |
|
533 | - * @return object the current Database instance |
|
534 | - */ |
|
535 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
536 | - return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Set the SQL WHERE CLAUSE statment using OR and NOT |
|
541 | - * @see Database::where() |
|
542 | - * @return object the current Database instance |
|
543 | - */ |
|
544 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
545 | - return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Set the opened parenthesis for the complex SQL query |
|
550 | - * @param string $type the type of this grouped (NOT, etc.) |
|
551 | - * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
|
552 | - * @return object the current Database instance |
|
553 | - */ |
|
554 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
555 | - if (is_null($this->where)){ |
|
556 | - $this->where = $type . ' ('; |
|
557 | - } |
|
558 | - else{ |
|
559 | - if(substr($this->where, -1) == '('){ |
|
560 | - $this->where .= $type . ' ('; |
|
561 | - } |
|
562 | - else{ |
|
563 | - $this->where .= $andOr . ' ' . $type . ' ('; |
|
564 | - } |
|
565 | - } |
|
566 | - return $this; |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Set the opened parenthesis for the complex SQL query using NOT type |
|
571 | - * @see Database::groupStart() |
|
572 | - * @return object the current Database instance |
|
573 | - */ |
|
574 | - public function notGroupStart(){ |
|
575 | - return $this->groupStart('NOT'); |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Set the opened parenthesis for the complex SQL query using OR for separator |
|
580 | - * @see Database::groupStart() |
|
581 | - * @return object the current Database instance |
|
582 | - */ |
|
583 | - public function orGroupStart(){ |
|
584 | - return $this->groupStart('', ' OR'); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
589 | - * @see Database::groupStart() |
|
590 | - * @return object the current Database instance |
|
591 | - */ |
|
592 | - public function orNotGroupStart(){ |
|
593 | - return $this->groupStart('NOT', ' OR'); |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Close the parenthesis for the grouped SQL |
|
598 | - * @return object the current Database instance |
|
599 | - */ |
|
600 | - public function groupEnd(){ |
|
601 | - $this->where .= ')'; |
|
602 | - return $this; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set the SQL WHERE CLAUSE statment for IN |
|
607 | - * @param string $field the field name for IN statment |
|
608 | - * @param array $keys the list of values used |
|
609 | - * @param string $type the condition separator type (NOT) |
|
610 | - * @param string $andOr the multiple conditions separator (OR, AND) |
|
611 | - * @param boolean $escape whether to escape or not the values |
|
612 | - * @return object the current Database instance |
|
613 | - */ |
|
614 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
615 | - if (is_array($keys)){ |
|
616 | - $_keys = array(); |
|
617 | - foreach ($keys as $k => $v){ |
|
618 | - if(is_null($v)){ |
|
619 | - $v = ''; |
|
620 | - } |
|
621 | - $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v)); |
|
622 | - } |
|
623 | - $keys = implode(', ', $_keys); |
|
624 | - if (is_null($this->where)){ |
|
625 | - $this->where = $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
626 | - } |
|
627 | - else{ |
|
628 | - if(substr($this->where, -1) == '('){ |
|
629 | - $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
630 | - } |
|
631 | - else{ |
|
632 | - $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
633 | - } |
|
634 | - } |
|
635 | - } |
|
636 | - return $this; |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Set the SQL WHERE CLAUSE statment for NOT IN with AND separator |
|
641 | - * @see Database::in() |
|
642 | - * @return object the current Database instance |
|
643 | - */ |
|
644 | - public function notIn($field, array $keys, $escape = true){ |
|
645 | - return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Set the SQL WHERE CLAUSE statment for IN with OR separator |
|
650 | - * @see Database::in() |
|
651 | - * @return object the current Database instance |
|
652 | - */ |
|
653 | - public function orIn($field, array $keys, $escape = true){ |
|
654 | - return $this->in($field, $keys, '', 'OR', $escape); |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Set the SQL WHERE CLAUSE statment for NOT IN with OR separator |
|
659 | - * @see Database::in() |
|
660 | - * @return object the current Database instance |
|
661 | - */ |
|
662 | - public function orNotIn($field, array $keys, $escape = true){ |
|
663 | - return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Set the SQL WHERE CLAUSE statment for BETWEEN |
|
668 | - * @param string $field the field used for the BETWEEN statment |
|
669 | - * @param mixed $value1 the BETWEEN begin value |
|
670 | - * @param mixed $value2 the BETWEEN end value |
|
671 | - * @param string $type the condition separator type (NOT) |
|
672 | - * @param string $andOr the multiple conditions separator (OR, AND) |
|
673 | - * @param boolean $escape whether to escape or not the values |
|
674 | - * @return object the current Database instance |
|
675 | - */ |
|
676 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
677 | - if(is_null($value1)){ |
|
678 | - $value1 = ''; |
|
679 | - } |
|
680 | - if(is_null($value2)){ |
|
681 | - $value2 = ''; |
|
682 | - } |
|
683 | - if (is_null($this->where)){ |
|
684 | - $this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
|
685 | - } |
|
686 | - else{ |
|
687 | - if(substr($this->where, -1) == '('){ |
|
688 | - $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
|
689 | - } |
|
690 | - else{ |
|
691 | - $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
|
692 | - } |
|
693 | - } |
|
694 | - return $this; |
|
695 | - } |
|
696 | - |
|
697 | - /** |
|
698 | - * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and AND separator |
|
699 | - * @see Database::between() |
|
700 | - * @return object the current Database instance |
|
701 | - */ |
|
702 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
703 | - return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * Set the SQL WHERE CLAUSE statment for BETWEEN with OR separator |
|
708 | - * @see Database::between() |
|
709 | - * @return object the current Database instance |
|
710 | - */ |
|
711 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
712 | - return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and OR separator |
|
717 | - * @see Database::between() |
|
718 | - * @return object the current Database instance |
|
719 | - */ |
|
720 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
721 | - return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Set the SQL WHERE CLAUSE statment for LIKE |
|
726 | - * @param string $field the field name used in LIKE statment |
|
727 | - * @param string $data the LIKE value for this field including the '%', and '_' part |
|
728 | - * @param string $type the condition separator type (NOT) |
|
729 | - * @param string $andOr the multiple conditions separator (OR, AND) |
|
730 | - * @param boolean $escape whether to escape or not the values |
|
731 | - * @return object the current Database instance |
|
732 | - */ |
|
733 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
734 | - if(is_null($data)){ |
|
735 | - $data = ''; |
|
736 | - } |
|
737 | - $like = $escape ? $this->escape($data) : $data; |
|
738 | - if (is_null($this->where)){ |
|
739 | - $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
|
740 | - } |
|
741 | - else{ |
|
742 | - if(substr($this->where, -1) == '('){ |
|
743 | - $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
744 | - } |
|
745 | - else{ |
|
746 | - $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
747 | - } |
|
748 | - } |
|
749 | - return $this; |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * Set the SQL WHERE CLAUSE statment for LIKE with OR separator |
|
754 | - * @see Database::like() |
|
755 | - * @return object the current Database instance |
|
756 | - */ |
|
757 | - public function orLike($field, $data, $escape = true){ |
|
758 | - return $this->like($field, $data, '', 'OR', $escape); |
|
759 | - } |
|
760 | - |
|
761 | - /** |
|
762 | - * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and AND separator |
|
763 | - * @see Database::like() |
|
764 | - * @return object the current Database instance |
|
765 | - */ |
|
766 | - public function notLike($field, $data, $escape = true){ |
|
767 | - return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and OR separator |
|
772 | - * @see Database::like() |
|
773 | - * @return object the current Database instance |
|
774 | - */ |
|
775 | - public function orNotLike($field, $data, $escape = true){ |
|
776 | - return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Set the SQL LIMIT statment |
|
781 | - * @param int $limit the limit offset. If $limitEnd is null this will be the limit count |
|
782 | - * like LIMIT n; |
|
783 | - * @param int $limitEnd the limit count |
|
784 | - * @return object the current Database instance |
|
785 | - */ |
|
786 | - public function limit($limit, $limitEnd = null){ |
|
787 | - if(is_null($limit)){ |
|
788 | - return; |
|
789 | - } |
|
790 | - if (! is_null($limitEnd)){ |
|
791 | - $this->limit = $limit . ', ' . $limitEnd; |
|
792 | - } |
|
793 | - else{ |
|
794 | - $this->limit = $limit; |
|
795 | - } |
|
796 | - return $this; |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Set the SQL ORDER BY CLAUSE statment |
|
801 | - * @param string $orderBy the field name used for order |
|
802 | - * @param string $orderDir the order direction (ASC or DESC) |
|
803 | - * @return object the current Database instance |
|
804 | - */ |
|
805 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
806 | - if (! is_null($orderDir)){ |
|
807 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
808 | - } |
|
809 | - else{ |
|
810 | - if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
811 | - $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
812 | - } |
|
813 | - else{ |
|
814 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
815 | - } |
|
816 | - } |
|
817 | - return $this; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Set the SQL GROUP BY CLAUSE statment |
|
822 | - * @param string|array $field the field name used or array of field list |
|
823 | - * @return object the current Database instance |
|
824 | - */ |
|
825 | - public function groupBy($field){ |
|
826 | - if(is_array($field)){ |
|
827 | - $this->groupBy = implode(', ', $field); |
|
828 | - } |
|
829 | - else{ |
|
830 | - $this->groupBy = $field; |
|
831 | - } |
|
832 | - return $this; |
|
833 | - } |
|
834 | - |
|
835 | - /** |
|
836 | - * Set the SQL HAVING CLAUSE statment |
|
837 | - * @param string $field the field name used for HAVING statment |
|
838 | - * @param string|array $op the operator used or array |
|
839 | - * @param mixed $val the value for HAVING comparaison |
|
840 | - * @param boolean $escape whether to escape or not the values |
|
841 | - * @return object the current Database instance |
|
842 | - */ |
|
843 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
844 | - if(is_array($op)){ |
|
845 | - $x = explode('?', $field); |
|
846 | - $w = ''; |
|
847 | - foreach($x as $k => $v){ |
|
848 | - if(!empty($v)){ |
|
849 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
850 | - $op[$k] = ''; |
|
851 | - } |
|
852 | - $w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
|
853 | - } |
|
854 | - } |
|
855 | - $this->having = $w; |
|
856 | - } |
|
857 | - else if (! in_array($op, $this->operatorList)){ |
|
858 | - if(is_null($op)){ |
|
859 | - $op = ''; |
|
860 | - } |
|
861 | - $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
|
862 | - } |
|
863 | - else{ |
|
864 | - if(is_null($val)){ |
|
865 | - $val = ''; |
|
866 | - } |
|
867 | - $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val); |
|
868 | - } |
|
869 | - return $this; |
|
870 | - } |
|
871 | - |
|
872 | - /** |
|
873 | - * Return the number of rows returned by the current query |
|
874 | - * @return int |
|
875 | - */ |
|
876 | - public function numRows(){ |
|
877 | - return $this->numRows; |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * Return the last insert id value |
|
882 | - * @return mixed |
|
883 | - */ |
|
884 | - public function insertId(){ |
|
885 | - return $this->insertId; |
|
886 | - } |
|
887 | - |
|
888 | - /** |
|
889 | - * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.) |
|
890 | - */ |
|
891 | - public function error(){ |
|
458 | + /** |
|
459 | + * Set the SQL WHERE CLAUSE statment |
|
460 | + * @param string|array $where the where field or array of field list |
|
461 | + * @param string $op the condition operator. If is null the default will be "=" |
|
462 | + * @param mixed $val the where value |
|
463 | + * @param string $type the type used for this where clause (NOT, etc.) |
|
464 | + * @param string $andOr the separator type used 'AND', 'OR', etc. |
|
465 | + * @param boolean $escape whether to escape or not the $val |
|
466 | + * @return object the current Database instance |
|
467 | + */ |
|
468 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
469 | + if (is_array($where)){ |
|
470 | + $_where = array(); |
|
471 | + foreach ($where as $column => $data){ |
|
472 | + if(is_null($data)){ |
|
473 | + $data = ''; |
|
474 | + } |
|
475 | + $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data); |
|
476 | + } |
|
477 | + $where = implode(' '.$andOr.' ', $_where); |
|
478 | + } |
|
479 | + else{ |
|
480 | + if(is_array($op)){ |
|
481 | + $x = explode('?', $where); |
|
482 | + $w = ''; |
|
483 | + foreach($x as $k => $v){ |
|
484 | + if(! empty($v)){ |
|
485 | + if(isset($op[$k]) && is_null($op[$k])){ |
|
486 | + $op[$k] = ''; |
|
487 | + } |
|
488 | + $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
|
489 | + } |
|
490 | + } |
|
491 | + $where = $w; |
|
492 | + } |
|
493 | + else if (! in_array((string)$op, $this->operatorList)){ |
|
494 | + if(is_null($op)){ |
|
495 | + $op = ''; |
|
496 | + } |
|
497 | + $where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
|
498 | + } |
|
499 | + else{ |
|
500 | + if(is_null($val)){ |
|
501 | + $val = ''; |
|
502 | + } |
|
503 | + $where = $type . $where . $op . ($escape ? $this->escape($val) : $val); |
|
504 | + } |
|
505 | + } |
|
506 | + if (is_null($this->where)){ |
|
507 | + $this->where = $where; |
|
508 | + } |
|
509 | + else{ |
|
510 | + if(substr($this->where, -1) == '('){ |
|
511 | + $this->where = $this->where . ' ' . $where; |
|
512 | + } |
|
513 | + else{ |
|
514 | + $this->where = $this->where . ' '.$andOr.' ' . $where; |
|
515 | + } |
|
516 | + } |
|
517 | + return $this; |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Set the SQL WHERE CLAUSE statment using OR |
|
522 | + * @see Database::where() |
|
523 | + * @return object the current Database instance |
|
524 | + */ |
|
525 | + public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
526 | + return $this->where($where, $op, $val, '', 'OR', $escape); |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * Set the SQL WHERE CLAUSE statment using AND and NOT |
|
532 | + * @see Database::where() |
|
533 | + * @return object the current Database instance |
|
534 | + */ |
|
535 | + public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
536 | + return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Set the SQL WHERE CLAUSE statment using OR and NOT |
|
541 | + * @see Database::where() |
|
542 | + * @return object the current Database instance |
|
543 | + */ |
|
544 | + public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
545 | + return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Set the opened parenthesis for the complex SQL query |
|
550 | + * @param string $type the type of this grouped (NOT, etc.) |
|
551 | + * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
|
552 | + * @return object the current Database instance |
|
553 | + */ |
|
554 | + public function groupStart($type = '', $andOr = ' AND'){ |
|
555 | + if (is_null($this->where)){ |
|
556 | + $this->where = $type . ' ('; |
|
557 | + } |
|
558 | + else{ |
|
559 | + if(substr($this->where, -1) == '('){ |
|
560 | + $this->where .= $type . ' ('; |
|
561 | + } |
|
562 | + else{ |
|
563 | + $this->where .= $andOr . ' ' . $type . ' ('; |
|
564 | + } |
|
565 | + } |
|
566 | + return $this; |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Set the opened parenthesis for the complex SQL query using NOT type |
|
571 | + * @see Database::groupStart() |
|
572 | + * @return object the current Database instance |
|
573 | + */ |
|
574 | + public function notGroupStart(){ |
|
575 | + return $this->groupStart('NOT'); |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Set the opened parenthesis for the complex SQL query using OR for separator |
|
580 | + * @see Database::groupStart() |
|
581 | + * @return object the current Database instance |
|
582 | + */ |
|
583 | + public function orGroupStart(){ |
|
584 | + return $this->groupStart('', ' OR'); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type |
|
589 | + * @see Database::groupStart() |
|
590 | + * @return object the current Database instance |
|
591 | + */ |
|
592 | + public function orNotGroupStart(){ |
|
593 | + return $this->groupStart('NOT', ' OR'); |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Close the parenthesis for the grouped SQL |
|
598 | + * @return object the current Database instance |
|
599 | + */ |
|
600 | + public function groupEnd(){ |
|
601 | + $this->where .= ')'; |
|
602 | + return $this; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set the SQL WHERE CLAUSE statment for IN |
|
607 | + * @param string $field the field name for IN statment |
|
608 | + * @param array $keys the list of values used |
|
609 | + * @param string $type the condition separator type (NOT) |
|
610 | + * @param string $andOr the multiple conditions separator (OR, AND) |
|
611 | + * @param boolean $escape whether to escape or not the values |
|
612 | + * @return object the current Database instance |
|
613 | + */ |
|
614 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
615 | + if (is_array($keys)){ |
|
616 | + $_keys = array(); |
|
617 | + foreach ($keys as $k => $v){ |
|
618 | + if(is_null($v)){ |
|
619 | + $v = ''; |
|
620 | + } |
|
621 | + $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v)); |
|
622 | + } |
|
623 | + $keys = implode(', ', $_keys); |
|
624 | + if (is_null($this->where)){ |
|
625 | + $this->where = $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
626 | + } |
|
627 | + else{ |
|
628 | + if(substr($this->where, -1) == '('){ |
|
629 | + $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
630 | + } |
|
631 | + else{ |
|
632 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
633 | + } |
|
634 | + } |
|
635 | + } |
|
636 | + return $this; |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * Set the SQL WHERE CLAUSE statment for NOT IN with AND separator |
|
641 | + * @see Database::in() |
|
642 | + * @return object the current Database instance |
|
643 | + */ |
|
644 | + public function notIn($field, array $keys, $escape = true){ |
|
645 | + return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Set the SQL WHERE CLAUSE statment for IN with OR separator |
|
650 | + * @see Database::in() |
|
651 | + * @return object the current Database instance |
|
652 | + */ |
|
653 | + public function orIn($field, array $keys, $escape = true){ |
|
654 | + return $this->in($field, $keys, '', 'OR', $escape); |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Set the SQL WHERE CLAUSE statment for NOT IN with OR separator |
|
659 | + * @see Database::in() |
|
660 | + * @return object the current Database instance |
|
661 | + */ |
|
662 | + public function orNotIn($field, array $keys, $escape = true){ |
|
663 | + return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Set the SQL WHERE CLAUSE statment for BETWEEN |
|
668 | + * @param string $field the field used for the BETWEEN statment |
|
669 | + * @param mixed $value1 the BETWEEN begin value |
|
670 | + * @param mixed $value2 the BETWEEN end value |
|
671 | + * @param string $type the condition separator type (NOT) |
|
672 | + * @param string $andOr the multiple conditions separator (OR, AND) |
|
673 | + * @param boolean $escape whether to escape or not the values |
|
674 | + * @return object the current Database instance |
|
675 | + */ |
|
676 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
677 | + if(is_null($value1)){ |
|
678 | + $value1 = ''; |
|
679 | + } |
|
680 | + if(is_null($value2)){ |
|
681 | + $value2 = ''; |
|
682 | + } |
|
683 | + if (is_null($this->where)){ |
|
684 | + $this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
|
685 | + } |
|
686 | + else{ |
|
687 | + if(substr($this->where, -1) == '('){ |
|
688 | + $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
|
689 | + } |
|
690 | + else{ |
|
691 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
|
692 | + } |
|
693 | + } |
|
694 | + return $this; |
|
695 | + } |
|
696 | + |
|
697 | + /** |
|
698 | + * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and AND separator |
|
699 | + * @see Database::between() |
|
700 | + * @return object the current Database instance |
|
701 | + */ |
|
702 | + public function notBetween($field, $value1, $value2, $escape = true){ |
|
703 | + return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * Set the SQL WHERE CLAUSE statment for BETWEEN with OR separator |
|
708 | + * @see Database::between() |
|
709 | + * @return object the current Database instance |
|
710 | + */ |
|
711 | + public function orBetween($field, $value1, $value2, $escape = true){ |
|
712 | + return $this->between($field, $value1, $value2, '', 'OR', $escape); |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Set the SQL WHERE CLAUSE statment for BETWEEN with NOT type and OR separator |
|
717 | + * @see Database::between() |
|
718 | + * @return object the current Database instance |
|
719 | + */ |
|
720 | + public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
721 | + return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Set the SQL WHERE CLAUSE statment for LIKE |
|
726 | + * @param string $field the field name used in LIKE statment |
|
727 | + * @param string $data the LIKE value for this field including the '%', and '_' part |
|
728 | + * @param string $type the condition separator type (NOT) |
|
729 | + * @param string $andOr the multiple conditions separator (OR, AND) |
|
730 | + * @param boolean $escape whether to escape or not the values |
|
731 | + * @return object the current Database instance |
|
732 | + */ |
|
733 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
734 | + if(is_null($data)){ |
|
735 | + $data = ''; |
|
736 | + } |
|
737 | + $like = $escape ? $this->escape($data) : $data; |
|
738 | + if (is_null($this->where)){ |
|
739 | + $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
|
740 | + } |
|
741 | + else{ |
|
742 | + if(substr($this->where, -1) == '('){ |
|
743 | + $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
744 | + } |
|
745 | + else{ |
|
746 | + $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
747 | + } |
|
748 | + } |
|
749 | + return $this; |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * Set the SQL WHERE CLAUSE statment for LIKE with OR separator |
|
754 | + * @see Database::like() |
|
755 | + * @return object the current Database instance |
|
756 | + */ |
|
757 | + public function orLike($field, $data, $escape = true){ |
|
758 | + return $this->like($field, $data, '', 'OR', $escape); |
|
759 | + } |
|
760 | + |
|
761 | + /** |
|
762 | + * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and AND separator |
|
763 | + * @see Database::like() |
|
764 | + * @return object the current Database instance |
|
765 | + */ |
|
766 | + public function notLike($field, $data, $escape = true){ |
|
767 | + return $this->like($field, $data, 'NOT ', 'AND', $escape); |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * Set the SQL WHERE CLAUSE statment for LIKE with NOT type and OR separator |
|
772 | + * @see Database::like() |
|
773 | + * @return object the current Database instance |
|
774 | + */ |
|
775 | + public function orNotLike($field, $data, $escape = true){ |
|
776 | + return $this->like($field, $data, 'NOT ', 'OR', $escape); |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Set the SQL LIMIT statment |
|
781 | + * @param int $limit the limit offset. If $limitEnd is null this will be the limit count |
|
782 | + * like LIMIT n; |
|
783 | + * @param int $limitEnd the limit count |
|
784 | + * @return object the current Database instance |
|
785 | + */ |
|
786 | + public function limit($limit, $limitEnd = null){ |
|
787 | + if(is_null($limit)){ |
|
788 | + return; |
|
789 | + } |
|
790 | + if (! is_null($limitEnd)){ |
|
791 | + $this->limit = $limit . ', ' . $limitEnd; |
|
792 | + } |
|
793 | + else{ |
|
794 | + $this->limit = $limit; |
|
795 | + } |
|
796 | + return $this; |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Set the SQL ORDER BY CLAUSE statment |
|
801 | + * @param string $orderBy the field name used for order |
|
802 | + * @param string $orderDir the order direction (ASC or DESC) |
|
803 | + * @return object the current Database instance |
|
804 | + */ |
|
805 | + public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
806 | + if (! is_null($orderDir)){ |
|
807 | + $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
808 | + } |
|
809 | + else{ |
|
810 | + if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
811 | + $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
812 | + } |
|
813 | + else{ |
|
814 | + $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
815 | + } |
|
816 | + } |
|
817 | + return $this; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Set the SQL GROUP BY CLAUSE statment |
|
822 | + * @param string|array $field the field name used or array of field list |
|
823 | + * @return object the current Database instance |
|
824 | + */ |
|
825 | + public function groupBy($field){ |
|
826 | + if(is_array($field)){ |
|
827 | + $this->groupBy = implode(', ', $field); |
|
828 | + } |
|
829 | + else{ |
|
830 | + $this->groupBy = $field; |
|
831 | + } |
|
832 | + return $this; |
|
833 | + } |
|
834 | + |
|
835 | + /** |
|
836 | + * Set the SQL HAVING CLAUSE statment |
|
837 | + * @param string $field the field name used for HAVING statment |
|
838 | + * @param string|array $op the operator used or array |
|
839 | + * @param mixed $val the value for HAVING comparaison |
|
840 | + * @param boolean $escape whether to escape or not the values |
|
841 | + * @return object the current Database instance |
|
842 | + */ |
|
843 | + public function having($field, $op = null, $val = null, $escape = true){ |
|
844 | + if(is_array($op)){ |
|
845 | + $x = explode('?', $field); |
|
846 | + $w = ''; |
|
847 | + foreach($x as $k => $v){ |
|
848 | + if(!empty($v)){ |
|
849 | + if(isset($op[$k]) && is_null($op[$k])){ |
|
850 | + $op[$k] = ''; |
|
851 | + } |
|
852 | + $w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
|
853 | + } |
|
854 | + } |
|
855 | + $this->having = $w; |
|
856 | + } |
|
857 | + else if (! in_array($op, $this->operatorList)){ |
|
858 | + if(is_null($op)){ |
|
859 | + $op = ''; |
|
860 | + } |
|
861 | + $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
|
862 | + } |
|
863 | + else{ |
|
864 | + if(is_null($val)){ |
|
865 | + $val = ''; |
|
866 | + } |
|
867 | + $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val); |
|
868 | + } |
|
869 | + return $this; |
|
870 | + } |
|
871 | + |
|
872 | + /** |
|
873 | + * Return the number of rows returned by the current query |
|
874 | + * @return int |
|
875 | + */ |
|
876 | + public function numRows(){ |
|
877 | + return $this->numRows; |
|
878 | + } |
|
879 | + |
|
880 | + /** |
|
881 | + * Return the last insert id value |
|
882 | + * @return mixed |
|
883 | + */ |
|
884 | + public function insertId(){ |
|
885 | + return $this->insertId; |
|
886 | + } |
|
887 | + |
|
888 | + /** |
|
889 | + * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.) |
|
890 | + */ |
|
891 | + public function error(){ |
|
892 | 892 | if($this->error){ |
893 | 893 | show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error'); |
894 | 894 | } |
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Get the result of one record rows returned by the current query |
|
899 | - * @param boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string. |
|
900 | - * If is string will determine the result type "array" or "object" |
|
901 | - * @return mixed the query SQL string or the record result |
|
902 | - */ |
|
903 | - public function get($returnSQLQueryOrResultType = false){ |
|
904 | - $this->limit = 1; |
|
905 | - $query = $this->getAll(true); |
|
906 | - if($returnSQLQueryOrResultType === true){ |
|
907 | - return $query; |
|
908 | - } |
|
909 | - else{ |
|
910 | - return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
911 | - } |
|
912 | - } |
|
913 | - |
|
914 | - /** |
|
915 | - * Get the result of record rows list returned by the current query |
|
916 | - * @param boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string. |
|
917 | - * If is string will determine the result type "array" or "object" |
|
918 | - * @return mixed the query SQL string or the record result |
|
919 | - */ |
|
920 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
921 | - $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
922 | - if (! is_null($this->join)){ |
|
923 | - $query .= $this->join; |
|
924 | - } |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Get the result of one record rows returned by the current query |
|
899 | + * @param boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string. |
|
900 | + * If is string will determine the result type "array" or "object" |
|
901 | + * @return mixed the query SQL string or the record result |
|
902 | + */ |
|
903 | + public function get($returnSQLQueryOrResultType = false){ |
|
904 | + $this->limit = 1; |
|
905 | + $query = $this->getAll(true); |
|
906 | + if($returnSQLQueryOrResultType === true){ |
|
907 | + return $query; |
|
908 | + } |
|
909 | + else{ |
|
910 | + return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
911 | + } |
|
912 | + } |
|
913 | + |
|
914 | + /** |
|
915 | + * Get the result of record rows list returned by the current query |
|
916 | + * @param boolean $returnSQLQueryOrResultType if is boolean and true will return the SQL query string. |
|
917 | + * If is string will determine the result type "array" or "object" |
|
918 | + * @return mixed the query SQL string or the record result |
|
919 | + */ |
|
920 | + public function getAll($returnSQLQueryOrResultType = false){ |
|
921 | + $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
|
922 | + if (! is_null($this->join)){ |
|
923 | + $query .= $this->join; |
|
924 | + } |
|
925 | 925 | |
926 | - if (! is_null($this->where)){ |
|
927 | - $query .= ' WHERE ' . $this->where; |
|
928 | - } |
|
926 | + if (! is_null($this->where)){ |
|
927 | + $query .= ' WHERE ' . $this->where; |
|
928 | + } |
|
929 | 929 | |
930 | - if (! is_null($this->groupBy)){ |
|
931 | - $query .= ' GROUP BY ' . $this->groupBy; |
|
932 | - } |
|
930 | + if (! is_null($this->groupBy)){ |
|
931 | + $query .= ' GROUP BY ' . $this->groupBy; |
|
932 | + } |
|
933 | 933 | |
934 | - if (! is_null($this->having)){ |
|
935 | - $query .= ' HAVING ' . $this->having; |
|
936 | - } |
|
934 | + if (! is_null($this->having)){ |
|
935 | + $query .= ' HAVING ' . $this->having; |
|
936 | + } |
|
937 | 937 | |
938 | - if (! is_null($this->orderBy)){ |
|
939 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
940 | - } |
|
938 | + if (! is_null($this->orderBy)){ |
|
939 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
940 | + } |
|
941 | 941 | |
942 | - if(! is_null($this->limit)){ |
|
943 | - $query .= ' LIMIT ' . $this->limit; |
|
944 | - } |
|
942 | + if(! is_null($this->limit)){ |
|
943 | + $query .= ' LIMIT ' . $this->limit; |
|
944 | + } |
|
945 | 945 | |
946 | 946 | if($returnSQLQueryOrResultType === true){ |
947 | - return $query; |
|
948 | - } |
|
949 | - else{ |
|
950 | - return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
951 | - } |
|
952 | - } |
|
953 | - |
|
954 | - /** |
|
955 | - * Insert new record in the database |
|
956 | - * @param array $data the record data if is empty will use the $this->data array. |
|
957 | - * @param boolean $escape whether to escape or not the values |
|
958 | - * @return mixed the insert id of the new record or null |
|
959 | - */ |
|
960 | - public function insert($data = array(), $escape = true){ |
|
961 | - $column = array(); |
|
962 | - $val = array(); |
|
963 | - if(! $data && $this->getData()){ |
|
964 | - $columns = array_keys($this->getData()); |
|
965 | - $column = implode(',', $columns); |
|
966 | - $val = implode(', ', $this->getData()); |
|
967 | - } |
|
968 | - else{ |
|
969 | - $columns = array_keys($data); |
|
970 | - $column = implode(',', $columns); |
|
971 | - $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
972 | - } |
|
973 | - |
|
974 | - $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
975 | - $query = $this->query($query); |
|
976 | - |
|
977 | - if ($query){ |
|
978 | - $this->insertId = $this->pdo->lastInsertId(); |
|
979 | - return $this->insertId(); |
|
980 | - } |
|
981 | - else{ |
|
947 | + return $query; |
|
948 | + } |
|
949 | + else{ |
|
950 | + return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
951 | + } |
|
952 | + } |
|
953 | + |
|
954 | + /** |
|
955 | + * Insert new record in the database |
|
956 | + * @param array $data the record data if is empty will use the $this->data array. |
|
957 | + * @param boolean $escape whether to escape or not the values |
|
958 | + * @return mixed the insert id of the new record or null |
|
959 | + */ |
|
960 | + public function insert($data = array(), $escape = true){ |
|
961 | + $column = array(); |
|
962 | + $val = array(); |
|
963 | + if(! $data && $this->getData()){ |
|
964 | + $columns = array_keys($this->getData()); |
|
965 | + $column = implode(',', $columns); |
|
966 | + $val = implode(', ', $this->getData()); |
|
967 | + } |
|
968 | + else{ |
|
969 | + $columns = array_keys($data); |
|
970 | + $column = implode(',', $columns); |
|
971 | + $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
|
972 | + } |
|
973 | + |
|
974 | + $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
|
975 | + $query = $this->query($query); |
|
976 | + |
|
977 | + if ($query){ |
|
978 | + $this->insertId = $this->pdo->lastInsertId(); |
|
979 | + return $this->insertId(); |
|
980 | + } |
|
981 | + else{ |
|
982 | 982 | return false; |
983 | - } |
|
984 | - } |
|
985 | - |
|
986 | - /** |
|
987 | - * Update record in the database |
|
988 | - * @param array $data the record data if is empty will use the $this->data array. |
|
989 | - * @param boolean $escape whether to escape or not the values |
|
990 | - * @return mixed the update status |
|
991 | - */ |
|
992 | - public function update($data = array(), $escape = true){ |
|
993 | - $query = 'UPDATE ' . $this->from . ' SET '; |
|
994 | - $values = array(); |
|
995 | - if(! $data && $this->getData()){ |
|
996 | - foreach ($this->getData() as $column => $val){ |
|
997 | - $values[] = $column . ' = ' . $val; |
|
998 | - } |
|
999 | - } |
|
1000 | - else{ |
|
1001 | - foreach ($data as $column => $val){ |
|
1002 | - $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
|
1003 | - } |
|
1004 | - } |
|
1005 | - $query .= (is_array($data) ? implode(', ', $values) : $data); |
|
1006 | - if (! is_null($this->where)){ |
|
1007 | - $query .= ' WHERE ' . $this->where; |
|
1008 | - } |
|
1009 | - |
|
1010 | - if (! is_null($this->orderBy)){ |
|
1011 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
1012 | - } |
|
1013 | - |
|
1014 | - if (! is_null($this->limit)){ |
|
1015 | - $query .= ' LIMIT ' . $this->limit; |
|
1016 | - } |
|
1017 | - return $this->query($query); |
|
1018 | - } |
|
1019 | - |
|
1020 | - /** |
|
1021 | - * Delete the record in database |
|
1022 | - * @return mixed the delete status |
|
1023 | - */ |
|
1024 | - public function delete(){ |
|
1025 | - $query = 'DELETE FROM ' . $this->from; |
|
1026 | - |
|
1027 | - if (! is_null($this->where)){ |
|
1028 | - $query .= ' WHERE ' . $this->where; |
|
1029 | - } |
|
1030 | - |
|
1031 | - if (! is_null($this->orderBy)){ |
|
1032 | - $query .= ' ORDER BY ' . $this->orderBy; |
|
1033 | - } |
|
1034 | - |
|
1035 | - if (! is_null($this->limit)){ |
|
1036 | - $query .= ' LIMIT ' . $this->limit; |
|
1037 | - } |
|
1038 | - |
|
1039 | - if($query == 'DELETE FROM ' . $this->from){ |
|
1040 | - $query = 'TRUNCATE TABLE ' . $this->from; |
|
1041 | - } |
|
1042 | - return $this->query($query); |
|
1043 | - } |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Execute an SQL query |
|
1047 | - * @param string $query the query SQL string |
|
1048 | - * @param boolean $all whether to return all record or not |
|
1049 | - * @param boolean $array return the result as array |
|
1050 | - * @return mixed the query result |
|
1051 | - */ |
|
1052 | - public function query($query, $all = true, $array = false){ |
|
1053 | - $this->reset(); |
|
1054 | - if(is_array($all)){ |
|
1055 | - $x = explode('?', $query); |
|
1056 | - $q = ''; |
|
1057 | - foreach($x as $k => $v){ |
|
1058 | - if(! empty($v)){ |
|
1059 | - $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : ''); |
|
1060 | - } |
|
1061 | - } |
|
1062 | - $query = $q; |
|
1063 | - } |
|
1064 | - |
|
1065 | - $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
|
1066 | - $sqlSELECTQuery = stristr($this->query, 'SELECT'); |
|
1067 | - $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO')); |
|
1068 | - //cache expire time |
|
983 | + } |
|
984 | + } |
|
985 | + |
|
986 | + /** |
|
987 | + * Update record in the database |
|
988 | + * @param array $data the record data if is empty will use the $this->data array. |
|
989 | + * @param boolean $escape whether to escape or not the values |
|
990 | + * @return mixed the update status |
|
991 | + */ |
|
992 | + public function update($data = array(), $escape = true){ |
|
993 | + $query = 'UPDATE ' . $this->from . ' SET '; |
|
994 | + $values = array(); |
|
995 | + if(! $data && $this->getData()){ |
|
996 | + foreach ($this->getData() as $column => $val){ |
|
997 | + $values[] = $column . ' = ' . $val; |
|
998 | + } |
|
999 | + } |
|
1000 | + else{ |
|
1001 | + foreach ($data as $column => $val){ |
|
1002 | + $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
|
1003 | + } |
|
1004 | + } |
|
1005 | + $query .= (is_array($data) ? implode(', ', $values) : $data); |
|
1006 | + if (! is_null($this->where)){ |
|
1007 | + $query .= ' WHERE ' . $this->where; |
|
1008 | + } |
|
1009 | + |
|
1010 | + if (! is_null($this->orderBy)){ |
|
1011 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
1012 | + } |
|
1013 | + |
|
1014 | + if (! is_null($this->limit)){ |
|
1015 | + $query .= ' LIMIT ' . $this->limit; |
|
1016 | + } |
|
1017 | + return $this->query($query); |
|
1018 | + } |
|
1019 | + |
|
1020 | + /** |
|
1021 | + * Delete the record in database |
|
1022 | + * @return mixed the delete status |
|
1023 | + */ |
|
1024 | + public function delete(){ |
|
1025 | + $query = 'DELETE FROM ' . $this->from; |
|
1026 | + |
|
1027 | + if (! is_null($this->where)){ |
|
1028 | + $query .= ' WHERE ' . $this->where; |
|
1029 | + } |
|
1030 | + |
|
1031 | + if (! is_null($this->orderBy)){ |
|
1032 | + $query .= ' ORDER BY ' . $this->orderBy; |
|
1033 | + } |
|
1034 | + |
|
1035 | + if (! is_null($this->limit)){ |
|
1036 | + $query .= ' LIMIT ' . $this->limit; |
|
1037 | + } |
|
1038 | + |
|
1039 | + if($query == 'DELETE FROM ' . $this->from){ |
|
1040 | + $query = 'TRUNCATE TABLE ' . $this->from; |
|
1041 | + } |
|
1042 | + return $this->query($query); |
|
1043 | + } |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Execute an SQL query |
|
1047 | + * @param string $query the query SQL string |
|
1048 | + * @param boolean $all whether to return all record or not |
|
1049 | + * @param boolean $array return the result as array |
|
1050 | + * @return mixed the query result |
|
1051 | + */ |
|
1052 | + public function query($query, $all = true, $array = false){ |
|
1053 | + $this->reset(); |
|
1054 | + if(is_array($all)){ |
|
1055 | + $x = explode('?', $query); |
|
1056 | + $q = ''; |
|
1057 | + foreach($x as $k => $v){ |
|
1058 | + if(! empty($v)){ |
|
1059 | + $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : ''); |
|
1060 | + } |
|
1061 | + } |
|
1062 | + $query = $q; |
|
1063 | + } |
|
1064 | + |
|
1065 | + $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
|
1066 | + $sqlSELECTQuery = stristr($this->query, 'SELECT'); |
|
1067 | + $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO')); |
|
1068 | + //cache expire time |
|
1069 | 1069 | $cacheExpire = $this->temporaryCacheTtl; |
1070 | 1070 | |
1071 | 1071 | //return to the initial cache time |
1072 | 1072 | $this->temporaryCacheTtl = $this->cacheTtl; |
1073 | 1073 | |
1074 | 1074 | //config for cache |
1075 | - $cacheEnable = get_config('cache_enable'); |
|
1075 | + $cacheEnable = get_config('cache_enable'); |
|
1076 | 1076 | |
1077 | 1077 | //the database cache content |
1078 | - $cacheContent = null; |
|
1078 | + $cacheContent = null; |
|
1079 | 1079 | |
1080 | 1080 | //this database query cache key |
1081 | - $cacheKey = null; |
|
1081 | + $cacheKey = null; |
|
1082 | 1082 | |
1083 | 1083 | //the cache manager instance |
1084 | - $cacheInstance = null; |
|
1084 | + $cacheInstance = null; |
|
1085 | 1085 | |
1086 | 1086 | //the instance of the super controller |
1087 | - $obj = & get_instance(); |
|
1087 | + $obj = & get_instance(); |
|
1088 | 1088 | |
1089 | 1089 | //if can use cache feature for this query |
1090 | 1090 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
1091 | 1091 | |
1092 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1093 | - $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
|
1094 | - $cacheKey = md5($query . $all . $array); |
|
1095 | - $cacheInstance = $obj->cache; |
|
1096 | - $cacheContent = $cacheInstance->get($cacheKey); |
|
1097 | - } |
|
1098 | - else{ |
|
1092 | + if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1093 | + $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
|
1094 | + $cacheKey = md5($query . $all . $array); |
|
1095 | + $cacheInstance = $obj->cache; |
|
1096 | + $cacheContent = $cacheInstance->get($cacheKey); |
|
1097 | + } |
|
1098 | + else{ |
|
1099 | 1099 | $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database'); |
1100 | - } |
|
1100 | + } |
|
1101 | 1101 | |
1102 | - if (! $cacheContent && $sqlSELECTQuery){ |
|
1103 | - //for database query execution time |
|
1104 | - $benchmarkMarkerKey = md5($query . $all . $array); |
|
1105 | - $obj->benchmark->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')'); |
|
1106 | - //Now execute the query |
|
1107 | - $sqlQuery = $this->pdo->query($this->query); |
|
1102 | + if (! $cacheContent && $sqlSELECTQuery){ |
|
1103 | + //for database query execution time |
|
1104 | + $benchmarkMarkerKey = md5($query . $all . $array); |
|
1105 | + $obj->benchmark->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')'); |
|
1106 | + //Now execute the query |
|
1107 | + $sqlQuery = $this->pdo->query($this->query); |
|
1108 | 1108 | |
1109 | - //get response time for this query |
|
1110 | - $responseTime = $obj->benchmark->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'); |
|
1111 | - //TODO use the configuration value for the high response time currently is 1 second |
|
1112 | - if($responseTime >= 1 ){ |
|
1113 | - $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.'); |
|
1114 | - } |
|
1115 | - if ($sqlQuery){ |
|
1116 | - $this->numRows = $sqlQuery->rowCount(); |
|
1117 | - if (($this->numRows > 0)){ |
|
1118 | - //if need return all result like list of record |
|
1119 | - if ($all){ |
|
1120 | - $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
|
1121 | - } |
|
1122 | - else{ |
|
1123 | - $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
|
1124 | - } |
|
1125 | - } |
|
1126 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1127 | - $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
|
1128 | - $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
|
1129 | - } |
|
1130 | - } |
|
1131 | - else{ |
|
1132 | - $error = $this->pdo->errorInfo(); |
|
1133 | - $this->error = $error[2]; |
|
1134 | - $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
|
1135 | - $this->error(); |
|
1136 | - } |
|
1137 | - } |
|
1138 | - else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
1139 | - $queryStr = $this->pdo->query($this->query); |
|
1140 | - if($queryStr){ |
|
1141 | - $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
|
1142 | - $this->numRows = $queryStr->rowCount(); |
|
1143 | - } |
|
1144 | - if (! $this->result){ |
|
1145 | - $error = $this->pdo->errorInfo(); |
|
1146 | - $this->error = $error[2]; |
|
1147 | - $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
|
1148 | - $this->error(); |
|
1149 | - } |
|
1150 | - } |
|
1151 | - else{ |
|
1152 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
1153 | - $this->result = $cacheContent; |
|
1154 | - $this->numRows = count($this->result); |
|
1155 | - } |
|
1156 | - $this->queryCount++; |
|
1157 | - if(! $this->result){ |
|
1158 | - $this->logger->info('No result where found for the query [' . $query . ']'); |
|
1159 | - } |
|
1160 | - return $this->result; |
|
1161 | - } |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Set database cache time to live |
|
1165 | - * @param integer $ttl the cache time to live in second |
|
1166 | - * @return object the current Database instance |
|
1167 | - */ |
|
1168 | - public function setCache($ttl = 0){ |
|
1169 | - if($ttl > 0){ |
|
1170 | - $this->cacheTtl = $ttl; |
|
1171 | - $this->temporaryCacheTtl = $ttl; |
|
1172 | - } |
|
1173 | - return $this; |
|
1174 | - } |
|
1109 | + //get response time for this query |
|
1110 | + $responseTime = $obj->benchmark->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'); |
|
1111 | + //TODO use the configuration value for the high response time currently is 1 second |
|
1112 | + if($responseTime >= 1 ){ |
|
1113 | + $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.'); |
|
1114 | + } |
|
1115 | + if ($sqlQuery){ |
|
1116 | + $this->numRows = $sqlQuery->rowCount(); |
|
1117 | + if (($this->numRows > 0)){ |
|
1118 | + //if need return all result like list of record |
|
1119 | + if ($all){ |
|
1120 | + $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
|
1121 | + } |
|
1122 | + else{ |
|
1123 | + $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
|
1124 | + } |
|
1125 | + } |
|
1126 | + if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1127 | + $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
|
1128 | + $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
|
1129 | + } |
|
1130 | + } |
|
1131 | + else{ |
|
1132 | + $error = $this->pdo->errorInfo(); |
|
1133 | + $this->error = $error[2]; |
|
1134 | + $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
|
1135 | + $this->error(); |
|
1136 | + } |
|
1137 | + } |
|
1138 | + else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
1139 | + $queryStr = $this->pdo->query($this->query); |
|
1140 | + if($queryStr){ |
|
1141 | + $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
|
1142 | + $this->numRows = $queryStr->rowCount(); |
|
1143 | + } |
|
1144 | + if (! $this->result){ |
|
1145 | + $error = $this->pdo->errorInfo(); |
|
1146 | + $this->error = $error[2]; |
|
1147 | + $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
|
1148 | + $this->error(); |
|
1149 | + } |
|
1150 | + } |
|
1151 | + else{ |
|
1152 | + $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
1153 | + $this->result = $cacheContent; |
|
1154 | + $this->numRows = count($this->result); |
|
1155 | + } |
|
1156 | + $this->queryCount++; |
|
1157 | + if(! $this->result){ |
|
1158 | + $this->logger->info('No result where found for the query [' . $query . ']'); |
|
1159 | + } |
|
1160 | + return $this->result; |
|
1161 | + } |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Set database cache time to live |
|
1165 | + * @param integer $ttl the cache time to live in second |
|
1166 | + * @return object the current Database instance |
|
1167 | + */ |
|
1168 | + public function setCache($ttl = 0){ |
|
1169 | + if($ttl > 0){ |
|
1170 | + $this->cacheTtl = $ttl; |
|
1171 | + $this->temporaryCacheTtl = $ttl; |
|
1172 | + } |
|
1173 | + return $this; |
|
1174 | + } |
|
1175 | 1175 | |
1176 | 1176 | /** |
1177 | 1177 | * Enabled cache temporary for the current query not globally |
@@ -1179,110 +1179,110 @@ discard block |
||
1179 | 1179 | * @return object the current Database instance |
1180 | 1180 | */ |
1181 | 1181 | public function cached($ttl = 0){ |
1182 | - if($ttl > 0){ |
|
1183 | - $this->temporaryCacheTtl = $ttl; |
|
1184 | - } |
|
1182 | + if($ttl > 0){ |
|
1183 | + $this->temporaryCacheTtl = $ttl; |
|
1184 | + } |
|
1185 | 1185 | return $this; |
1186 | - } |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * Escape the data before execute query useful for security. |
|
1190 | - * @param mixed $data the data to be escaped |
|
1191 | - * @return mixed the data after escaped |
|
1192 | - */ |
|
1193 | - public function escape($data){ |
|
1194 | - if(is_null($data)){ |
|
1195 | - return null; |
|
1196 | - } |
|
1197 | - return $this->pdo->quote(trim($data)); |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * Return the number query executed count for the current request |
|
1202 | - * @return int |
|
1203 | - */ |
|
1204 | - public function queryCount(){ |
|
1205 | - return $this->queryCount; |
|
1206 | - } |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * Return the current query SQL string |
|
1210 | - * @return string |
|
1211 | - */ |
|
1212 | - public function getQuery(){ |
|
1213 | - return $this->query; |
|
1214 | - } |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * Return the application database name |
|
1218 | - * @return string |
|
1219 | - */ |
|
1220 | - public function getDatabaseName(){ |
|
1221 | - return $this->databaseName; |
|
1222 | - } |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * Return the database configuration |
|
1226 | - * @return array |
|
1227 | - */ |
|
1228 | - public static function getDatabaseConfiguration(){ |
|
1229 | - return static::$config; |
|
1230 | - } |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * Return the PDO instance |
|
1234 | - * @return PDO |
|
1235 | - */ |
|
1236 | - public function getPdo(){ |
|
1237 | - return $this->pdo; |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Return the data to be used for insert, update, etc. |
|
1242 | - * @return array |
|
1243 | - */ |
|
1244 | - public function getData(){ |
|
1245 | - return $this->data; |
|
1246 | - } |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Set the data to be used for insert, update, etc. |
|
1250 | - * @param string $key the data key identified |
|
1251 | - * @param mixed $value the data value |
|
1252 | - * @param boolean $escape whether to escape or not the $value |
|
1253 | - * @return object the current Database instance |
|
1254 | - */ |
|
1255 | - public function setData($key, $value, $escape = true){ |
|
1256 | - $this->data[$key] = $escape ? $this->escape($value) : $value; |
|
1257 | - return $this; |
|
1258 | - } |
|
1186 | + } |
|
1187 | + |
|
1188 | + /** |
|
1189 | + * Escape the data before execute query useful for security. |
|
1190 | + * @param mixed $data the data to be escaped |
|
1191 | + * @return mixed the data after escaped |
|
1192 | + */ |
|
1193 | + public function escape($data){ |
|
1194 | + if(is_null($data)){ |
|
1195 | + return null; |
|
1196 | + } |
|
1197 | + return $this->pdo->quote(trim($data)); |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * Return the number query executed count for the current request |
|
1202 | + * @return int |
|
1203 | + */ |
|
1204 | + public function queryCount(){ |
|
1205 | + return $this->queryCount; |
|
1206 | + } |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * Return the current query SQL string |
|
1210 | + * @return string |
|
1211 | + */ |
|
1212 | + public function getQuery(){ |
|
1213 | + return $this->query; |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Return the application database name |
|
1218 | + * @return string |
|
1219 | + */ |
|
1220 | + public function getDatabaseName(){ |
|
1221 | + return $this->databaseName; |
|
1222 | + } |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * Return the database configuration |
|
1226 | + * @return array |
|
1227 | + */ |
|
1228 | + public static function getDatabaseConfiguration(){ |
|
1229 | + return static::$config; |
|
1230 | + } |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * Return the PDO instance |
|
1234 | + * @return PDO |
|
1235 | + */ |
|
1236 | + public function getPdo(){ |
|
1237 | + return $this->pdo; |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Return the data to be used for insert, update, etc. |
|
1242 | + * @return array |
|
1243 | + */ |
|
1244 | + public function getData(){ |
|
1245 | + return $this->data; |
|
1246 | + } |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Set the data to be used for insert, update, etc. |
|
1250 | + * @param string $key the data key identified |
|
1251 | + * @param mixed $value the data value |
|
1252 | + * @param boolean $escape whether to escape or not the $value |
|
1253 | + * @return object the current Database instance |
|
1254 | + */ |
|
1255 | + public function setData($key, $value, $escape = true){ |
|
1256 | + $this->data[$key] = $escape ? $this->escape($value) : $value; |
|
1257 | + return $this; |
|
1258 | + } |
|
1259 | 1259 | |
1260 | 1260 | |
1261 | 1261 | /** |
1262 | 1262 | * Reset the database class attributs to the initail values before each query. |
1263 | 1263 | */ |
1264 | 1264 | private function reset(){ |
1265 | - $this->select = '*'; |
|
1266 | - $this->from = null; |
|
1267 | - $this->where = null; |
|
1268 | - $this->limit = null; |
|
1269 | - $this->orderBy = null; |
|
1270 | - $this->groupBy = null; |
|
1271 | - $this->having = null; |
|
1272 | - $this->join = null; |
|
1273 | - $this->numRows = 0; |
|
1274 | - $this->insertId = null; |
|
1275 | - $this->query = null; |
|
1276 | - $this->error = null; |
|
1277 | - $this->result = array(); |
|
1278 | - $this->data = array(); |
|
1265 | + $this->select = '*'; |
|
1266 | + $this->from = null; |
|
1267 | + $this->where = null; |
|
1268 | + $this->limit = null; |
|
1269 | + $this->orderBy = null; |
|
1270 | + $this->groupBy = null; |
|
1271 | + $this->having = null; |
|
1272 | + $this->join = null; |
|
1273 | + $this->numRows = 0; |
|
1274 | + $this->insertId = null; |
|
1275 | + $this->query = null; |
|
1276 | + $this->error = null; |
|
1277 | + $this->result = array(); |
|
1278 | + $this->data = array(); |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | 1281 | /** |
1282 | 1282 | * The class destructor |
1283 | 1283 | */ |
1284 | 1284 | function __destruct(){ |
1285 | - $this->pdo = null; |
|
1285 | + $this->pdo = null; |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | } |
@@ -23,165 +23,165 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Database{ |
|
26 | + class Database { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * The PDO instance |
30 | 30 | * @var object |
31 | 31 | */ |
32 | - private $pdo = null; |
|
32 | + private $pdo = null; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * The database name used for the application |
36 | 36 | * @var string |
37 | 37 | */ |
38 | - private $databaseName = null; |
|
38 | + private $databaseName = null; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * The SQL SELECT statment |
42 | 42 | * @var string |
43 | 43 | */ |
44 | - private $select = '*'; |
|
44 | + private $select = '*'; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * The SQL FROM statment |
48 | 48 | * @var string |
49 | 49 | */ |
50 | - private $from = null; |
|
50 | + private $from = null; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * The SQL WHERE statment |
54 | 54 | * @var string |
55 | 55 | */ |
56 | - private $where = null; |
|
56 | + private $where = null; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * The SQL LIMIT statment |
60 | 60 | * @var string |
61 | 61 | */ |
62 | - private $limit = null; |
|
62 | + private $limit = null; |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * The SQL JOIN statment |
66 | 66 | * @var string |
67 | 67 | */ |
68 | - private $join = null; |
|
68 | + private $join = null; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * The SQL ORDER BY statment |
72 | 72 | * @var string |
73 | 73 | */ |
74 | - private $orderBy = null; |
|
74 | + private $orderBy = null; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * The SQL GROUP BY statment |
78 | 78 | * @var string |
79 | 79 | */ |
80 | - private $groupBy = null; |
|
80 | + private $groupBy = null; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * The SQL HAVING statment |
84 | 84 | * @var string |
85 | 85 | */ |
86 | - private $having = null; |
|
86 | + private $having = null; |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * The number of rows returned by the last query |
90 | 90 | * @var int |
91 | 91 | */ |
92 | - private $numRows = 0; |
|
92 | + private $numRows = 0; |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * The last insert id for the primary key column that have auto increment or sequence |
96 | 96 | * @var mixed |
97 | 97 | */ |
98 | - private $insertId = null; |
|
98 | + private $insertId = null; |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * The full SQL query statment after build for each command |
102 | 102 | * @var string |
103 | 103 | */ |
104 | - private $query = null; |
|
104 | + private $query = null; |
|
105 | 105 | |
106 | 106 | /** |
107 | 107 | * The error returned for the last query |
108 | 108 | * @var string |
109 | 109 | */ |
110 | - private $error = null; |
|
110 | + private $error = null; |
|
111 | 111 | |
112 | 112 | /** |
113 | 113 | * The result returned for the last query |
114 | 114 | * @var mixed |
115 | 115 | */ |
116 | - private $result = array(); |
|
116 | + private $result = array(); |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * The prefix used in each database table |
120 | 120 | * @var string |
121 | 121 | */ |
122 | - private $prefix = null; |
|
122 | + private $prefix = null; |
|
123 | 123 | |
124 | 124 | /** |
125 | 125 | * The list of SQL valid operators |
126 | 126 | * @var array |
127 | 127 | */ |
128 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
128 | + private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>'); |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * The cache default time to live in second. 0 means no need to use the cache feature |
132 | 132 | * @var int |
133 | 133 | */ |
134 | - private $cacheTtl = 0; |
|
134 | + private $cacheTtl = 0; |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * The cache current time to live. 0 means no need to use the cache feature |
138 | 138 | * @var int |
139 | 139 | */ |
140 | - private $temporaryCacheTtl = 0; |
|
140 | + private $temporaryCacheTtl = 0; |
|
141 | 141 | |
142 | 142 | /** |
143 | 143 | * The number of executed query for the current request |
144 | 144 | * @var int |
145 | 145 | */ |
146 | - private $queryCount = 0; |
|
146 | + private $queryCount = 0; |
|
147 | 147 | |
148 | 148 | /** |
149 | 149 | * The default data to be used in the statments query INSERT, UPDATE |
150 | 150 | * @var array |
151 | 151 | */ |
152 | - private $data = array(); |
|
152 | + private $data = array(); |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * The database configuration |
156 | 156 | * @var array |
157 | 157 | */ |
158 | - private static $config = array(); |
|
158 | + private static $config = array(); |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * The logger instance |
162 | 162 | * @var Log |
163 | 163 | */ |
164 | - private $logger = null; |
|
164 | + private $logger = null; |
|
165 | 165 | |
166 | 166 | /** |
167 | 167 | * Construct new database |
168 | 168 | * @param array $overwriteConfig the config to overwrite with the config set in database.php |
169 | 169 | */ |
170 | - public function __construct($overwriteConfig = array()){ |
|
170 | + public function __construct($overwriteConfig = array()) { |
|
171 | 171 | /** |
172 | 172 | * instance of the Log class |
173 | 173 | */ |
174 | - $this->logger =& class_loader('Log', 'classes'); |
|
174 | + $this->logger = & class_loader('Log', 'classes'); |
|
175 | 175 | $this->logger->setLogger('Library::Database'); |
176 | 176 | |
177 | - if(file_exists(CONFIG_PATH . 'database.php')){ |
|
177 | + if (file_exists(CONFIG_PATH . 'database.php')) { |
|
178 | 178 | //here don't use require_once because somewhere user can create database instance directly |
179 | 179 | require CONFIG_PATH . 'database.php'; |
180 | - if(empty($db) || !is_array($db)){ |
|
180 | + if (empty($db) || !is_array($db)) { |
|
181 | 181 | show_error('No database configuration found in database.php'); |
182 | 182 | } |
183 | - else{ |
|
184 | - if(! empty($overwriteConfig)){ |
|
183 | + else { |
|
184 | + if (!empty($overwriteConfig)) { |
|
185 | 185 | $db = array_merge($db, $overwriteConfig); |
186 | 186 | } |
187 | 187 | $config['driver'] = isset($db['driver']) ? $db['driver'] : 'mysql'; |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | $this->databaseName = $config['database']; |
198 | 198 | |
199 | 199 | $dsn = ''; |
200 | - if($config['driver'] == 'mysql' || $config['driver'] == '' || $config['driver'] == 'pgsql'){ |
|
200 | + if ($config['driver'] == 'mysql' || $config['driver'] == '' || $config['driver'] == 'pgsql') { |
|
201 | 201 | $dsn = $config['driver'] . ':host=' . $config['hostname'] . ';' |
202 | 202 | . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') |
203 | 203 | . 'dbname=' . $config['database']; |
204 | 204 | } |
205 | - else if ($config['driver'] == 'sqlite'){ |
|
205 | + else if ($config['driver'] == 'sqlite') { |
|
206 | 206 | $dsn = 'sqlite:' . $config['database']; |
207 | 207 | } |
208 | - else if($config['driver'] == 'oracle'){ |
|
208 | + else if ($config['driver'] == 'oracle') { |
|
209 | 209 | $dsn = 'oci:dbname=' . $config['host'] . '/' . $config['database']; |
210 | 210 | } |
211 | 211 | |
212 | - try{ |
|
212 | + try { |
|
213 | 213 | $this->pdo = new PDO($dsn, $config['username'], $config['password']); |
214 | 214 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
215 | 215 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
216 | 216 | $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
217 | 217 | } |
218 | - catch (PDOException $e){ |
|
218 | + catch (PDOException $e) { |
|
219 | 219 | $this->logger->fatal($e->getMessage()); |
220 | 220 | show_error('Cannot connect to Database.'); |
221 | 221 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $this->logger->info('The database configuration are listed below: ' . stringfy_vars(array_merge($config, array('password' => string_hidden($config['password']))))); |
225 | 225 | } |
226 | 226 | } |
227 | - else{ |
|
227 | + else { |
|
228 | 228 | show_error('Unable to find database configuration'); |
229 | 229 | } |
230 | 230 | } |
@@ -234,15 +234,15 @@ discard block |
||
234 | 234 | * @param string|array $table the table name or array of table list |
235 | 235 | * @return object the current Database instance |
236 | 236 | */ |
237 | - public function from($table){ |
|
238 | - if(is_array($table)){ |
|
237 | + public function from($table) { |
|
238 | + if (is_array($table)) { |
|
239 | 239 | $froms = ''; |
240 | - foreach($table as $key){ |
|
240 | + foreach ($table as $key) { |
|
241 | 241 | $froms .= $this->prefix . $key . ', '; |
242 | 242 | } |
243 | 243 | $this->from = rtrim($froms, ', '); |
244 | 244 | } |
245 | - else{ |
|
245 | + else { |
|
246 | 246 | $this->from = $this->prefix . $table; |
247 | 247 | } |
248 | 248 | return $this; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param string|array $fields the field name or array of field list |
254 | 254 | * @return object the current Database instance |
255 | 255 | */ |
256 | - public function select($fields){ |
|
256 | + public function select($fields) { |
|
257 | 257 | $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
258 | 258 | $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select); |
259 | 259 | return $this; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param string $field the field name to distinct |
265 | 265 | * @return object the current Database instance |
266 | 266 | */ |
267 | - public function distinct($field){ |
|
267 | + public function distinct($field) { |
|
268 | 268 | $distinct = ' DISTINCT ' . $field; |
269 | 269 | $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct); |
270 | 270 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param string $name if is not null represent the alias used for this field in the result |
278 | 278 | * @return object the current Database instance |
279 | 279 | */ |
280 | - public function max($field, $name = null){ |
|
280 | + public function max($field, $name = null) { |
|
281 | 281 | $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
282 | 282 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
283 | 283 | return $this; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param string $name if is not null represent the alias used for this field in the result |
290 | 290 | * @return object the current Database instance |
291 | 291 | */ |
292 | - public function min($field, $name = null){ |
|
292 | + public function min($field, $name = null) { |
|
293 | 293 | $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
294 | 294 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
295 | 295 | return $this; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param string $name if is not null represent the alias used for this field in the result |
302 | 302 | * @return object the current Database instance |
303 | 303 | */ |
304 | - public function sum($field, $name = null){ |
|
304 | + public function sum($field, $name = null) { |
|
305 | 305 | $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
306 | 306 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
307 | 307 | return $this; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * @param string $name if is not null represent the alias used for this field in the result |
314 | 314 | * @return object the current Database instance |
315 | 315 | */ |
316 | - public function count($field = '*', $name = null){ |
|
316 | + public function count($field = '*', $name = null) { |
|
317 | 317 | $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
318 | 318 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
319 | 319 | return $this; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $name if is not null represent the alias used for this field in the result |
326 | 326 | * @return object the current Database instance |
327 | 327 | */ |
328 | - public function avg($field, $name = null){ |
|
328 | + public function avg($field, $name = null) { |
|
329 | 329 | $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
330 | 330 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
331 | 331 | return $this; |
@@ -340,16 +340,16 @@ discard block |
||
340 | 340 | * @param string $type the type of join (INNER, LEFT, RIGHT) |
341 | 341 | * @return object the current Database instance |
342 | 342 | */ |
343 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
343 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') { |
|
344 | 344 | $on = $field1; |
345 | 345 | $table = $this->prefix . $table; |
346 | - if(! is_null($op)){ |
|
347 | - $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
346 | + if (!is_null($op)) { |
|
347 | + $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
348 | 348 | } |
349 | - if (is_null($this->join)){ |
|
349 | + if (is_null($this->join)) { |
|
350 | 350 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
351 | 351 | } |
352 | - else{ |
|
352 | + else { |
|
353 | 353 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
354 | 354 | } |
355 | 355 | return $this; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @see Database::join() |
361 | 361 | * @return object the current Database instance |
362 | 362 | */ |
363 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
363 | + public function innerJoin($table, $field1, $op = null, $field2 = '') { |
|
364 | 364 | return $this->join($table, $field1, $op, $field2, 'INNER '); |
365 | 365 | } |
366 | 366 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @see Database::join() |
370 | 370 | * @return object the current Database instance |
371 | 371 | */ |
372 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
372 | + public function leftJoin($table, $field1, $op = null, $field2 = '') { |
|
373 | 373 | return $this->join($table, $field1, $op, $field2, 'LEFT '); |
374 | 374 | } |
375 | 375 | |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @see Database::join() |
379 | 379 | * @return object the current Database instance |
380 | 380 | */ |
381 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
381 | + public function rightJoin($table, $field1, $op = null, $field2 = '') { |
|
382 | 382 | return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
383 | 383 | } |
384 | 384 | |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @see Database::join() |
388 | 388 | * @return object the current Database instance |
389 | 389 | */ |
390 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
390 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
391 | 391 | return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
392 | 392 | } |
393 | 393 | |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @see Database::join() |
397 | 397 | * @return object the current Database instance |
398 | 398 | */ |
399 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
399 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
400 | 400 | return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
401 | 401 | } |
402 | 402 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @see Database::join() |
406 | 406 | * @return object the current Database instance |
407 | 407 | */ |
408 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
408 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
409 | 409 | return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
410 | 410 | } |
411 | 411 | |
@@ -415,18 +415,18 @@ discard block |
||
415 | 415 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
416 | 416 | * @return object the current Database instance |
417 | 417 | */ |
418 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
419 | - if(is_array($field)){ |
|
420 | - foreach($field as $f){ |
|
418 | + public function whereIsNull($field, $andOr = 'AND') { |
|
419 | + if (is_array($field)) { |
|
420 | + foreach ($field as $f) { |
|
421 | 421 | $this->whereIsNull($f, $andOr); |
422 | 422 | } |
423 | 423 | } |
424 | - else{ |
|
425 | - if (! $this->where){ |
|
426 | - $this->where = $field.' IS NULL '; |
|
424 | + else { |
|
425 | + if (!$this->where) { |
|
426 | + $this->where = $field . ' IS NULL '; |
|
427 | 427 | } |
428 | - else{ |
|
429 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
|
428 | + else { |
|
429 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NULL '; |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | return $this; |
@@ -438,18 +438,18 @@ discard block |
||
438 | 438 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
439 | 439 | * @return object the current Database instance |
440 | 440 | */ |
441 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
442 | - if(is_array($field)){ |
|
443 | - foreach($field as $f){ |
|
441 | + public function whereIsNotNull($field, $andOr = 'AND') { |
|
442 | + if (is_array($field)) { |
|
443 | + foreach ($field as $f) { |
|
444 | 444 | $this->whereIsNotNull($f, $andOr); |
445 | 445 | } |
446 | 446 | } |
447 | - else{ |
|
448 | - if (! $this->where){ |
|
449 | - $this->where = $field.' IS NOT NULL '; |
|
447 | + else { |
|
448 | + if (!$this->where) { |
|
449 | + $this->where = $field . ' IS NOT NULL '; |
|
450 | 450 | } |
451 | - else{ |
|
452 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
|
451 | + else { |
|
452 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NOT NULL '; |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | return $this; |
@@ -465,24 +465,24 @@ discard block |
||
465 | 465 | * @param boolean $escape whether to escape or not the $val |
466 | 466 | * @return object the current Database instance |
467 | 467 | */ |
468 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
469 | - if (is_array($where)){ |
|
468 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) { |
|
469 | + if (is_array($where)) { |
|
470 | 470 | $_where = array(); |
471 | - foreach ($where as $column => $data){ |
|
472 | - if(is_null($data)){ |
|
471 | + foreach ($where as $column => $data) { |
|
472 | + if (is_null($data)) { |
|
473 | 473 | $data = ''; |
474 | 474 | } |
475 | 475 | $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data); |
476 | 476 | } |
477 | - $where = implode(' '.$andOr.' ', $_where); |
|
477 | + $where = implode(' ' . $andOr . ' ', $_where); |
|
478 | 478 | } |
479 | - else{ |
|
480 | - if(is_array($op)){ |
|
479 | + else { |
|
480 | + if (is_array($op)) { |
|
481 | 481 | $x = explode('?', $where); |
482 | 482 | $w = ''; |
483 | - foreach($x as $k => $v){ |
|
484 | - if(! empty($v)){ |
|
485 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
483 | + foreach ($x as $k => $v) { |
|
484 | + if (!empty($v)) { |
|
485 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
486 | 486 | $op[$k] = ''; |
487 | 487 | } |
488 | 488 | $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
@@ -490,28 +490,28 @@ discard block |
||
490 | 490 | } |
491 | 491 | $where = $w; |
492 | 492 | } |
493 | - else if (! in_array((string)$op, $this->operatorList)){ |
|
494 | - if(is_null($op)){ |
|
493 | + else if (!in_array((string) $op, $this->operatorList)) { |
|
494 | + if (is_null($op)) { |
|
495 | 495 | $op = ''; |
496 | 496 | } |
497 | 497 | $where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
498 | 498 | } |
499 | - else{ |
|
500 | - if(is_null($val)){ |
|
499 | + else { |
|
500 | + if (is_null($val)) { |
|
501 | 501 | $val = ''; |
502 | 502 | } |
503 | 503 | $where = $type . $where . $op . ($escape ? $this->escape($val) : $val); |
504 | 504 | } |
505 | 505 | } |
506 | - if (is_null($this->where)){ |
|
506 | + if (is_null($this->where)) { |
|
507 | 507 | $this->where = $where; |
508 | 508 | } |
509 | - else{ |
|
510 | - if(substr($this->where, -1) == '('){ |
|
509 | + else { |
|
510 | + if (substr($this->where, -1) == '(') { |
|
511 | 511 | $this->where = $this->where . ' ' . $where; |
512 | 512 | } |
513 | - else{ |
|
514 | - $this->where = $this->where . ' '.$andOr.' ' . $where; |
|
513 | + else { |
|
514 | + $this->where = $this->where . ' ' . $andOr . ' ' . $where; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | return $this; |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | * @see Database::where() |
523 | 523 | * @return object the current Database instance |
524 | 524 | */ |
525 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
525 | + public function orWhere($where, $op = null, $val = null, $escape = true) { |
|
526 | 526 | return $this->where($where, $op, $val, '', 'OR', $escape); |
527 | 527 | } |
528 | 528 | |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | * @see Database::where() |
533 | 533 | * @return object the current Database instance |
534 | 534 | */ |
535 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
535 | + public function notWhere($where, $op = null, $val = null, $escape = true) { |
|
536 | 536 | return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
537 | 537 | } |
538 | 538 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @see Database::where() |
542 | 542 | * @return object the current Database instance |
543 | 543 | */ |
544 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
544 | + public function orNotWhere($where, $op = null, $val = null, $escape = true) { |
|
545 | 545 | return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
546 | 546 | } |
547 | 547 | |
@@ -551,15 +551,15 @@ discard block |
||
551 | 551 | * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
552 | 552 | * @return object the current Database instance |
553 | 553 | */ |
554 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
555 | - if (is_null($this->where)){ |
|
554 | + public function groupStart($type = '', $andOr = ' AND') { |
|
555 | + if (is_null($this->where)) { |
|
556 | 556 | $this->where = $type . ' ('; |
557 | 557 | } |
558 | - else{ |
|
559 | - if(substr($this->where, -1) == '('){ |
|
558 | + else { |
|
559 | + if (substr($this->where, -1) == '(') { |
|
560 | 560 | $this->where .= $type . ' ('; |
561 | 561 | } |
562 | - else{ |
|
562 | + else { |
|
563 | 563 | $this->where .= $andOr . ' ' . $type . ' ('; |
564 | 564 | } |
565 | 565 | } |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | * @see Database::groupStart() |
572 | 572 | * @return object the current Database instance |
573 | 573 | */ |
574 | - public function notGroupStart(){ |
|
574 | + public function notGroupStart() { |
|
575 | 575 | return $this->groupStart('NOT'); |
576 | 576 | } |
577 | 577 | |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @see Database::groupStart() |
581 | 581 | * @return object the current Database instance |
582 | 582 | */ |
583 | - public function orGroupStart(){ |
|
583 | + public function orGroupStart() { |
|
584 | 584 | return $this->groupStart('', ' OR'); |
585 | 585 | } |
586 | 586 | |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | * @see Database::groupStart() |
590 | 590 | * @return object the current Database instance |
591 | 591 | */ |
592 | - public function orNotGroupStart(){ |
|
592 | + public function orNotGroupStart() { |
|
593 | 593 | return $this->groupStart('NOT', ' OR'); |
594 | 594 | } |
595 | 595 | |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | * Close the parenthesis for the grouped SQL |
598 | 598 | * @return object the current Database instance |
599 | 599 | */ |
600 | - public function groupEnd(){ |
|
600 | + public function groupEnd() { |
|
601 | 601 | $this->where .= ')'; |
602 | 602 | return $this; |
603 | 603 | } |
@@ -611,25 +611,25 @@ discard block |
||
611 | 611 | * @param boolean $escape whether to escape or not the values |
612 | 612 | * @return object the current Database instance |
613 | 613 | */ |
614 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
615 | - if (is_array($keys)){ |
|
614 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) { |
|
615 | + if (is_array($keys)) { |
|
616 | 616 | $_keys = array(); |
617 | - foreach ($keys as $k => $v){ |
|
618 | - if(is_null($v)){ |
|
617 | + foreach ($keys as $k => $v) { |
|
618 | + if (is_null($v)) { |
|
619 | 619 | $v = ''; |
620 | 620 | } |
621 | 621 | $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v)); |
622 | 622 | } |
623 | 623 | $keys = implode(', ', $_keys); |
624 | - if (is_null($this->where)){ |
|
624 | + if (is_null($this->where)) { |
|
625 | 625 | $this->where = $field . ' ' . $type . 'IN (' . $keys . ')'; |
626 | 626 | } |
627 | - else{ |
|
628 | - if(substr($this->where, -1) == '('){ |
|
629 | - $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
627 | + else { |
|
628 | + if (substr($this->where, -1) == '(') { |
|
629 | + $this->where = $this->where . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
630 | 630 | } |
631 | - else{ |
|
632 | - $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
631 | + else { |
|
632 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
633 | 633 | } |
634 | 634 | } |
635 | 635 | } |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | * @see Database::in() |
642 | 642 | * @return object the current Database instance |
643 | 643 | */ |
644 | - public function notIn($field, array $keys, $escape = true){ |
|
644 | + public function notIn($field, array $keys, $escape = true) { |
|
645 | 645 | return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
646 | 646 | } |
647 | 647 | |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @see Database::in() |
651 | 651 | * @return object the current Database instance |
652 | 652 | */ |
653 | - public function orIn($field, array $keys, $escape = true){ |
|
653 | + public function orIn($field, array $keys, $escape = true) { |
|
654 | 654 | return $this->in($field, $keys, '', 'OR', $escape); |
655 | 655 | } |
656 | 656 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | * @see Database::in() |
660 | 660 | * @return object the current Database instance |
661 | 661 | */ |
662 | - public function orNotIn($field, array $keys, $escape = true){ |
|
662 | + public function orNotIn($field, array $keys, $escape = true) { |
|
663 | 663 | return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
664 | 664 | } |
665 | 665 | |
@@ -673,21 +673,21 @@ discard block |
||
673 | 673 | * @param boolean $escape whether to escape or not the values |
674 | 674 | * @return object the current Database instance |
675 | 675 | */ |
676 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
677 | - if(is_null($value1)){ |
|
676 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) { |
|
677 | + if (is_null($value1)) { |
|
678 | 678 | $value1 = ''; |
679 | 679 | } |
680 | - if(is_null($value2)){ |
|
680 | + if (is_null($value2)) { |
|
681 | 681 | $value2 = ''; |
682 | 682 | } |
683 | - if (is_null($this->where)){ |
|
683 | + if (is_null($this->where)) { |
|
684 | 684 | $this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
685 | 685 | } |
686 | - else{ |
|
687 | - if(substr($this->where, -1) == '('){ |
|
686 | + else { |
|
687 | + if (substr($this->where, -1) == '(') { |
|
688 | 688 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
689 | 689 | } |
690 | - else{ |
|
690 | + else { |
|
691 | 691 | $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
692 | 692 | } |
693 | 693 | } |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | * @see Database::between() |
700 | 700 | * @return object the current Database instance |
701 | 701 | */ |
702 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
702 | + public function notBetween($field, $value1, $value2, $escape = true) { |
|
703 | 703 | return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
704 | 704 | } |
705 | 705 | |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | * @see Database::between() |
709 | 709 | * @return object the current Database instance |
710 | 710 | */ |
711 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
711 | + public function orBetween($field, $value1, $value2, $escape = true) { |
|
712 | 712 | return $this->between($field, $value1, $value2, '', 'OR', $escape); |
713 | 713 | } |
714 | 714 | |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | * @see Database::between() |
718 | 718 | * @return object the current Database instance |
719 | 719 | */ |
720 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
720 | + public function orNotBetween($field, $value1, $value2, $escape = true) { |
|
721 | 721 | return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
722 | 722 | } |
723 | 723 | |
@@ -730,20 +730,20 @@ discard block |
||
730 | 730 | * @param boolean $escape whether to escape or not the values |
731 | 731 | * @return object the current Database instance |
732 | 732 | */ |
733 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
734 | - if(is_null($data)){ |
|
733 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) { |
|
734 | + if (is_null($data)) { |
|
735 | 735 | $data = ''; |
736 | 736 | } |
737 | 737 | $like = $escape ? $this->escape($data) : $data; |
738 | - if (is_null($this->where)){ |
|
738 | + if (is_null($this->where)) { |
|
739 | 739 | $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
740 | 740 | } |
741 | - else{ |
|
742 | - if(substr($this->where, -1) == '('){ |
|
741 | + else { |
|
742 | + if (substr($this->where, -1) == '(') { |
|
743 | 743 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
744 | 744 | } |
745 | - else{ |
|
746 | - $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
745 | + else { |
|
746 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
747 | 747 | } |
748 | 748 | } |
749 | 749 | return $this; |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | * @see Database::like() |
755 | 755 | * @return object the current Database instance |
756 | 756 | */ |
757 | - public function orLike($field, $data, $escape = true){ |
|
757 | + public function orLike($field, $data, $escape = true) { |
|
758 | 758 | return $this->like($field, $data, '', 'OR', $escape); |
759 | 759 | } |
760 | 760 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | * @see Database::like() |
764 | 764 | * @return object the current Database instance |
765 | 765 | */ |
766 | - public function notLike($field, $data, $escape = true){ |
|
766 | + public function notLike($field, $data, $escape = true) { |
|
767 | 767 | return $this->like($field, $data, 'NOT ', 'AND', $escape); |
768 | 768 | } |
769 | 769 | |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | * @see Database::like() |
773 | 773 | * @return object the current Database instance |
774 | 774 | */ |
775 | - public function orNotLike($field, $data, $escape = true){ |
|
775 | + public function orNotLike($field, $data, $escape = true) { |
|
776 | 776 | return $this->like($field, $data, 'NOT ', 'OR', $escape); |
777 | 777 | } |
778 | 778 | |
@@ -783,14 +783,14 @@ discard block |
||
783 | 783 | * @param int $limitEnd the limit count |
784 | 784 | * @return object the current Database instance |
785 | 785 | */ |
786 | - public function limit($limit, $limitEnd = null){ |
|
787 | - if(is_null($limit)){ |
|
786 | + public function limit($limit, $limitEnd = null) { |
|
787 | + if (is_null($limit)) { |
|
788 | 788 | return; |
789 | 789 | } |
790 | - if (! is_null($limitEnd)){ |
|
790 | + if (!is_null($limitEnd)) { |
|
791 | 791 | $this->limit = $limit . ', ' . $limitEnd; |
792 | 792 | } |
793 | - else{ |
|
793 | + else { |
|
794 | 794 | $this->limit = $limit; |
795 | 795 | } |
796 | 796 | return $this; |
@@ -802,16 +802,16 @@ discard block |
||
802 | 802 | * @param string $orderDir the order direction (ASC or DESC) |
803 | 803 | * @return object the current Database instance |
804 | 804 | */ |
805 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
806 | - if (! is_null($orderDir)){ |
|
807 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
805 | + public function orderBy($orderBy, $orderDir = ' ASC') { |
|
806 | + if (!is_null($orderDir)) { |
|
807 | + $this->orderBy = !$this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
808 | 808 | } |
809 | - else{ |
|
810 | - if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
811 | - $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
809 | + else { |
|
810 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()') { |
|
811 | + $this->orderBy = !$this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
812 | 812 | } |
813 | - else{ |
|
814 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
813 | + else { |
|
814 | + $this->orderBy = !$this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
815 | 815 | } |
816 | 816 | } |
817 | 817 | return $this; |
@@ -822,11 +822,11 @@ discard block |
||
822 | 822 | * @param string|array $field the field name used or array of field list |
823 | 823 | * @return object the current Database instance |
824 | 824 | */ |
825 | - public function groupBy($field){ |
|
826 | - if(is_array($field)){ |
|
825 | + public function groupBy($field) { |
|
826 | + if (is_array($field)) { |
|
827 | 827 | $this->groupBy = implode(', ', $field); |
828 | 828 | } |
829 | - else{ |
|
829 | + else { |
|
830 | 830 | $this->groupBy = $field; |
831 | 831 | } |
832 | 832 | return $this; |
@@ -840,13 +840,13 @@ discard block |
||
840 | 840 | * @param boolean $escape whether to escape or not the values |
841 | 841 | * @return object the current Database instance |
842 | 842 | */ |
843 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
844 | - if(is_array($op)){ |
|
843 | + public function having($field, $op = null, $val = null, $escape = true) { |
|
844 | + if (is_array($op)) { |
|
845 | 845 | $x = explode('?', $field); |
846 | 846 | $w = ''; |
847 | - foreach($x as $k => $v){ |
|
848 | - if(!empty($v)){ |
|
849 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
847 | + foreach ($x as $k => $v) { |
|
848 | + if (!empty($v)) { |
|
849 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
850 | 850 | $op[$k] = ''; |
851 | 851 | } |
852 | 852 | $w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
@@ -854,14 +854,14 @@ discard block |
||
854 | 854 | } |
855 | 855 | $this->having = $w; |
856 | 856 | } |
857 | - else if (! in_array($op, $this->operatorList)){ |
|
858 | - if(is_null($op)){ |
|
857 | + else if (!in_array($op, $this->operatorList)) { |
|
858 | + if (is_null($op)) { |
|
859 | 859 | $op = ''; |
860 | 860 | } |
861 | 861 | $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
862 | 862 | } |
863 | - else{ |
|
864 | - if(is_null($val)){ |
|
863 | + else { |
|
864 | + if (is_null($val)) { |
|
865 | 865 | $val = ''; |
866 | 866 | } |
867 | 867 | $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val); |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | * Return the number of rows returned by the current query |
874 | 874 | * @return int |
875 | 875 | */ |
876 | - public function numRows(){ |
|
876 | + public function numRows() { |
|
877 | 877 | return $this->numRows; |
878 | 878 | } |
879 | 879 | |
@@ -881,15 +881,15 @@ discard block |
||
881 | 881 | * Return the last insert id value |
882 | 882 | * @return mixed |
883 | 883 | */ |
884 | - public function insertId(){ |
|
884 | + public function insertId() { |
|
885 | 885 | return $this->insertId; |
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
889 | 889 | * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.) |
890 | 890 | */ |
891 | - public function error(){ |
|
892 | - if($this->error){ |
|
891 | + public function error() { |
|
892 | + if ($this->error) { |
|
893 | 893 | show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error'); |
894 | 894 | } |
895 | 895 | } |
@@ -900,14 +900,14 @@ discard block |
||
900 | 900 | * If is string will determine the result type "array" or "object" |
901 | 901 | * @return mixed the query SQL string or the record result |
902 | 902 | */ |
903 | - public function get($returnSQLQueryOrResultType = false){ |
|
903 | + public function get($returnSQLQueryOrResultType = false) { |
|
904 | 904 | $this->limit = 1; |
905 | 905 | $query = $this->getAll(true); |
906 | - if($returnSQLQueryOrResultType === true){ |
|
906 | + if ($returnSQLQueryOrResultType === true) { |
|
907 | 907 | return $query; |
908 | 908 | } |
909 | - else{ |
|
910 | - return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
909 | + else { |
|
910 | + return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false)); |
|
911 | 911 | } |
912 | 912 | } |
913 | 913 | |
@@ -917,37 +917,37 @@ discard block |
||
917 | 917 | * If is string will determine the result type "array" or "object" |
918 | 918 | * @return mixed the query SQL string or the record result |
919 | 919 | */ |
920 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
920 | + public function getAll($returnSQLQueryOrResultType = false) { |
|
921 | 921 | $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
922 | - if (! is_null($this->join)){ |
|
922 | + if (!is_null($this->join)) { |
|
923 | 923 | $query .= $this->join; |
924 | 924 | } |
925 | 925 | |
926 | - if (! is_null($this->where)){ |
|
926 | + if (!is_null($this->where)) { |
|
927 | 927 | $query .= ' WHERE ' . $this->where; |
928 | 928 | } |
929 | 929 | |
930 | - if (! is_null($this->groupBy)){ |
|
930 | + if (!is_null($this->groupBy)) { |
|
931 | 931 | $query .= ' GROUP BY ' . $this->groupBy; |
932 | 932 | } |
933 | 933 | |
934 | - if (! is_null($this->having)){ |
|
934 | + if (!is_null($this->having)) { |
|
935 | 935 | $query .= ' HAVING ' . $this->having; |
936 | 936 | } |
937 | 937 | |
938 | - if (! is_null($this->orderBy)){ |
|
938 | + if (!is_null($this->orderBy)) { |
|
939 | 939 | $query .= ' ORDER BY ' . $this->orderBy; |
940 | 940 | } |
941 | 941 | |
942 | - if(! is_null($this->limit)){ |
|
942 | + if (!is_null($this->limit)) { |
|
943 | 943 | $query .= ' LIMIT ' . $this->limit; |
944 | 944 | } |
945 | 945 | |
946 | - if($returnSQLQueryOrResultType === true){ |
|
946 | + if ($returnSQLQueryOrResultType === true) { |
|
947 | 947 | return $query; |
948 | 948 | } |
949 | - else{ |
|
950 | - return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
949 | + else { |
|
950 | + return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false)); |
|
951 | 951 | } |
952 | 952 | } |
953 | 953 | |
@@ -957,15 +957,15 @@ discard block |
||
957 | 957 | * @param boolean $escape whether to escape or not the values |
958 | 958 | * @return mixed the insert id of the new record or null |
959 | 959 | */ |
960 | - public function insert($data = array(), $escape = true){ |
|
960 | + public function insert($data = array(), $escape = true) { |
|
961 | 961 | $column = array(); |
962 | 962 | $val = array(); |
963 | - if(! $data && $this->getData()){ |
|
963 | + if (!$data && $this->getData()) { |
|
964 | 964 | $columns = array_keys($this->getData()); |
965 | 965 | $column = implode(',', $columns); |
966 | 966 | $val = implode(', ', $this->getData()); |
967 | 967 | } |
968 | - else{ |
|
968 | + else { |
|
969 | 969 | $columns = array_keys($data); |
970 | 970 | $column = implode(',', $columns); |
971 | 971 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -974,11 +974,11 @@ discard block |
||
974 | 974 | $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
975 | 975 | $query = $this->query($query); |
976 | 976 | |
977 | - if ($query){ |
|
977 | + if ($query) { |
|
978 | 978 | $this->insertId = $this->pdo->lastInsertId(); |
979 | 979 | return $this->insertId(); |
980 | 980 | } |
981 | - else{ |
|
981 | + else { |
|
982 | 982 | return false; |
983 | 983 | } |
984 | 984 | } |
@@ -989,29 +989,29 @@ discard block |
||
989 | 989 | * @param boolean $escape whether to escape or not the values |
990 | 990 | * @return mixed the update status |
991 | 991 | */ |
992 | - public function update($data = array(), $escape = true){ |
|
992 | + public function update($data = array(), $escape = true) { |
|
993 | 993 | $query = 'UPDATE ' . $this->from . ' SET '; |
994 | 994 | $values = array(); |
995 | - if(! $data && $this->getData()){ |
|
996 | - foreach ($this->getData() as $column => $val){ |
|
995 | + if (!$data && $this->getData()) { |
|
996 | + foreach ($this->getData() as $column => $val) { |
|
997 | 997 | $values[] = $column . ' = ' . $val; |
998 | 998 | } |
999 | 999 | } |
1000 | - else{ |
|
1001 | - foreach ($data as $column => $val){ |
|
1000 | + else { |
|
1001 | + foreach ($data as $column => $val) { |
|
1002 | 1002 | $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
1003 | 1003 | } |
1004 | 1004 | } |
1005 | 1005 | $query .= (is_array($data) ? implode(', ', $values) : $data); |
1006 | - if (! is_null($this->where)){ |
|
1006 | + if (!is_null($this->where)) { |
|
1007 | 1007 | $query .= ' WHERE ' . $this->where; |
1008 | 1008 | } |
1009 | 1009 | |
1010 | - if (! is_null($this->orderBy)){ |
|
1010 | + if (!is_null($this->orderBy)) { |
|
1011 | 1011 | $query .= ' ORDER BY ' . $this->orderBy; |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - if (! is_null($this->limit)){ |
|
1014 | + if (!is_null($this->limit)) { |
|
1015 | 1015 | $query .= ' LIMIT ' . $this->limit; |
1016 | 1016 | } |
1017 | 1017 | return $this->query($query); |
@@ -1021,22 +1021,22 @@ discard block |
||
1021 | 1021 | * Delete the record in database |
1022 | 1022 | * @return mixed the delete status |
1023 | 1023 | */ |
1024 | - public function delete(){ |
|
1024 | + public function delete() { |
|
1025 | 1025 | $query = 'DELETE FROM ' . $this->from; |
1026 | 1026 | |
1027 | - if (! is_null($this->where)){ |
|
1027 | + if (!is_null($this->where)) { |
|
1028 | 1028 | $query .= ' WHERE ' . $this->where; |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - if (! is_null($this->orderBy)){ |
|
1031 | + if (!is_null($this->orderBy)) { |
|
1032 | 1032 | $query .= ' ORDER BY ' . $this->orderBy; |
1033 | 1033 | } |
1034 | 1034 | |
1035 | - if (! is_null($this->limit)){ |
|
1035 | + if (!is_null($this->limit)) { |
|
1036 | 1036 | $query .= ' LIMIT ' . $this->limit; |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if($query == 'DELETE FROM ' . $this->from){ |
|
1039 | + if ($query == 'DELETE FROM ' . $this->from) { |
|
1040 | 1040 | $query = 'TRUNCATE TABLE ' . $this->from; |
1041 | 1041 | } |
1042 | 1042 | return $this->query($query); |
@@ -1049,13 +1049,13 @@ discard block |
||
1049 | 1049 | * @param boolean $array return the result as array |
1050 | 1050 | * @return mixed the query result |
1051 | 1051 | */ |
1052 | - public function query($query, $all = true, $array = false){ |
|
1052 | + public function query($query, $all = true, $array = false) { |
|
1053 | 1053 | $this->reset(); |
1054 | - if(is_array($all)){ |
|
1054 | + if (is_array($all)) { |
|
1055 | 1055 | $x = explode('?', $query); |
1056 | 1056 | $q = ''; |
1057 | - foreach($x as $k => $v){ |
|
1058 | - if(! empty($v)){ |
|
1057 | + foreach ($x as $k => $v) { |
|
1058 | + if (!empty($v)) { |
|
1059 | 1059 | $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : ''); |
1060 | 1060 | } |
1061 | 1061 | } |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | |
1065 | 1065 | $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
1066 | 1066 | $sqlSELECTQuery = stristr($this->query, 'SELECT'); |
1067 | - $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO')); |
|
1067 | + $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . ($all ? 'YES' : 'NO')); |
|
1068 | 1068 | //cache expire time |
1069 | 1069 | $cacheExpire = $this->temporaryCacheTtl; |
1070 | 1070 | |
@@ -1089,17 +1089,17 @@ discard block |
||
1089 | 1089 | //if can use cache feature for this query |
1090 | 1090 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
1091 | 1091 | |
1092 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1092 | + if ($dbCacheStatus && $sqlSELECTQuery) { |
|
1093 | 1093 | $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
1094 | 1094 | $cacheKey = md5($query . $all . $array); |
1095 | 1095 | $cacheInstance = $obj->cache; |
1096 | 1096 | $cacheContent = $cacheInstance->get($cacheKey); |
1097 | 1097 | } |
1098 | - else{ |
|
1098 | + else { |
|
1099 | 1099 | $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database'); |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if (! $cacheContent && $sqlSELECTQuery){ |
|
1102 | + if (!$cacheContent && $sqlSELECTQuery) { |
|
1103 | 1103 | //for database query execution time |
1104 | 1104 | $benchmarkMarkerKey = md5($query . $all . $array); |
1105 | 1105 | $obj->benchmark->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')'); |
@@ -1109,52 +1109,52 @@ discard block |
||
1109 | 1109 | //get response time for this query |
1110 | 1110 | $responseTime = $obj->benchmark->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'); |
1111 | 1111 | //TODO use the configuration value for the high response time currently is 1 second |
1112 | - if($responseTime >= 1 ){ |
|
1113 | - $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.'); |
|
1112 | + if ($responseTime >= 1) { |
|
1113 | + $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.'); |
|
1114 | 1114 | } |
1115 | - if ($sqlQuery){ |
|
1115 | + if ($sqlQuery) { |
|
1116 | 1116 | $this->numRows = $sqlQuery->rowCount(); |
1117 | - if (($this->numRows > 0)){ |
|
1117 | + if (($this->numRows > 0)) { |
|
1118 | 1118 | //if need return all result like list of record |
1119 | - if ($all){ |
|
1119 | + if ($all) { |
|
1120 | 1120 | $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
1121 | 1121 | } |
1122 | - else{ |
|
1122 | + else { |
|
1123 | 1123 | $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
1124 | 1124 | } |
1125 | 1125 | } |
1126 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1127 | - $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
|
1126 | + if ($dbCacheStatus && $sqlSELECTQuery) { |
|
1127 | + $this->logger->info('Save the result for query [' . $this->query . '] into cache for future use'); |
|
1128 | 1128 | $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
1129 | 1129 | } |
1130 | 1130 | } |
1131 | - else{ |
|
1131 | + else { |
|
1132 | 1132 | $error = $this->pdo->errorInfo(); |
1133 | 1133 | $this->error = $error[2]; |
1134 | 1134 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
1135 | 1135 | $this->error(); |
1136 | 1136 | } |
1137 | 1137 | } |
1138 | - else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
1138 | + else if ((!$cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)) { |
|
1139 | 1139 | $queryStr = $this->pdo->query($this->query); |
1140 | - if($queryStr){ |
|
1140 | + if ($queryStr) { |
|
1141 | 1141 | $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
1142 | 1142 | $this->numRows = $queryStr->rowCount(); |
1143 | 1143 | } |
1144 | - if (! $this->result){ |
|
1144 | + if (!$this->result) { |
|
1145 | 1145 | $error = $this->pdo->errorInfo(); |
1146 | 1146 | $this->error = $error[2]; |
1147 | 1147 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
1148 | 1148 | $this->error(); |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | - else{ |
|
1152 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
1151 | + else { |
|
1152 | + $this->logger->info('The result for query [' . $this->query . '] already cached use it'); |
|
1153 | 1153 | $this->result = $cacheContent; |
1154 | 1154 | $this->numRows = count($this->result); |
1155 | 1155 | } |
1156 | 1156 | $this->queryCount++; |
1157 | - if(! $this->result){ |
|
1157 | + if (!$this->result) { |
|
1158 | 1158 | $this->logger->info('No result where found for the query [' . $query . ']'); |
1159 | 1159 | } |
1160 | 1160 | return $this->result; |
@@ -1165,8 +1165,8 @@ discard block |
||
1165 | 1165 | * @param integer $ttl the cache time to live in second |
1166 | 1166 | * @return object the current Database instance |
1167 | 1167 | */ |
1168 | - public function setCache($ttl = 0){ |
|
1169 | - if($ttl > 0){ |
|
1168 | + public function setCache($ttl = 0) { |
|
1169 | + if ($ttl > 0) { |
|
1170 | 1170 | $this->cacheTtl = $ttl; |
1171 | 1171 | $this->temporaryCacheTtl = $ttl; |
1172 | 1172 | } |
@@ -1178,8 +1178,8 @@ discard block |
||
1178 | 1178 | * @param integer $ttl the cache time to live in second |
1179 | 1179 | * @return object the current Database instance |
1180 | 1180 | */ |
1181 | - public function cached($ttl = 0){ |
|
1182 | - if($ttl > 0){ |
|
1181 | + public function cached($ttl = 0) { |
|
1182 | + if ($ttl > 0) { |
|
1183 | 1183 | $this->temporaryCacheTtl = $ttl; |
1184 | 1184 | } |
1185 | 1185 | return $this; |
@@ -1190,8 +1190,8 @@ discard block |
||
1190 | 1190 | * @param mixed $data the data to be escaped |
1191 | 1191 | * @return mixed the data after escaped |
1192 | 1192 | */ |
1193 | - public function escape($data){ |
|
1194 | - if(is_null($data)){ |
|
1193 | + public function escape($data) { |
|
1194 | + if (is_null($data)) { |
|
1195 | 1195 | return null; |
1196 | 1196 | } |
1197 | 1197 | return $this->pdo->quote(trim($data)); |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | * Return the number query executed count for the current request |
1202 | 1202 | * @return int |
1203 | 1203 | */ |
1204 | - public function queryCount(){ |
|
1204 | + public function queryCount() { |
|
1205 | 1205 | return $this->queryCount; |
1206 | 1206 | } |
1207 | 1207 | |
@@ -1209,7 +1209,7 @@ discard block |
||
1209 | 1209 | * Return the current query SQL string |
1210 | 1210 | * @return string |
1211 | 1211 | */ |
1212 | - public function getQuery(){ |
|
1212 | + public function getQuery() { |
|
1213 | 1213 | return $this->query; |
1214 | 1214 | } |
1215 | 1215 | |
@@ -1217,7 +1217,7 @@ discard block |
||
1217 | 1217 | * Return the application database name |
1218 | 1218 | * @return string |
1219 | 1219 | */ |
1220 | - public function getDatabaseName(){ |
|
1220 | + public function getDatabaseName() { |
|
1221 | 1221 | return $this->databaseName; |
1222 | 1222 | } |
1223 | 1223 | |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | * Return the database configuration |
1226 | 1226 | * @return array |
1227 | 1227 | */ |
1228 | - public static function getDatabaseConfiguration(){ |
|
1228 | + public static function getDatabaseConfiguration() { |
|
1229 | 1229 | return static::$config; |
1230 | 1230 | } |
1231 | 1231 | |
@@ -1233,7 +1233,7 @@ discard block |
||
1233 | 1233 | * Return the PDO instance |
1234 | 1234 | * @return PDO |
1235 | 1235 | */ |
1236 | - public function getPdo(){ |
|
1236 | + public function getPdo() { |
|
1237 | 1237 | return $this->pdo; |
1238 | 1238 | } |
1239 | 1239 | |
@@ -1241,7 +1241,7 @@ discard block |
||
1241 | 1241 | * Return the data to be used for insert, update, etc. |
1242 | 1242 | * @return array |
1243 | 1243 | */ |
1244 | - public function getData(){ |
|
1244 | + public function getData() { |
|
1245 | 1245 | return $this->data; |
1246 | 1246 | } |
1247 | 1247 | |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | * @param boolean $escape whether to escape or not the $value |
1253 | 1253 | * @return object the current Database instance |
1254 | 1254 | */ |
1255 | - public function setData($key, $value, $escape = true){ |
|
1255 | + public function setData($key, $value, $escape = true) { |
|
1256 | 1256 | $this->data[$key] = $escape ? $this->escape($value) : $value; |
1257 | 1257 | return $this; |
1258 | 1258 | } |
@@ -1261,7 +1261,7 @@ discard block |
||
1261 | 1261 | /** |
1262 | 1262 | * Reset the database class attributs to the initail values before each query. |
1263 | 1263 | */ |
1264 | - private function reset(){ |
|
1264 | + private function reset() { |
|
1265 | 1265 | $this->select = '*'; |
1266 | 1266 | $this->from = null; |
1267 | 1267 | $this->where = null; |
@@ -1281,7 +1281,7 @@ discard block |
||
1281 | 1281 | /** |
1282 | 1282 | * The class destructor |
1283 | 1283 | */ |
1284 | - function __destruct(){ |
|
1284 | + function __destruct() { |
|
1285 | 1285 | $this->pdo = null; |
1286 | 1286 | } |
1287 | 1287 |
@@ -179,8 +179,7 @@ discard block |
||
179 | 179 | require CONFIG_PATH . 'database.php'; |
180 | 180 | if(empty($db) || !is_array($db)){ |
181 | 181 | show_error('No database configuration found in database.php'); |
182 | - } |
|
183 | - else{ |
|
182 | + } else{ |
|
184 | 183 | if(! empty($overwriteConfig)){ |
185 | 184 | $db = array_merge($db, $overwriteConfig); |
186 | 185 | } |
@@ -201,11 +200,9 @@ discard block |
||
201 | 200 | $dsn = $config['driver'] . ':host=' . $config['hostname'] . ';' |
202 | 201 | . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') |
203 | 202 | . 'dbname=' . $config['database']; |
204 | - } |
|
205 | - else if ($config['driver'] == 'sqlite'){ |
|
203 | + } else if ($config['driver'] == 'sqlite'){ |
|
206 | 204 | $dsn = 'sqlite:' . $config['database']; |
207 | - } |
|
208 | - else if($config['driver'] == 'oracle'){ |
|
205 | + } else if($config['driver'] == 'oracle'){ |
|
209 | 206 | $dsn = 'oci:dbname=' . $config['host'] . '/' . $config['database']; |
210 | 207 | } |
211 | 208 | |
@@ -214,8 +211,7 @@ discard block |
||
214 | 211 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
215 | 212 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
216 | 213 | $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
217 | - } |
|
218 | - catch (PDOException $e){ |
|
214 | + } catch (PDOException $e){ |
|
219 | 215 | $this->logger->fatal($e->getMessage()); |
220 | 216 | show_error('Cannot connect to Database.'); |
221 | 217 | } |
@@ -223,8 +219,7 @@ discard block |
||
223 | 219 | $this->temporaryCacheTtl = $this->cacheTtl; |
224 | 220 | $this->logger->info('The database configuration are listed below: ' . stringfy_vars(array_merge($config, array('password' => string_hidden($config['password']))))); |
225 | 221 | } |
226 | - } |
|
227 | - else{ |
|
222 | + } else{ |
|
228 | 223 | show_error('Unable to find database configuration'); |
229 | 224 | } |
230 | 225 | } |
@@ -241,8 +236,7 @@ discard block |
||
241 | 236 | $froms .= $this->prefix . $key . ', '; |
242 | 237 | } |
243 | 238 | $this->from = rtrim($froms, ', '); |
244 | - } |
|
245 | - else{ |
|
239 | + } else{ |
|
246 | 240 | $this->from = $this->prefix . $table; |
247 | 241 | } |
248 | 242 | return $this; |
@@ -348,8 +342,7 @@ discard block |
||
348 | 342 | } |
349 | 343 | if (is_null($this->join)){ |
350 | 344 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
351 | - } |
|
352 | - else{ |
|
345 | + } else{ |
|
353 | 346 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
354 | 347 | } |
355 | 348 | return $this; |
@@ -420,12 +413,10 @@ discard block |
||
420 | 413 | foreach($field as $f){ |
421 | 414 | $this->whereIsNull($f, $andOr); |
422 | 415 | } |
423 | - } |
|
424 | - else{ |
|
416 | + } else{ |
|
425 | 417 | if (! $this->where){ |
426 | 418 | $this->where = $field.' IS NULL '; |
427 | - } |
|
428 | - else{ |
|
419 | + } else{ |
|
429 | 420 | $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
430 | 421 | } |
431 | 422 | } |
@@ -443,12 +434,10 @@ discard block |
||
443 | 434 | foreach($field as $f){ |
444 | 435 | $this->whereIsNotNull($f, $andOr); |
445 | 436 | } |
446 | - } |
|
447 | - else{ |
|
437 | + } else{ |
|
448 | 438 | if (! $this->where){ |
449 | 439 | $this->where = $field.' IS NOT NULL '; |
450 | - } |
|
451 | - else{ |
|
440 | + } else{ |
|
452 | 441 | $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
453 | 442 | } |
454 | 443 | } |
@@ -475,8 +464,7 @@ discard block |
||
475 | 464 | $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data); |
476 | 465 | } |
477 | 466 | $where = implode(' '.$andOr.' ', $_where); |
478 | - } |
|
479 | - else{ |
|
467 | + } else{ |
|
480 | 468 | if(is_array($op)){ |
481 | 469 | $x = explode('?', $where); |
482 | 470 | $w = ''; |
@@ -489,14 +477,12 @@ discard block |
||
489 | 477 | } |
490 | 478 | } |
491 | 479 | $where = $w; |
492 | - } |
|
493 | - else if (! in_array((string)$op, $this->operatorList)){ |
|
480 | + } else if (! in_array((string)$op, $this->operatorList)){ |
|
494 | 481 | if(is_null($op)){ |
495 | 482 | $op = ''; |
496 | 483 | } |
497 | 484 | $where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
498 | - } |
|
499 | - else{ |
|
485 | + } else{ |
|
500 | 486 | if(is_null($val)){ |
501 | 487 | $val = ''; |
502 | 488 | } |
@@ -505,12 +491,10 @@ discard block |
||
505 | 491 | } |
506 | 492 | if (is_null($this->where)){ |
507 | 493 | $this->where = $where; |
508 | - } |
|
509 | - else{ |
|
494 | + } else{ |
|
510 | 495 | if(substr($this->where, -1) == '('){ |
511 | 496 | $this->where = $this->where . ' ' . $where; |
512 | - } |
|
513 | - else{ |
|
497 | + } else{ |
|
514 | 498 | $this->where = $this->where . ' '.$andOr.' ' . $where; |
515 | 499 | } |
516 | 500 | } |
@@ -554,12 +538,10 @@ discard block |
||
554 | 538 | public function groupStart($type = '', $andOr = ' AND'){ |
555 | 539 | if (is_null($this->where)){ |
556 | 540 | $this->where = $type . ' ('; |
557 | - } |
|
558 | - else{ |
|
541 | + } else{ |
|
559 | 542 | if(substr($this->where, -1) == '('){ |
560 | 543 | $this->where .= $type . ' ('; |
561 | - } |
|
562 | - else{ |
|
544 | + } else{ |
|
563 | 545 | $this->where .= $andOr . ' ' . $type . ' ('; |
564 | 546 | } |
565 | 547 | } |
@@ -623,12 +605,10 @@ discard block |
||
623 | 605 | $keys = implode(', ', $_keys); |
624 | 606 | if (is_null($this->where)){ |
625 | 607 | $this->where = $field . ' ' . $type . 'IN (' . $keys . ')'; |
626 | - } |
|
627 | - else{ |
|
608 | + } else{ |
|
628 | 609 | if(substr($this->where, -1) == '('){ |
629 | 610 | $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
630 | - } |
|
631 | - else{ |
|
611 | + } else{ |
|
632 | 612 | $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
633 | 613 | } |
634 | 614 | } |
@@ -682,12 +662,10 @@ discard block |
||
682 | 662 | } |
683 | 663 | if (is_null($this->where)){ |
684 | 664 | $this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
685 | - } |
|
686 | - else{ |
|
665 | + } else{ |
|
687 | 666 | if(substr($this->where, -1) == '('){ |
688 | 667 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
689 | - } |
|
690 | - else{ |
|
668 | + } else{ |
|
691 | 669 | $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
692 | 670 | } |
693 | 671 | } |
@@ -737,12 +715,10 @@ discard block |
||
737 | 715 | $like = $escape ? $this->escape($data) : $data; |
738 | 716 | if (is_null($this->where)){ |
739 | 717 | $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
740 | - } |
|
741 | - else{ |
|
718 | + } else{ |
|
742 | 719 | if(substr($this->where, -1) == '('){ |
743 | 720 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
744 | - } |
|
745 | - else{ |
|
721 | + } else{ |
|
746 | 722 | $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
747 | 723 | } |
748 | 724 | } |
@@ -789,8 +765,7 @@ discard block |
||
789 | 765 | } |
790 | 766 | if (! is_null($limitEnd)){ |
791 | 767 | $this->limit = $limit . ', ' . $limitEnd; |
792 | - } |
|
793 | - else{ |
|
768 | + } else{ |
|
794 | 769 | $this->limit = $limit; |
795 | 770 | } |
796 | 771 | return $this; |
@@ -805,12 +780,10 @@ discard block |
||
805 | 780 | public function orderBy($orderBy, $orderDir = ' ASC'){ |
806 | 781 | if (! is_null($orderDir)){ |
807 | 782 | $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
808 | - } |
|
809 | - else{ |
|
783 | + } else{ |
|
810 | 784 | if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
811 | 785 | $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
812 | - } |
|
813 | - else{ |
|
786 | + } else{ |
|
814 | 787 | $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
815 | 788 | } |
816 | 789 | } |
@@ -825,8 +798,7 @@ discard block |
||
825 | 798 | public function groupBy($field){ |
826 | 799 | if(is_array($field)){ |
827 | 800 | $this->groupBy = implode(', ', $field); |
828 | - } |
|
829 | - else{ |
|
801 | + } else{ |
|
830 | 802 | $this->groupBy = $field; |
831 | 803 | } |
832 | 804 | return $this; |
@@ -853,14 +825,12 @@ discard block |
||
853 | 825 | } |
854 | 826 | } |
855 | 827 | $this->having = $w; |
856 | - } |
|
857 | - else if (! in_array($op, $this->operatorList)){ |
|
828 | + } else if (! in_array($op, $this->operatorList)){ |
|
858 | 829 | if(is_null($op)){ |
859 | 830 | $op = ''; |
860 | 831 | } |
861 | 832 | $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
862 | - } |
|
863 | - else{ |
|
833 | + } else{ |
|
864 | 834 | if(is_null($val)){ |
865 | 835 | $val = ''; |
866 | 836 | } |
@@ -905,8 +875,7 @@ discard block |
||
905 | 875 | $query = $this->getAll(true); |
906 | 876 | if($returnSQLQueryOrResultType === true){ |
907 | 877 | return $query; |
908 | - } |
|
909 | - else{ |
|
878 | + } else{ |
|
910 | 879 | return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
911 | 880 | } |
912 | 881 | } |
@@ -945,8 +914,7 @@ discard block |
||
945 | 914 | |
946 | 915 | if($returnSQLQueryOrResultType === true){ |
947 | 916 | return $query; |
948 | - } |
|
949 | - else{ |
|
917 | + } else{ |
|
950 | 918 | return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
951 | 919 | } |
952 | 920 | } |
@@ -964,8 +932,7 @@ discard block |
||
964 | 932 | $columns = array_keys($this->getData()); |
965 | 933 | $column = implode(',', $columns); |
966 | 934 | $val = implode(', ', $this->getData()); |
967 | - } |
|
968 | - else{ |
|
935 | + } else{ |
|
969 | 936 | $columns = array_keys($data); |
970 | 937 | $column = implode(',', $columns); |
971 | 938 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -977,8 +944,7 @@ discard block |
||
977 | 944 | if ($query){ |
978 | 945 | $this->insertId = $this->pdo->lastInsertId(); |
979 | 946 | return $this->insertId(); |
980 | - } |
|
981 | - else{ |
|
947 | + } else{ |
|
982 | 948 | return false; |
983 | 949 | } |
984 | 950 | } |
@@ -996,8 +962,7 @@ discard block |
||
996 | 962 | foreach ($this->getData() as $column => $val){ |
997 | 963 | $values[] = $column . ' = ' . $val; |
998 | 964 | } |
999 | - } |
|
1000 | - else{ |
|
965 | + } else{ |
|
1001 | 966 | foreach ($data as $column => $val){ |
1002 | 967 | $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
1003 | 968 | } |
@@ -1094,8 +1059,7 @@ discard block |
||
1094 | 1059 | $cacheKey = md5($query . $all . $array); |
1095 | 1060 | $cacheInstance = $obj->cache; |
1096 | 1061 | $cacheContent = $cacheInstance->get($cacheKey); |
1097 | - } |
|
1098 | - else{ |
|
1062 | + } else{ |
|
1099 | 1063 | $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database'); |
1100 | 1064 | } |
1101 | 1065 | |
@@ -1118,8 +1082,7 @@ discard block |
||
1118 | 1082 | //if need return all result like list of record |
1119 | 1083 | if ($all){ |
1120 | 1084 | $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
1121 | - } |
|
1122 | - else{ |
|
1085 | + } else{ |
|
1123 | 1086 | $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
1124 | 1087 | } |
1125 | 1088 | } |
@@ -1127,15 +1090,13 @@ discard block |
||
1127 | 1090 | $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
1128 | 1091 | $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
1129 | 1092 | } |
1130 | - } |
|
1131 | - else{ |
|
1093 | + } else{ |
|
1132 | 1094 | $error = $this->pdo->errorInfo(); |
1133 | 1095 | $this->error = $error[2]; |
1134 | 1096 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
1135 | 1097 | $this->error(); |
1136 | 1098 | } |
1137 | - } |
|
1138 | - else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
1099 | + } else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
1139 | 1100 | $queryStr = $this->pdo->query($this->query); |
1140 | 1101 | if($queryStr){ |
1141 | 1102 | $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
@@ -1147,8 +1108,7 @@ discard block |
||
1147 | 1108 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
1148 | 1109 | $this->error(); |
1149 | 1110 | } |
1150 | - } |
|
1151 | - else{ |
|
1111 | + } else{ |
|
1152 | 1112 | $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
1153 | 1113 | $this->result = $cacheContent; |
1154 | 1114 | $this->numRows = count($this->result); |
@@ -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 | class Response{ |
28 | 28 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | private $_currentUrlCacheKey = null; |
58 | 58 | |
59 | 59 | /** |
60 | - * Whether we can compress the output using Gzip |
|
61 | - * @var boolean |
|
62 | - */ |
|
60 | + * Whether we can compress the output using Gzip |
|
61 | + * @var boolean |
|
62 | + */ |
|
63 | 63 | private static $_canCompressOutput = false; |
64 | 64 | |
65 | 65 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
239 | - * Send the final page output to user |
|
240 | - */ |
|
239 | + * Send the final page output to user |
|
240 | + */ |
|
241 | 241 | public function renderFinalPage(){ |
242 | 242 | $logger = static::getLogger(); |
243 | 243 | $obj = & get_instance(); |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Send the final page output to user if is cached |
|
305 | - */ |
|
304 | + * Send the final page output to user if is cached |
|
305 | + */ |
|
306 | 306 | public function renderFinalPageFromCache(&$cache){ |
307 | 307 | $logger = static::getLogger(); |
308 | 308 | $url = $this->_currentUrl; |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
365 | - * Get the final page to be rendered |
|
366 | - * @return string |
|
367 | - */ |
|
365 | + * Get the final page to be rendered |
|
366 | + * @return string |
|
367 | + */ |
|
368 | 368 | public function getFinalPageRendered(){ |
369 | 369 | return $this->_pageRender; |
370 | 370 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Response{ |
|
27 | + class Response { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of request header to send with response |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Construct new response instance |
67 | 67 | */ |
68 | - public function __construct(){ |
|
69 | - $this->_currentUrl = (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' ) |
|
70 | - . (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' ); |
|
68 | + public function __construct() { |
|
69 | + $this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') |
|
70 | + . (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : ''); |
|
71 | 71 | |
72 | 72 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
73 | 73 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * Get the logger singleton instance |
83 | 83 | * @return Log the logger instance |
84 | 84 | */ |
85 | - private static function getLogger(){ |
|
86 | - if(static::$logger == null){ |
|
87 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
85 | + private static function getLogger() { |
|
86 | + if (static::$logger == null) { |
|
87 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
88 | 88 | static::$logger[0]->setLogger('Library::Response'); |
89 | 89 | } |
90 | 90 | return static::$logger[0]; |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | * @param integer $httpCode the HTTP status code |
96 | 96 | * @param array $headers the additional headers to add to the existing headers list |
97 | 97 | */ |
98 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
98 | + public static function sendHeaders($httpCode = 200, array $headers = array()) { |
|
99 | 99 | set_http_status_header($httpCode); |
100 | 100 | static::setHeaders($headers); |
101 | - if(! headers_sent()){ |
|
102 | - foreach(static::getHeaders() as $key => $value){ |
|
103 | - header($key .': '.$value); |
|
101 | + if (!headers_sent()) { |
|
102 | + foreach (static::getHeaders() as $key => $value) { |
|
103 | + header($key . ': ' . $value); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * Get the list of the headers |
110 | 110 | * @return array the headers list |
111 | 111 | */ |
112 | - public static function getHeaders(){ |
|
112 | + public static function getHeaders() { |
|
113 | 113 | return static::$headers; |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $name the header name |
119 | 119 | * @return string the header value |
120 | 120 | */ |
121 | - public static function getHeader($name){ |
|
121 | + public static function getHeader($name) { |
|
122 | 122 | return array_key_exists($name, static::$headers) ? static::$headers[$name] : null; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param string $name the header name |
129 | 129 | * @param string $value the header value to be set |
130 | 130 | */ |
131 | - public static function setHeader($name, $value){ |
|
131 | + public static function setHeader($name, $value) { |
|
132 | 132 | static::$headers[$name] = $value; |
133 | 133 | } |
134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param array $headers the list of the headers to set. |
138 | 138 | * Note: this will merge with the existing headers |
139 | 139 | */ |
140 | - public static function setHeaders(array $headers){ |
|
140 | + public static function setHeaders(array $headers) { |
|
141 | 141 | static::$headers = array_merge(static::getHeaders(), $headers); |
142 | 142 | } |
143 | 143 | |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | * Redirect user in the specified page |
146 | 146 | * @param string $path the URL or URI to be redirect to |
147 | 147 | */ |
148 | - public static function redirect($path = ''){ |
|
148 | + public static function redirect($path = '') { |
|
149 | 149 | $logger = static::getLogger(); |
150 | 150 | $url = Url::site_url($path); |
151 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
152 | - if(! headers_sent()){ |
|
153 | - header('Location: '.$url); |
|
151 | + $logger->info('Redirect to URL [' . $url . ']'); |
|
152 | + if (!headers_sent()) { |
|
153 | + header('Location: ' . $url); |
|
154 | 154 | exit; |
155 | 155 | } |
156 | - else{ |
|
156 | + else { |
|
157 | 157 | echo '<script> |
158 | - location.href = "'.$url.'"; |
|
158 | + location.href = "'.$url . '"; |
|
159 | 159 | </script>'; |
160 | 160 | } |
161 | 161 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * @return void|string if $return is true will return the view content otherwise |
169 | 169 | * will display the view content. |
170 | 170 | */ |
171 | - public function render($view, $data = array(), $return = false){ |
|
171 | + public function render($view, $data = array(), $return = false) { |
|
172 | 172 | $logger = static::getLogger(); |
173 | 173 | //convert data to an array |
174 | - $data = ! is_array($data) ? (array) $data : $data; |
|
174 | + $data = !is_array($data) ? (array) $data : $data; |
|
175 | 175 | $view = str_ireplace('.php', '', $view); |
176 | 176 | $view = trim($view, '/\\'); |
177 | 177 | $viewFile = $view . '.php'; |
@@ -180,42 +180,42 @@ discard block |
||
180 | 180 | //super instance |
181 | 181 | $obj = & get_instance(); |
182 | 182 | |
183 | - if(Module::hasModule()){ |
|
183 | + if (Module::hasModule()) { |
|
184 | 184 | //check in module first |
185 | 185 | $logger->debug('Checking the view [' . $view . '] from module list ...'); |
186 | 186 | $mod = null; |
187 | 187 | //check if the request class contains module name |
188 | - if(strpos($view, '/') !== false){ |
|
188 | + if (strpos($view, '/') !== false) { |
|
189 | 189 | $viewPath = explode('/', $view); |
190 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
190 | + if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) { |
|
191 | 191 | $mod = $viewPath[0]; |
192 | 192 | array_shift($viewPath); |
193 | 193 | $view = implode('/', $viewPath); |
194 | 194 | $viewFile = $view . '.php'; |
195 | 195 | } |
196 | 196 | } |
197 | - if(! $mod && !empty($obj->moduleName)){ |
|
197 | + if (!$mod && !empty($obj->moduleName)) { |
|
198 | 198 | $mod = $obj->moduleName; |
199 | 199 | } |
200 | - if($mod){ |
|
200 | + if ($mod) { |
|
201 | 201 | $moduleViewPath = Module::findViewFullPath($view, $mod); |
202 | - if($moduleViewPath){ |
|
202 | + if ($moduleViewPath) { |
|
203 | 203 | $path = $moduleViewPath; |
204 | - $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
204 | + $logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
205 | 205 | } |
206 | - else{ |
|
207 | - $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
|
206 | + else { |
|
207 | + $logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location'); |
|
208 | 208 | } |
209 | 209 | } |
210 | - else{ |
|
210 | + else { |
|
211 | 211 | $logger->info('The current request does not use module using the default location.'); |
212 | 212 | } |
213 | 213 | } |
214 | 214 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
215 | 215 | $found = false; |
216 | - if(file_exists($path)){ |
|
217 | - foreach(get_object_vars($obj) as $key => $value){ |
|
218 | - if(! isset($this->{$key})){ |
|
216 | + if (file_exists($path)) { |
|
217 | + foreach (get_object_vars($obj) as $key => $value) { |
|
218 | + if (!isset($this->{$key})) { |
|
219 | 219 | $this->{$key} = & $obj->{$key}; |
220 | 220 | } |
221 | 221 | } |
@@ -224,39 +224,39 @@ discard block |
||
224 | 224 | //need use require() instead of require_once because can load this view many time |
225 | 225 | require $path; |
226 | 226 | $content = ob_get_clean(); |
227 | - if($return){ |
|
227 | + if ($return) { |
|
228 | 228 | return $content; |
229 | 229 | } |
230 | 230 | $this->_pageRender .= $content; |
231 | 231 | $found = true; |
232 | 232 | } |
233 | - if(! $found){ |
|
234 | - show_error('Unable to find view [' .$view . ']'); |
|
233 | + if (!$found) { |
|
234 | + show_error('Unable to find view [' . $view . ']'); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
239 | 239 | * Send the final page output to user |
240 | 240 | */ |
241 | - public function renderFinalPage(){ |
|
241 | + public function renderFinalPage() { |
|
242 | 242 | $logger = static::getLogger(); |
243 | 243 | $obj = & get_instance(); |
244 | 244 | $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
245 | 245 | $dispatcher = $obj->eventdispatcher; |
246 | 246 | $content = $this->_pageRender; |
247 | - if(! $content){ |
|
247 | + if (!$content) { |
|
248 | 248 | $logger->warning('The final view content is empty.'); |
249 | 249 | return; |
250 | 250 | } |
251 | 251 | //dispatch |
252 | 252 | $event = $dispatcher->dispatch(new Event('FINAL_VIEW_READY', $content, true)); |
253 | - $content = ! empty($event->payload) ? $event->payload : null; |
|
254 | - if(empty($content)){ |
|
253 | + $content = !empty($event->payload) ? $event->payload : null; |
|
254 | + if (empty($content)) { |
|
255 | 255 | $logger->warning('The view content is empty after dispatch to Event Listeners.'); |
256 | 256 | } |
257 | 257 | |
258 | 258 | //check whether need save the page into cache. |
259 | - if($cachePageStatus){ |
|
259 | + if ($cachePageStatus) { |
|
260 | 260 | //current page URL |
261 | 261 | $url = $this->_currentUrl; |
262 | 262 | //Cache view Time to live in second |
@@ -271,14 +271,14 @@ discard block |
||
271 | 271 | |
272 | 272 | //get the cache information to prepare header to send to browser |
273 | 273 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
274 | - if($cacheInfo){ |
|
274 | + if ($cacheInfo) { |
|
275 | 275 | $lastModified = $cacheInfo['mtime']; |
276 | 276 | $expire = $cacheInfo['expire']; |
277 | 277 | $maxAge = $expire - time(); |
278 | 278 | static::setHeader('Pragma', 'public'); |
279 | 279 | static::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
280 | - static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
281 | - static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
280 | + static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
281 | + static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
290 | 290 | |
291 | 291 | //compress the output if is available |
292 | - if (static::$_canCompressOutput){ |
|
292 | + if (static::$_canCompressOutput) { |
|
293 | 293 | ob_start('ob_gzhandler'); |
294 | 294 | } |
295 | - else{ |
|
295 | + else { |
|
296 | 296 | ob_start(); |
297 | 297 | } |
298 | 298 | static::sendHeaders(200); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * Send the final page output to user if is cached |
305 | 305 | */ |
306 | - public function renderFinalPageFromCache(&$cache){ |
|
306 | + public function renderFinalPageFromCache(&$cache) { |
|
307 | 307 | $logger = static::getLogger(); |
308 | 308 | $url = $this->_currentUrl; |
309 | 309 | //the current page cache key for identification |
@@ -312,25 +312,25 @@ discard block |
||
312 | 312 | $logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...'); |
313 | 313 | //get the cache information to prepare header to send to browser |
314 | 314 | $cacheInfo = $cache->getInfo($pageCacheKey); |
315 | - if($cacheInfo){ |
|
315 | + if ($cacheInfo) { |
|
316 | 316 | $lastModified = $cacheInfo['mtime']; |
317 | 317 | $expire = $cacheInfo['expire']; |
318 | 318 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
319 | 319 | static::setHeader('Pragma', 'public'); |
320 | 320 | static::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
321 | - static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
322 | - static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
323 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
321 | + static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
322 | + static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
323 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
324 | 324 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
325 | 325 | static::sendHeaders(304); |
326 | 326 | exit; |
327 | 327 | } |
328 | - else{ |
|
328 | + else { |
|
329 | 329 | $logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser'); |
330 | 330 | static::sendHeaders(200); |
331 | 331 | //get the cache content |
332 | 332 | $content = $cache->get($pageCacheKey); |
333 | - if($content){ |
|
333 | + if ($content) { |
|
334 | 334 | $logger->info('The page content for the URL [' . $url . '] already cached just display it'); |
335 | 335 | //load benchmark class |
336 | 336 | $benchmark = & class_loader('Benchmark'); |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | |
344 | 344 | ///display the final output |
345 | 345 | //compress the output if is available |
346 | - if (static::$_canCompressOutput){ |
|
346 | + if (static::$_canCompressOutput) { |
|
347 | 347 | ob_start('ob_gzhandler'); |
348 | 348 | } |
349 | - else{ |
|
349 | + else { |
|
350 | 350 | ob_start(); |
351 | 351 | } |
352 | 352 | echo $content; |
353 | 353 | @ob_end_flush(); |
354 | 354 | exit; |
355 | 355 | } |
356 | - else{ |
|
356 | + else { |
|
357 | 357 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
358 | 358 | $cache->delete($pageCacheKey); |
359 | 359 | } |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * Get the final page to be rendered |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public function getFinalPageRendered(){ |
|
368 | + public function getFinalPageRendered() { |
|
369 | 369 | return $this->_pageRender; |
370 | 370 | } |
371 | 371 | |
@@ -373,14 +373,14 @@ discard block |
||
373 | 373 | * Send the HTTP 404 error if can not found the |
374 | 374 | * routing information for the current request |
375 | 375 | */ |
376 | - public static function send404(){ |
|
376 | + public static function send404() { |
|
377 | 377 | /********* for logs **************/ |
378 | 378 | //can't use $obj = & get_instance() here because the global super object will be available until |
379 | 379 | //the main controller is loaded even for Loader::library('xxxx'); |
380 | 380 | $logger = static::getLogger(); |
381 | - $request =& class_loader('Request', 'classes'); |
|
382 | - $userAgent =& class_loader('Browser'); |
|
383 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
381 | + $request = & class_loader('Request', 'classes'); |
|
382 | + $userAgent = & class_loader('Browser'); |
|
383 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
384 | 384 | |
385 | 385 | //here can't use Loader::functions just include the helper manually |
386 | 386 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -390,12 +390,12 @@ discard block |
||
390 | 390 | $logger->error($str); |
391 | 391 | /***********************************/ |
392 | 392 | $path = CORE_VIEWS_PATH . '404.php'; |
393 | - if(file_exists($path)){ |
|
393 | + if (file_exists($path)) { |
|
394 | 394 | //compress the output if is available |
395 | - if (static::$_canCompressOutput){ |
|
395 | + if (static::$_canCompressOutput) { |
|
396 | 396 | ob_start('ob_gzhandler'); |
397 | 397 | } |
398 | - else{ |
|
398 | + else { |
|
399 | 399 | ob_start(); |
400 | 400 | } |
401 | 401 | require_once $path; |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | static::sendHeaders(404); |
404 | 404 | echo $output; |
405 | 405 | } |
406 | - else{ |
|
407 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
406 | + else { |
|
407 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
@@ -412,14 +412,14 @@ discard block |
||
412 | 412 | * Display the error to user |
413 | 413 | * @param array $data the error information |
414 | 414 | */ |
415 | - public static function sendError(array $data = array()){ |
|
415 | + public static function sendError(array $data = array()) { |
|
416 | 416 | $path = CORE_VIEWS_PATH . 'errors.php'; |
417 | - if(file_exists($path)){ |
|
417 | + if (file_exists($path)) { |
|
418 | 418 | //compress the output if exists |
419 | - if (static::$_canCompressOutput){ |
|
419 | + if (static::$_canCompressOutput) { |
|
420 | 420 | ob_start('ob_gzhandler'); |
421 | 421 | } |
422 | - else{ |
|
422 | + else { |
|
423 | 423 | ob_start(); |
424 | 424 | } |
425 | 425 | extract($data); |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | static::sendHeaders(503); |
429 | 429 | echo $output; |
430 | 430 | } |
431 | - else{ |
|
431 | + else { |
|
432 | 432 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
433 | 433 | set_http_status_header(503); |
434 | 434 | echo 'The error view [' . $path . '] does not exist'; |
@@ -152,8 +152,7 @@ discard block |
||
152 | 152 | if(! headers_sent()){ |
153 | 153 | header('Location: '.$url); |
154 | 154 | exit; |
155 | - } |
|
156 | - else{ |
|
155 | + } else{ |
|
157 | 156 | echo '<script> |
158 | 157 | location.href = "'.$url.'"; |
159 | 158 | </script>'; |
@@ -202,12 +201,10 @@ discard block |
||
202 | 201 | if($moduleViewPath){ |
203 | 202 | $path = $moduleViewPath; |
204 | 203 | $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
205 | - } |
|
206 | - else{ |
|
204 | + } else{ |
|
207 | 205 | $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
208 | 206 | } |
209 | - } |
|
210 | - else{ |
|
207 | + } else{ |
|
211 | 208 | $logger->info('The current request does not use module using the default location.'); |
212 | 209 | } |
213 | 210 | } |
@@ -291,8 +288,7 @@ discard block |
||
291 | 288 | //compress the output if is available |
292 | 289 | if (static::$_canCompressOutput){ |
293 | 290 | ob_start('ob_gzhandler'); |
294 | - } |
|
295 | - else{ |
|
291 | + } else{ |
|
296 | 292 | ob_start(); |
297 | 293 | } |
298 | 294 | static::sendHeaders(200); |
@@ -324,8 +320,7 @@ discard block |
||
324 | 320 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
325 | 321 | static::sendHeaders(304); |
326 | 322 | exit; |
327 | - } |
|
328 | - else{ |
|
323 | + } else{ |
|
329 | 324 | $logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser'); |
330 | 325 | static::sendHeaders(200); |
331 | 326 | //get the cache content |
@@ -345,15 +340,13 @@ discard block |
||
345 | 340 | //compress the output if is available |
346 | 341 | if (static::$_canCompressOutput){ |
347 | 342 | ob_start('ob_gzhandler'); |
348 | - } |
|
349 | - else{ |
|
343 | + } else{ |
|
350 | 344 | ob_start(); |
351 | 345 | } |
352 | 346 | echo $content; |
353 | 347 | @ob_end_flush(); |
354 | 348 | exit; |
355 | - } |
|
356 | - else{ |
|
349 | + } else{ |
|
357 | 350 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
358 | 351 | $cache->delete($pageCacheKey); |
359 | 352 | } |
@@ -394,16 +387,14 @@ discard block |
||
394 | 387 | //compress the output if is available |
395 | 388 | if (static::$_canCompressOutput){ |
396 | 389 | ob_start('ob_gzhandler'); |
397 | - } |
|
398 | - else{ |
|
390 | + } else{ |
|
399 | 391 | ob_start(); |
400 | 392 | } |
401 | 393 | require_once $path; |
402 | 394 | $output = ob_get_clean(); |
403 | 395 | static::sendHeaders(404); |
404 | 396 | echo $output; |
405 | - } |
|
406 | - else{ |
|
397 | + } else{ |
|
407 | 398 | show_error('The 404 view [' .$path. '] does not exist'); |
408 | 399 | } |
409 | 400 | } |
@@ -418,8 +409,7 @@ discard block |
||
418 | 409 | //compress the output if exists |
419 | 410 | if (static::$_canCompressOutput){ |
420 | 411 | ob_start('ob_gzhandler'); |
421 | - } |
|
422 | - else{ |
|
412 | + } else{ |
|
423 | 413 | ob_start(); |
424 | 414 | } |
425 | 415 | extract($data); |
@@ -427,8 +417,7 @@ discard block |
||
427 | 417 | $output = ob_get_clean(); |
428 | 418 | static::sendHeaders(503); |
429 | 419 | echo $output; |
430 | - } |
|
431 | - else{ |
|
420 | + } else{ |
|
432 | 421 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
433 | 422 | set_http_status_header(503); |
434 | 423 | echo 'The error view [' . $path . '] does not exist'; |
@@ -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 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | private $logger; |
84 | 84 | |
85 | 85 | public function __construct(){ |
86 | - $this->logger =& class_loader('Log', 'classes'); |
|
87 | - $this->logger->setLogger('Library::DBSessionHandler'); |
|
86 | + $this->logger =& class_loader('Log', 'classes'); |
|
87 | + $this->logger->setLogger('Library::DBSessionHandler'); |
|
88 | 88 | $this->OBJ = & get_instance(); |
89 | 89 | |
90 | 90 | $secret = get_config('session_secret', false); |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
29 | 29 | */ |
30 | - if( !interface_exists('SessionHandlerInterface')){ |
|
30 | + if (!interface_exists('SessionHandlerInterface')) { |
|
31 | 31 | show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.'); |
32 | 32 | } |
33 | 33 | |
34 | - class DBSessionHandler implements SessionHandlerInterface{ |
|
34 | + class DBSessionHandler implements SessionHandlerInterface { |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * The encryption method to use to encrypt session data in database |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | */ |
83 | 83 | private $logger; |
84 | 84 | |
85 | - public function __construct(){ |
|
86 | - $this->logger =& class_loader('Log', 'classes'); |
|
85 | + public function __construct() { |
|
86 | + $this->logger = & class_loader('Log', 'classes'); |
|
87 | 87 | $this->logger->setLogger('Library::DBSessionHandler'); |
88 | 88 | $this->OBJ = & get_instance(); |
89 | 89 | |
90 | 90 | $secret = get_config('session_secret', false); |
91 | 91 | //try to check if session secret is set and the length is >= SESSION_SECRET_MIN_LENGTH |
92 | - if(! $secret || strlen($secret) < self::SESSION_SECRET_MIN_LENGTH){ |
|
93 | - show_error('Session secret is not set or the length is below to '.self::SESSION_SECRET_MIN_LENGTH.' caracters'); |
|
92 | + if (!$secret || strlen($secret) < self::SESSION_SECRET_MIN_LENGTH) { |
|
93 | + show_error('Session secret is not set or the length is below to ' . self::SESSION_SECRET_MIN_LENGTH . ' caracters'); |
|
94 | 94 | } |
95 | 95 | $this->logger->info('Session secret: ' . $secret); |
96 | 96 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | //set model instance name |
102 | 102 | $this->modelInstanceName = $this->OBJ->dbsessionhanlderinstance; |
103 | 103 | |
104 | - if(! $this->modelInstanceName instanceof DBSessionHandlerModel){ |
|
105 | - show_error('To use database session handler, your class model "'.$modelName.'" need extends "DBSessionHandlerModel"'); |
|
104 | + if (!$this->modelInstanceName instanceof DBSessionHandlerModel) { |
|
105 | + show_error('To use database session handler, your class model "' . $modelName . '" need extends "DBSessionHandlerModel"'); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | //set session tables columns |
109 | 109 | $this->sessionTableColumns = $this->modelInstanceName->getSessionTableColumns(); |
110 | 110 | |
111 | - if(empty($this->sessionTableColumns)){ |
|
111 | + if (empty($this->sessionTableColumns)) { |
|
112 | 112 | show_error('The session handler is "database" but the table columns not set'); |
113 | 113 | } |
114 | 114 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $sessionName the session name |
131 | 131 | * @return boolean |
132 | 132 | */ |
133 | - public function open($savePath, $sessionName){ |
|
133 | + public function open($savePath, $sessionName) { |
|
134 | 134 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
135 | 135 | return true; |
136 | 136 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * Close the session |
140 | 140 | * @return boolean |
141 | 141 | */ |
142 | - public function close(){ |
|
142 | + public function close() { |
|
143 | 143 | $this->logger->debug('Closing database session handler'); |
144 | 144 | return true; |
145 | 145 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param string $sid the session id to use |
150 | 150 | * @return mixed the session data in serialiaze format |
151 | 151 | */ |
152 | - public function read($sid){ |
|
152 | + public function read($sid) { |
|
153 | 153 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
154 | 154 | $instance = $this->modelInstanceName; |
155 | 155 | $columns = $this->sessionTableColumns; |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | $keyValue = $instance->getKeyValue(); |
159 | 159 | $host = @gethostbyaddr($ip) or null; |
160 | 160 | Loader::library('Browser'); |
161 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
161 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
162 | 162 | |
163 | 163 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
164 | - if($data && isset($data->{$columns['sdata']})){ |
|
164 | + if ($data && isset($data->{$columns['sdata']})) { |
|
165 | 165 | //checking inactivity |
166 | 166 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
167 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
167 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
168 | 168 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
169 | 169 | $this->destroy($sid); |
170 | 170 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param mixed $data the session data to save in serialize format |
182 | 182 | * @return boolean |
183 | 183 | */ |
184 | - public function write($sid, $data){ |
|
184 | + public function write($sid, $data) { |
|
185 | 185 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
186 | 186 | $instance = $this->modelInstanceName; |
187 | 187 | $columns = $this->sessionTableColumns; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $keyValue = $instance->getKeyValue(); |
192 | 192 | $host = @gethostbyaddr($ip) or null; |
193 | 193 | Loader::library('Browser'); |
194 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
194 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
195 | 195 | $data = $this->encode($data); |
196 | 196 | $params = array( |
197 | 197 | $columns['sid'] => $sid, |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | ); |
205 | 205 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
206 | 206 | $exists = $instance->get($sid); |
207 | - if($exists){ |
|
207 | + if ($exists) { |
|
208 | 208 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
209 | 209 | //update |
210 | 210 | unset($params[$columns['sid']]); |
211 | 211 | $instance->update($sid, $params); |
212 | 212 | } |
213 | - else{ |
|
213 | + else { |
|
214 | 214 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
215 | 215 | $instance->insert($params); |
216 | 216 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @param string $sid the session id value |
224 | 224 | * @return boolean |
225 | 225 | */ |
226 | - public function destroy($sid){ |
|
226 | + public function destroy($sid) { |
|
227 | 227 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
228 | 228 | $instance = $this->modelInstanceName; |
229 | 229 | $instance->delete($sid); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param ineteger $maxLifetime the max lifetime |
236 | 236 | * @return boolean |
237 | 237 | */ |
238 | - public function gc($maxLifetime){ |
|
238 | + public function gc($maxLifetime) { |
|
239 | 239 | $instance = $this->modelInstanceName; |
240 | 240 | $time = time() - $maxLifetime; |
241 | 241 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @param mixed $data the data to decode |
249 | 249 | * @return mixed the decoded data |
250 | 250 | */ |
251 | - public function decode($data){ |
|
251 | + public function decode($data) { |
|
252 | 252 | $key = base64_decode($this->sessionSecret); |
253 | 253 | $data = base64_decode($data); |
254 | 254 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->iv); |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | * @param mixed $data the session data to encode |
261 | 261 | * @return mixed the encoded session data |
262 | 262 | */ |
263 | - public function encode($data){ |
|
263 | + public function encode($data) { |
|
264 | 264 | $key = base64_decode($this->sessionSecret); |
265 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->iv); |
|
265 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->iv); |
|
266 | 266 | $output = base64_encode($dataEncrypted); |
267 | 267 | return $output; |
268 | 268 | } |
@@ -209,8 +209,7 @@ |
||
209 | 209 | //update |
210 | 210 | unset($params[$columns['sid']]); |
211 | 211 | $instance->update($sid, $params); |
212 | - } |
|
213 | - else{ |
|
212 | + } else{ |
|
214 | 213 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
215 | 214 | $instance->insert($params); |
216 | 215 | } |
@@ -22,7 +22,7 @@ |
||
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 | class Loader{ |
27 | 27 | |
28 | 28 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Loader{ |
|
26 | + class Loader { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * List of loaded resources |
@@ -38,85 +38,85 @@ discard block |
||
38 | 38 | private static $logger; |
39 | 39 | |
40 | 40 | |
41 | - public function __construct(){ |
|
41 | + public function __construct() { |
|
42 | 42 | //add the resources already loaded during application bootstrap |
43 | 43 | //in the list to prevent duplicate or loading the resources again. |
44 | 44 | static::$loaded = class_loaded(); |
45 | 45 | |
46 | 46 | $autoloads = array(); |
47 | 47 | //loading of the resources in autoload.php configuration file |
48 | - if(file_exists(CONFIG_PATH . 'autoload.php')){ |
|
48 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
49 | 49 | require_once CONFIG_PATH . 'autoload.php'; |
50 | - if(! empty($autoload) && is_array($autoload)){ |
|
50 | + if (!empty($autoload) && is_array($autoload)) { |
|
51 | 51 | $autoloads = $autoload; |
52 | 52 | unset($autoload); |
53 | 53 | } |
54 | - else{ |
|
54 | + else { |
|
55 | 55 | show_error('No autoload configuration found in autoload.php'); |
56 | 56 | } |
57 | 57 | } |
58 | 58 | //loading autoload configuration for modules |
59 | 59 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
60 | - if($modulesAutoloads && is_array($modulesAutoloads)){ |
|
60 | + if ($modulesAutoloads && is_array($modulesAutoloads)) { |
|
61 | 61 | //libraries autoload |
62 | - if(! empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])){ |
|
62 | + if (!empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])) { |
|
63 | 63 | $autoloads['libraries'] = array_merge($autoloads['libraries'], $modulesAutoloads['libraries']); |
64 | 64 | } |
65 | 65 | //config autoload |
66 | - if(! empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])){ |
|
66 | + if (!empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])) { |
|
67 | 67 | $autoloads['config'] = array_merge($autoloads['config'], $modulesAutoloads['config']); |
68 | 68 | } |
69 | 69 | //models autoload |
70 | - if(! empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])){ |
|
70 | + if (!empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])) { |
|
71 | 71 | $autoloads['models'] = array_merge($autoloads['models'], $modulesAutoloads['models']); |
72 | 72 | } |
73 | 73 | //functions autoload |
74 | - if(! empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])){ |
|
74 | + if (!empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])) { |
|
75 | 75 | $autoloads['functions'] = array_merge($autoloads['functions'], $modulesAutoloads['functions']); |
76 | 76 | } |
77 | 77 | //languages autoload |
78 | - if(! empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])){ |
|
78 | + if (!empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])) { |
|
79 | 79 | $autoloads['languages'] = array_merge($autoloads['languages'], $modulesAutoloads['languages']); |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | 83 | //config autoload |
84 | - if(! empty($autoloads['config']) && is_array($autoloads['config'])){ |
|
85 | - foreach($autoloads['config'] as $c){ |
|
84 | + if (!empty($autoloads['config']) && is_array($autoloads['config'])) { |
|
85 | + foreach ($autoloads['config'] as $c) { |
|
86 | 86 | Loader::config($c); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | 90 | //languages autoload |
91 | - if(! empty($autoloads['languages']) && is_array($autoloads['languages'])){ |
|
92 | - foreach($autoloads['languages'] as $language){ |
|
91 | + if (!empty($autoloads['languages']) && is_array($autoloads['languages'])) { |
|
92 | + foreach ($autoloads['languages'] as $language) { |
|
93 | 93 | Loader::lang($language); |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | //libraries autoload |
98 | - if(! empty($autoloads['libraries']) && is_array($autoloads['libraries'])){ |
|
99 | - foreach($autoloads['libraries'] as $library){ |
|
98 | + if (!empty($autoloads['libraries']) && is_array($autoloads['libraries'])) { |
|
99 | + foreach ($autoloads['libraries'] as $library) { |
|
100 | 100 | Loader::library($library); |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | 104 | //before load models check if database library is loaded and then load model library |
105 | 105 | //if Database is loaded load the required library |
106 | - if(isset(static::$loaded['database']) || ! empty($autoloads['models'])){ |
|
106 | + if (isset(static::$loaded['database']) || !empty($autoloads['models'])) { |
|
107 | 107 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
108 | 108 | } |
109 | 109 | |
110 | 110 | //models autoload |
111 | - if(! empty($autoloads['models']) && is_array($autoloads['models'])){ |
|
112 | - foreach($autoloads['models'] as $model){ |
|
111 | + if (!empty($autoloads['models']) && is_array($autoloads['models'])) { |
|
112 | + foreach ($autoloads['models'] as $model) { |
|
113 | 113 | Loader::model($model); |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | 117 | //functions autoload |
118 | - if(! empty($autoloads['functions']) && is_array($autoloads['functions'])){ |
|
119 | - foreach($autoloads['functions'] as $function){ |
|
118 | + if (!empty($autoloads['functions']) && is_array($autoloads['functions'])) { |
|
119 | + foreach ($autoloads['functions'] as $function) { |
|
120 | 120 | Loader::functions($function); |
121 | 121 | } |
122 | 122 | } |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * Get the logger singleton instance |
128 | 128 | * @return Log the logger instance |
129 | 129 | */ |
130 | - private static function getLogger(){ |
|
131 | - if(static::$logger == null){ |
|
132 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
130 | + private static function getLogger() { |
|
131 | + if (static::$logger == null) { |
|
132 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
133 | 133 | static::$logger[0]->setLogger('Library::Loader'); |
134 | 134 | } |
135 | 135 | return static::$logger[0]; |
@@ -143,25 +143,25 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - public static function model($class, $instance = null){ |
|
146 | + public static function model($class, $instance = null) { |
|
147 | 147 | $logger = static::getLogger(); |
148 | 148 | $class = str_ireplace('.php', '', $class); |
149 | 149 | $class = trim($class, '/\\'); |
150 | - $file = ucfirst($class).'.php'; |
|
150 | + $file = ucfirst($class) . '.php'; |
|
151 | 151 | $logger->debug('Loading model [' . $class . '] ...'); |
152 | - if(! $instance){ |
|
152 | + if (!$instance) { |
|
153 | 153 | //for module |
154 | - if(strpos($class, '/') !== false){ |
|
154 | + if (strpos($class, '/') !== false) { |
|
155 | 155 | $path = explode('/', $class); |
156 | - if(isset($path[1])){ |
|
156 | + if (isset($path[1])) { |
|
157 | 157 | $instance = strtolower($path[1]); |
158 | 158 | } |
159 | 159 | } |
160 | - else{ |
|
160 | + else { |
|
161 | 161 | $instance = strtolower($class); |
162 | 162 | } |
163 | 163 | } |
164 | - if(isset(static::$loaded[$instance])){ |
|
164 | + if (isset(static::$loaded[$instance])) { |
|
165 | 165 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
166 | 166 | return; |
167 | 167 | } |
@@ -171,43 +171,43 @@ discard block |
||
171 | 171 | $searchModuleName = null; |
172 | 172 | $obj = & get_instance(); |
173 | 173 | //check if the request class contains module name |
174 | - if(strpos($class, '/') !== false){ |
|
174 | + if (strpos($class, '/') !== false) { |
|
175 | 175 | $path = explode('/', $class); |
176 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
176 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
177 | 177 | $searchModuleName = $path[0]; |
178 | 178 | $class = ucfirst($path[1]); |
179 | 179 | } |
180 | 180 | } |
181 | - else{ |
|
181 | + else { |
|
182 | 182 | $class = ucfirst($class); |
183 | 183 | } |
184 | 184 | |
185 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
185 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
186 | 186 | $searchModuleName = $obj->moduleName; |
187 | 187 | } |
188 | 188 | $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName); |
189 | - if($moduleModelFilePath){ |
|
190 | - $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
189 | + if ($moduleModelFilePath) { |
|
190 | + $logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
191 | 191 | $classFilePath = $moduleModelFilePath; |
192 | 192 | } |
193 | - else{ |
|
193 | + else { |
|
194 | 194 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
195 | 195 | } |
196 | 196 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
197 | - if(file_exists($classFilePath)){ |
|
197 | + if (file_exists($classFilePath)) { |
|
198 | 198 | require_once $classFilePath; |
199 | - if(class_exists($class)){ |
|
199 | + if (class_exists($class)) { |
|
200 | 200 | $c = new $class(); |
201 | 201 | $obj = & get_instance(); |
202 | 202 | $obj->{$instance} = $c; |
203 | 203 | static::$loaded[$instance] = $class; |
204 | 204 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
205 | 205 | } |
206 | - else{ |
|
207 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
206 | + else { |
|
207 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
208 | 208 | } |
209 | 209 | } |
210 | - else{ |
|
210 | + else { |
|
211 | 211 | show_error('Unable to find the model [' . $class . ']'); |
212 | 212 | } |
213 | 213 | } |
@@ -222,31 +222,31 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return void |
224 | 224 | */ |
225 | - public static function library($class, $instance = null, array $params = array()){ |
|
225 | + public static function library($class, $instance = null, array $params = array()) { |
|
226 | 226 | $logger = static::getLogger(); |
227 | 227 | $class = str_ireplace('.php', '', $class); |
228 | 228 | $class = trim($class, '/\\'); |
229 | - $file = ucfirst($class) .'.php'; |
|
229 | + $file = ucfirst($class) . '.php'; |
|
230 | 230 | $logger->debug('Loading library [' . $class . '] ...'); |
231 | - if(! $instance){ |
|
231 | + if (!$instance) { |
|
232 | 232 | //for module |
233 | - if(strpos($class, '/') !== false){ |
|
233 | + if (strpos($class, '/') !== false) { |
|
234 | 234 | $path = explode('/', $class); |
235 | - if(isset($path[1])){ |
|
235 | + if (isset($path[1])) { |
|
236 | 236 | $instance = strtolower($path[1]); |
237 | 237 | } |
238 | 238 | } |
239 | - else{ |
|
239 | + else { |
|
240 | 240 | $instance = strtolower($class); |
241 | 241 | } |
242 | 242 | } |
243 | - if(isset(static::$loaded[$instance])){ |
|
243 | + if (isset(static::$loaded[$instance])) { |
|
244 | 244 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
245 | 245 | return; |
246 | 246 | } |
247 | 247 | $obj = & get_instance(); |
248 | 248 | //TODO for Database library |
249 | - if(strtolower($class) == 'database'){ |
|
249 | + if (strtolower($class) == 'database') { |
|
250 | 250 | $logger->info('This is the Database library ...'); |
251 | 251 | $dbInstance = & class_loader('Database', 'classes', $params); |
252 | 252 | $obj->{$instance} = $dbInstance; |
@@ -257,45 +257,45 @@ discard block |
||
257 | 257 | $libraryFilePath = null; |
258 | 258 | $isSystem = false; |
259 | 259 | $logger->debug('Check if this is a system library ...'); |
260 | - if(file_exists(CORE_LIBRARY_PATH . $file)){ |
|
260 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
261 | 261 | $isSystem = true; |
262 | 262 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
263 | 263 | $class = ucfirst($class); |
264 | 264 | $logger->info('This library is a system library'); |
265 | 265 | } |
266 | - else{ |
|
266 | + else { |
|
267 | 267 | $logger->info('This library is not a system library'); |
268 | 268 | //first check if this library is in the module |
269 | 269 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
270 | 270 | $searchModuleName = null; |
271 | 271 | //check if the request class contains module name |
272 | - if(strpos($class, '/') !== false){ |
|
272 | + if (strpos($class, '/') !== false) { |
|
273 | 273 | $path = explode('/', $class); |
274 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
274 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
275 | 275 | $searchModuleName = $path[0]; |
276 | 276 | $class = ucfirst($path[1]); |
277 | 277 | } |
278 | 278 | } |
279 | - else{ |
|
279 | + else { |
|
280 | 280 | $class = ucfirst($class); |
281 | 281 | } |
282 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
282 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
283 | 283 | $searchModuleName = $obj->moduleName; |
284 | 284 | } |
285 | 285 | $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName); |
286 | - if($moduleLibraryPath){ |
|
287 | - $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
286 | + if ($moduleLibraryPath) { |
|
287 | + $logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
288 | 288 | $libraryFilePath = $moduleLibraryPath; |
289 | 289 | } |
290 | - else{ |
|
290 | + else { |
|
291 | 291 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
292 | 292 | } |
293 | 293 | } |
294 | - if(! $libraryFilePath){ |
|
294 | + if (!$libraryFilePath) { |
|
295 | 295 | $searchDir = array(LIBRARY_PATH); |
296 | - foreach($searchDir as $dir){ |
|
296 | + foreach ($searchDir as $dir) { |
|
297 | 297 | $filePath = $dir . $file; |
298 | - if(file_exists($filePath)){ |
|
298 | + if (file_exists($filePath)) { |
|
299 | 299 | $libraryFilePath = $filePath; |
300 | 300 | //is already found not to continue |
301 | 301 | break; |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | } |
304 | 304 | } |
305 | 305 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
306 | - if($libraryFilePath){ |
|
306 | + if ($libraryFilePath) { |
|
307 | 307 | require_once $libraryFilePath; |
308 | - if(class_exists($class)){ |
|
308 | + if (class_exists($class)) { |
|
309 | 309 | $c = $params ? new $class($params) : new $class(); |
310 | 310 | $obj = & get_instance(); |
311 | 311 | $obj->{$instance} = $c; |
312 | 312 | static::$loaded[$instance] = $class; |
313 | 313 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
314 | 314 | } |
315 | - else{ |
|
316 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
315 | + else { |
|
316 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
317 | 317 | } |
318 | 318 | } |
319 | - else{ |
|
319 | + else { |
|
320 | 320 | show_error('Unable to find library class [' . $class . ']'); |
321 | 321 | } |
322 | 322 | } |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * |
329 | 329 | * @return void |
330 | 330 | */ |
331 | - public static function functions($function){ |
|
331 | + public static function functions($function) { |
|
332 | 332 | $logger = static::getLogger(); |
333 | 333 | $function = str_ireplace('.php', '', $function); |
334 | 334 | $function = trim($function, '/\\'); |
335 | 335 | $function = str_ireplace('function_', '', $function); |
336 | - $file = 'function_'.$function.'.php'; |
|
336 | + $file = 'function_' . $function . '.php'; |
|
337 | 337 | $logger->debug('Loading helper [' . $function . '] ...'); |
338 | - if(isset(static::$loaded['function_' . $function])){ |
|
338 | + if (isset(static::$loaded['function_' . $function])) { |
|
339 | 339 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
340 | 340 | return; |
341 | 341 | } |
@@ -345,30 +345,30 @@ discard block |
||
345 | 345 | $searchModuleName = null; |
346 | 346 | $obj = & get_instance(); |
347 | 347 | //check if the request class contains module name |
348 | - if(strpos($function, '/') !== false){ |
|
348 | + if (strpos($function, '/') !== false) { |
|
349 | 349 | $path = explode('/', $function); |
350 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
350 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
351 | 351 | $searchModuleName = $path[0]; |
352 | 352 | $function = 'function_' . $path[1] . '.php'; |
353 | - $file = $path[0] . DS . 'function_'.$function.'.php'; |
|
353 | + $file = $path[0] . DS . 'function_' . $function . '.php'; |
|
354 | 354 | } |
355 | 355 | } |
356 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
356 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
357 | 357 | $searchModuleName = $obj->moduleName; |
358 | 358 | } |
359 | 359 | $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName); |
360 | - if($moduleFunctionPath){ |
|
361 | - $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
360 | + if ($moduleFunctionPath) { |
|
361 | + $logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
362 | 362 | $functionFilePath = $moduleFunctionPath; |
363 | 363 | } |
364 | - else{ |
|
364 | + else { |
|
365 | 365 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
366 | 366 | } |
367 | - if(! $functionFilePath){ |
|
367 | + if (!$functionFilePath) { |
|
368 | 368 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
369 | - foreach($searchDir as $dir){ |
|
369 | + foreach ($searchDir as $dir) { |
|
370 | 370 | $filePath = $dir . $file; |
371 | - if(file_exists($filePath)){ |
|
371 | + if (file_exists($filePath)) { |
|
372 | 372 | $functionFilePath = $filePath; |
373 | 373 | //is already found not to continue |
374 | 374 | break; |
@@ -376,12 +376,12 @@ discard block |
||
376 | 376 | } |
377 | 377 | } |
378 | 378 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
379 | - if($functionFilePath){ |
|
379 | + if ($functionFilePath) { |
|
380 | 380 | require_once $functionFilePath; |
381 | 381 | static::$loaded['function_' . $function] = $functionFilePath; |
382 | 382 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
383 | 383 | } |
384 | - else{ |
|
384 | + else { |
|
385 | 385 | show_error('Unable to find helper file [' . $file . ']'); |
386 | 386 | } |
387 | 387 | } |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | * |
394 | 394 | * @return void |
395 | 395 | */ |
396 | - public static function config($filename){ |
|
396 | + public static function config($filename) { |
|
397 | 397 | $logger = static::getLogger(); |
398 | 398 | $filename = str_ireplace('.php', '', $filename); |
399 | 399 | $filename = trim($filename, '/\\'); |
400 | 400 | $filename = str_ireplace('config_', '', $filename); |
401 | - $file = 'config_'.$filename.'.php'; |
|
401 | + $file = 'config_' . $filename . '.php'; |
|
402 | 402 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
403 | - if(isset(static::$loaded['config_' . $filename])){ |
|
403 | + if (isset(static::$loaded['config_' . $filename])) { |
|
404 | 404 | $logger->info('Configuration [' . $path . '] already loaded no need to load it again, cost in performance'); |
405 | 405 | return; |
406 | 406 | } |
@@ -410,37 +410,37 @@ discard block |
||
410 | 410 | $searchModuleName = null; |
411 | 411 | $obj = & get_instance(); |
412 | 412 | //check if the request class contains module name |
413 | - if(strpos($filename, '/') !== false){ |
|
413 | + if (strpos($filename, '/') !== false) { |
|
414 | 414 | $path = explode('/', $filename); |
415 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
415 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
416 | 416 | $searchModuleName = $path[0]; |
417 | 417 | $filename = $path[1] . '.php'; |
418 | - $file = $path[0] . DS .$filename; |
|
418 | + $file = $path[0] . DS . $filename; |
|
419 | 419 | } |
420 | 420 | } |
421 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
421 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
422 | 422 | $searchModuleName = $obj->moduleName; |
423 | 423 | } |
424 | 424 | $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName); |
425 | - if($moduleConfigPath){ |
|
426 | - $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
425 | + if ($moduleConfigPath) { |
|
426 | + $logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
427 | 427 | $configFilePath = $moduleConfigPath; |
428 | 428 | } |
429 | - else{ |
|
429 | + else { |
|
430 | 430 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
431 | 431 | } |
432 | 432 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
433 | - if(file_exists($configFilePath)){ |
|
433 | + if (file_exists($configFilePath)) { |
|
434 | 434 | require_once $configFilePath; |
435 | - if(! empty($config) && is_array($config)){ |
|
435 | + if (!empty($config) && is_array($config)) { |
|
436 | 436 | Config::setAll($config); |
437 | 437 | } |
438 | - else{ |
|
439 | - show_error('No configuration found in ['. $configFilePath . ']'); |
|
438 | + else { |
|
439 | + show_error('No configuration found in [' . $configFilePath . ']'); |
|
440 | 440 | } |
441 | 441 | } |
442 | - else{ |
|
443 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
442 | + else { |
|
443 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
444 | 444 | } |
445 | 445 | static::$loaded['config_' . $filename] = $configFilePath; |
446 | 446 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -456,14 +456,14 @@ discard block |
||
456 | 456 | * |
457 | 457 | * @return void |
458 | 458 | */ |
459 | - public static function lang($language){ |
|
459 | + public static function lang($language) { |
|
460 | 460 | $logger = static::getLogger(); |
461 | 461 | $language = str_ireplace('.php', '', $language); |
462 | 462 | $language = trim($language, '/\\'); |
463 | 463 | $language = str_ireplace('lang_', '', $language); |
464 | - $file = 'lang_'.$language.'.php'; |
|
464 | + $file = 'lang_' . $language . '.php'; |
|
465 | 465 | $logger->debug('Loading language [' . $language . '] ...'); |
466 | - if(isset(static::$loaded['lang_' . $language])){ |
|
466 | + if (isset(static::$loaded['lang_' . $language])) { |
|
467 | 467 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
468 | 468 | return; |
469 | 469 | } |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | $cfgKey = get_config('language_cookie_name'); |
474 | 474 | $objCookie = & class_loader('Cookie'); |
475 | 475 | $cookieLang = $objCookie->get($cfgKey); |
476 | - if($cookieLang){ |
|
476 | + if ($cookieLang) { |
|
477 | 477 | $appLang = $cookieLang; |
478 | 478 | } |
479 | 479 | $languageFilePath = null; |
@@ -482,30 +482,30 @@ discard block |
||
482 | 482 | $searchModuleName = null; |
483 | 483 | $obj = & get_instance(); |
484 | 484 | //check if the request class contains module name |
485 | - if(strpos($language, '/') !== false){ |
|
485 | + if (strpos($language, '/') !== false) { |
|
486 | 486 | $path = explode('/', $language); |
487 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
487 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
488 | 488 | $searchModuleName = $path[0]; |
489 | 489 | $language = 'lang_' . $path[1] . '.php'; |
490 | - $file = $path[0] . DS .$language; |
|
490 | + $file = $path[0] . DS . $language; |
|
491 | 491 | } |
492 | 492 | } |
493 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
493 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
494 | 494 | $searchModuleName = $obj->moduleName; |
495 | 495 | } |
496 | 496 | $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang); |
497 | - if($moduleLanguagePath){ |
|
498 | - $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
497 | + if ($moduleLanguagePath) { |
|
498 | + $logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
499 | 499 | $languageFilePath = $moduleLanguagePath; |
500 | 500 | } |
501 | - else{ |
|
501 | + else { |
|
502 | 502 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
503 | 503 | } |
504 | - if(! $languageFilePath){ |
|
504 | + if (!$languageFilePath) { |
|
505 | 505 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
506 | - foreach($searchDir as $dir){ |
|
506 | + foreach ($searchDir as $dir) { |
|
507 | 507 | $filePath = $dir . $appLang . DS . $file; |
508 | - if(file_exists($filePath)){ |
|
508 | + if (file_exists($filePath)) { |
|
509 | 509 | $languageFilePath = $filePath; |
510 | 510 | //is already found not to continue |
511 | 511 | break; |
@@ -513,23 +513,23 @@ discard block |
||
513 | 513 | } |
514 | 514 | } |
515 | 515 | $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
516 | - if($languageFilePath){ |
|
516 | + if ($languageFilePath) { |
|
517 | 517 | require_once $languageFilePath; |
518 | - if(! empty($lang) && is_array($lang)){ |
|
519 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
518 | + if (!empty($lang) && is_array($lang)) { |
|
519 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
520 | 520 | //Note: may be here the class 'Lang' not yet loaded |
521 | - $langObj =& class_loader('Lang', 'classes'); |
|
521 | + $langObj = & class_loader('Lang', 'classes'); |
|
522 | 522 | $langObj->addLangMessages($lang); |
523 | 523 | //free the memory |
524 | 524 | unset($lang); |
525 | 525 | } |
526 | - else{ |
|
526 | + else { |
|
527 | 527 | show_error('No language messages found in [' . $languageFilePath . ']'); |
528 | 528 | } |
529 | 529 | static::$loaded['lang_' . $language] = $languageFilePath; |
530 | 530 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
531 | 531 | } |
532 | - else{ |
|
532 | + else { |
|
533 | 533 | show_error('Unable to find language file [' . $file . ']'); |
534 | 534 | } |
535 | 535 | } |
@@ -50,8 +50,7 @@ discard block |
||
50 | 50 | if(! empty($autoload) && is_array($autoload)){ |
51 | 51 | $autoloads = $autoload; |
52 | 52 | unset($autoload); |
53 | - } |
|
54 | - else{ |
|
53 | + } else{ |
|
55 | 54 | show_error('No autoload configuration found in autoload.php'); |
56 | 55 | } |
57 | 56 | } |
@@ -156,8 +155,7 @@ discard block |
||
156 | 155 | if(isset($path[1])){ |
157 | 156 | $instance = strtolower($path[1]); |
158 | 157 | } |
159 | - } |
|
160 | - else{ |
|
158 | + } else{ |
|
161 | 159 | $instance = strtolower($class); |
162 | 160 | } |
163 | 161 | } |
@@ -177,8 +175,7 @@ discard block |
||
177 | 175 | $searchModuleName = $path[0]; |
178 | 176 | $class = ucfirst($path[1]); |
179 | 177 | } |
180 | - } |
|
181 | - else{ |
|
178 | + } else{ |
|
182 | 179 | $class = ucfirst($class); |
183 | 180 | } |
184 | 181 | |
@@ -189,8 +186,7 @@ discard block |
||
189 | 186 | if($moduleModelFilePath){ |
190 | 187 | $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
191 | 188 | $classFilePath = $moduleModelFilePath; |
192 | - } |
|
193 | - else{ |
|
189 | + } else{ |
|
194 | 190 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
195 | 191 | } |
196 | 192 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
@@ -202,12 +198,10 @@ discard block |
||
202 | 198 | $obj->{$instance} = $c; |
203 | 199 | static::$loaded[$instance] = $class; |
204 | 200 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
205 | - } |
|
206 | - else{ |
|
201 | + } else{ |
|
207 | 202 | show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
208 | 203 | } |
209 | - } |
|
210 | - else{ |
|
204 | + } else{ |
|
211 | 205 | show_error('Unable to find the model [' . $class . ']'); |
212 | 206 | } |
213 | 207 | } |
@@ -235,8 +229,7 @@ discard block |
||
235 | 229 | if(isset($path[1])){ |
236 | 230 | $instance = strtolower($path[1]); |
237 | 231 | } |
238 | - } |
|
239 | - else{ |
|
232 | + } else{ |
|
240 | 233 | $instance = strtolower($class); |
241 | 234 | } |
242 | 235 | } |
@@ -262,8 +255,7 @@ discard block |
||
262 | 255 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
263 | 256 | $class = ucfirst($class); |
264 | 257 | $logger->info('This library is a system library'); |
265 | - } |
|
266 | - else{ |
|
258 | + } else{ |
|
267 | 259 | $logger->info('This library is not a system library'); |
268 | 260 | //first check if this library is in the module |
269 | 261 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
@@ -275,8 +267,7 @@ discard block |
||
275 | 267 | $searchModuleName = $path[0]; |
276 | 268 | $class = ucfirst($path[1]); |
277 | 269 | } |
278 | - } |
|
279 | - else{ |
|
270 | + } else{ |
|
280 | 271 | $class = ucfirst($class); |
281 | 272 | } |
282 | 273 | if(! $searchModuleName && !empty($obj->moduleName)){ |
@@ -286,8 +277,7 @@ discard block |
||
286 | 277 | if($moduleLibraryPath){ |
287 | 278 | $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
288 | 279 | $libraryFilePath = $moduleLibraryPath; |
289 | - } |
|
290 | - else{ |
|
280 | + } else{ |
|
291 | 281 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
292 | 282 | } |
293 | 283 | } |
@@ -311,12 +301,10 @@ discard block |
||
311 | 301 | $obj->{$instance} = $c; |
312 | 302 | static::$loaded[$instance] = $class; |
313 | 303 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
314 | - } |
|
315 | - else{ |
|
304 | + } else{ |
|
316 | 305 | show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
317 | 306 | } |
318 | - } |
|
319 | - else{ |
|
307 | + } else{ |
|
320 | 308 | show_error('Unable to find library class [' . $class . ']'); |
321 | 309 | } |
322 | 310 | } |
@@ -360,8 +348,7 @@ discard block |
||
360 | 348 | if($moduleFunctionPath){ |
361 | 349 | $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
362 | 350 | $functionFilePath = $moduleFunctionPath; |
363 | - } |
|
364 | - else{ |
|
351 | + } else{ |
|
365 | 352 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
366 | 353 | } |
367 | 354 | if(! $functionFilePath){ |
@@ -380,8 +367,7 @@ discard block |
||
380 | 367 | require_once $functionFilePath; |
381 | 368 | static::$loaded['function_' . $function] = $functionFilePath; |
382 | 369 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
383 | - } |
|
384 | - else{ |
|
370 | + } else{ |
|
385 | 371 | show_error('Unable to find helper file [' . $file . ']'); |
386 | 372 | } |
387 | 373 | } |
@@ -425,8 +411,7 @@ discard block |
||
425 | 411 | if($moduleConfigPath){ |
426 | 412 | $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
427 | 413 | $configFilePath = $moduleConfigPath; |
428 | - } |
|
429 | - else{ |
|
414 | + } else{ |
|
430 | 415 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
431 | 416 | } |
432 | 417 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
@@ -434,12 +419,10 @@ discard block |
||
434 | 419 | require_once $configFilePath; |
435 | 420 | if(! empty($config) && is_array($config)){ |
436 | 421 | Config::setAll($config); |
437 | - } |
|
438 | - else{ |
|
422 | + } else{ |
|
439 | 423 | show_error('No configuration found in ['. $configFilePath . ']'); |
440 | 424 | } |
441 | - } |
|
442 | - else{ |
|
425 | + } else{ |
|
443 | 426 | show_error('Unable to find config file ['. $configFilePath . ']'); |
444 | 427 | } |
445 | 428 | static::$loaded['config_' . $filename] = $configFilePath; |
@@ -497,8 +480,7 @@ discard block |
||
497 | 480 | if($moduleLanguagePath){ |
498 | 481 | $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
499 | 482 | $languageFilePath = $moduleLanguagePath; |
500 | - } |
|
501 | - else{ |
|
483 | + } else{ |
|
502 | 484 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
503 | 485 | } |
504 | 486 | if(! $languageFilePath){ |
@@ -522,14 +504,12 @@ discard block |
||
522 | 504 | $langObj->addLangMessages($lang); |
523 | 505 | //free the memory |
524 | 506 | unset($lang); |
525 | - } |
|
526 | - else{ |
|
507 | + } else{ |
|
527 | 508 | show_error('No language messages found in [' . $languageFilePath . ']'); |
528 | 509 | } |
529 | 510 | static::$loaded['lang_' . $language] = $languageFilePath; |
530 | 511 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
531 | - } |
|
532 | - else{ |
|
512 | + } else{ |
|
533 | 513 | show_error('Unable to find language file [' . $file . ']'); |
534 | 514 | } |
535 | 515 | } |
@@ -22,7 +22,7 @@ |
||
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 | * This class represent the event detail to dispatch to correspond listener |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * This class represent the event detail to dispatch to correspond listener |
29 | 29 | */ |
30 | - class Event{ |
|
30 | + class Event { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public $stop; |
56 | 56 | |
57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
58 | 58 | $this->name = $name; |
59 | 59 | $this->payload = $payload; |
60 | 60 | $this->returnBack = $returnBack; |
@@ -22,7 +22,7 @@ |
||
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 | class Request{ |
28 | 28 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Request{ |
|
27 | + class Request { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The value for the super global $_GET |
@@ -90,21 +90,21 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * Construct new request instance |
92 | 92 | */ |
93 | - public function __construct(){ |
|
93 | + public function __construct() { |
|
94 | 94 | $this->get = $_GET; |
95 | 95 | $this->post = $_POST; |
96 | 96 | $this->server = $_SERVER; |
97 | 97 | $this->query = $_REQUEST; |
98 | 98 | $this->cookie = $_COOKIE; |
99 | 99 | $this->file = $_FILES; |
100 | - $this->session =& class_loader('Session', 'classes'); |
|
100 | + $this->session = & class_loader('Session', 'classes'); |
|
101 | 101 | $this->method = $this->server('REQUEST_METHOD'); |
102 | 102 | $this->requestUri = $this->server('REQUEST_URI'); |
103 | 103 | $this->header = array(); |
104 | - if(function_exists('apache_request_headers')){ |
|
104 | + if (function_exists('apache_request_headers')) { |
|
105 | 105 | $this->header = apache_request_headers(); |
106 | 106 | } |
107 | - else if(function_exists('getallheaders')){ |
|
107 | + else if (function_exists('getallheaders')) { |
|
108 | 108 | $this->header = getallheaders(); |
109 | 109 | } |
110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * Get the request method |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public function method(){ |
|
116 | + public function method() { |
|
117 | 117 | return $this->method; |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * Get the request URI |
122 | 122 | * @return string |
123 | 123 | */ |
124 | - public function requestUri(){ |
|
124 | + public function requestUri() { |
|
125 | 125 | return $this->requestUri; |
126 | 126 | } |
127 | 127 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @param boolean $xss if need apply some XSS attack rule on the value |
132 | 132 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
133 | 133 | */ |
134 | - public function query($key = null, $xss = true){ |
|
135 | - if(empty($key)){ |
|
134 | + public function query($key = null, $xss = true) { |
|
135 | + if (empty($key)) { |
|
136 | 136 | //return all |
137 | 137 | return $xss ? clean_input($this->query) : $this->query; |
138 | 138 | } |
139 | 139 | $query = array_key_exists($key, $this->query) ? $this->query[$key] : null; |
140 | - if($xss){ |
|
140 | + if ($xss) { |
|
141 | 141 | $query = clean_input($query); |
142 | 142 | } |
143 | 143 | return $query; |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | * @param boolean $xss if need apply some XSS attack rule on the value |
150 | 150 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
151 | 151 | */ |
152 | - public function get($key = null, $xss = true){ |
|
153 | - if(empty($key)){ |
|
152 | + public function get($key = null, $xss = true) { |
|
153 | + if (empty($key)) { |
|
154 | 154 | //return all |
155 | 155 | return $xss ? clean_input($this->get) : $this->get; |
156 | 156 | } |
157 | 157 | $get = array_key_exists($key, $this->get) ? $this->get[$key] : null; |
158 | - if($xss){ |
|
158 | + if ($xss) { |
|
159 | 159 | $get = clean_input($get); |
160 | 160 | } |
161 | 161 | return $get; |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @param boolean $xss if need apply some XSS attack rule on the value |
168 | 168 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
169 | 169 | */ |
170 | - public function post($key = null, $xss = true){ |
|
171 | - if(empty($key)){ |
|
170 | + public function post($key = null, $xss = true) { |
|
171 | + if (empty($key)) { |
|
172 | 172 | //return all |
173 | 173 | return $xss ? clean_input($this->post) : $this->post; |
174 | 174 | } |
175 | 175 | $post = array_key_exists($key, $this->post) ? $this->post[$key] : null; |
176 | - if($xss){ |
|
176 | + if ($xss) { |
|
177 | 177 | $post = clean_input($post); |
178 | 178 | } |
179 | 179 | return $post; |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @param boolean $xss if need apply some XSS attack rule on the value |
186 | 186 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
187 | 187 | */ |
188 | - public function server($key = null, $xss = true){ |
|
189 | - if(empty($key)){ |
|
188 | + public function server($key = null, $xss = true) { |
|
189 | + if (empty($key)) { |
|
190 | 190 | //return all |
191 | 191 | return $xss ? clean_input($this->server) : $this->server; |
192 | 192 | } |
193 | 193 | $server = array_key_exists($key, $this->server) ? $this->server[$key] : null; |
194 | - if($xss){ |
|
194 | + if ($xss) { |
|
195 | 195 | $server = clean_input($server); |
196 | 196 | } |
197 | 197 | return $server; |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | * @param boolean $xss if need apply some XSS attack rule on the value |
204 | 204 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
205 | 205 | */ |
206 | - public function cookie($key = null, $xss = true){ |
|
207 | - if(empty($key)){ |
|
206 | + public function cookie($key = null, $xss = true) { |
|
207 | + if (empty($key)) { |
|
208 | 208 | //return all |
209 | 209 | return $xss ? clean_input($this->cookie) : $this->cookie; |
210 | 210 | } |
211 | 211 | $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null; |
212 | - if($xss){ |
|
212 | + if ($xss) { |
|
213 | 213 | $cookie = clean_input($cookie); |
214 | 214 | } |
215 | 215 | return $cookie; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param boolean $xss if need apply some XSS attack rule on the value |
222 | 222 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
223 | 223 | */ |
224 | - public function file($key, $xss = true){ |
|
224 | + public function file($key, $xss = true) { |
|
225 | 225 | $file = array_key_exists($key, $this->file) ? $this->file[$key] : null; |
226 | 226 | return $file; |
227 | 227 | } |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | * @param boolean $xss if need apply some XSS attack rule on the value |
233 | 233 | * @return array|mixed the item value if the key exists or null if the key does not exists |
234 | 234 | */ |
235 | - public function session($key, $xss = true){ |
|
235 | + public function session($key, $xss = true) { |
|
236 | 236 | $session = $this->session->get($key); |
237 | - if($xss){ |
|
237 | + if ($xss) { |
|
238 | 238 | $session = clean_input($session); |
239 | 239 | } |
240 | 240 | return $session; |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | * @param boolean $xss if need apply some XSS attack rule on the value |
247 | 247 | * @return mixed the item value if the key exists or null if the key does not exists |
248 | 248 | */ |
249 | - public function header($key, $xss = true){ |
|
249 | + public function header($key, $xss = true) { |
|
250 | 250 | $header = array_key_exists($key, $this->header) ? $this->header[$key] : null; |
251 | - if($xss){ |
|
251 | + if ($xss) { |
|
252 | 252 | $header = clean_input($header); |
253 | 253 | } |
254 | 254 | return $header; |
@@ -103,8 +103,7 @@ |
||
103 | 103 | $this->header = array(); |
104 | 104 | if(function_exists('apache_request_headers')){ |
105 | 105 | $this->header = apache_request_headers(); |
106 | - } |
|
107 | - else if(function_exists('getallheaders')){ |
|
106 | + } else if(function_exists('getallheaders')){ |
|
108 | 107 | $this->header = getallheaders(); |
109 | 108 | } |
110 | 109 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
3 | 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 | - */ |
|
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 Module{ |
28 | 28 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Module{ |
|
27 | + class Module { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * list of loaded module |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * The signleton of the logger |
43 | 43 | * @return Object the Log instance |
44 | 44 | */ |
45 | - private static function getLogger(){ |
|
46 | - if(static::$logger == null){ |
|
47 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
45 | + private static function getLogger() { |
|
46 | + if (static::$logger == null) { |
|
47 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
48 | 48 | static::$logger[0]->setLogger('Library::Module'); |
49 | 49 | } |
50 | 50 | return static::$logger[0]; |
@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * Initialise the module list by scanning the directory MODULE_PATH |
55 | 55 | */ |
56 | - public function init(){ |
|
56 | + public function init() { |
|
57 | 57 | $logger = static::getLogger(); |
58 | 58 | $logger->debug('Check if the application contains the modules ...'); |
59 | 59 | $moduleDir = opendir(MODULE_PATH); |
60 | - while(($module = readdir($moduleDir)) !== false){ |
|
61 | - if($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
60 | + while (($module = readdir($moduleDir)) !== false) { |
|
61 | + if ($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
62 | 62 | static::$list[] = $module; |
63 | 63 | } |
64 | - else{ |
|
65 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
64 | + else { |
|
65 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | closedir($moduleDir); |
69 | 69 | ksort(static::$list); |
70 | 70 | |
71 | - if(static::hasModule()){ |
|
71 | + if (static::hasModule()) { |
|
72 | 72 | $logger->info('The application contains the module below [' . implode(', ', static::getModuleList()) . ']'); |
73 | 73 | } |
74 | - else{ |
|
74 | + else { |
|
75 | 75 | $logger->info('The application contains no module skipping'); |
76 | 76 | } |
77 | 77 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * Get the list of the custom autoload configuration from module if exists |
81 | 81 | * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
82 | 82 | */ |
83 | - public static function getModulesAutoloadConfig(){ |
|
83 | + public static function getModulesAutoloadConfig() { |
|
84 | 84 | $logger = static::getLogger(); |
85 | - if(! static::hasModule()){ |
|
85 | + if (!static::hasModule()) { |
|
86 | 86 | $logger->info('No module was loaded skipping.'); |
87 | 87 | return false; |
88 | 88 | } |
@@ -94,33 +94,33 @@ discard block |
||
94 | 94 | |
95 | 95 | foreach (static::$list as $module) { |
96 | 96 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
97 | - if(file_exists($file)){ |
|
97 | + if (file_exists($file)) { |
|
98 | 98 | require_once $file; |
99 | - if(! empty($autoload) && is_array($autoload)){ |
|
99 | + if (!empty($autoload) && is_array($autoload)) { |
|
100 | 100 | //libraries autoload |
101 | - if(! empty($autoload['libraries']) && is_array($autoload['libraries'])){ |
|
101 | + if (!empty($autoload['libraries']) && is_array($autoload['libraries'])) { |
|
102 | 102 | $autoloads['libraries'] = array_merge($autoloads['libraries'], $autoload['libraries']); |
103 | 103 | } |
104 | 104 | //config autoload |
105 | - if(! empty($autoload['config']) && is_array($autoload['config'])){ |
|
105 | + if (!empty($autoload['config']) && is_array($autoload['config'])) { |
|
106 | 106 | $autoloads['config'] = array_merge($autoloads['config'], $autoload['config']); |
107 | 107 | } |
108 | 108 | //models autoload |
109 | - if(! empty($autoload['models']) && is_array($autoload['models'])){ |
|
109 | + if (!empty($autoload['models']) && is_array($autoload['models'])) { |
|
110 | 110 | $autoloads['models'] = array_merge($autoloads['models'], $autoload['models']); |
111 | 111 | } |
112 | 112 | //functions autoload |
113 | - if(! empty($autoload['functions']) && is_array($autoload['functions'])){ |
|
113 | + if (!empty($autoload['functions']) && is_array($autoload['functions'])) { |
|
114 | 114 | $autoloads['functions'] = array_merge($autoloads['functions'], $autoload['functions']); |
115 | 115 | } |
116 | 116 | //languages autoload |
117 | - if(! empty($autoload['languages']) && is_array($autoload['languages'])){ |
|
117 | + if (!empty($autoload['languages']) && is_array($autoload['languages'])) { |
|
118 | 118 | $autoloads['languages'] = array_merge($autoloads['languages'], $autoload['languages']); |
119 | 119 | } |
120 | 120 | unset($autoload); |
121 | 121 | } |
122 | - else{ |
|
123 | - show_error('No autoload configuration found in autoload.php for module [' .$module. ']'); |
|
122 | + else { |
|
123 | + show_error('No autoload configuration found in autoload.php for module [' . $module . ']'); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -131,23 +131,23 @@ discard block |
||
131 | 131 | * Get the list of the custom routes configuration from module if exists |
132 | 132 | * @return array|boolean the routes list or false if no module contains the routes configuration |
133 | 133 | */ |
134 | - public static function getModulesRoutes(){ |
|
134 | + public static function getModulesRoutes() { |
|
135 | 135 | $logger = static::getLogger(); |
136 | - if(! static::hasModule()){ |
|
136 | + if (!static::hasModule()) { |
|
137 | 137 | $logger->info('No module was loaded skipping.'); |
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | $routes = array(); |
141 | 141 | foreach (static::$list as $module) { |
142 | 142 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
143 | - if(file_exists($file)){ |
|
143 | + if (file_exists($file)) { |
|
144 | 144 | require_once $file; |
145 | - if(! empty($route) && is_array($route)){ |
|
145 | + if (!empty($route) && is_array($route)) { |
|
146 | 146 | $routes = array_merge($routes, $route); |
147 | 147 | unset($route); |
148 | 148 | } |
149 | - else{ |
|
150 | - show_error('No routing configuration found in [' .$file. '] for module [' . $module . ']'); |
|
149 | + else { |
|
150 | + show_error('No routing configuration found in [' . $file . '] for module [' . $module . ']'); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
@@ -161,23 +161,23 @@ discard block |
||
161 | 161 | * @param string $module the module name |
162 | 162 | * @return boolean|string false or null if no module have this controller, path the full path of the controller |
163 | 163 | */ |
164 | - public static function findControllerFullPath($class, $module = null){ |
|
164 | + public static function findControllerFullPath($class, $module = null) { |
|
165 | 165 | $logger = static::getLogger(); |
166 | - if(! static::hasModule()){ |
|
166 | + if (!static::hasModule()) { |
|
167 | 167 | $logger->info('No module was loaded skiping.'); |
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | $class = str_ireplace('.php', '', $class); |
171 | 171 | $class = ucfirst($class); |
172 | - $classFile = $class.'.php'; |
|
173 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
172 | + $classFile = $class . '.php'; |
|
173 | + $logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...'); |
|
174 | 174 | $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
175 | - if(file_exists($filePath)){ |
|
176 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
175 | + if (file_exists($filePath)) { |
|
176 | + $logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
177 | 177 | return $filePath; |
178 | 178 | } |
179 | - else{ |
|
180 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
179 | + else { |
|
180 | + $logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']'); |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | } |
@@ -188,23 +188,23 @@ discard block |
||
188 | 188 | * @param string $module the module name |
189 | 189 | * @return boolean|string false or null if no module have this model, return the full path of this model |
190 | 190 | */ |
191 | - public static function findModelFullPath($class, $module = null){ |
|
191 | + public static function findModelFullPath($class, $module = null) { |
|
192 | 192 | $logger = static::getLogger(); |
193 | - if(! static::hasModule()){ |
|
193 | + if (!static::hasModule()) { |
|
194 | 194 | $logger->info('No module was loaded skiping.'); |
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | $class = str_ireplace('.php', '', $class); |
198 | 198 | $class = ucfirst($class); |
199 | - $classFile = $class.'.php'; |
|
200 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
199 | + $classFile = $class . '.php'; |
|
200 | + $logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...'); |
|
201 | 201 | $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
202 | - if(file_exists($filePath)){ |
|
203 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
202 | + if (file_exists($filePath)) { |
|
203 | + $logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
204 | 204 | return $filePath; |
205 | 205 | } |
206 | - else{ |
|
207 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
206 | + else { |
|
207 | + $logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']'); |
|
208 | 208 | return false; |
209 | 209 | } |
210 | 210 | } |
@@ -215,22 +215,22 @@ discard block |
||
215 | 215 | * @param string $module the module name |
216 | 216 | * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
217 | 217 | */ |
218 | - public static function findConfigFullPath($configuration, $module = null){ |
|
218 | + public static function findConfigFullPath($configuration, $module = null) { |
|
219 | 219 | $logger = static::getLogger(); |
220 | - if(! static::hasModule()){ |
|
220 | + if (!static::hasModule()) { |
|
221 | 221 | $logger->info('No module was loaded skiping.'); |
222 | 222 | return false; |
223 | 223 | } |
224 | 224 | $configuration = str_ireplace('.php', '', $configuration); |
225 | - $file = $configuration.'.php'; |
|
226 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
225 | + $file = $configuration . '.php'; |
|
226 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...'); |
|
227 | 227 | $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
228 | - if(file_exists($filePath)){ |
|
229 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
228 | + if (file_exists($filePath)) { |
|
229 | + $logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
230 | 230 | return $filePath; |
231 | 231 | } |
232 | - else{ |
|
233 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
232 | + else { |
|
233 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']'); |
|
234 | 234 | return false; |
235 | 235 | } |
236 | 236 | } |
@@ -241,23 +241,23 @@ discard block |
||
241 | 241 | * @param string $module the module name |
242 | 242 | * @return boolean|string false or null if no module have this helper, return the full path of this helper |
243 | 243 | */ |
244 | - public static function findFunctionFullPath($helper, $module = null){ |
|
244 | + public static function findFunctionFullPath($helper, $module = null) { |
|
245 | 245 | $logger = static::getLogger(); |
246 | - if(! static::hasModule()){ |
|
246 | + if (!static::hasModule()) { |
|
247 | 247 | $logger->info('No module was loaded skiping.'); |
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | $helper = str_ireplace('.php', '', $helper); |
251 | 251 | $helper = str_ireplace('function_', '', $helper); |
252 | - $file = 'function_'.$helper.'.php'; |
|
253 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
252 | + $file = 'function_' . $helper . '.php'; |
|
253 | + $logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...'); |
|
254 | 254 | $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
255 | - if(file_exists($filePath)){ |
|
256 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
255 | + if (file_exists($filePath)) { |
|
256 | + $logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
257 | 257 | return $filePath; |
258 | 258 | } |
259 | - else{ |
|
260 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
259 | + else { |
|
260 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']'); |
|
261 | 261 | return false; |
262 | 262 | } |
263 | 263 | } |
@@ -269,22 +269,22 @@ discard block |
||
269 | 269 | * @param string $module the module name |
270 | 270 | * @return boolean|string false or null if no module have this library, return the full path of this library |
271 | 271 | */ |
272 | - public static function findLibraryFullPath($class, $module = null){ |
|
272 | + public static function findLibraryFullPath($class, $module = null) { |
|
273 | 273 | $logger = static::getLogger(); |
274 | - if(! static::hasModule()){ |
|
274 | + if (!static::hasModule()) { |
|
275 | 275 | $logger->info('No module was loaded skiping.'); |
276 | 276 | return false; |
277 | 277 | } |
278 | 278 | $class = str_ireplace('.php', '', $class); |
279 | - $file = $class.'.php'; |
|
280 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
279 | + $file = $class . '.php'; |
|
280 | + $logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...'); |
|
281 | 281 | $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
282 | - if(file_exists($filePath)){ |
|
283 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
282 | + if (file_exists($filePath)) { |
|
283 | + $logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
284 | 284 | return $filePath; |
285 | 285 | } |
286 | - else{ |
|
287 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
286 | + else { |
|
287 | + $logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']'); |
|
288 | 288 | return false; |
289 | 289 | } |
290 | 290 | } |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | * @param string $module the module name to check |
297 | 297 | * @return boolean|string false or null if no module have this view, path the full path of the view |
298 | 298 | */ |
299 | - public static function findViewFullPath($view, $module = null){ |
|
299 | + public static function findViewFullPath($view, $module = null) { |
|
300 | 300 | $logger = static::getLogger(); |
301 | - if(! static::hasModule()){ |
|
301 | + if (!static::hasModule()) { |
|
302 | 302 | $logger->info('No module was loaded skiping.'); |
303 | 303 | return false; |
304 | 304 | } |
@@ -306,14 +306,14 @@ discard block |
||
306 | 306 | $view = trim($view, '/\\'); |
307 | 307 | $view = str_ireplace('/', DS, $view); |
308 | 308 | $viewFile = $view . '.php'; |
309 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
309 | + $logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...'); |
|
310 | 310 | $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
311 | - if(file_exists($filePath)){ |
|
312 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
311 | + if (file_exists($filePath)) { |
|
312 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
313 | 313 | return $filePath; |
314 | 314 | } |
315 | - else{ |
|
316 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
315 | + else { |
|
316 | + $logger->info('View [' . $view . '] does not exist in the module [' . $module . ']'); |
|
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | } |
@@ -325,23 +325,23 @@ discard block |
||
325 | 325 | * @param string $appLang the application language like 'en', 'fr' |
326 | 326 | * @return boolean|string false or null if no module have this language, return the full path of this language |
327 | 327 | */ |
328 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
328 | + public static function findLanguageFullPath($language, $module = null, $appLang) { |
|
329 | 329 | $logger = static::getLogger(); |
330 | - if(! static::hasModule()){ |
|
330 | + if (!static::hasModule()) { |
|
331 | 331 | $logger->info('No module was loaded skiping.'); |
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | $language = str_ireplace('.php', '', $language); |
335 | 335 | $language = str_ireplace('lang_', '', $language); |
336 | - $file = 'lang_'.$language.'.php'; |
|
337 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
336 | + $file = 'lang_' . $language . '.php'; |
|
337 | + $logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...'); |
|
338 | 338 | $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
339 | - if(file_exists($filePath)){ |
|
340 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
339 | + if (file_exists($filePath)) { |
|
340 | + $logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
341 | 341 | return $filePath; |
342 | 342 | } |
343 | - else{ |
|
344 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
343 | + else { |
|
344 | + $logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']'); |
|
345 | 345 | return false; |
346 | 346 | } |
347 | 347 | } |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | * Get the list of module loaded |
351 | 351 | * @return array the module list |
352 | 352 | */ |
353 | - public static function getModuleList(){ |
|
353 | + public static function getModuleList() { |
|
354 | 354 | return static::$list; |
355 | 355 | } |
356 | 356 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * Check if the application has an module |
359 | 359 | * @return boolean |
360 | 360 | */ |
361 | - public static function hasModule(){ |
|
361 | + public static function hasModule() { |
|
362 | 362 | return !empty(static::$list); |
363 | 363 | } |
364 | 364 |
@@ -60,8 +60,7 @@ discard block |
||
60 | 60 | while(($module = readdir($moduleDir)) !== false){ |
61 | 61 | if($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
62 | 62 | static::$list[] = $module; |
63 | - } |
|
64 | - else{ |
|
63 | + } else{ |
|
65 | 64 | $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
66 | 65 | } |
67 | 66 | } |
@@ -70,8 +69,7 @@ discard block |
||
70 | 69 | |
71 | 70 | if(static::hasModule()){ |
72 | 71 | $logger->info('The application contains the module below [' . implode(', ', static::getModuleList()) . ']'); |
73 | - } |
|
74 | - else{ |
|
72 | + } else{ |
|
75 | 73 | $logger->info('The application contains no module skipping'); |
76 | 74 | } |
77 | 75 | } |
@@ -118,8 +116,7 @@ discard block |
||
118 | 116 | $autoloads['languages'] = array_merge($autoloads['languages'], $autoload['languages']); |
119 | 117 | } |
120 | 118 | unset($autoload); |
121 | - } |
|
122 | - else{ |
|
119 | + } else{ |
|
123 | 120 | show_error('No autoload configuration found in autoload.php for module [' .$module. ']'); |
124 | 121 | } |
125 | 122 | } |
@@ -145,8 +142,7 @@ discard block |
||
145 | 142 | if(! empty($route) && is_array($route)){ |
146 | 143 | $routes = array_merge($routes, $route); |
147 | 144 | unset($route); |
148 | - } |
|
149 | - else{ |
|
145 | + } else{ |
|
150 | 146 | show_error('No routing configuration found in [' .$file. '] for module [' . $module . ']'); |
151 | 147 | } |
152 | 148 | } |
@@ -175,8 +171,7 @@ discard block |
||
175 | 171 | if(file_exists($filePath)){ |
176 | 172 | $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
177 | 173 | return $filePath; |
178 | - } |
|
179 | - else{ |
|
174 | + } else{ |
|
180 | 175 | $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
181 | 176 | return false; |
182 | 177 | } |
@@ -202,8 +197,7 @@ discard block |
||
202 | 197 | if(file_exists($filePath)){ |
203 | 198 | $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
204 | 199 | return $filePath; |
205 | - } |
|
206 | - else{ |
|
200 | + } else{ |
|
207 | 201 | $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
208 | 202 | return false; |
209 | 203 | } |
@@ -228,8 +222,7 @@ discard block |
||
228 | 222 | if(file_exists($filePath)){ |
229 | 223 | $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
230 | 224 | return $filePath; |
231 | - } |
|
232 | - else{ |
|
225 | + } else{ |
|
233 | 226 | $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
234 | 227 | return false; |
235 | 228 | } |
@@ -255,8 +248,7 @@ discard block |
||
255 | 248 | if(file_exists($filePath)){ |
256 | 249 | $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
257 | 250 | return $filePath; |
258 | - } |
|
259 | - else{ |
|
251 | + } else{ |
|
260 | 252 | $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
261 | 253 | return false; |
262 | 254 | } |
@@ -282,8 +274,7 @@ discard block |
||
282 | 274 | if(file_exists($filePath)){ |
283 | 275 | $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
284 | 276 | return $filePath; |
285 | - } |
|
286 | - else{ |
|
277 | + } else{ |
|
287 | 278 | $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
288 | 279 | return false; |
289 | 280 | } |
@@ -311,8 +302,7 @@ discard block |
||
311 | 302 | if(file_exists($filePath)){ |
312 | 303 | $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
313 | 304 | return $filePath; |
314 | - } |
|
315 | - else{ |
|
305 | + } else{ |
|
316 | 306 | $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
317 | 307 | return false; |
318 | 308 | } |
@@ -339,8 +329,7 @@ discard block |
||
339 | 329 | if(file_exists($filePath)){ |
340 | 330 | $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
341 | 331 | return $filePath; |
342 | - } |
|
343 | - else{ |
|
332 | + } else{ |
|
344 | 333 | $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
345 | 334 | return false; |
346 | 335 | } |
@@ -22,7 +22,7 @@ |
||
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 | class Log{ |
28 | 28 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Log{ |
|
27 | + class Log { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The defined constante for Log level |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Create new Log instance |
54 | 54 | */ |
55 | - public function __construct(){ |
|
55 | + public function __construct() { |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Set the logger to identify each message in the log |
60 | 60 | * @param string $logger the logger name |
61 | 61 | */ |
62 | - public function setLogger($logger){ |
|
62 | + public function setLogger($logger) { |
|
63 | 63 | $this->logger = $logger; |
64 | 64 | } |
65 | 65 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @see Log::writeLog for more detail |
69 | 69 | * @param string $message the log message to save |
70 | 70 | */ |
71 | - public function fatal($message){ |
|
71 | + public function fatal($message) { |
|
72 | 72 | $this->writeLog($message, self::FATAL); |
73 | 73 | } |
74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @see Log::writeLog for more detail |
78 | 78 | * @param string $message the log message to save |
79 | 79 | */ |
80 | - public function error($message){ |
|
80 | + public function error($message) { |
|
81 | 81 | $this->writeLog($message, self::ERROR); |
82 | 82 | } |
83 | 83 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @see Log::writeLog for more detail |
87 | 87 | * @param string $message the log message to save |
88 | 88 | */ |
89 | - public function warning($message){ |
|
89 | + public function warning($message) { |
|
90 | 90 | $this->writeLog($message, self::WARNING); |
91 | 91 | } |
92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @see Log::writeLog for more detail |
96 | 96 | * @param string $message the log message to save |
97 | 97 | */ |
98 | - public function info($message){ |
|
98 | + public function info($message) { |
|
99 | 99 | $this->writeLog($message, self::INFO); |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @see Log::writeLog for more detail |
105 | 105 | * @param string $message the log message to save |
106 | 106 | */ |
107 | - public function debug($message){ |
|
107 | + public function debug($message) { |
|
108 | 108 | $this->writeLog($message, self::DEBUG); |
109 | 109 | } |
110 | 110 | |
@@ -115,59 +115,59 @@ discard block |
||
115 | 115 | * @param int|string $level the log level in integer or string format, if is string will convert into integer |
116 | 116 | * to allow check the log level threshold. |
117 | 117 | */ |
118 | - public function writeLog($message, $level = self::INFO){ |
|
118 | + public function writeLog($message, $level = self::INFO) { |
|
119 | 119 | $configLogLevel = get_config('log_level'); |
120 | - if(! $configLogLevel){ |
|
120 | + if (!$configLogLevel) { |
|
121 | 121 | //so means no need log just stop here |
122 | 122 | return; |
123 | 123 | } |
124 | 124 | //check config log level |
125 | - if(! static::isValidConfigLevel($configLogLevel)){ |
|
125 | + if (!static::isValidConfigLevel($configLogLevel)) { |
|
126 | 126 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
127 | 127 | show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', static::$validConfigLevel)), $title = 'Log Config Error', $logging = false); |
128 | 128 | } |
129 | 129 | |
130 | 130 | //check if config log_logger_name is set |
131 | - if($this->logger){ |
|
131 | + if ($this->logger) { |
|
132 | 132 | $configLoggerName = get_config('log_logger_name', ''); |
133 | - if($configLoggerName){ |
|
134 | - if (is_array($configLoggerName)){ |
|
133 | + if ($configLoggerName) { |
|
134 | + if (is_array($configLoggerName)) { |
|
135 | 135 | //for best comparaison put all string to lowercase |
136 | 136 | $configLoggerName = array_map('strtolower', $configLoggerName); |
137 | - if(! in_array(strtolower($this->logger), $configLoggerName)){ |
|
137 | + if (!in_array(strtolower($this->logger), $configLoggerName)) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | } |
141 | - else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
141 | + else if (strtolower($this->logger) !== strtolower($configLoggerName)) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | //if $level is not an integer |
148 | - if(! is_numeric($level)){ |
|
148 | + if (!is_numeric($level)) { |
|
149 | 149 | $level = static::getLevelValue($level); |
150 | 150 | } |
151 | 151 | |
152 | 152 | //check if can logging regarding the log level config |
153 | 153 | $configLevel = static::getLevelValue($configLogLevel); |
154 | - if($configLevel > $level){ |
|
154 | + if ($configLevel > $level) { |
|
155 | 155 | //can't log |
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $logSavePath = get_config('log_save_path'); |
160 | - if(! $logSavePath){ |
|
160 | + if (!$logSavePath) { |
|
161 | 161 | $logSavePath = LOGS_PATH; |
162 | 162 | } |
163 | 163 | |
164 | - if(! is_dir($logSavePath) || !is_writable($logSavePath)){ |
|
164 | + if (!is_dir($logSavePath) || !is_writable($logSavePath)) { |
|
165 | 165 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
166 | 166 | show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false); |
167 | 167 | } |
168 | 168 | |
169 | 169 | $path = $logSavePath . 'logs-' . date('Y-m-d') . '.log'; |
170 | - if(! file_exists($path)){ |
|
170 | + if (!file_exists($path)) { |
|
171 | 171 | @touch($path); |
172 | 172 | } |
173 | 173 | //may be at this time helper user_agent not yet included |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return boolean true if the given log level is valid, false if not |
203 | 203 | */ |
204 | - private static function isValidConfigLevel($level){ |
|
204 | + private static function isValidConfigLevel($level) { |
|
205 | 205 | $level = strtolower($level); |
206 | 206 | return in_array($level, static::$validConfigLevel); |
207 | 207 | } |
@@ -211,27 +211,27 @@ discard block |
||
211 | 211 | * @param string $level the log level in string format |
212 | 212 | * @return int the log level in integer format using the predefinied constants |
213 | 213 | */ |
214 | - private static function getLevelValue($level){ |
|
214 | + private static function getLevelValue($level) { |
|
215 | 215 | $level = strtolower($level); |
216 | 216 | $value = self::NONE; |
217 | 217 | |
218 | 218 | //the default value is NONE, so means no need test for NONE |
219 | - if($level == 'fatal'){ |
|
219 | + if ($level == 'fatal') { |
|
220 | 220 | $value = self::FATAL; |
221 | 221 | } |
222 | - else if($level == 'error'){ |
|
222 | + else if ($level == 'error') { |
|
223 | 223 | $value = self::ERROR; |
224 | 224 | } |
225 | - else if($level == 'warning' || $level == 'warn'){ |
|
225 | + else if ($level == 'warning' || $level == 'warn') { |
|
226 | 226 | $value = self::WARNING; |
227 | 227 | } |
228 | - else if($level == 'info'){ |
|
228 | + else if ($level == 'info') { |
|
229 | 229 | $value = self::INFO; |
230 | 230 | } |
231 | - else if($level == 'debug'){ |
|
231 | + else if ($level == 'debug') { |
|
232 | 232 | $value = self::DEBUG; |
233 | 233 | } |
234 | - else if($level == 'all'){ |
|
234 | + else if ($level == 'all') { |
|
235 | 235 | $value = self::ALL; |
236 | 236 | } |
237 | 237 | return $value; |
@@ -242,23 +242,23 @@ discard block |
||
242 | 242 | * @param integer $level the log level in integer format |
243 | 243 | * @return int the log level in string format |
244 | 244 | */ |
245 | - private static function getLevelName($level){ |
|
245 | + private static function getLevelName($level) { |
|
246 | 246 | $value = ''; |
247 | 247 | |
248 | 248 | //the default value is NONE, so means no need test for NONE |
249 | - if($level == self::FATAL){ |
|
249 | + if ($level == self::FATAL) { |
|
250 | 250 | $value = 'FATAL'; |
251 | 251 | } |
252 | - else if($level == self::ERROR){ |
|
252 | + else if ($level == self::ERROR) { |
|
253 | 253 | $value = 'ERROR'; |
254 | 254 | } |
255 | - else if($level == self::WARNING){ |
|
255 | + else if ($level == self::WARNING) { |
|
256 | 256 | $value = 'WARNING'; |
257 | 257 | } |
258 | - else if($level == self::INFO){ |
|
258 | + else if ($level == self::INFO) { |
|
259 | 259 | $value = 'INFO'; |
260 | 260 | } |
261 | - else if($level == self::DEBUG){ |
|
261 | + else if ($level == self::DEBUG) { |
|
262 | 262 | $value = 'DEBUG'; |
263 | 263 | } |
264 | 264 | //no need for ALL |
@@ -137,8 +137,7 @@ discard block |
||
137 | 137 | if(! in_array(strtolower($this->logger), $configLoggerName)){ |
138 | 138 | return; |
139 | 139 | } |
140 | - } |
|
141 | - else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
140 | + } else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
142 | 141 | return; |
143 | 142 | } |
144 | 143 | } |
@@ -218,20 +217,15 @@ discard block |
||
218 | 217 | //the default value is NONE, so means no need test for NONE |
219 | 218 | if($level == 'fatal'){ |
220 | 219 | $value = self::FATAL; |
221 | - } |
|
222 | - else if($level == 'error'){ |
|
220 | + } else if($level == 'error'){ |
|
223 | 221 | $value = self::ERROR; |
224 | - } |
|
225 | - else if($level == 'warning' || $level == 'warn'){ |
|
222 | + } else if($level == 'warning' || $level == 'warn'){ |
|
226 | 223 | $value = self::WARNING; |
227 | - } |
|
228 | - else if($level == 'info'){ |
|
224 | + } else if($level == 'info'){ |
|
229 | 225 | $value = self::INFO; |
230 | - } |
|
231 | - else if($level == 'debug'){ |
|
226 | + } else if($level == 'debug'){ |
|
232 | 227 | $value = self::DEBUG; |
233 | - } |
|
234 | - else if($level == 'all'){ |
|
228 | + } else if($level == 'all'){ |
|
235 | 229 | $value = self::ALL; |
236 | 230 | } |
237 | 231 | return $value; |
@@ -248,17 +242,13 @@ discard block |
||
248 | 242 | //the default value is NONE, so means no need test for NONE |
249 | 243 | if($level == self::FATAL){ |
250 | 244 | $value = 'FATAL'; |
251 | - } |
|
252 | - else if($level == self::ERROR){ |
|
245 | + } else if($level == self::ERROR){ |
|
253 | 246 | $value = 'ERROR'; |
254 | - } |
|
255 | - else if($level == self::WARNING){ |
|
247 | + } else if($level == self::WARNING){ |
|
256 | 248 | $value = 'WARNING'; |
257 | - } |
|
258 | - else if($level == self::INFO){ |
|
249 | + } else if($level == self::INFO){ |
|
259 | 250 | $value = 'INFO'; |
260 | - } |
|
261 | - else if($level == self::DEBUG){ |
|
251 | + } else if($level == self::DEBUG){ |
|
262 | 252 | $value = 'DEBUG'; |
263 | 253 | } |
264 | 254 | //no need for ALL |
@@ -22,7 +22,7 @@ |
||
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 | class Controller{ |
28 | 28 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Controller{ |
|
27 | + class Controller { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The name of the module if this controller belong to an module |
@@ -47,37 +47,37 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * Class constructor |
49 | 49 | */ |
50 | - public function __construct(){ |
|
51 | - $this->logger =& class_loader('Log', 'classes'); |
|
50 | + public function __construct() { |
|
51 | + $this->logger = & class_loader('Log', 'classes'); |
|
52 | 52 | $this->logger->setLogger('MainController'); |
53 | 53 | self::$instance = & $this; |
54 | 54 | |
55 | 55 | $this->logger->debug('Adding the loaded classes to the super instance'); |
56 | - foreach (class_loaded() as $var => $class){ |
|
57 | - $this->$var =& class_loader($class); |
|
56 | + foreach (class_loaded() as $var => $class) { |
|
57 | + $this->$var = & class_loader($class); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->logger->debug('Setting the cache handler instance'); |
61 | 61 | //set cache hanlder instance |
62 | - if(get_config('cache_enable', false)){ |
|
63 | - if(isset($this->{strtolower(get_config('cache_handler'))})){ |
|
62 | + if (get_config('cache_enable', false)) { |
|
63 | + if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
64 | 64 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
65 | 65 | unset($this->{strtolower(get_config('cache_handler'))}); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | $this->logger->debug('Loading the required classes into super instance'); |
69 | - $this->loader =& class_loader('Loader', 'classes'); |
|
70 | - $this->lang =& class_loader('Lang', 'classes'); |
|
71 | - $this->request =& class_loader('Request', 'classes'); |
|
69 | + $this->loader = & class_loader('Loader', 'classes'); |
|
70 | + $this->lang = & class_loader('Lang', 'classes'); |
|
71 | + $this->request = & class_loader('Request', 'classes'); |
|
72 | 72 | //dispatch the request instance created event |
73 | 73 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
74 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
74 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
75 | 75 | |
76 | 76 | $this->logger->debug('Setting the supported languages'); |
77 | 77 | //add the supported languages ('key', 'display name') |
78 | 78 | $languages = get_config('languages', null); |
79 | - if(! empty($languages)){ |
|
80 | - foreach($languages as $key => $displayName){ |
|
79 | + if (!empty($languages)) { |
|
80 | + foreach ($languages as $key => $displayName) { |
|
81 | 81 | $this->lang->addLang($key, $displayName); |
82 | 82 | } |
83 | 83 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | set_session_config(); |
88 | 88 | |
89 | 89 | //determine the current module |
90 | - if($this->router->getModule()){ |
|
90 | + if ($this->router->getModule()) { |
|
91 | 91 | $this->moduleName = $this->router->getModule(); |
92 | 92 | } |
93 | 93 | //dispatch the loaded instance of super controller event |