Passed
Push — 1.0.0-dev ( 9c9ab7...066288 )
by nguereza
02:38
created
core/classes/database/DatabaseQueryResult.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,43 +1,43 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
-  /**
4
-   * TNH Framework
5
-   *
6
-   * A simple PHP framework using HMVC architecture
7
-   *
8
-   * This content is released under the GNU GPL License (GPL)
9
-   *
10
-   * Copyright (C) 2017 Tony NGUEREZA
11
-   *
12
-   * This program is free software; you can redistribute it and/or
13
-   * modify it under the terms of the GNU General Public License
14
-   * as published by the Free Software Foundation; either version 3
15
-   * of the License, or (at your option) any later version.
16
-   *
17
-   * This program is distributed in the hope that it will be useful,
18
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-   * GNU General Public License for more details.
21
-   *
22
-   * You should have received a copy of the GNU General Public License
23
-   * along with this program; if not, write to the Free Software
24
-   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-  */
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
   
27
-  class DatabaseQueryResult{
27
+    class DatabaseQueryResult{
28 28
   	
29
-  	/**
30
-  	 * The database query result
31
-  	 * @var mixed
32
-  	 */
33
-     private $result  = null;
29
+        /**
30
+         * The database query result
31
+         * @var mixed
32
+         */
33
+        private $result  = null;
34 34
   	
35 35
     
36
-  	/**
37
-	 * The number of rows returned by the last query
38
-	 * @var int
39
-     */
40
-     private $numRows = 0;
36
+        /**
37
+         * The number of rows returned by the last query
38
+         * @var int
39
+         */
40
+        private $numRows = 0;
41 41
   	
42 42
 	
43 43
     /**
@@ -51,24 +51,24 @@  discard block
 block discarded – undo
51 51
     }
52 52
 
53 53
     
54
-     /**
55
-     * Return the query result
56
-     *
57
-     * @return mixed
58
-     */
54
+        /**
55
+         * Return the query result
56
+         *
57
+         * @return mixed
58
+         */
59 59
     public function getResult(){
60
-      return $this->result;
60
+        return $this->result;
61 61
     }
62 62
 
63 63
     /**
64 64
      * Set the query result
65 65
      * @param mixed $result the query result
66 66
      *
67
-	 * @return object DatabaseQueryResult
67
+     * @return object DatabaseQueryResult
68 68
      */
69 69
     public function setResult($result){
70
-      $this->result = $result;
71
-      return $this;
70
+        $this->result = $result;
71
+        return $this;
72 72
     }
73 73
     
74 74
     /**
@@ -77,18 +77,18 @@  discard block
 block discarded – undo
77 77
      * @return int
78 78
      */
79 79
     public function getNumRows(){
80
-      return $this->numRows;
80
+        return $this->numRows;
81 81
     }
82 82
 
83 83
     /**
84 84
      * Set the number of rows returned by the query
85 85
      * @param int $numRows the number of rows returned
86 86
      *
87
-	 * @return object DatabaseQueryResult
87
+     * @return object DatabaseQueryResult
88 88
      */
89 89
     public function setNumRows($numRows){
90
-      $this->numRows = $numRows;
91
-      return $this;
90
+        $this->numRows = $numRows;
91
+        return $this;
92 92
     }
93 93
    
94 94
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26 26
   
27
-  class DatabaseQueryResult{
27
+  class DatabaseQueryResult {
28 28
   	
29 29
   	/**
30 30
   	 * The database query result
31 31
   	 * @var mixed
32 32
   	 */
33
-     private $result  = null;
33
+     private $result = null;
34 34
   	
35 35
     
36 36
   	/**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @param mixed $result the query result
46 46
      * @param int $numRows the number of rows returned by the query
47 47
      */
48
-    public function __construct($result = null, $numRows = 0){
48
+    public function __construct($result = null, $numRows = 0) {
49 49
         $this->result = $result;
50 50
         $this->numRows = $numRows;
51 51
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @return mixed
58 58
      */
59
-    public function getResult(){
59
+    public function getResult() {
60 60
       return $this->result;
61 61
     }
62 62
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *
67 67
 	 * @return object DatabaseQueryResult
68 68
      */
69
-    public function setResult($result){
69
+    public function setResult($result) {
70 70
       $this->result = $result;
71 71
       return $this;
72 72
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return int
78 78
      */
79
-    public function getNumRows(){
79
+    public function getNumRows() {
80 80
       return $this->numRows;
81 81
     }
82 82
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      *
87 87
 	 * @return object DatabaseQueryResult
88 88
      */
89
-    public function setNumRows($numRows){
89
+    public function setNumRows($numRows) {
90 90
       $this->numRows = $numRows;
91 91
       return $this;
92 92
     }
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryBuilder.php 3 patches
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -225,8 +225,7 @@  discard block
 block discarded – undo
225 225
       }
226 226
       if (empty($this->join)){
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      }
229
-      else{
228
+      } else{
230 229
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231 230
       }
232 231
       return $this;
@@ -334,8 +333,7 @@  discard block
 block discarded – undo
334 333
       $whereStr = '';
335 334
       if (is_array($where)){
336 335
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337
-      }
338
-      else{
336
+      } else{
339 337
         if (is_array($op)){
340 338
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 339
         } else {
@@ -585,8 +583,7 @@  discard block
 block discarded – undo
585 583
       }
586 584
       if (! is_null($limitEnd)){
587 585
         $this->limit = $limit . ', ' . $limitEnd;
588
-      }
589
-      else{
586
+      } else{
590 587
         $this->limit = $limit;
591 588
       }
592 589
       return $this;
@@ -601,8 +598,7 @@  discard block
 block discarded – undo
601 598
     public function orderBy($orderBy, $orderDir = ' ASC'){
602 599
       if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
603 600
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604
-      }
605
-      else{
601
+      } else{
606 602
         $this->orderBy = empty($this->orderBy) 
607 603
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 604
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -618,8 +614,7 @@  discard block
 block discarded – undo
618 614
     public function groupBy($field){
619 615
       if (is_array($field)){
620 616
         $this->groupBy = implode(', ', $field);
621
-      }
622
-      else{
617
+      } else{
623 618
         $this->groupBy = $field;
624 619
       }
625 620
       return $this;
@@ -636,14 +631,12 @@  discard block
 block discarded – undo
636 631
     public function having($field, $op = null, $val = null, $escape = true){
637 632
       if (is_array($op)){
638 633
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639
-      }
640
-      else if (! in_array($op, $this->operatorList)){
634
+      } else if (! in_array($op, $this->operatorList)){
641 635
         if (is_null($op)){
642 636
           $op = '';
643 637
         }
644 638
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645
-      }
646
-      else{
639
+      } else{
647 640
         if (is_null($val)){
648 641
           $val = '';
649 642
         }
Please login to merge, or discard this patch.
Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -1,108 +1,108 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
-  /**
4
-   * TNH Framework
5
-   *
6
-   * A simple PHP framework using HMVC architecture
7
-   *
8
-   * This content is released under the GNU GPL License (GPL)
9
-   *
10
-   * Copyright (C) 2017 Tony NGUEREZA
11
-   *
12
-   * This program is free software; you can redistribute it and/or
13
-   * modify it under the terms of the GNU General Public License
14
-   * as published by the Free Software Foundation; either version 3
15
-   * of the License, or (at your option) any later version.
16
-   *
17
-   * This program is distributed in the hope that it will be useful,
18
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-   * GNU General Public License for more details.
21
-   *
22
-   * You should have received a copy of the GNU General Public License
23
-   * along with this program; if not, write to the Free Software
24
-   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-  */
26
-  class DatabaseQueryBuilder{
27
-  	/**
28
-  	 * The SQL SELECT statment
29
-  	 * @var string
30
-  	*/
31
-  	private $select              = '*';
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class DatabaseQueryBuilder{
27
+        /**
28
+         * The SQL SELECT statment
29
+         * @var string
30
+         */
31
+        private $select              = '*';
32 32
   	
33
-  	/**
34
-  	 * The SQL FROM statment
35
-  	 * @var string
36
-  	*/
37
-      private $from              = null;
33
+        /**
34
+         * The SQL FROM statment
35
+         * @var string
36
+         */
37
+        private $from              = null;
38 38
   	
39
-  	/**
40
-  	 * The SQL WHERE statment
41
-  	 * @var string
42
-  	*/
43
-      private $where               = null;
39
+        /**
40
+         * The SQL WHERE statment
41
+         * @var string
42
+         */
43
+        private $where               = null;
44 44
   	
45
-  	/**
46
-  	 * The SQL LIMIT statment
47
-  	 * @var string
48
-  	*/
49
-      private $limit               = null;
45
+        /**
46
+         * The SQL LIMIT statment
47
+         * @var string
48
+         */
49
+        private $limit               = null;
50 50
   	
51
-  	/**
52
-  	 * The SQL JOIN statment
53
-  	 * @var string
54
-  	*/
55
-      private $join                = null;
51
+        /**
52
+         * The SQL JOIN statment
53
+         * @var string
54
+         */
55
+        private $join                = null;
56 56
   	
57
-  	/**
58
-  	 * The SQL ORDER BY statment
59
-  	 * @var string
60
-  	*/
61
-      private $orderBy             = null;
57
+        /**
58
+         * The SQL ORDER BY statment
59
+         * @var string
60
+         */
61
+        private $orderBy             = null;
62 62
   	
63
-  	/**
64
-  	 * The SQL GROUP BY statment
65
-  	 * @var string
66
-  	*/
67
-      private $groupBy             = null;
63
+        /**
64
+         * The SQL GROUP BY statment
65
+         * @var string
66
+         */
67
+        private $groupBy             = null;
68 68
   	
69
-  	/**
70
-  	 * The SQL HAVING statment
71
-  	 * @var string
72
-  	*/
73
-      private $having              = null;
69
+        /**
70
+         * The SQL HAVING statment
71
+         * @var string
72
+         */
73
+        private $having              = null;
74 74
   	
75
-  	/**
76
-  	 * The full SQL query statment after build for each command
77
-  	 * @var string
78
-  	*/
79
-      private $query               = null;
75
+        /**
76
+         * The full SQL query statment after build for each command
77
+         * @var string
78
+         */
79
+        private $query               = null;
80 80
   	
81
-  	/**
82
-  	 * The list of SQL valid operators
83
-  	 * @var array
84
-  	*/
81
+        /**
82
+         * The list of SQL valid operators
83
+         * @var array
84
+         */
85 85
     private $operatorList        = array('=','!=','<','>','<=','>=','<>');
86 86
   	
87 87
 	
88
-	/**
89
-	 * The prefix used in each database table
90
-	 * @var string
91
-	*/
88
+    /**
89
+     * The prefix used in each database table
90
+     * @var string
91
+     */
92 92
     private $prefix              = null;
93 93
     
94 94
 
95 95
     /**
96
-  	 * The PDO instance
97
-  	 * @var object
98
-  	*/
96
+     * The PDO instance
97
+     * @var object
98
+     */
99 99
     private $pdo                 = null;
100 100
 	
101
-  	/**
102
-  	 * The database driver name used
103
-  	 * @var string
104
-  	*/
105
-  	private $driver              = null;
101
+        /**
102
+         * The database driver name used
103
+         * @var string
104
+         */
105
+        private $driver              = null;
106 106
   	
107 107
 	
108 108
     /**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function __construct(PDO $pdo = null){
113 113
         if (is_object($pdo)){
114
-          $this->setPdo($pdo);
114
+            $this->setPdo($pdo);
115 115
         }
116 116
     }
117 117
 
@@ -121,16 +121,16 @@  discard block
 block discarded – undo
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123 123
     public function from($table){
124
-	  if (is_array($table)){
124
+        if (is_array($table)){
125 125
         $froms = '';
126 126
         foreach($table as $key){
127
-          $froms .= $this->getPrefix() . $key . ', ';
127
+            $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
130
-      } else {
130
+        } else {
131 131
         $this->from = $this->getPrefix() . $table;
132
-      }
133
-      return $this;
132
+        }
133
+        return $this;
134 134
     }
135 135
 
136 136
     /**
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141 141
     public function select($fields){
142
-      $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143
-      $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144
-      return $this;
142
+        $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143
+        $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144
+        return $this;
145 145
     }
146 146
 
147 147
     /**
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152 152
     public function distinct($field){
153
-      $distinct = ' DISTINCT ' . $field;
154
-      $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155
-      return $this;
153
+        $distinct = ' DISTINCT ' . $field;
154
+        $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155
+        return $this;
156 156
     }
157 157
 
158
-     /**
159
-     * Set the SQL function COUNT in SELECT statment
160
-     * @param  string $field the field name
161
-     * @param  string $name  if is not null represent the alias used for this field in the result
162
-     * @return object        the current DatabaseQueryBuilder instance
163
-     */
158
+        /**
159
+         * Set the SQL function COUNT in SELECT statment
160
+         * @param  string $field the field name
161
+         * @param  string $name  if is not null represent the alias used for this field in the result
162
+         * @return object        the current DatabaseQueryBuilder instance
163
+         */
164 164
     public function count($field = '*', $name = null){
165
-      return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
165
+        return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
168 168
     /**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174 174
     public function min($field, $name = null){
175
-      return $this->select_min_max_sum_count_avg('MIN', $field, $name);
175
+        return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
178 178
     /**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184 184
     public function max($field, $name = null){
185
-      return $this->select_min_max_sum_count_avg('MAX', $field, $name);
185
+        return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
188 188
     /**
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194 194
     public function sum($field, $name = null){
195
-      return $this->select_min_max_sum_count_avg('SUM', $field, $name);
195
+        return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
198 198
     /**
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204 204
     public function avg($field, $name = null){
205
-      return $this->select_min_max_sum_count_avg('AVG', $field, $name);
205
+        return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
208 208
 
@@ -216,20 +216,20 @@  discard block
 block discarded – undo
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218 218
     public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
219
-      $on = $field1;
220
-      $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
219
+        $on = $field1;
220
+        $table = $this->getPrefix() . $table;
221
+        if (! is_null($op)){
222 222
         $on = (! in_array($op, $this->operatorList) 
223
-													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224
-													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
-      }
226
-      if (empty($this->join)){
223
+                                                    ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224
+                                                    : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
+        }
226
+        if (empty($this->join)){
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      }
229
-      else{
228
+        }
229
+        else{
230 230
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231
-      }
232
-      return $this;
231
+        }
232
+        return $this;
233 233
     }
234 234
 
235 235
     /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      * @return object        the current DatabaseQueryBuilder instance
239 239
      */
240 240
     public function innerJoin($table, $field1, $op = null, $field2 = ''){
241
-      return $this->join($table, $field1, $op, $field2, 'INNER ');
241
+        return $this->join($table, $field1, $op, $field2, 'INNER ');
242 242
     }
243 243
 
244 244
     /**
@@ -247,16 +247,16 @@  discard block
 block discarded – undo
247 247
      * @return object        the current DatabaseQueryBuilder instance
248 248
      */
249 249
     public function leftJoin($table, $field1, $op = null, $field2 = ''){
250
-      return $this->join($table, $field1, $op, $field2, 'LEFT ');
251
-	}
250
+        return $this->join($table, $field1, $op, $field2, 'LEFT ');
251
+    }
252 252
 
253
-	/**
253
+    /**
254 254
      * Set the SQL RIGHT JOIN statment
255 255
      * @see  DatabaseQueryBuilder::join()
256 256
      * @return object        the current DatabaseQueryBuilder instance
257 257
      */
258 258
     public function rightJoin($table, $field1, $op = null, $field2 = ''){
259
-      return $this->join($table, $field1, $op, $field2, 'RIGHT ');
259
+        return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260 260
     }
261 261
 
262 262
     /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      * @return object        the current DatabaseQueryBuilder instance
266 266
      */
267 267
     public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
268
-    	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
268
+        return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269 269
     }
270 270
 
271 271
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @return object        the current DatabaseQueryBuilder instance
275 275
      */
276 276
     public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
277
-      return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
277
+        return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278 278
     }
279 279
 
280 280
     /**
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      * @return object        the current DatabaseQueryBuilder instance
284 284
      */
285 285
     public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
286
-      return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
286
+        return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287 287
     }
288 288
 
289 289
     /**
@@ -293,14 +293,14 @@  discard block
 block discarded – undo
293 293
      * @return object        the current DatabaseQueryBuilder instance
294 294
      */
295 295
     public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
296
+        if (is_array($field)){
297 297
         foreach($field as $f){
298
-        	$this->whereIsNull($f, $andOr);
298
+            $this->whereIsNull($f, $andOr);
299 299
         }
300
-      } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
302
-      }
303
-      return $this;
300
+        } else {
301
+            $this->setWhereStr($field.' IS NULL ', $andOr);
302
+        }
303
+        return $this;
304 304
     }
305 305
 
306 306
     /**
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
      * @return object        the current DatabaseQueryBuilder instance
311 311
      */
312 312
     public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
313
+        if (is_array($field)){
314 314
         foreach($field as $f){
315
-          $this->whereIsNotNull($f, $andOr);
315
+            $this->whereIsNotNull($f, $andOr);
316
+        }
317
+        } else {
318
+            $this->setWhereStr($field.' IS NOT NULL ', $andOr);
316 319
         }
317
-      } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
319
-      }
320
-      return $this;
320
+        return $this;
321 321
     }
322 322
     
323 323
     /**
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
      * @return object        the current DatabaseQueryBuilder instance
332 332
      */
333 333
     public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
334
-      $whereStr = '';
335
-      if (is_array($where)){
334
+        $whereStr = '';
335
+        if (is_array($where)){
336 336
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337
-      }
338
-      else{
337
+        }
338
+        else{
339 339
         if (is_array($op)){
340
-          $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
340
+            $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 341
         } else {
342
-          $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
342
+            $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
343
+        }
343 344
         }
344
-      }
345
-      $this->setWhereStr($whereStr, $andOr);
346
-      return $this;
345
+        $this->setWhereStr($whereStr, $andOr);
346
+        return $this;
347 347
     }
348 348
 
349 349
     /**
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
      * @return object        the current DatabaseQueryBuilder instance
353 353
      */
354 354
     public function orWhere($where, $op = null, $val = null, $escape = true){
355
-      return $this->where($where, $op, $val, '', 'OR', $escape);
355
+        return $this->where($where, $op, $val, '', 'OR', $escape);
356 356
     }
357 357
 
358 358
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * @return object        the current DatabaseQueryBuilder instance
363 363
      */
364 364
     public function notWhere($where, $op = null, $val = null, $escape = true){
365
-      return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
365
+        return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366 366
     }
367 367
 
368 368
     /**
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      * @return object        the current DatabaseQueryBuilder instance
372 372
      */
373 373
     public function orNotWhere($where, $op = null, $val = null, $escape = true){
374
-    	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
374
+        return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375 375
     }
376 376
 
377 377
     /**
@@ -381,16 +381,16 @@  discard block
 block discarded – undo
381 381
      * @return object        the current DatabaseQueryBuilder instance
382 382
      */
383 383
     public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
384
+        if (empty($this->where)){
385 385
         $this->where = $type . ' (';
386
-      } else {
387
-          if (substr(trim($this->where), -1) == '('){
386
+        } else {
387
+            if (substr(trim($this->where), -1) == '('){
388 388
             $this->where .= $type . ' (';
389
-          } else {
390
-          	$this->where .= $andOr . ' ' . $type . ' (';
391
-          }
392
-      }
393
-      return $this;
389
+            } else {
390
+                $this->where .= $andOr . ' ' . $type . ' (';
391
+            }
392
+        }
393
+        return $this;
394 394
     }
395 395
 
396 396
     /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @return object        the current DatabaseQueryBuilder instance
400 400
      */
401 401
     public function notGroupStart(){
402
-      return $this->groupStart('NOT');
402
+        return $this->groupStart('NOT');
403 403
     }
404 404
 
405 405
     /**
@@ -408,16 +408,16 @@  discard block
 block discarded – undo
408 408
      * @return object        the current DatabaseQueryBuilder instance
409 409
      */
410 410
     public function orGroupStart(){
411
-      return $this->groupStart('', ' OR');
411
+        return $this->groupStart('', ' OR');
412 412
     }
413 413
 
414
-     /**
415
-     * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
416
-     * @see  DatabaseQueryBuilder::groupStart()
417
-     * @return object        the current DatabaseQueryBuilder instance
418
-     */
414
+        /**
415
+         * Set the opened parenthesis for the complex SQL query using OR for separator and NOT for type
416
+         * @see  DatabaseQueryBuilder::groupStart()
417
+         * @return object        the current DatabaseQueryBuilder instance
418
+         */
419 419
     public function orNotGroupStart(){
420
-      return $this->groupStart('NOT', ' OR');
420
+        return $this->groupStart('NOT', ' OR');
421 421
     }
422 422
 
423 423
     /**
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
      * @return object        the current DatabaseQueryBuilder instance
426 426
      */
427 427
     public function groupEnd(){
428
-      $this->where .= ')';
429
-      return $this;
428
+        $this->where .= ')';
429
+        return $this;
430 430
     }
431 431
 
432 432
     /**
@@ -439,17 +439,17 @@  discard block
 block discarded – undo
439 439
      * @return object        the current DatabaseQueryBuilder instance
440 440
      */
441 441
     public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
442
-      $_keys = array();
443
-      foreach ($keys as $k => $v){
442
+        $_keys = array();
443
+        foreach ($keys as $k => $v){
444 444
         if (is_null($v)){
445
-          $v = '';
445
+            $v = '';
446 446
         }
447 447
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
448
-      }
449
-      $keys = implode(', ', $_keys);
450
-      $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
451
-      $this->setWhereStr($whereStr, $andOr);
452
-      return $this;
448
+        }
449
+        $keys = implode(', ', $_keys);
450
+        $whereStr = $field . ' ' . $type . ' IN (' . $keys . ')';
451
+        $this->setWhereStr($whereStr, $andOr);
452
+        return $this;
453 453
     }
454 454
 
455 455
     /**
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
      * @return object        the current DatabaseQueryBuilder instance
459 459
      */
460 460
     public function notIn($field, array $keys, $escape = true){
461
-      return $this->in($field, $keys, 'NOT ', 'AND', $escape);
461
+        return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462 462
     }
463 463
 
464 464
     /**
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      * @return object        the current DatabaseQueryBuilder instance
468 468
      */
469 469
     public function orIn($field, array $keys, $escape = true){
470
-      return $this->in($field, $keys, '', 'OR', $escape);
470
+        return $this->in($field, $keys, '', 'OR', $escape);
471 471
     }
472 472
 
473 473
     /**
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
      * @return object        the current DatabaseQueryBuilder instance
477 477
      */
478 478
     public function orNotIn($field, array $keys, $escape = true){
479
-      return $this->in($field, $keys, 'NOT ', 'OR', $escape);
479
+        return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480 480
     }
481 481
 
482 482
     /**
@@ -490,15 +490,15 @@  discard block
 block discarded – undo
490 490
      * @return object        the current DatabaseQueryBuilder instance
491 491
      */
492 492
     public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
493
+        if (is_null($value1)){
494 494
         $value1 = '';
495
-      }
496
-      if (is_null($value2)){
495
+        }
496
+        if (is_null($value2)){
497 497
         $value2 = '';
498
-      }
499
-      $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
500
-      $this->setWhereStr($whereStr, $andOr);
501
-      return $this;
498
+        }
499
+        $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
500
+        $this->setWhereStr($whereStr, $andOr);
501
+        return $this;
502 502
     }
503 503
 
504 504
     /**
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
      * @return object        the current DatabaseQueryBuilder instance
508 508
      */
509 509
     public function notBetween($field, $value1, $value2, $escape = true){
510
-      return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
510
+        return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511 511
     }
512 512
 
513 513
     /**
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
      * @return object        the current DatabaseQueryBuilder instance
517 517
      */
518 518
     public function orBetween($field, $value1, $value2, $escape = true){
519
-      return $this->between($field, $value1, $value2, '', 'OR', $escape);
519
+        return $this->between($field, $value1, $value2, '', 'OR', $escape);
520 520
     }
521 521
 
522 522
     /**
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
      * @return object        the current DatabaseQueryBuilder instance
526 526
      */
527 527
     public function orNotBetween($field, $value1, $value2, $escape = true){
528
-      return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
528
+        return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529 529
     }
530 530
 
531 531
     /**
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
      * @return object        the current DatabaseQueryBuilder instance
539 539
      */
540 540
     public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
541
+        if (empty($data)){
542 542
         $data = '';
543
-      }
544
-      $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
545
-      return $this;
543
+        }
544
+        $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
545
+        return $this;
546 546
     }
547 547
 
548 548
     /**
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
      * @return object        the current DatabaseQueryBuilder instance
552 552
      */
553 553
     public function orLike($field, $data, $escape = true){
554
-      return $this->like($field, $data, '', 'OR', $escape);
554
+        return $this->like($field, $data, '', 'OR', $escape);
555 555
     }
556 556
 
557 557
     /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
      * @return object        the current DatabaseQueryBuilder instance
561 561
      */
562 562
     public function notLike($field, $data, $escape = true){
563
-      return $this->like($field, $data, 'NOT ', 'AND', $escape);
563
+        return $this->like($field, $data, 'NOT ', 'AND', $escape);
564 564
     }
565 565
 
566 566
     /**
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
      * @return object        the current DatabaseQueryBuilder instance
570 570
      */
571 571
     public function orNotLike($field, $data, $escape = true){
572
-      return $this->like($field, $data, 'NOT ', 'OR', $escape);
572
+        return $this->like($field, $data, 'NOT ', 'OR', $escape);
573 573
     }
574 574
 
575 575
     /**
@@ -580,16 +580,16 @@  discard block
 block discarded – undo
580 580
      * @return object        the current DatabaseQueryBuilder instance
581 581
      */
582 582
     public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
583
+        if (empty($limit)){
584 584
         $limit = 0;
585
-      }
586
-      if (! is_null($limitEnd)){
585
+        }
586
+        if (! is_null($limitEnd)){
587 587
         $this->limit = $limit . ', ' . $limitEnd;
588
-      }
589
-      else{
588
+        }
589
+        else{
590 590
         $this->limit = $limit;
591
-      }
592
-      return $this;
591
+        }
592
+        return $this;
593 593
     }
594 594
 
595 595
     /**
@@ -599,15 +599,15 @@  discard block
 block discarded – undo
599 599
      * @return object        the current DatabaseQueryBuilder instance
600 600
      */
601 601
     public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
602
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
603 603
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604
-      }
605
-      else{
604
+        }
605
+        else{
606 606
         $this->orderBy = empty($this->orderBy) 
607
-						? ($orderBy . ' ' . strtoupper($orderDir)) 
608
-						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
609
-      }
610
-      return $this;
607
+                        ? ($orderBy . ' ' . strtoupper($orderDir)) 
608
+                        : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
609
+        }
610
+        return $this;
611 611
     }
612 612
 
613 613
     /**
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
      * @return object        the current DatabaseQueryBuilder instance
617 617
      */
618 618
     public function groupBy($field){
619
-      if (is_array($field)){
619
+        if (is_array($field)){
620 620
         $this->groupBy = implode(', ', $field);
621
-      }
622
-      else{
621
+        }
622
+        else{
623 623
         $this->groupBy = $field;
624
-      }
625
-      return $this;
624
+        }
625
+        return $this;
626 626
     }
627 627
 
628 628
     /**
@@ -634,22 +634,22 @@  discard block
 block discarded – undo
634 634
      * @return object        the current DatabaseQueryBuilder instance
635 635
      */
636 636
     public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
637
+        if (is_array($op)){
638 638
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639
-      }
640
-      else if (! in_array($op, $this->operatorList)){
639
+        }
640
+        else if (! in_array($op, $this->operatorList)){
641 641
         if (is_null($op)){
642
-          $op = '';
642
+            $op = '';
643 643
         }
644 644
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645
-      }
646
-      else{
645
+        }
646
+        else{
647 647
         if (is_null($val)){
648
-          $val = '';
648
+            $val = '';
649 649
         }
650 650
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
651
-      }
652
-      return $this;
651
+        }
652
+        return $this;
653 653
     }
654 654
 
655 655
     /**
@@ -659,12 +659,12 @@  discard block
 block discarded – undo
659 659
      * @return object  the current DatabaseQueryBuilder instance        
660 660
      */
661 661
     public function insert($data = array(), $escape = true){
662
-      $columns = array_keys($data);
663
-      $column = implode(', ', $columns);
664
-      $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
662
+        $columns = array_keys($data);
663
+        $column = implode(', ', $columns);
664
+        $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
665 665
 
666
-      $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
667
-      return $this;
666
+        $this->query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
667
+        return $this;
668 668
     }
669 669
 
670 670
     /**
@@ -674,25 +674,25 @@  discard block
 block discarded – undo
674 674
      * @return object  the current DatabaseQueryBuilder instance 
675 675
      */
676 676
     public function update($data = array(), $escape = true){
677
-      $query = 'UPDATE ' . $this->from . ' SET ';
678
-      $values = array();
679
-      foreach ($data as $column => $val){
677
+        $query = 'UPDATE ' . $this->from . ' SET ';
678
+        $values = array();
679
+        foreach ($data as $column => $val){
680 680
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
681
-      }
682
-      $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
681
+        }
682
+        $query .= implode(', ', $values);
683
+        if (! empty($this->where)){
684 684
         $query .= ' WHERE ' . $this->where;
685
-      }
685
+        }
686 686
 
687
-      if (! empty($this->orderBy)){
687
+        if (! empty($this->orderBy)){
688 688
         $query .= ' ORDER BY ' . $this->orderBy;
689
-      }
689
+        }
690 690
 
691
-      if (! empty($this->limit)){
691
+        if (! empty($this->limit)){
692 692
         $query .= ' LIMIT ' . $this->limit;
693
-      }
694
-      $this->query = $query;
695
-      return $this;
693
+        }
694
+        $this->query = $query;
695
+        return $this;
696 696
     }
697 697
 
698 698
     /**
@@ -700,25 +700,25 @@  discard block
 block discarded – undo
700 700
      * @return object  the current DatabaseQueryBuilder instance 
701 701
      */
702 702
     public function delete(){
703
-    	$query = 'DELETE FROM ' . $this->from;
704
-      $isTruncate = $query;
705
-    	if (! empty($this->where)){
706
-  		  $query .= ' WHERE ' . $this->where;
707
-    	}
703
+        $query = 'DELETE FROM ' . $this->from;
704
+        $isTruncate = $query;
705
+        if (! empty($this->where)){
706
+            $query .= ' WHERE ' . $this->where;
707
+        }
708 708
 
709
-    	if (! empty($this->orderBy)){
710
-    	  $query .= ' ORDER BY ' . $this->orderBy;
711
-      }
709
+        if (! empty($this->orderBy)){
710
+            $query .= ' ORDER BY ' . $this->orderBy;
711
+        }
712 712
 
713
-    	if (! empty($this->limit)){
714
-    		$query .= ' LIMIT ' . $this->limit;
715
-      }
713
+        if (! empty($this->limit)){
714
+            $query .= ' LIMIT ' . $this->limit;
715
+        }
716 716
 
717
-  		if ($isTruncate == $query && $this->driver != 'sqlite'){  
718
-      	$query = 'TRUNCATE TABLE ' . $this->from;
719
-  		}
720
-	   $this->query = $query;
721
-	   return $this;
717
+            if ($isTruncate == $query && $this->driver != 'sqlite'){  
718
+            $query = 'TRUNCATE TABLE ' . $this->from;
719
+            }
720
+        $this->query = $query;
721
+        return $this;
722 722
     }
723 723
 
724 724
     /**
@@ -728,11 +728,11 @@  discard block
 block discarded – undo
728 728
      * @return mixed       the data after escaped or the same data if not
729 729
      */
730 730
     public function escape($data, $escaped = true){
731
-      $data = trim($data);
732
-      if($escaped){
731
+        $data = trim($data);
732
+        if($escaped){
733 733
         return $this->pdo->quote($data);
734
-      }
735
-      return $data;  
734
+        }
735
+        return $data;  
736 736
     }
737 737
 
738 738
 
@@ -741,126 +741,126 @@  discard block
 block discarded – undo
741 741
      * @return string
742 742
      */
743 743
     public function getQuery(){
744
-  	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
745
-  	  if(empty($this->query)){
746
-  		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
747
-  		  if (! empty($this->join)){
748
-          $query .= $this->join;
749
-  		  }
744
+        //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
745
+        if(empty($this->query)){
746
+            $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
747
+            if (! empty($this->join)){
748
+            $query .= $this->join;
749
+            }
750 750
   		  
751
-  		  if (! empty($this->where)){
752
-          $query .= ' WHERE ' . $this->where;
753
-  		  }
751
+            if (! empty($this->where)){
752
+            $query .= ' WHERE ' . $this->where;
753
+            }
754 754
 
755
-  		  if (! empty($this->groupBy)){
756
-          $query .= ' GROUP BY ' . $this->groupBy;
757
-  		  }
755
+            if (! empty($this->groupBy)){
756
+            $query .= ' GROUP BY ' . $this->groupBy;
757
+            }
758 758
 
759
-  		  if (! empty($this->having)){
760
-          $query .= ' HAVING ' . $this->having;
761
-  		  }
759
+            if (! empty($this->having)){
760
+            $query .= ' HAVING ' . $this->having;
761
+            }
762 762
 
763
-  		  if (! empty($this->orderBy)){
764
-  			  $query .= ' ORDER BY ' . $this->orderBy;
765
-  		  }
763
+            if (! empty($this->orderBy)){
764
+                $query .= ' ORDER BY ' . $this->orderBy;
765
+            }
766 766
 
767
-  		  if (! empty($this->limit)){
768
-          $query .= ' LIMIT ' . $this->limit;
769
-  		  }
770
-  		  $this->query = $query;
771
-  	  }
772
-      return $this->query;
767
+            if (! empty($this->limit)){
768
+            $query .= ' LIMIT ' . $this->limit;
769
+            }
770
+            $this->query = $query;
771
+        }
772
+        return $this->query;
773 773
     }
774 774
 
775 775
 	
776
-	 /**
777
-     * Return the PDO instance
778
-     * @return object
779
-     */
776
+        /**
777
+         * Return the PDO instance
778
+         * @return object
779
+         */
780 780
     public function getPdo(){
781
-      return $this->pdo;
781
+        return $this->pdo;
782 782
     }
783 783
 
784 784
     /**
785 785
      * Set the PDO instance
786 786
      * @param PDO $pdo the pdo object
787
-	   * @return object DatabaseQueryBuilder
787
+     * @return object DatabaseQueryBuilder
788 788
      */
789 789
     public function setPdo(PDO $pdo = null){
790
-      $this->pdo = $pdo;
791
-      return $this;
790
+        $this->pdo = $pdo;
791
+        return $this;
792 792
     }
793 793
 	
794
-   /**
795
-   * Return the database table prefix
796
-   * @return string
797
-   */
794
+    /**
795
+     * Return the database table prefix
796
+     * @return string
797
+     */
798 798
     public function getPrefix(){
799
-      return $this->prefix;
799
+        return $this->prefix;
800 800
     }
801 801
 
802 802
     /**
803 803
      * Set the database table prefix
804 804
      * @param string $prefix the new prefix
805
-	   * @return object DatabaseQueryBuilder
805
+     * @return object DatabaseQueryBuilder
806 806
      */
807 807
     public function setPrefix($prefix){
808
-      $this->prefix = $prefix;
809
-      return $this;
808
+        $this->prefix = $prefix;
809
+        return $this;
810 810
     }
811 811
 	
812
-	   /**
813
-     * Return the database driver
814
-     * @return string
815
-     */
812
+        /**
813
+         * Return the database driver
814
+         * @return string
815
+         */
816 816
     public function getDriver(){
817
-      return $this->driver;
817
+        return $this->driver;
818 818
     }
819 819
 
820 820
     /**
821 821
      * Set the database driver
822 822
      * @param string $driver the new driver
823
-	   * @return object DatabaseQueryBuilder
823
+     * @return object DatabaseQueryBuilder
824 824
      */
825 825
     public function setDriver($driver){
826
-      $this->driver = $driver;
827
-      return $this;
826
+        $this->driver = $driver;
827
+        return $this;
828 828
     }
829 829
 	
830
-	   /**
831
-     * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
832
-	   * @return object  the current DatabaseQueryBuilder instance 
833
-     */
830
+        /**
831
+         * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
832
+         * @return object  the current DatabaseQueryBuilder instance 
833
+         */
834 834
     public function reset(){
835
-      $this->select   = '*';
836
-      $this->from     = null;
837
-      $this->where    = null;
838
-      $this->limit    = null;
839
-      $this->orderBy  = null;
840
-      $this->groupBy  = null;
841
-      $this->having   = null;
842
-      $this->join     = null;
843
-      $this->query    = null;
844
-      return $this;
845
-    }
846
-
847
-	   /**
848
-     * Get the SQL HAVING clause when operator argument is an array
849
-     * @see DatabaseQueryBuilder::having
850
-     *
851
-     * @return string
852
-     */
835
+        $this->select   = '*';
836
+        $this->from     = null;
837
+        $this->where    = null;
838
+        $this->limit    = null;
839
+        $this->orderBy  = null;
840
+        $this->groupBy  = null;
841
+        $this->having   = null;
842
+        $this->join     = null;
843
+        $this->query    = null;
844
+        return $this;
845
+    }
846
+
847
+        /**
848
+         * Get the SQL HAVING clause when operator argument is an array
849
+         * @see DatabaseQueryBuilder::having
850
+         *
851
+         * @return string
852
+         */
853 853
     protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
854 854
         $x = explode('?', $field);
855 855
         $w = '';
856 856
         foreach($x as $k => $v){
857
-  	      if (!empty($v)){
857
+            if (!empty($v)){
858 858
             if (! isset($op[$k])){
859
-              $op[$k] = '';
859
+                $op[$k] = '';
860
+            }
861
+                $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
862
+            }
860 863
             }
861
-  	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
862
-  	      }
863
-      	}
864 864
         return $w;
865 865
     }
866 866
 
@@ -872,35 +872,35 @@  discard block
 block discarded – undo
872 872
      * @return string
873 873
      */
874 874
     protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
875
-      $_where = array();
876
-      foreach ($where as $column => $data){
875
+        $_where = array();
876
+        foreach ($where as $column => $data){
877 877
         if (is_null($data)){
878
-          $data = '';
878
+            $data = '';
879 879
         }
880 880
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
881
-      }
882
-      $where = implode(' '.$andOr.' ', $_where);
883
-      return $where;
881
+        }
882
+        $where = implode(' '.$andOr.' ', $_where);
883
+        return $where;
884 884
     }
885 885
 
886
-     /**
887
-     * Get the SQL WHERE clause when operator argument is an array
888
-     * @see DatabaseQueryBuilder::where
889
-     *
890
-     * @return string
891
-     */
886
+        /**
887
+         * Get the SQL WHERE clause when operator argument is an array
888
+         * @see DatabaseQueryBuilder::where
889
+         *
890
+         * @return string
891
+         */
892 892
     protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
893
-     $x = explode('?', $where);
894
-     $w = '';
895
-      foreach($x as $k => $v){
893
+        $x = explode('?', $where);
894
+        $w = '';
895
+        foreach($x as $k => $v){
896 896
         if (! empty($v)){
897 897
             if (isset($op[$k]) && is_null($op[$k])){
898
-              $op[$k] = '';
898
+                $op[$k] = '';
899 899
             }
900 900
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
901 901
         }
902
-      }
903
-      return $w;
902
+        }
903
+        return $w;
904 904
     }
905 905
 
906 906
     /**
@@ -910,53 +910,53 @@  discard block
 block discarded – undo
910 910
      * @return string
911 911
      */
912 912
     protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
913
-       $w = '';
914
-       if (! in_array((string)$op, $this->operatorList)){
915
-          if (is_null($op)){
913
+        $w = '';
914
+        if (! in_array((string)$op, $this->operatorList)){
915
+            if (is_null($op)){
916 916
             $op = '';
917
-          }
918
-          $w = $type . $where . ' = ' . ($this->escape($op, $escape));
917
+            }
918
+            $w = $type . $where . ' = ' . ($this->escape($op, $escape));
919 919
         } else {
920
-          if (is_null($val)){
920
+            if (is_null($val)){
921 921
             $val = '';
922
-          }
923
-          $w = $type . $where . $op . ($this->escape($val, $escape));
922
+            }
923
+            $w = $type . $where . $op . ($this->escape($val, $escape));
924 924
         }
925 925
         return $w;
926
-      }
927
-
928
-      /**
929
-       * Set the $this->where property 
930
-       * @param string $whereStr the WHERE clause string
931
-       * @param  string  $andOr the separator type used 'AND', 'OR', etc.
932
-       */
933
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
926
+        }
927
+
928
+        /**
929
+         * Set the $this->where property 
930
+         * @param string $whereStr the WHERE clause string
931
+         * @param  string  $andOr the separator type used 'AND', 'OR', etc.
932
+         */
933
+        protected function setWhereStr($whereStr, $andOr = 'AND'){
934 934
         if (empty($this->where)){
935
-          $this->where = $whereStr;
935
+            $this->where = $whereStr;
936 936
         } else {
937
-          if (substr(trim($this->where), -1) == '('){
937
+            if (substr(trim($this->where), -1) == '('){
938 938
             $this->where = $this->where . ' ' . $whereStr;
939
-          } else {
939
+            } else {
940 940
             $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
941
-          }
941
+            }
942
+        }
942 943
         }
943
-      }
944 944
 
945 945
 
946
-	 /**
947
-     * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG
948
-     * @param  string $clause the clause type like MIN, MAX, etc.
949
-     * @see  DatabaseQueryBuilder::min
950
-     * @see  DatabaseQueryBuilder::max
951
-     * @see  DatabaseQueryBuilder::sum
952
-     * @see  DatabaseQueryBuilder::count
953
-     * @see  DatabaseQueryBuilder::avg
954
-     * @return object
955
-     */
946
+        /**
947
+         * Set the SQL SELECT for function MIN, MAX, SUM, AVG, COUNT, AVG
948
+         * @param  string $clause the clause type like MIN, MAX, etc.
949
+         * @see  DatabaseQueryBuilder::min
950
+         * @see  DatabaseQueryBuilder::max
951
+         * @see  DatabaseQueryBuilder::sum
952
+         * @see  DatabaseQueryBuilder::count
953
+         * @see  DatabaseQueryBuilder::avg
954
+         * @return object
955
+         */
956 956
     protected function select_min_max_sum_count_avg($clause, $field, $name = null){
957
-      $clause = strtoupper($clause);
958
-      $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
959
-      $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
960
-      return $this;
957
+        $clause = strtoupper($clause);
958
+        $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
959
+        $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
960
+        return $this;
961 961
     }
962 962
 }
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -23,94 +23,94 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class DatabaseQueryBuilder{
26
+  class DatabaseQueryBuilder {
27 27
   	/**
28 28
   	 * The SQL SELECT statment
29 29
   	 * @var string
30 30
   	*/
31
-  	private $select              = '*';
31
+  	private $select = '*';
32 32
   	
33 33
   	/**
34 34
   	 * The SQL FROM statment
35 35
   	 * @var string
36 36
   	*/
37
-      private $from              = null;
37
+      private $from = null;
38 38
   	
39 39
   	/**
40 40
   	 * The SQL WHERE statment
41 41
   	 * @var string
42 42
   	*/
43
-      private $where               = null;
43
+      private $where = null;
44 44
   	
45 45
   	/**
46 46
   	 * The SQL LIMIT statment
47 47
   	 * @var string
48 48
   	*/
49
-      private $limit               = null;
49
+      private $limit = null;
50 50
   	
51 51
   	/**
52 52
   	 * The SQL JOIN statment
53 53
   	 * @var string
54 54
   	*/
55
-      private $join                = null;
55
+      private $join = null;
56 56
   	
57 57
   	/**
58 58
   	 * The SQL ORDER BY statment
59 59
   	 * @var string
60 60
   	*/
61
-      private $orderBy             = null;
61
+      private $orderBy = null;
62 62
   	
63 63
   	/**
64 64
   	 * The SQL GROUP BY statment
65 65
   	 * @var string
66 66
   	*/
67
-      private $groupBy             = null;
67
+      private $groupBy = null;
68 68
   	
69 69
   	/**
70 70
   	 * The SQL HAVING statment
71 71
   	 * @var string
72 72
   	*/
73
-      private $having              = null;
73
+      private $having = null;
74 74
   	
75 75
   	/**
76 76
   	 * The full SQL query statment after build for each command
77 77
   	 * @var string
78 78
   	*/
79
-      private $query               = null;
79
+      private $query = null;
80 80
   	
81 81
   	/**
82 82
   	 * The list of SQL valid operators
83 83
   	 * @var array
84 84
   	*/
85
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
85
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
86 86
   	
87 87
 	
88 88
 	/**
89 89
 	 * The prefix used in each database table
90 90
 	 * @var string
91 91
 	*/
92
-    private $prefix              = null;
92
+    private $prefix = null;
93 93
     
94 94
 
95 95
     /**
96 96
   	 * The PDO instance
97 97
   	 * @var object
98 98
   	*/
99
-    private $pdo                 = null;
99
+    private $pdo = null;
100 100
 	
101 101
   	/**
102 102
   	 * The database driver name used
103 103
   	 * @var string
104 104
   	*/
105
-  	private $driver              = null;
105
+  	private $driver = null;
106 106
   	
107 107
 	
108 108
     /**
109 109
      * Construct new DatabaseQueryBuilder
110 110
      * @param object $pdo the PDO object
111 111
      */
112
-    public function __construct(PDO $pdo = null){
113
-        if (is_object($pdo)){
112
+    public function __construct(PDO $pdo = null) {
113
+        if (is_object($pdo)) {
114 114
           $this->setPdo($pdo);
115 115
         }
116 116
     }
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
      * @param  string|array $table the table name or array of table list
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123
-    public function from($table){
124
-	  if (is_array($table)){
123
+    public function from($table) {
124
+	  if (is_array($table)) {
125 125
         $froms = '';
126
-        foreach($table as $key){
126
+        foreach ($table as $key) {
127 127
           $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  string|array $fields the field name or array of field list
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141
-    public function select($fields){
141
+    public function select($fields) {
142 142
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143 143
       $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144 144
       return $this;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param  string $field the field name to distinct
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152
-    public function distinct($field){
152
+    public function distinct($field) {
153 153
       $distinct = ' DISTINCT ' . $field;
154 154
       $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155 155
       return $this;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      * @param  string $name  if is not null represent the alias used for this field in the result
162 162
      * @return object        the current DatabaseQueryBuilder instance
163 163
      */
164
-    public function count($field = '*', $name = null){
164
+    public function count($field = '*', $name = null) {
165 165
       return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param  string $name  if is not null represent the alias used for this field in the result
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174
-    public function min($field, $name = null){
174
+    public function min($field, $name = null) {
175 175
       return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param  string $name  if is not null represent the alias used for this field in the result
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184
-    public function max($field, $name = null){
184
+    public function max($field, $name = null) {
185 185
       return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param  string $name  if is not null represent the alias used for this field in the result
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194
-    public function sum($field, $name = null){
194
+    public function sum($field, $name = null) {
195 195
       return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * @param  string $name  if is not null represent the alias used for this field in the result
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204
-    public function avg($field, $name = null){
204
+    public function avg($field, $name = null) {
205 205
       return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
218
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
219 219
       $on = $field1;
220 220
       $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
221
+      if (!is_null($op)) {
222
+        $on = (!in_array($op, $this->operatorList) 
223 223
 													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
 													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225 225
       }
226
-      if (empty($this->join)){
226
+      if (empty($this->join)) {
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228 228
       }
229
-      else{
229
+      else {
230 230
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
231 231
       }
232 232
       return $this;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
      * @see  DatabaseQueryBuilder::join()
238 238
      * @return object        the current DatabaseQueryBuilder instance
239 239
      */
240
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
240
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
241 241
       return $this->join($table, $field1, $op, $field2, 'INNER ');
242 242
     }
243 243
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * @see  DatabaseQueryBuilder::join()
247 247
      * @return object        the current DatabaseQueryBuilder instance
248 248
      */
249
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
249
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
250 250
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
251 251
 	}
252 252
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      * @see  DatabaseQueryBuilder::join()
256 256
      * @return object        the current DatabaseQueryBuilder instance
257 257
      */
258
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
258
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
259 259
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
260 260
     }
261 261
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @see  DatabaseQueryBuilder::join()
265 265
      * @return object        the current DatabaseQueryBuilder instance
266 266
      */
267
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
267
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
268 268
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
269 269
     }
270 270
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      * @see  DatabaseQueryBuilder::join()
274 274
      * @return object        the current DatabaseQueryBuilder instance
275 275
      */
276
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
276
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
277 277
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
278 278
     }
279 279
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      * @see  DatabaseQueryBuilder::join()
283 283
      * @return object        the current DatabaseQueryBuilder instance
284 284
      */
285
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
285
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
286 286
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
287 287
     }
288 288
 
@@ -292,13 +292,13 @@  discard block
 block discarded – undo
292 292
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
293 293
      * @return object        the current DatabaseQueryBuilder instance
294 294
      */
295
-    public function whereIsNull($field, $andOr = 'AND'){
296
-      if (is_array($field)){
297
-        foreach($field as $f){
295
+    public function whereIsNull($field, $andOr = 'AND') {
296
+      if (is_array($field)) {
297
+        foreach ($field as $f) {
298 298
         	$this->whereIsNull($f, $andOr);
299 299
         }
300 300
       } else {
301
-          $this->setWhereStr($field.' IS NULL ', $andOr);
301
+          $this->setWhereStr($field . ' IS NULL ', $andOr);
302 302
       }
303 303
       return $this;
304 304
     }
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
310 310
      * @return object        the current DatabaseQueryBuilder instance
311 311
      */
312
-    public function whereIsNotNull($field, $andOr = 'AND'){
313
-      if (is_array($field)){
314
-        foreach($field as $f){
312
+    public function whereIsNotNull($field, $andOr = 'AND') {
313
+      if (is_array($field)) {
314
+        foreach ($field as $f) {
315 315
           $this->whereIsNotNull($f, $andOr);
316 316
         }
317 317
       } else {
318
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
318
+          $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
319 319
       }
320 320
       return $this;
321 321
     }
@@ -330,13 +330,13 @@  discard block
 block discarded – undo
330 330
      * @param  boolean $escape whether to escape or not the $val
331 331
      * @return object        the current DatabaseQueryBuilder instance
332 332
      */
333
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
333
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
334 334
       $whereStr = '';
335
-      if (is_array($where)){
335
+      if (is_array($where)) {
336 336
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
337 337
       }
338
-      else{
339
-        if (is_array($op)){
338
+      else {
339
+        if (is_array($op)) {
340 340
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
341 341
         } else {
342 342
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @see  DatabaseQueryBuilder::where()
352 352
      * @return object        the current DatabaseQueryBuilder instance
353 353
      */
354
-    public function orWhere($where, $op = null, $val = null, $escape = true){
354
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
355 355
       return $this->where($where, $op, $val, '', 'OR', $escape);
356 356
     }
357 357
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      * @see  DatabaseQueryBuilder::where()
362 362
      * @return object        the current DatabaseQueryBuilder instance
363 363
      */
364
-    public function notWhere($where, $op = null, $val = null, $escape = true){
364
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
365 365
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
366 366
     }
367 367
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      * @see  DatabaseQueryBuilder::where()
371 371
      * @return object        the current DatabaseQueryBuilder instance
372 372
      */
373
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
373
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
374 374
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
375 375
     }
376 376
 
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
381 381
      * @return object        the current DatabaseQueryBuilder instance
382 382
      */
383
-    public function groupStart($type = '', $andOr = ' AND'){
384
-      if (empty($this->where)){
383
+    public function groupStart($type = '', $andOr = ' AND') {
384
+      if (empty($this->where)) {
385 385
         $this->where = $type . ' (';
386 386
       } else {
387
-          if (substr(trim($this->where), -1) == '('){
387
+          if (substr(trim($this->where), -1) == '(') {
388 388
             $this->where .= $type . ' (';
389 389
           } else {
390 390
           	$this->where .= $andOr . ' ' . $type . ' (';
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      * @see  DatabaseQueryBuilder::groupStart()
399 399
      * @return object        the current DatabaseQueryBuilder instance
400 400
      */
401
-    public function notGroupStart(){
401
+    public function notGroupStart() {
402 402
       return $this->groupStart('NOT');
403 403
     }
404 404
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      * @see  DatabaseQueryBuilder::groupStart()
408 408
      * @return object        the current DatabaseQueryBuilder instance
409 409
      */
410
-    public function orGroupStart(){
410
+    public function orGroupStart() {
411 411
       return $this->groupStart('', ' OR');
412 412
     }
413 413
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @see  DatabaseQueryBuilder::groupStart()
417 417
      * @return object        the current DatabaseQueryBuilder instance
418 418
      */
419
-    public function orNotGroupStart(){
419
+    public function orNotGroupStart() {
420 420
       return $this->groupStart('NOT', ' OR');
421 421
     }
422 422
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * Close the parenthesis for the grouped SQL
425 425
      * @return object        the current DatabaseQueryBuilder instance
426 426
      */
427
-    public function groupEnd(){
427
+    public function groupEnd() {
428 428
       $this->where .= ')';
429 429
       return $this;
430 430
     }
@@ -438,10 +438,10 @@  discard block
 block discarded – undo
438 438
      * @param  boolean $escape whether to escape or not the values
439 439
      * @return object        the current DatabaseQueryBuilder instance
440 440
      */
441
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
441
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
442 442
       $_keys = array();
443
-      foreach ($keys as $k => $v){
444
-        if (is_null($v)){
443
+      foreach ($keys as $k => $v) {
444
+        if (is_null($v)) {
445 445
           $v = '';
446 446
         }
447 447
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      * @see  DatabaseQueryBuilder::in()
458 458
      * @return object        the current DatabaseQueryBuilder instance
459 459
      */
460
-    public function notIn($field, array $keys, $escape = true){
460
+    public function notIn($field, array $keys, $escape = true) {
461 461
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
462 462
     }
463 463
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @see  DatabaseQueryBuilder::in()
467 467
      * @return object        the current DatabaseQueryBuilder instance
468 468
      */
469
-    public function orIn($field, array $keys, $escape = true){
469
+    public function orIn($field, array $keys, $escape = true) {
470 470
       return $this->in($field, $keys, '', 'OR', $escape);
471 471
     }
472 472
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      * @see  DatabaseQueryBuilder::in()
476 476
      * @return object        the current DatabaseQueryBuilder instance
477 477
      */
478
-    public function orNotIn($field, array $keys, $escape = true){
478
+    public function orNotIn($field, array $keys, $escape = true) {
479 479
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
480 480
     }
481 481
 
@@ -489,11 +489,11 @@  discard block
 block discarded – undo
489 489
      * @param  boolean $escape whether to escape or not the values
490 490
      * @return object        the current DatabaseQueryBuilder instance
491 491
      */
492
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
493
-      if (is_null($value1)){
492
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
493
+      if (is_null($value1)) {
494 494
         $value1 = '';
495 495
       }
496
-      if (is_null($value2)){
496
+      if (is_null($value2)) {
497 497
         $value2 = '';
498 498
       }
499 499
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @see  DatabaseQueryBuilder::between()
507 507
      * @return object        the current DatabaseQueryBuilder instance
508 508
      */
509
-    public function notBetween($field, $value1, $value2, $escape = true){
509
+    public function notBetween($field, $value1, $value2, $escape = true) {
510 510
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
511 511
     }
512 512
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
      * @see  DatabaseQueryBuilder::between()
516 516
      * @return object        the current DatabaseQueryBuilder instance
517 517
      */
518
-    public function orBetween($field, $value1, $value2, $escape = true){
518
+    public function orBetween($field, $value1, $value2, $escape = true) {
519 519
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
520 520
     }
521 521
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
      * @see  DatabaseQueryBuilder::between()
525 525
      * @return object        the current DatabaseQueryBuilder instance
526 526
      */
527
-    public function orNotBetween($field, $value1, $value2, $escape = true){
527
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
528 528
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
529 529
     }
530 530
 
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
      * @param  boolean $escape whether to escape or not the values
538 538
      * @return object        the current DatabaseQueryBuilder instance
539 539
      */
540
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
541
-      if (empty($data)){
540
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
541
+      if (empty($data)) {
542 542
         $data = '';
543 543
       }
544 544
       $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
      * @see  DatabaseQueryBuilder::like()
551 551
      * @return object        the current DatabaseQueryBuilder instance
552 552
      */
553
-    public function orLike($field, $data, $escape = true){
553
+    public function orLike($field, $data, $escape = true) {
554 554
       return $this->like($field, $data, '', 'OR', $escape);
555 555
     }
556 556
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      * @see  DatabaseQueryBuilder::like()
560 560
      * @return object        the current DatabaseQueryBuilder instance
561 561
      */
562
-    public function notLike($field, $data, $escape = true){
562
+    public function notLike($field, $data, $escape = true) {
563 563
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
564 564
     }
565 565
 
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
      * @see  DatabaseQueryBuilder::like()
569 569
      * @return object        the current DatabaseQueryBuilder instance
570 570
      */
571
-    public function orNotLike($field, $data, $escape = true){
571
+    public function orNotLike($field, $data, $escape = true) {
572 572
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
573 573
     }
574 574
 
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
      * @param  int $limitEnd the limit count
580 580
      * @return object        the current DatabaseQueryBuilder instance
581 581
      */
582
-    public function limit($limit, $limitEnd = null){
583
-      if (empty($limit)){
582
+    public function limit($limit, $limitEnd = null) {
583
+      if (empty($limit)) {
584 584
         $limit = 0;
585 585
       }
586
-      if (! is_null($limitEnd)){
586
+      if (!is_null($limitEnd)) {
587 587
         $this->limit = $limit . ', ' . $limitEnd;
588 588
       }
589
-      else{
589
+      else {
590 590
         $this->limit = $limit;
591 591
       }
592 592
       return $this;
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
      * @param  string $orderDir the order direction (ASC or DESC)
599 599
      * @return object        the current DatabaseQueryBuilder instance
600 600
      */
601
-    public function orderBy($orderBy, $orderDir = ' ASC'){
602
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
601
+    public function orderBy($orderBy, $orderDir = ' ASC') {
602
+      if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
603 603
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
604 604
       }
605
-      else{
605
+      else {
606 606
         $this->orderBy = empty($this->orderBy) 
607 607
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
608 608
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -615,11 +615,11 @@  discard block
 block discarded – undo
615 615
      * @param  string|array $field the field name used or array of field list
616 616
      * @return object        the current DatabaseQueryBuilder instance
617 617
      */
618
-    public function groupBy($field){
619
-      if (is_array($field)){
618
+    public function groupBy($field) {
619
+      if (is_array($field)) {
620 620
         $this->groupBy = implode(', ', $field);
621 621
       }
622
-      else{
622
+      else {
623 623
         $this->groupBy = $field;
624 624
       }
625 625
       return $this;
@@ -633,18 +633,18 @@  discard block
 block discarded – undo
633 633
      * @param  boolean $escape whether to escape or not the values
634 634
      * @return object        the current DatabaseQueryBuilder instance
635 635
      */
636
-    public function having($field, $op = null, $val = null, $escape = true){
637
-      if (is_array($op)){
636
+    public function having($field, $op = null, $val = null, $escape = true) {
637
+      if (is_array($op)) {
638 638
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
639 639
       }
640
-      else if (! in_array($op, $this->operatorList)){
641
-        if (is_null($op)){
640
+      else if (!in_array($op, $this->operatorList)) {
641
+        if (is_null($op)) {
642 642
           $op = '';
643 643
         }
644 644
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
645 645
       }
646
-      else{
647
-        if (is_null($val)){
646
+      else {
647
+        if (is_null($val)) {
648 648
           $val = '';
649 649
         }
650 650
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
      * @param  boolean $escape  whether to escape or not the values
659 659
      * @return object  the current DatabaseQueryBuilder instance        
660 660
      */
661
-    public function insert($data = array(), $escape = true){
661
+    public function insert($data = array(), $escape = true) {
662 662
       $columns = array_keys($data);
663 663
       $column = implode(', ', $columns);
664 664
       $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -673,22 +673,22 @@  discard block
 block discarded – undo
673 673
      * @param  boolean $escape  whether to escape or not the values
674 674
      * @return object  the current DatabaseQueryBuilder instance 
675 675
      */
676
-    public function update($data = array(), $escape = true){
676
+    public function update($data = array(), $escape = true) {
677 677
       $query = 'UPDATE ' . $this->from . ' SET ';
678 678
       $values = array();
679
-      foreach ($data as $column => $val){
679
+      foreach ($data as $column => $val) {
680 680
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
681 681
       }
682 682
       $query .= implode(', ', $values);
683
-      if (! empty($this->where)){
683
+      if (!empty($this->where)) {
684 684
         $query .= ' WHERE ' . $this->where;
685 685
       }
686 686
 
687
-      if (! empty($this->orderBy)){
687
+      if (!empty($this->orderBy)) {
688 688
         $query .= ' ORDER BY ' . $this->orderBy;
689 689
       }
690 690
 
691
-      if (! empty($this->limit)){
691
+      if (!empty($this->limit)) {
692 692
         $query .= ' LIMIT ' . $this->limit;
693 693
       }
694 694
       $this->query = $query;
@@ -699,22 +699,22 @@  discard block
 block discarded – undo
699 699
      * Delete the record in database
700 700
      * @return object  the current DatabaseQueryBuilder instance 
701 701
      */
702
-    public function delete(){
702
+    public function delete() {
703 703
     	$query = 'DELETE FROM ' . $this->from;
704 704
       $isTruncate = $query;
705
-    	if (! empty($this->where)){
705
+    	if (!empty($this->where)) {
706 706
   		  $query .= ' WHERE ' . $this->where;
707 707
     	}
708 708
 
709
-    	if (! empty($this->orderBy)){
709
+    	if (!empty($this->orderBy)) {
710 710
     	  $query .= ' ORDER BY ' . $this->orderBy;
711 711
       }
712 712
 
713
-    	if (! empty($this->limit)){
713
+    	if (!empty($this->limit)) {
714 714
     		$query .= ' LIMIT ' . $this->limit;
715 715
       }
716 716
 
717
-  		if ($isTruncate == $query && $this->driver != 'sqlite'){  
717
+  		if ($isTruncate == $query && $this->driver != 'sqlite') {  
718 718
       	$query = 'TRUNCATE TABLE ' . $this->from;
719 719
   		}
720 720
 	   $this->query = $query;
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
      * @param boolean $escaped whether we can do escape of not 
728 728
      * @return mixed       the data after escaped or the same data if not
729 729
      */
730
-    public function escape($data, $escaped = true){
730
+    public function escape($data, $escaped = true) {
731 731
       $data = trim($data);
732
-      if($escaped){
732
+      if ($escaped) {
733 733
         return $this->pdo->quote($data);
734 734
       }
735 735
       return $data;  
@@ -740,31 +740,31 @@  discard block
 block discarded – undo
740 740
      * Return the current SQL query string
741 741
      * @return string
742 742
      */
743
-    public function getQuery(){
743
+    public function getQuery() {
744 744
   	  //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
745
-  	  if(empty($this->query)){
745
+  	  if (empty($this->query)) {
746 746
   		  $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
747
-  		  if (! empty($this->join)){
747
+  		  if (!empty($this->join)) {
748 748
           $query .= $this->join;
749 749
   		  }
750 750
   		  
751
-  		  if (! empty($this->where)){
751
+  		  if (!empty($this->where)) {
752 752
           $query .= ' WHERE ' . $this->where;
753 753
   		  }
754 754
 
755
-  		  if (! empty($this->groupBy)){
755
+  		  if (!empty($this->groupBy)) {
756 756
           $query .= ' GROUP BY ' . $this->groupBy;
757 757
   		  }
758 758
 
759
-  		  if (! empty($this->having)){
759
+  		  if (!empty($this->having)) {
760 760
           $query .= ' HAVING ' . $this->having;
761 761
   		  }
762 762
 
763
-  		  if (! empty($this->orderBy)){
763
+  		  if (!empty($this->orderBy)) {
764 764
   			  $query .= ' ORDER BY ' . $this->orderBy;
765 765
   		  }
766 766
 
767
-  		  if (! empty($this->limit)){
767
+  		  if (!empty($this->limit)) {
768 768
           $query .= ' LIMIT ' . $this->limit;
769 769
   		  }
770 770
   		  $this->query = $query;
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
      * Return the PDO instance
778 778
      * @return object
779 779
      */
780
-    public function getPdo(){
780
+    public function getPdo() {
781 781
       return $this->pdo;
782 782
     }
783 783
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
      * @param PDO $pdo the pdo object
787 787
 	   * @return object DatabaseQueryBuilder
788 788
      */
789
-    public function setPdo(PDO $pdo = null){
789
+    public function setPdo(PDO $pdo = null) {
790 790
       $this->pdo = $pdo;
791 791
       return $this;
792 792
     }
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
    * Return the database table prefix
796 796
    * @return string
797 797
    */
798
-    public function getPrefix(){
798
+    public function getPrefix() {
799 799
       return $this->prefix;
800 800
     }
801 801
 
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
      * @param string $prefix the new prefix
805 805
 	   * @return object DatabaseQueryBuilder
806 806
      */
807
-    public function setPrefix($prefix){
807
+    public function setPrefix($prefix) {
808 808
       $this->prefix = $prefix;
809 809
       return $this;
810 810
     }
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
      * Return the database driver
814 814
      * @return string
815 815
      */
816
-    public function getDriver(){
816
+    public function getDriver() {
817 817
       return $this->driver;
818 818
     }
819 819
 
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
      * @param string $driver the new driver
823 823
 	   * @return object DatabaseQueryBuilder
824 824
      */
825
-    public function setDriver($driver){
825
+    public function setDriver($driver) {
826 826
       $this->driver = $driver;
827 827
       return $this;
828 828
     }
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
      * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
832 832
 	   * @return object  the current DatabaseQueryBuilder instance 
833 833
      */
834
-    public function reset(){
834
+    public function reset() {
835 835
       $this->select   = '*';
836 836
       $this->from     = null;
837 837
       $this->where    = null;
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
      *
851 851
      * @return string
852 852
      */
853
-    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
853
+    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) {
854 854
         $x = explode('?', $field);
855 855
         $w = '';
856
-        foreach($x as $k => $v){
857
-  	      if (!empty($v)){
858
-            if (! isset($op[$k])){
856
+        foreach ($x as $k => $v) {
857
+  	      if (!empty($v)) {
858
+            if (!isset($op[$k])) {
859 859
               $op[$k] = '';
860 860
             }
861 861
   	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -871,15 +871,15 @@  discard block
 block discarded – undo
871 871
      *
872 872
      * @return string
873 873
      */
874
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
874
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
875 875
       $_where = array();
876
-      foreach ($where as $column => $data){
877
-        if (is_null($data)){
876
+      foreach ($where as $column => $data) {
877
+        if (is_null($data)) {
878 878
           $data = '';
879 879
         }
880 880
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
881 881
       }
882
-      $where = implode(' '.$andOr.' ', $_where);
882
+      $where = implode(' ' . $andOr . ' ', $_where);
883 883
       return $where;
884 884
     }
885 885
 
@@ -889,12 +889,12 @@  discard block
 block discarded – undo
889 889
      *
890 890
      * @return string
891 891
      */
892
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
892
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
893 893
      $x = explode('?', $where);
894 894
      $w = '';
895
-      foreach($x as $k => $v){
896
-        if (! empty($v)){
897
-            if (isset($op[$k]) && is_null($op[$k])){
895
+      foreach ($x as $k => $v) {
896
+        if (!empty($v)) {
897
+            if (isset($op[$k]) && is_null($op[$k])) {
898 898
               $op[$k] = '';
899 899
             }
900 900
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -909,15 +909,15 @@  discard block
 block discarded – undo
909 909
      *
910 910
      * @return string
911 911
      */
912
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
912
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
913 913
        $w = '';
914
-       if (! in_array((string)$op, $this->operatorList)){
915
-          if (is_null($op)){
914
+       if (!in_array((string) $op, $this->operatorList)) {
915
+          if (is_null($op)) {
916 916
             $op = '';
917 917
           }
918 918
           $w = $type . $where . ' = ' . ($this->escape($op, $escape));
919 919
         } else {
920
-          if (is_null($val)){
920
+          if (is_null($val)) {
921 921
             $val = '';
922 922
           }
923 923
           $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -930,14 +930,14 @@  discard block
 block discarded – undo
930 930
        * @param string $whereStr the WHERE clause string
931 931
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
932 932
        */
933
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
934
-        if (empty($this->where)){
933
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
934
+        if (empty($this->where)) {
935 935
           $this->where = $whereStr;
936 936
         } else {
937
-          if (substr(trim($this->where), -1) == '('){
937
+          if (substr(trim($this->where), -1) == '(') {
938 938
             $this->where = $this->where . ' ' . $whereStr;
939 939
           } else {
940
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
940
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
941 941
           }
942 942
         }
943 943
       }
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
      * @see  DatabaseQueryBuilder::avg
954 954
      * @return object
955 955
      */
956
-    protected function select_min_max_sum_count_avg($clause, $field, $name = null){
956
+    protected function select_min_max_sum_count_avg($clause, $field, $name = null) {
957 957
       $clause = strtoupper($clause);
958 958
       $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
959 959
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 3 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -149,8 +149,7 @@  discard block
 block discarded – undo
149 149
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
150 150
           if($isSqlSELECTQuery){
151 151
               $this->setResultForSelect();              
152
-          }
153
-          else{
152
+          } else{
154 153
               $this->setResultForNonSelect();
155 154
           }
156 155
           return $this->queryResult;
@@ -172,15 +171,13 @@  discard block
 block discarded – undo
172 171
       }
173 172
       if ($this->returnAsList){
174 173
           $result = $this->pdoStatment->fetchAll($fetchMode);
175
-      }
176
-      else{
174
+      } else{
177 175
           $result = $this->pdoStatment->fetch($fetchMode);
178 176
       }
179 177
       //Sqlite and pgsql always return 0 when using rowCount()
180 178
       if (in_array($this->driver, array('sqlite', 'pgsql'))){
181 179
         $numRows = count($result);  
182
-      }
183
-      else{
180
+      } else{
184 181
         $numRows = $this->pdoStatment->rowCount(); 
185 182
       }
186 183
       if(! is_object($this->queryResult)){
@@ -201,8 +198,7 @@  discard block
 block discarded – undo
201 198
       if (in_array($this->driver, array('sqlite', 'pgsql'))){
202 199
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
203 200
         $numRows = 1; //TODO use the correct method to get the exact affected row
204
-      }
205
-      else{
201
+      } else{
206 202
           //to test the result for the query like UPDATE, INSERT, DELETE
207 203
           $result  = $this->pdoStatment->rowCount() >= 0; 
208 204
           $numRows = $this->pdoStatment->rowCount(); 
@@ -380,8 +376,7 @@  discard block
 block discarded – undo
380 376
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
381 377
       if ($logger !== null){
382 378
         $this->logger = $logger;
383
-      }
384
-      else{
379
+      } else{
385 380
           $this->logger =& class_loader('Log', 'classes');
386 381
           $this->logger->setLogger('Library::DatabaseQueryRunner');
387 382
       }
Please login to merge, or discard this patch.
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -1,90 +1,90 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
     defined('ROOT_PATH') || exit('Access denied');
3
-  /**
4
-   * TNH Framework
5
-   *
6
-   * A simple PHP framework using HMVC architecture
7
-   *
8
-   * This content is released under the GNU GPL License (GPL)
9
-   *
10
-   * Copyright (C) 2017 Tony NGUEREZA
11
-   *
12
-   * This program is free software; you can redistribute it and/or
13
-   * modify it under the terms of the GNU General Public License
14
-   * as published by the Free Software Foundation; either version 3
15
-   * of the License, or (at your option) any later version.
16
-   *
17
-   * This program is distributed in the hope that it will be useful,
18
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-   * GNU General Public License for more details.
21
-   *
22
-   * You should have received a copy of the GNU General Public License
23
-   * along with this program; if not, write to the Free Software
24
-   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-  */
26
-  class DatabaseQueryRunner{
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class DatabaseQueryRunner{
27 27
       
28 28
     /**
29
-	* The logger instance
30
-	* @var object
31
-	*/
29
+     * The logger instance
30
+     * @var object
31
+     */
32 32
     private $logger            = null;
33 33
     
34
-  	/**
35
-  	 * The last query result
36
-  	 * @var object
37
-  	*/
38
-  	private $queryResult       = null;
34
+        /**
35
+         * The last query result
36
+         * @var object
37
+         */
38
+        private $queryResult       = null;
39 39
   	
40
-  	/**
41
-    * The benchmark instance
42
-    * @var object
43
-    */
40
+        /**
41
+         * The benchmark instance
42
+         * @var object
43
+         */
44 44
     private $benchmarkInstance = null;
45 45
     
46 46
     /**
47
-	 * The SQL query statment to execute
48
-	 * @var string
49
-	*/
47
+     * The SQL query statment to execute
48
+     * @var string
49
+     */
50 50
     private $query             = null;
51 51
     
52 52
     /**
53
-	 * Indicate if we need return result as list (boolean) 
53
+     * Indicate if we need return result as list (boolean) 
54 54
      * or the data used to replace the placeholder (array)
55
-	 * @var array|boolean
56
-	 */
57
-     private $returnAsList     = true;
55
+     * @var array|boolean
56
+     */
57
+        private $returnAsList     = true;
58 58
      
59 59
      
60
-     /**
61
-	   * Indicate if we need return result as array or not
62
-     * @var boolean
63
-	   */
64
-     private $returnAsArray     = true;
60
+        /**
61
+         * Indicate if we need return result as array or not
62
+         * @var boolean
63
+         */
64
+        private $returnAsArray     = true;
65 65
      
66
-     /**
67
-     * The last PDOStatment instance
68
-     * @var object
69
-     */
70
-     private $pdoStatment       = null;
66
+        /**
67
+         * The last PDOStatment instance
68
+         * @var object
69
+         */
70
+        private $pdoStatment       = null;
71 71
      
72
-     /**
73
-  	 * The error returned for the last query
74
-  	 * @var string
75
-  	 */
76
-     private $error             = null;
72
+        /**
73
+         * The error returned for the last query
74
+         * @var string
75
+         */
76
+        private $error             = null;
77 77
 	
78 78
     /**
79 79
      * The PDO instance
80 80
      * @var object
81
-    */
81
+     */
82 82
     private $pdo                = null;
83 83
   
84 84
     /**
85 85
      * The database driver name used
86 86
      * @var string
87
-    */
87
+     */
88 88
     private $driver             = null;
89 89
 
90 90
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
100 100
         if (is_object($pdo)){
101
-          $this->pdo = $pdo;
101
+            $this->pdo = $pdo;
102 102
         }
103 103
         $this->query         = $query;
104 104
         $this->returnAsList  = $returnAsList;
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
         //reset instance
117 117
         $this->reset();
118 118
        
119
-       //for database query execution time
119
+        //for database query execution time
120 120
         $benchmarkMarkerKey = $this->getBenchmarkKey();
121 121
         if (! is_object($this->benchmarkInstance)){
122
-          $this->benchmarkInstance = & class_loader('Benchmark');
122
+            $this->benchmarkInstance = & class_loader('Benchmark');
123 123
         }
124 124
         
125 125
         $this->logger->info('Execute SQL query [' . $this->query . ']');
@@ -132,101 +132,101 @@  discard block
 block discarded – undo
132 132
         $responseTime = $this->benchmarkInstance->elapsedTime(
133 133
                                                                 'DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 
134 134
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
135
-                                                              );
136
-		    //TODO use the configuration value for the high response time currently is 1 second
135
+                                                                );
136
+            //TODO use the configuration value for the high response time currently is 1 second
137 137
         if ($responseTime >= 1 ){
138 138
             $this->logger->warning(
139 139
                                     'High response time while processing database query [' . $this->query . ']. 
140 140
                                      The response time is [' .$responseTime. '] sec.'
141
-                                  );
141
+                                    );
142 142
         }
143 143
 		
144 144
         if ($this->pdoStatment !== false){
145
-          $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
-          if($isSqlSELECTQuery){
147
-              $this->setResultForSelect();              
148
-          }
149
-          else{
150
-              $this->setResultForNonSelect();
151
-          }
152
-          return $this->queryResult;
145
+            $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
+            if($isSqlSELECTQuery){
147
+                $this->setResultForSelect();              
148
+            }
149
+            else{
150
+                $this->setResultForNonSelect();
151
+            }
152
+            return $this->queryResult;
153 153
         }
154 154
         $this->setQueryRunnerError();
155 155
     }
156 156
 	
157
-   /**
158
-   * Return the result for SELECT query
159
-   * @see DatabaseQueryRunner::execute
160
-   */
157
+    /**
158
+     * Return the result for SELECT query
159
+     * @see DatabaseQueryRunner::execute
160
+     */
161 161
     protected function setResultForSelect(){
162
-      //if need return all result like list of record
163
-      $result = null;
164
-      $numRows = 0;
165
-      $fetchMode = PDO::FETCH_OBJ;
166
-      if($this->returnAsArray){
162
+        //if need return all result like list of record
163
+        $result = null;
164
+        $numRows = 0;
165
+        $fetchMode = PDO::FETCH_OBJ;
166
+        if($this->returnAsArray){
167 167
         $fetchMode = PDO::FETCH_ASSOC;
168
-      }
169
-      if ($this->returnAsList){
170
-          $result = $this->pdoStatment->fetchAll($fetchMode);
171
-      }
172
-      else{
173
-          $result = $this->pdoStatment->fetch($fetchMode);
174
-      }
175
-      //Sqlite and pgsql always return 0 when using rowCount()
176
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
168
+        }
169
+        if ($this->returnAsList){
170
+            $result = $this->pdoStatment->fetchAll($fetchMode);
171
+        }
172
+        else{
173
+            $result = $this->pdoStatment->fetch($fetchMode);
174
+        }
175
+        //Sqlite and pgsql always return 0 when using rowCount()
176
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
177 177
         $numRows = count($result);  
178
-      }
179
-      else{
178
+        }
179
+        else{
180 180
         $numRows = $this->pdoStatment->rowCount(); 
181
-      }
182
-      if(! is_object($this->queryResult)){
183
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184
-      }
185
-      $this->queryResult->setResult($result);
186
-      $this->queryResult->setNumRows($numRows);
181
+        }
182
+        if(! is_object($this->queryResult)){
183
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184
+        }
185
+        $this->queryResult->setResult($result);
186
+        $this->queryResult->setNumRows($numRows);
187 187
     }
188 188
 
189 189
     /**
190
-   * Return the result for non SELECT query
191
-   * @see DatabaseQueryRunner::execute
192
-   */
190
+     * Return the result for non SELECT query
191
+     * @see DatabaseQueryRunner::execute
192
+     */
193 193
     protected function setResultForNonSelect(){
194
-      //Sqlite and pgsql always return 0 when using rowCount()
195
-      $result = false;
196
-      $numRows = 0;
197
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
194
+        //Sqlite and pgsql always return 0 when using rowCount()
195
+        $result = false;
196
+        $numRows = 0;
197
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
198 198
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
199 199
         $numRows = 1; //TODO use the correct method to get the exact affected row
200
-      }
201
-      else{
202
-          //to test the result for the query like UPDATE, INSERT, DELETE
203
-          $result  = $this->pdoStatment->rowCount() >= 0; 
204
-          $numRows = $this->pdoStatment->rowCount(); 
205
-      }
206
-      if(! is_object($this->queryResult)){
207
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208
-      }
209
-      $this->queryResult->setResult($result);
210
-      $this->queryResult->setNumRows($numRows);
200
+        }
201
+        else{
202
+            //to test the result for the query like UPDATE, INSERT, DELETE
203
+            $result  = $this->pdoStatment->rowCount() >= 0; 
204
+            $numRows = $this->pdoStatment->rowCount(); 
205
+        }
206
+        if(! is_object($this->queryResult)){
207
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208
+        }
209
+        $this->queryResult->setResult($result);
210
+        $this->queryResult->setNumRows($numRows);
211 211
     }
212 212
 
213 213
 
214
-	/**
214
+    /**
215 215
      * Return the benchmark instance
216 216
      * @return Benchmark
217 217
      */
218 218
     public function getBenchmark(){
219
-      return $this->benchmarkInstance;
219
+        return $this->benchmarkInstance;
220 220
     }
221 221
 
222 222
     /**
223 223
      * Set the benchmark instance
224 224
      * @param Benchmark $benchmark the benchmark object
225
-	 * @return object DatabaseQueryRunner
225
+     * @return object DatabaseQueryRunner
226 226
      */
227 227
     public function setBenchmark($benchmark){
228
-      $this->benchmarkInstance = $benchmark;
229
-      return $this;
228
+        $this->benchmarkInstance = $benchmark;
229
+        return $this;
230 230
     }
231 231
     
232 232
     /**
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
      * @return object DatabaseQueryResult
236 236
      */
237 237
     public function getQueryResult(){
238
-      return $this->queryResult;
238
+        return $this->queryResult;
239 239
     }
240 240
 
241 241
     /**
242 242
      * Set the database query result instance
243 243
      * @param object $queryResult the query result
244 244
      *
245
-	 * @return object DatabaseQueryRunner
245
+     * @return object DatabaseQueryRunner
246 246
      */
247 247
     public function setQueryResult(DatabaseQueryResult $queryResult){
248
-      $this->queryResult = $queryResult;
249
-      return $this;
248
+        $this->queryResult = $queryResult;
249
+        return $this;
250 250
     }
251 251
     
252 252
     /**
@@ -254,17 +254,17 @@  discard block
 block discarded – undo
254 254
      * @return Log
255 255
      */
256 256
     public function getLogger(){
257
-      return $this->logger;
257
+        return $this->logger;
258 258
     }
259 259
 
260 260
     /**
261 261
      * Set the log instance
262 262
      * @param Log $logger the log object
263
-	 * @return object DatabaseQueryRunner
263
+     * @return object DatabaseQueryRunner
264 264
      */
265 265
     public function setLogger($logger){
266
-      $this->logger = $logger;
267
-      return $this;
266
+        $this->logger = $logger;
267
+        return $this;
268 268
     }
269 269
     
270 270
     /**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      * @return string
273 273
      */
274 274
     public function getQuery(){
275
-      return $this->query;
275
+        return $this->query;
276 276
     }
277 277
     
278 278
     /**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
      * @return object DatabaseQueryRunner
282 282
      */
283 283
     public function setQuery($query){
284
-       $this->query = $query;
285
-       return $this;
284
+        $this->query = $query;
285
+        return $this;
286 286
     }
287 287
     
288 288
     /**
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
      * @return object DatabaseQueryRunner
292 292
      */
293 293
     public function setReturnType($returnType){
294
-       $this->returnAsList = $returnType;
295
-       return $this;
294
+        $this->returnAsList = $returnType;
295
+        return $this;
296 296
     }
297 297
     
298 298
     /**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
      * @return object DatabaseQueryRunner
302 302
      */
303 303
     public function setReturnAsArray($status = true){
304
-       $this->returnAsArray = $status;
305
-       return $this;
304
+        $this->returnAsArray = $status;
305
+        return $this;
306 306
     }
307 307
     
308 308
     /**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      * @return string
311 311
      */
312 312
     public function getQueryError(){
313
-      return $this->error;
313
+        return $this->error;
314 314
     }
315 315
 
316 316
     /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      * @return object
319 319
      */
320 320
     public function getPdo(){
321
-      return $this->pdo;
321
+        return $this->pdo;
322 322
     }
323 323
 
324 324
     /**
@@ -327,16 +327,16 @@  discard block
 block discarded – undo
327 327
      * @return object DatabaseQueryRunner
328 328
      */
329 329
     public function setPdo(PDO $pdo = null){
330
-      $this->pdo = $pdo;
331
-      return $this;
330
+        $this->pdo = $pdo;
331
+        return $this;
332 332
     }
333 333
   
334
-     /**
335
-     * Return the database driver
336
-     * @return string
337
-     */
334
+        /**
335
+         * Return the database driver
336
+         * @return string
337
+         */
338 338
     public function getDriver(){
339
-      return $this->driver;
339
+        return $this->driver;
340 340
     }
341 341
 
342 342
     /**
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
      * @return object DatabaseQueryRunner
346 346
      */
347 347
     public function setDriver($driver){
348
-      $this->driver = $driver;
349
-      return $this;
348
+        $this->driver = $driver;
349
+        return $this;
350 350
     }
351 351
     
352 352
     /**
@@ -355,18 +355,18 @@  discard block
 block discarded – undo
355 355
      *  @return string
356 356
      */
357 357
     protected function getBenchmarkKey(){
358
-      return md5($this->query . $this->returnAsList . $this->returnAsArray);
358
+        return md5($this->query . $this->returnAsList . $this->returnAsArray);
359 359
     }
360 360
     
361 361
     /**
362 362
      * Set error for database query execution
363 363
      */
364 364
     protected function setQueryRunnerError(){
365
-      $error = $this->pdo->errorInfo();
366
-      $this->error = isset($error[2]) ? $error[2] : '';
367
-      $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
368
-	  //show error message
369
-      show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
365
+        $error = $this->pdo->errorInfo();
366
+        $this->error = isset($error[2]) ? $error[2] : '';
367
+        $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
368
+        //show error message
369
+        show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
370 370
     }
371 371
     
372 372
     /**
@@ -374,19 +374,19 @@  discard block
 block discarded – undo
374 374
      * @param object $logger the Log instance if not null
375 375
      */
376 376
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
377
-      if ($logger !== null){
377
+        if ($logger !== null){
378 378
         $this->logger = $logger;
379
-      }
380
-      else{
381
-          $this->logger =& class_loader('Log', 'classes');
382
-          $this->logger->setLogger('Library::DatabaseQueryRunner');
383
-      }
379
+        }
380
+        else{
381
+            $this->logger =& class_loader('Log', 'classes');
382
+            $this->logger->setLogger('Library::DatabaseQueryRunner');
383
+        }
384 384
     }
385 385
     
386 386
     
387 387
     /**
388
-    * Reset the instance before run each query
389
-    */
388
+     * Reset the instance before run each query
389
+     */
390 390
     private function reset(){
391 391
         $this->error = null;
392 392
         $this->pdoStatment = null;
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class DatabaseQueryRunner{
26
+  class DatabaseQueryRunner {
27 27
       
28 28
     /**
29 29
 	* The logger instance
30 30
 	* @var object
31 31
 	*/
32
-    private $logger            = null;
32
+    private $logger = null;
33 33
     
34 34
   	/**
35 35
   	 * The last query result
36 36
   	 * @var object
37 37
   	*/
38
-  	private $queryResult       = null;
38
+  	private $queryResult = null;
39 39
   	
40 40
   	/**
41 41
     * The benchmark instance
@@ -47,45 +47,45 @@  discard block
 block discarded – undo
47 47
 	 * The SQL query statment to execute
48 48
 	 * @var string
49 49
 	*/
50
-    private $query             = null;
50
+    private $query = null;
51 51
     
52 52
     /**
53 53
 	 * Indicate if we need return result as list (boolean) 
54 54
      * or the data used to replace the placeholder (array)
55 55
 	 * @var array|boolean
56 56
 	 */
57
-     private $returnAsList     = true;
57
+     private $returnAsList = true;
58 58
      
59 59
      
60 60
      /**
61 61
 	   * Indicate if we need return result as array or not
62 62
      * @var boolean
63 63
 	   */
64
-     private $returnAsArray     = true;
64
+     private $returnAsArray = true;
65 65
      
66 66
      /**
67 67
      * The last PDOStatment instance
68 68
      * @var object
69 69
      */
70
-     private $pdoStatment       = null;
70
+     private $pdoStatment = null;
71 71
      
72 72
      /**
73 73
   	 * The error returned for the last query
74 74
   	 * @var string
75 75
   	 */
76
-     private $error             = null;
76
+     private $error = null;
77 77
 	
78 78
     /**
79 79
      * The PDO instance
80 80
      * @var object
81 81
     */
82
-    private $pdo                = null;
82
+    private $pdo = null;
83 83
   
84 84
     /**
85 85
      * The database driver name used
86 86
      * @var string
87 87
     */
88
-    private $driver             = null;
88
+    private $driver = null;
89 89
 
90 90
 
91 91
 	
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      * @param boolean $returnAsList if need return as list or just one row
97 97
      * @param boolean $returnAsArray whether to return the result as array or not
98 98
      */
99
-    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
100
-        if (is_object($pdo)){
99
+    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) {
100
+        if (is_object($pdo)) {
101 101
           $this->pdo = $pdo;
102 102
         }
103 103
         $this->query         = $query;
@@ -112,13 +112,13 @@  discard block
 block discarded – undo
112 112
      * 
113 113
      * @return object|void
114 114
      */
115
-    public function execute(){
115
+    public function execute() {
116 116
         //reset instance
117 117
         $this->reset();
118 118
        
119 119
        //for database query execution time
120 120
         $benchmarkMarkerKey = $this->getBenchmarkKey();
121
-        if (! is_object($this->benchmarkInstance)){
121
+        if (!is_object($this->benchmarkInstance)) {
122 122
           $this->benchmarkInstance = & class_loader('Benchmark');
123 123
         }
124 124
         
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
135 135
                                                               );
136 136
 		    //TODO use the configuration value for the high response time currently is 1 second
137
-        if ($responseTime >= 1 ){
137
+        if ($responseTime >= 1) {
138 138
             $this->logger->warning(
139 139
                                     'High response time while processing database query [' . $this->query . ']. 
140
-                                     The response time is [' .$responseTime. '] sec.'
140
+                                     The response time is [' .$responseTime . '] sec.'
141 141
                                   );
142 142
         }
143 143
 		
144
-        if ($this->pdoStatment !== false){
144
+        if ($this->pdoStatment !== false) {
145 145
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
146
-          if($isSqlSELECTQuery){
146
+          if ($isSqlSELECTQuery) {
147 147
               $this->setResultForSelect();              
148 148
           }
149
-          else{
149
+          else {
150 150
               $this->setResultForNonSelect();
151 151
           }
152 152
           return $this->queryResult;
@@ -158,28 +158,28 @@  discard block
 block discarded – undo
158 158
    * Return the result for SELECT query
159 159
    * @see DatabaseQueryRunner::execute
160 160
    */
161
-    protected function setResultForSelect(){
161
+    protected function setResultForSelect() {
162 162
       //if need return all result like list of record
163 163
       $result = null;
164 164
       $numRows = 0;
165 165
       $fetchMode = PDO::FETCH_OBJ;
166
-      if($this->returnAsArray){
166
+      if ($this->returnAsArray) {
167 167
         $fetchMode = PDO::FETCH_ASSOC;
168 168
       }
169
-      if ($this->returnAsList){
169
+      if ($this->returnAsList) {
170 170
           $result = $this->pdoStatment->fetchAll($fetchMode);
171 171
       }
172
-      else{
172
+      else {
173 173
           $result = $this->pdoStatment->fetch($fetchMode);
174 174
       }
175 175
       //Sqlite and pgsql always return 0 when using rowCount()
176
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
176
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
177 177
         $numRows = count($result);  
178 178
       }
179
-      else{
179
+      else {
180 180
         $numRows = $this->pdoStatment->rowCount(); 
181 181
       }
182
-      if(! is_object($this->queryResult)){
182
+      if (!is_object($this->queryResult)) {
183 183
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
184 184
       }
185 185
       $this->queryResult->setResult($result);
@@ -190,20 +190,20 @@  discard block
 block discarded – undo
190 190
    * Return the result for non SELECT query
191 191
    * @see DatabaseQueryRunner::execute
192 192
    */
193
-    protected function setResultForNonSelect(){
193
+    protected function setResultForNonSelect() {
194 194
       //Sqlite and pgsql always return 0 when using rowCount()
195 195
       $result = false;
196 196
       $numRows = 0;
197
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
197
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
198 198
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
199 199
         $numRows = 1; //TODO use the correct method to get the exact affected row
200 200
       }
201
-      else{
201
+      else {
202 202
           //to test the result for the query like UPDATE, INSERT, DELETE
203 203
           $result  = $this->pdoStatment->rowCount() >= 0; 
204 204
           $numRows = $this->pdoStatment->rowCount(); 
205 205
       }
206
-      if(! is_object($this->queryResult)){
206
+      if (!is_object($this->queryResult)) {
207 207
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
208 208
       }
209 209
       $this->queryResult->setResult($result);
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * Return the benchmark instance
216 216
      * @return Benchmark
217 217
      */
218
-    public function getBenchmark(){
218
+    public function getBenchmark() {
219 219
       return $this->benchmarkInstance;
220 220
     }
221 221
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * @param Benchmark $benchmark the benchmark object
225 225
 	 * @return object DatabaseQueryRunner
226 226
      */
227
-    public function setBenchmark($benchmark){
227
+    public function setBenchmark($benchmark) {
228 228
       $this->benchmarkInstance = $benchmark;
229 229
       return $this;
230 230
     }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      *
235 235
      * @return object DatabaseQueryResult
236 236
      */
237
-    public function getQueryResult(){
237
+    public function getQueryResult() {
238 238
       return $this->queryResult;
239 239
     }
240 240
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
 	 * @return object DatabaseQueryRunner
246 246
      */
247
-    public function setQueryResult(DatabaseQueryResult $queryResult){
247
+    public function setQueryResult(DatabaseQueryResult $queryResult) {
248 248
       $this->queryResult = $queryResult;
249 249
       return $this;
250 250
     }
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      * Return the Log instance
254 254
      * @return Log
255 255
      */
256
-    public function getLogger(){
256
+    public function getLogger() {
257 257
       return $this->logger;
258 258
     }
259 259
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      * @param Log $logger the log object
263 263
 	 * @return object DatabaseQueryRunner
264 264
      */
265
-    public function setLogger($logger){
265
+    public function setLogger($logger) {
266 266
       $this->logger = $logger;
267 267
       return $this;
268 268
     }
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * Return the current query SQL string
272 272
      * @return string
273 273
      */
274
-    public function getQuery(){
274
+    public function getQuery() {
275 275
       return $this->query;
276 276
     }
277 277
     
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      * @param string $query the SQL query to set
281 281
      * @return object DatabaseQueryRunner
282 282
      */
283
-    public function setQuery($query){
283
+    public function setQuery($query) {
284 284
        $this->query = $query;
285 285
        return $this;
286 286
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * @param boolean $returnType
291 291
      * @return object DatabaseQueryRunner
292 292
      */
293
-    public function setReturnType($returnType){
293
+    public function setReturnType($returnType) {
294 294
        $this->returnAsList = $returnType;
295 295
        return $this;
296 296
     }
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      * @param boolean $status the status if true will return as array
301 301
      * @return object DatabaseQueryRunner
302 302
      */
303
-    public function setReturnAsArray($status = true){
303
+    public function setReturnAsArray($status = true) {
304 304
        $this->returnAsArray = $status;
305 305
        return $this;
306 306
     }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      * Return the error for last query execution
310 310
      * @return string
311 311
      */
312
-    public function getQueryError(){
312
+    public function getQueryError() {
313 313
       return $this->error;
314 314
     }
315 315
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      * Return the PDO instance
318 318
      * @return object
319 319
      */
320
-    public function getPdo(){
320
+    public function getPdo() {
321 321
       return $this->pdo;
322 322
     }
323 323
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      * @param PDO $pdo the pdo object
327 327
      * @return object DatabaseQueryRunner
328 328
      */
329
-    public function setPdo(PDO $pdo = null){
329
+    public function setPdo(PDO $pdo = null) {
330 330
       $this->pdo = $pdo;
331 331
       return $this;
332 332
     }
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      * Return the database driver
336 336
      * @return string
337 337
      */
338
-    public function getDriver(){
338
+    public function getDriver() {
339 339
       return $this->driver;
340 340
     }
341 341
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @param string $driver the new driver
345 345
      * @return object DatabaseQueryRunner
346 346
      */
347
-    public function setDriver($driver){
347
+    public function setDriver($driver) {
348 348
       $this->driver = $driver;
349 349
       return $this;
350 350
     }
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
      * 
355 355
      *  @return string
356 356
      */
357
-    protected function getBenchmarkKey(){
357
+    protected function getBenchmarkKey() {
358 358
       return md5($this->query . $this->returnAsList . $this->returnAsArray);
359 359
     }
360 360
     
361 361
     /**
362 362
      * Set error for database query execution
363 363
      */
364
-    protected function setQueryRunnerError(){
364
+    protected function setQueryRunnerError() {
365 365
       $error = $this->pdo->errorInfo();
366 366
       $this->error = isset($error[2]) ? $error[2] : '';
367 367
       $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
@@ -373,12 +373,12 @@  discard block
 block discarded – undo
373 373
      * Set the Log instance using argument or create new instance
374 374
      * @param object $logger the Log instance if not null
375 375
      */
376
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
377
-      if ($logger !== null){
376
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
377
+      if ($logger !== null) {
378 378
         $this->logger = $logger;
379 379
       }
380
-      else{
381
-          $this->logger =& class_loader('Log', 'classes');
380
+      else {
381
+          $this->logger = & class_loader('Log', 'classes');
382 382
           $this->logger->setLogger('Library::DatabaseQueryRunner');
383 383
       }
384 384
     }
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
     /**
388 388
     * Reset the instance before run each query
389 389
     */
390
-    private function reset(){
390
+    private function reset() {
391 391
         $this->error = null;
392 392
         $this->pdoStatment = null;
393 393
     }
Please login to merge, or discard this patch.
core/constants.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file constants.php
29
-	 *    
30
-	 *  This file contains the declaration of most of the constants used in the system, 
31
-	 *  for example: the version, the name of the framework, etc.
32
-	 *  
33
-	 *  @package	core	
34
-	 *  @author	Tony NGUEREZA
35
-	 *  @copyright	Copyright (c) 2017
36
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
-	 *  @link	http://www.iacademy.cf
38
-	 *  @version 1.0.0
39
-	 *  @filesource
40
-	 */
27
+    /**
28
+     *  @file constants.php
29
+     *    
30
+     *  This file contains the declaration of most of the constants used in the system, 
31
+     *  for example: the version, the name of the framework, etc.
32
+     *  
33
+     *  @package	core	
34
+     *  @author	Tony NGUEREZA
35
+     *  @copyright	Copyright (c) 2017
36
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
+     *  @link	http://www.iacademy.cf
38
+     *  @version 1.0.0
39
+     *  @filesource
40
+     */
41 41
 
42
-	/**
43
-	 *  The framework name
44
-	 */
45
-	define('TNH_NAME', 'TNH Framework');
42
+    /**
43
+     *  The framework name
44
+     */
45
+    define('TNH_NAME', 'TNH Framework');
46 46
 
47
-	/**
48
-	 *  The version of the framework in X.Y.Z format (Major, minor and bugs). 
49
-	 *  If there is the presence of the word "dev", it means that 
50
-	 *  it is a version under development.
51
-	 */
52
-	define('TNH_VERSION', '1.0.0-dev');
47
+    /**
48
+     *  The version of the framework in X.Y.Z format (Major, minor and bugs). 
49
+     *  If there is the presence of the word "dev", it means that 
50
+     *  it is a version under development.
51
+     */
52
+    define('TNH_VERSION', '1.0.0-dev');
53 53
 
54
-	/**
55
-	 *  The date of publication or release of the framework
56
-	 */
57
-	define('TNH_RELEASE_DATE', '2017/02/05');
54
+    /**
55
+     *  The date of publication or release of the framework
56
+     */
57
+    define('TNH_RELEASE_DATE', '2017/02/05');
58 58
 
59
-	/**
60
-	 *  The author of the framework, the person who developed the framework.
61
-	 */
62
-	define('TNH_AUTHOR', 'Tony NGUEREZA');
59
+    /**
60
+     *  The author of the framework, the person who developed the framework.
61
+     */
62
+    define('TNH_AUTHOR', 'Tony NGUEREZA');
63 63
 
64
-	/**
65
-	 *  Email address of the author of the framework.
66
-	 */
67
-	define('TNH_AUTHOR_EMAIL', '[email protected]');
64
+    /**
65
+     *  Email address of the author of the framework.
66
+     */
67
+    define('TNH_AUTHOR_EMAIL', '[email protected]');
68 68
 
69
-	/**
70
-	 *  The minimum PHP version required to use the framework. 
71
-	 *  If the version of PHP installed is lower, then the application will not work.
72
-	 *  Note: we use the PHP version_compare function to compare the required version with 
73
-	 *  the version installed on your system.
74
-	 */
75
-	define('TNH_REQUIRED_PHP_MIN_VERSION', '5.4');
69
+    /**
70
+     *  The minimum PHP version required to use the framework. 
71
+     *  If the version of PHP installed is lower, then the application will not work.
72
+     *  Note: we use the PHP version_compare function to compare the required version with 
73
+     *  the version installed on your system.
74
+     */
75
+    define('TNH_REQUIRED_PHP_MIN_VERSION', '5.4');
76 76
 
77
-	/**
78
-	 *  The maximum version of PHP required to use the framework. 
79
-	 *  If the version of PHP installed is higher than the required one, then the application will not work.
80
-	 */
81
-	define('TNH_REQUIRED_PHP_MAX_VERSION', '7.1');
82 77
\ No newline at end of file
78
+    /**
79
+     *  The maximum version of PHP required to use the framework. 
80
+     *  If the version of PHP installed is higher than the required one, then the application will not work.
81
+     */
82
+    define('TNH_REQUIRED_PHP_MAX_VERSION', '7.1');
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
core/classes/Url.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@
 block discarded – undo
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65
-				}
66
-				else{
65
+				} else{
67 66
 					$path .= $suffix;
68 67
 				}
69 68
 			}
Please login to merge, or discard this patch.
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -1,149 +1,149 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27 27
 
28
-	class Url{
28
+    class Url{
29 29
 
30
-		/**
31
-		 * Return the link using base_url config without front controller "index.php"
32
-		 * @param  string $path the link path or full URL
33
-		 * @return string the full link URL
34
-		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
37
-				return $path;
38
-			}
39
-			return get_config('base_url') . $path;
40
-		}
30
+        /**
31
+         * Return the link using base_url config without front controller "index.php"
32
+         * @param  string $path the link path or full URL
33
+         * @return string the full link URL
34
+         */
35
+        public static function base_url($path = ''){
36
+            if(is_url($path)){
37
+                return $path;
38
+            }
39
+            return get_config('base_url') . $path;
40
+        }
41 41
 
42
-		/**
43
-		 * Return the link using base_url config with front controller "index.php"
44
-		 * @param  string $path the link path or full URL
45
-		 * @return string the full link URL
46
-		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
49
-				return $path;
50
-			}
51
-			$path = rtrim($path, '/');
52
-			$baseUrl = get_config('base_url');
53
-			$frontController = get_config('front_controller');
54
-			$url = $baseUrl;
55
-			if($frontController){
56
-				$url .= $frontController . '/';
57
-			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
60
-					$query = explode('?', $path);
61
-					$query[0] = str_ireplace($suffix, '', $query[0]);
62
-					$query[0] = rtrim($query[0], '/');
63
-					$query[0] .= $suffix;
64
-					$path = implode('?', $query);
65
-				}
66
-				else{
67
-					$path .= $suffix;
68
-				}
69
-			}
70
-			return $url . $path;
71
-		}
42
+        /**
43
+         * Return the link using base_url config with front controller "index.php"
44
+         * @param  string $path the link path or full URL
45
+         * @return string the full link URL
46
+         */
47
+        public static function site_url($path = ''){
48
+            if(is_url($path)){
49
+                return $path;
50
+            }
51
+            $path = rtrim($path, '/');
52
+            $baseUrl = get_config('base_url');
53
+            $frontController = get_config('front_controller');
54
+            $url = $baseUrl;
55
+            if($frontController){
56
+                $url .= $frontController . '/';
57
+            }
58
+            if(($suffix = get_config('url_suffix')) && $path){
59
+                if(strpos($path, '?') !== false){
60
+                    $query = explode('?', $path);
61
+                    $query[0] = str_ireplace($suffix, '', $query[0]);
62
+                    $query[0] = rtrim($query[0], '/');
63
+                    $query[0] .= $suffix;
64
+                    $path = implode('?', $query);
65
+                }
66
+                else{
67
+                    $path .= $suffix;
68
+                }
69
+            }
70
+            return $url . $path;
71
+        }
72 72
 
73
-		/**
74
-		 * Return the current site URL
75
-		 * @return string
76
-		 */
77
-		public static function current(){
78
-			$current = '/';
79
-			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
81
-				$current = $requestUri;
82
-			}
83
-			return static::domain() . $current;
84
-		}
73
+        /**
74
+         * Return the current site URL
75
+         * @return string
76
+         */
77
+        public static function current(){
78
+            $current = '/';
79
+            $requestUri = get_instance()->request->requestUri();
80
+            if($requestUri){
81
+                $current = $requestUri;
82
+            }
83
+            return static::domain() . $current;
84
+        }
85 85
 
86
-		/**
87
-		 * Generate a friendly  text to use in link (slugs)
88
-		 * @param  string  $str       the title or text to use to get the friendly text
89
-		 * @param  string  $separator the caracters separator
90
-		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91
-		 * @return string the friendly generated text
92
-		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
94
-			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
97
-			$str = str_replace($from, $to, $str);
98
-			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99
-			$str = str_replace('--', $separator, $str);
100
-			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
102
-				$str = substr($str, 0, -1);
103
-			}
104
-			if($lowercase){
105
-				$str = strtolower($str);
106
-			}
107
-			return $str;
108
-		}
86
+        /**
87
+         * Generate a friendly  text to use in link (slugs)
88
+         * @param  string  $str       the title or text to use to get the friendly text
89
+         * @param  string  $separator the caracters separator
90
+         * @param  boolean $lowercase whether to set the final text to lowe case or not
91
+         * @return string the friendly generated text
92
+         */
93
+        public static function title($str = null, $separator = '-', $lowercase = true){
94
+            $str = trim($str);
95
+            $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
+            $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
97
+            $str = str_replace($from, $to, $str);
98
+            $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99
+            $str = str_replace('--', $separator, $str);
100
+            //if after process we get something like one-two-three-, need truncate the last separator "-"
101
+            if(substr($str, -1) == $separator){
102
+                $str = substr($str, 0, -1);
103
+            }
104
+            if($lowercase){
105
+                $str = strtolower($str);
106
+            }
107
+            return $str;
108
+        }
109 109
 
110
-		/**
111
-		 * Get the current application domain with protocol
112
-		 * @return string the domain name
113
-		 */
114
-		public static function domain(){
115
-			$domain = 'localhost';
116
-			$port = get_instance()->request->server('SERVER_PORT');
117
-			$protocol = 'http';
118
-			if(is_https()){
119
-				$protocol = 'https';
120
-			}
110
+        /**
111
+         * Get the current application domain with protocol
112
+         * @return string the domain name
113
+         */
114
+        public static function domain(){
115
+            $domain = 'localhost';
116
+            $port = get_instance()->request->server('SERVER_PORT');
117
+            $protocol = 'http';
118
+            if(is_https()){
119
+                $protocol = 'https';
120
+            }
121 121
 
122
-			$domainserverVars = array(
123
-				'HTTP_HOST',
124
-				'SERVER_NAME',
125
-				'SERVER_ADDR'
126
-			);
122
+            $domainserverVars = array(
123
+                'HTTP_HOST',
124
+                'SERVER_NAME',
125
+                'SERVER_ADDR'
126
+            );
127 127
 
128
-			foreach ($domainserverVars as $var) {
129
-				$value = get_instance()->request->server($var);
130
-				if($value){
131
-					$domain = $value;
132
-					break;
133
-				}
134
-			}
128
+            foreach ($domainserverVars as $var) {
129
+                $value = get_instance()->request->server($var);
130
+                if($value){
131
+                    $domain = $value;
132
+                    break;
133
+                }
134
+            }
135 135
 			
136
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
-				$domain .= ':'.$port;
138
-			}
139
-			return $protocol.'://'.$domain;
140
-		}
136
+            if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
+                $domain .= ':'.$port;
138
+            }
139
+            return $protocol.'://'.$domain;
140
+        }
141 141
 
142
-		/**
143
-		 * Get the current request query string
144
-		 * @return string
145
-		 */
146
-		public static function queryString(){
147
-			return get_instance()->request->server('QUERY_STRING');
148
-		}
149
-	}
142
+        /**
143
+         * Get the current request query string
144
+         * @return string
145
+         */
146
+        public static function queryString(){
147
+            return get_instance()->request->server('QUERY_STRING');
148
+        }
149
+    }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Url{
28
+	class Url {
29 29
 
30 30
 		/**
31 31
 		 * Return the link using base_url config without front controller "index.php"
32 32
 		 * @param  string $path the link path or full URL
33 33
 		 * @return string the full link URL
34 34
 		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
35
+		public static function base_url($path = '') {
36
+			if (is_url($path)) {
37 37
 				return $path;
38 38
 			}
39 39
 			return get_config('base_url') . $path;
@@ -44,26 +44,26 @@  discard block
 block discarded – undo
44 44
 		 * @param  string $path the link path or full URL
45 45
 		 * @return string the full link URL
46 46
 		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
47
+		public static function site_url($path = '') {
48
+			if (is_url($path)) {
49 49
 				return $path;
50 50
 			}
51 51
 			$path = rtrim($path, '/');
52 52
 			$baseUrl = get_config('base_url');
53 53
 			$frontController = get_config('front_controller');
54 54
 			$url = $baseUrl;
55
-			if($frontController){
55
+			if ($frontController) {
56 56
 				$url .= $frontController . '/';
57 57
 			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
58
+			if (($suffix = get_config('url_suffix')) && $path) {
59
+				if (strpos($path, '?') !== false) {
60 60
 					$query = explode('?', $path);
61 61
 					$query[0] = str_ireplace($suffix, '', $query[0]);
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65 65
 				}
66
-				else{
66
+				else {
67 67
 					$path .= $suffix;
68 68
 				}
69 69
 			}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 		 * Return the current site URL
75 75
 		 * @return string
76 76
 		 */
77
-		public static function current(){
77
+		public static function current() {
78 78
 			$current = '/';
79 79
 			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
80
+			if ($requestUri) {
81 81
 				$current = $requestUri;
82 82
 			}
83 83
 			return static::domain() . $current;
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91 91
 		 * @return string the friendly generated text
92 92
 		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
93
+		public static function title($str = null, $separator = '-', $lowercase = true) {
94 94
 			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
95
+			$from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ');
96
+			$to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n');
97 97
 			$str = str_replace($from, $to, $str);
98 98
 			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99 99
 			$str = str_replace('--', $separator, $str);
100 100
 			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
101
+			if (substr($str, -1) == $separator) {
102 102
 				$str = substr($str, 0, -1);
103 103
 			}
104
-			if($lowercase){
104
+			if ($lowercase) {
105 105
 				$str = strtolower($str);
106 106
 			}
107 107
 			return $str;
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 		 * Get the current application domain with protocol
112 112
 		 * @return string the domain name
113 113
 		 */
114
-		public static function domain(){
114
+		public static function domain() {
115 115
 			$domain = 'localhost';
116 116
 			$port = get_instance()->request->server('SERVER_PORT');
117 117
 			$protocol = 'http';
118
-			if(is_https()){
118
+			if (is_https()) {
119 119
 				$protocol = 'https';
120 120
 			}
121 121
 
@@ -127,23 +127,23 @@  discard block
 block discarded – undo
127 127
 
128 128
 			foreach ($domainserverVars as $var) {
129 129
 				$value = get_instance()->request->server($var);
130
-				if($value){
130
+				if ($value) {
131 131
 					$domain = $value;
132 132
 					break;
133 133
 				}
134 134
 			}
135 135
 			
136
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
-				$domain .= ':'.$port;
136
+			if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) {
137
+				$domain .= ':' . $port;
138 138
 			}
139
-			return $protocol.'://'.$domain;
139
+			return $protocol . '://' . $domain;
140 140
 		}
141 141
 
142 142
 		/**
143 143
 		 * Get the current request query string
144 144
 		 * @return string
145 145
 		 */
146
-		public static function queryString(){
146
+		public static function queryString() {
147 147
 			return get_instance()->request->server('QUERY_STRING');
148 148
 		}
149 149
 	}
Please login to merge, or discard this patch.
core/functions/function_user_agent.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,75 +1,75 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27 27
 
28
-	/**
29
-	 *  @file function_user_agent.php
30
-	 *    
31
-	 *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
-	 *  
33
-	 *  @package	core
34
-	 *  @author	Tony NGUEREZA
35
-	 *  @copyright	Copyright (c) 2017
36
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
-	 *  @link	http://www.iacademy.cf
38
-	 *  @version 1.0.0
39
-	 *  @since 1.0.0
40
-	 *  @filesource
41
-	 */
28
+    /**
29
+     *  @file function_user_agent.php
30
+     *    
31
+     *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
+     *  
33
+     *  @package	core
34
+     *  @author	Tony NGUEREZA
35
+     *  @copyright	Copyright (c) 2017
36
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
+     *  @link	http://www.iacademy.cf
38
+     *  @version 1.0.0
39
+     *  @since 1.0.0
40
+     *  @filesource
41
+     */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
45
-		/**
46
-		 *  Retrieves the user's IP address
47
-		 *  
48
-		 *  This function allows to retrieve the IP address of the client
49
-		 *  even if it uses a proxy, the actual IP address is retrieved.
50
-		 *  
51
-		 *  @return string the IP address.
52
-		 */
53
-		function get_ip(){
54
-			$ip = '127.0.0.1';
55
-			$ipServerVars = array(
56
-								'REMOTE_ADDR',
57
-								'HTTP_CLIENT_IP',
58
-								'HTTP_X_FORWARDED_FOR',
59
-								'HTTP_X_FORWARDED',
60
-								'HTTP_FORWARDED_FOR',
61
-								'HTTP_FORWARDED'
62
-							);
63
-			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
65
-					$ip = $_SERVER[$var];
66
-					break;
67
-				}
68
-			}
69
-			// Strip any secondary IP etc from the IP address
70
-			if (strpos($ip, ',') > 0) {
71
-				$ip = substr($ip, 0, strpos($ip, ','));
72
-			}
73
-			return $ip;
74
-		}
75
-	}
44
+    if(! function_exists('get_ip')){
45
+        /**
46
+         *  Retrieves the user's IP address
47
+         *  
48
+         *  This function allows to retrieve the IP address of the client
49
+         *  even if it uses a proxy, the actual IP address is retrieved.
50
+         *  
51
+         *  @return string the IP address.
52
+         */
53
+        function get_ip(){
54
+            $ip = '127.0.0.1';
55
+            $ipServerVars = array(
56
+                                'REMOTE_ADDR',
57
+                                'HTTP_CLIENT_IP',
58
+                                'HTTP_X_FORWARDED_FOR',
59
+                                'HTTP_X_FORWARDED',
60
+                                'HTTP_FORWARDED_FOR',
61
+                                'HTTP_FORWARDED'
62
+                            );
63
+            foreach ($ipServerVars as $var) {
64
+                if(isset($_SERVER[$var])){
65
+                    $ip = $_SERVER[$var];
66
+                    break;
67
+                }
68
+            }
69
+            // Strip any secondary IP etc from the IP address
70
+            if (strpos($ip, ',') > 0) {
71
+                $ip = substr($ip, 0, strpos($ip, ','));
72
+            }
73
+            return $ip;
74
+        }
75
+    }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
44
+	if (!function_exists('get_ip')) {
45 45
 		/**
46 46
 		 *  Retrieves the user's IP address
47 47
 		 *  
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		 *  
51 51
 		 *  @return string the IP address.
52 52
 		 */
53
-		function get_ip(){
53
+		function get_ip() {
54 54
 			$ip = '127.0.0.1';
55 55
 			$ipServerVars = array(
56 56
 								'REMOTE_ADDR',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 								'HTTP_FORWARDED'
62 62
 							);
63 63
 			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
64
+				if (isset($_SERVER[$var])) {
65 65
 					$ip = $_SERVER[$var];
66 66
 					break;
67 67
 				}
Please login to merge, or discard this patch.
core/libraries/Assets.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,168 +1,168 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file Assets.php
29
-	 *    
30
-	 *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
31
-	 *  
32
-	 *  @package	core	
33
-	 *  @author	Tony NGUEREZA
34
-	 *  @copyright	Copyright (c) 2017
35
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
-	 *  @link	http://www.iacademy.cf
37
-	 *  @version 1.0.0
38
-	 *  @since 1.0.0
39
-	 *  @filesource
40
-	 */
41
-	class Assets{
27
+    /**
28
+     *  @file Assets.php
29
+     *    
30
+     *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
31
+     *  
32
+     *  @package	core	
33
+     *  @author	Tony NGUEREZA
34
+     *  @copyright	Copyright (c) 2017
35
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
+     *  @link	http://www.iacademy.cf
37
+     *  @version 1.0.0
38
+     *  @since 1.0.0
39
+     *  @filesource
40
+     */
41
+    class Assets{
42 42
 		
43
-		/**
44
-		 * The logger instance
45
-		 * @var object
46
-		 */
47
-		private static $logger;
43
+        /**
44
+         * The logger instance
45
+         * @var object
46
+         */
47
+        private static $logger;
48 48
 
49
-		/**
50
-		 * The signleton of the logger
51
-		 * @return Object the Log instance
52
-		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
55
-				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Assets');
58
-			}
59
-			return self::$logger[0];
60
-		}
49
+        /**
50
+         * The signleton of the logger
51
+         * @return Object the Log instance
52
+         */
53
+        private static function getLogger(){
54
+            if(self::$logger == null){
55
+                //can't assign reference to static variable
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Assets');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62 62
 
63
-		/**
64
-		 *  Generate the link of the assets file.
65
-		 *  
66
-		 *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
-		 *  For example :
68
-		 *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
-		 *  Note:
70
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
-		 *  
72
-		 *  @param string $asset the name of the assets file path with the extension.
73
-		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
-		 */
75
-		public static function path($asset){
76
-			$logger = self::getLogger();	
77
-			$path = ASSETS_PATH . $asset;
63
+        /**
64
+         *  Generate the link of the assets file.
65
+         *  
66
+         *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
+         *  For example :
68
+         *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
+         *  Note:
70
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
+         *  
72
+         *  @param string $asset the name of the assets file path with the extension.
73
+         *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
+         */
75
+        public static function path($asset){
76
+            $logger = self::getLogger();	
77
+            $path = ASSETS_PATH . $asset;
78 78
 			
79
-			$logger->debug('Including the Assets file [' . $path . ']');
80
-			//Check if the file exists
81
-			if(file_exists($path)){
82
-				$logger->info('Assets file [' . $path . '] included successfully');
83
-				return Url::base_url($path);
84
-			}
85
-			$logger->warning('Assets file [' . $path . '] does not exist');
86
-			return null;
87
-		}
79
+            $logger->debug('Including the Assets file [' . $path . ']');
80
+            //Check if the file exists
81
+            if(file_exists($path)){
82
+                $logger->info('Assets file [' . $path . '] included successfully');
83
+                return Url::base_url($path);
84
+            }
85
+            $logger->warning('Assets file [' . $path . '] does not exist');
86
+            return null;
87
+        }
88 88
 		
89
-		/**
90
-		 *  Generate the link of the css file.
91
-		 *  
92
-		 *  Generates the absolute link of a file containing the CSS style.
93
-		 *  For example :
94
-		 *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
-		 *  Note:
96
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
-		 *  
98
-		 *  @param string $path the name of the css file without the extension.
99
-		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
-		 */
101
-		public static function css($path){
102
-			$logger = self::getLogger();
103
-			/*
89
+        /**
90
+         *  Generate the link of the css file.
91
+         *  
92
+         *  Generates the absolute link of a file containing the CSS style.
93
+         *  For example :
94
+         *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
+         *  Note:
96
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
+         *  
98
+         *  @param string $path the name of the css file without the extension.
99
+         *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
+         */
101
+        public static function css($path){
102
+            $logger = self::getLogger();
103
+            /*
104 104
 			* if the file name contains the ".css" extension, replace it with 
105 105
 			* an empty string for better processing.
106 106
 			*/
107
-			$path = str_ireplace('.css', '', $path);
108
-			$path = ASSETS_PATH . 'css/' . $path . '.css';
107
+            $path = str_ireplace('.css', '', $path);
108
+            $path = ASSETS_PATH . 'css/' . $path . '.css';
109 109
 			
110
-			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111
-			//Check if the file exists
112
-			if(file_exists($path)){
113
-				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114
-				return Url::base_url($path);
115
-			}
116
-			$logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
-			return null;
118
-		}
110
+            $logger->debug('Including the Assets file [' . $path . '] for CSS');
111
+            //Check if the file exists
112
+            if(file_exists($path)){
113
+                $logger->info('Assets file [' . $path . '] for CSS included successfully');
114
+                return Url::base_url($path);
115
+            }
116
+            $logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
+            return null;
118
+        }
119 119
 
120
-		/**
121
-		 *  Generate the link of the javascript file.
122
-		 *  
123
-		 *  Generates the absolute link of a file containing the javascript.
124
-		 *  For example :
125
-		 *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
-		 *  Note:
127
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
-		 *  
129
-		 *  @param string $path the name of the javascript file without the extension.
130
-		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
-		 */
132
-		public static function js($path){
133
-			$logger = self::getLogger();
134
-			$path = str_ireplace('.js', '', $path);
135
-			$path = ASSETS_PATH . 'js/' . $path . '.js';
136
-			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
138
-				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
-				return Url::base_url($path);
140
-			}
141
-			$logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
-			return null;
143
-		}
120
+        /**
121
+         *  Generate the link of the javascript file.
122
+         *  
123
+         *  Generates the absolute link of a file containing the javascript.
124
+         *  For example :
125
+         *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
+         *  Note:
127
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
+         *  
129
+         *  @param string $path the name of the javascript file without the extension.
130
+         *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
+         */
132
+        public static function js($path){
133
+            $logger = self::getLogger();
134
+            $path = str_ireplace('.js', '', $path);
135
+            $path = ASSETS_PATH . 'js/' . $path . '.js';
136
+            $logger->debug('Including the Assets file [' . $path . '] for javascript');
137
+            if(file_exists($path)){
138
+                $logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
+                return Url::base_url($path);
140
+            }
141
+            $logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
+            return null;
143
+        }
144 144
 
145
-		/**
146
-		 *  Generate the link of the image file.
147
-		 *  
148
-		 *  Generates the absolute link of a file containing the image.
149
-		 *  For example :
150
-		 *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
-		 *  Note:
152
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
-		 *  
154
-		 *  @param string $path the name of the image file with the extension.
155
-		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
-		 */
157
-		public static function img($path){
158
-			$logger = self::getLogger();
159
-			$path = ASSETS_PATH . 'images/' . $path;
160
-			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
162
-				$logger->info('Assets file [' . $path . '] for image included successfully');
163
-				return Url::base_url($path);
164
-			}
165
-			$logger->warning('Assets file [' . $path . '] for image does not exist');
166
-			return null;
167
-		}
168
-	}
145
+        /**
146
+         *  Generate the link of the image file.
147
+         *  
148
+         *  Generates the absolute link of a file containing the image.
149
+         *  For example :
150
+         *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
+         *  Note:
152
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
+         *  
154
+         *  @param string $path the name of the image file with the extension.
155
+         *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
+         */
157
+        public static function img($path){
158
+            $logger = self::getLogger();
159
+            $path = ASSETS_PATH . 'images/' . $path;
160
+            $logger->debug('Including the Assets file [' . $path . '] for image');
161
+            if(file_exists($path)){
162
+                $logger->info('Assets file [' . $path . '] for image included successfully');
163
+                return Url::base_url($path);
164
+            }
165
+            $logger->warning('Assets file [' . $path . '] for image does not exist');
166
+            return null;
167
+        }
168
+    }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *  @since 1.0.0
39 39
 	 *  @filesource
40 40
 	 */
41
-	class Assets{
41
+	class Assets {
42 42
 		
43 43
 		/**
44 44
 		 * The logger instance
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		 * The signleton of the logger
51 51
 		 * @return Object the Log instance
52 52
 		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
53
+		private static function getLogger() {
54
+			if (self::$logger == null) {
55 55
 				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Assets');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 		 *  @param string $asset the name of the assets file path with the extension.
73 73
 		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74 74
 		 */
75
-		public static function path($asset){
75
+		public static function path($asset) {
76 76
 			$logger = self::getLogger();	
77 77
 			$path = ASSETS_PATH . $asset;
78 78
 			
79 79
 			$logger->debug('Including the Assets file [' . $path . ']');
80 80
 			//Check if the file exists
81
-			if(file_exists($path)){
81
+			if (file_exists($path)) {
82 82
 				$logger->info('Assets file [' . $path . '] included successfully');
83 83
 				return Url::base_url($path);
84 84
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 *  @param string $path the name of the css file without the extension.
99 99
 		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100 100
 		 */
101
-		public static function css($path){
101
+		public static function css($path) {
102 102
 			$logger = self::getLogger();
103 103
 			/*
104 104
 			* if the file name contains the ".css" extension, replace it with 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			
110 110
 			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111 111
 			//Check if the file exists
112
-			if(file_exists($path)){
112
+			if (file_exists($path)) {
113 113
 				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114 114
 				return Url::base_url($path);
115 115
 			}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		 *  @param string $path the name of the javascript file without the extension.
130 130
 		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131 131
 		 */
132
-		public static function js($path){
132
+		public static function js($path) {
133 133
 			$logger = self::getLogger();
134 134
 			$path = str_ireplace('.js', '', $path);
135 135
 			$path = ASSETS_PATH . 'js/' . $path . '.js';
136 136
 			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
137
+			if (file_exists($path)) {
138 138
 				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139 139
 				return Url::base_url($path);
140 140
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		 *  @param string $path the name of the image file with the extension.
155 155
 		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156 156
 		 */
157
-		public static function img($path){
157
+		public static function img($path) {
158 158
 			$logger = self::getLogger();
159 159
 			$path = ASSETS_PATH . 'images/' . $path;
160 160
 			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
161
+			if (file_exists($path)) {
162 162
 				$logger->info('Assets file [' . $path . '] for image included successfully');
163 163
 				return Url::base_url($path);
164 164
 			}
Please login to merge, or discard this patch.
core/classes/Config.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -128,8 +128,7 @@  discard block
 block discarded – undo
128 128
 				$logger->info('Delete config item ['.$item.']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131
-			}
132
-			else{
131
+			} else{
133 132
 				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134 133
 				return false;
135 134
 			}
@@ -179,8 +178,7 @@  discard block
 block discarded – undo
179 178
 																		0, 
180 179
 																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
181 180
 																	);
182
-				}
183
-				else{
181
+				} else{
184 182
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
185 183
 					$baseUrl = 'http://localhost/';
186 184
 				}
Please login to merge, or discard this patch.
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -1,190 +1,190 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Config{
27
+    class Config{
28 28
 		
29
-		/**
30
-		 * The list of loaded configuration
31
-		 * @var array
32
-		 */
33
-		private static $config = array();
29
+        /**
30
+         * The list of loaded configuration
31
+         * @var array
32
+         */
33
+        private static $config = array();
34 34
 
35
-		/**
36
-		 * The logger instance
37
-		 * @var object
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var object
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		public static function getLogger(){
46
-			if(self::$logger == null){
47
-				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
49
-				$logger[0]->setLogger('Library::Config');
50
-				self::$logger = $logger[0];
51
-			}
52
-			return self::$logger;			
53
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        public static function getLogger(){
46
+            if(self::$logger == null){
47
+                $logger = array();
48
+                $logger[0] =& class_loader('Log', 'classes');
49
+                $logger[0]->setLogger('Library::Config');
50
+                self::$logger = $logger[0];
51
+            }
52
+            return self::$logger;			
53
+        }
54 54
 
55
-		/**
56
-		 * Set the log instance for future use
57
-		 * @param object $logger the log object
58
-		 * @return object the log instance
59
-		 */
60
-		public static function setLogger($logger){
61
-			self::$logger = $logger;
62
-			return self::$logger;
63
-		}
55
+        /**
56
+         * Set the log instance for future use
57
+         * @param object $logger the log object
58
+         * @return object the log instance
59
+         */
60
+        public static function setLogger($logger){
61
+            self::$logger = $logger;
62
+            return self::$logger;
63
+        }
64 64
 
65
-		/**
66
-		 * Initialize the configuration by loading all the configuration from config file
67
-		 */
68
-		public static function init(){
69
-			$logger = static::getLogger();
70
-			$logger->debug('Initialization of the configuration');
71
-			self::$config = & load_configurations();
72
-			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
-				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
-			}
76
-			$logger->info('Configuration initialized successfully');
77
-			$logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
-		}
65
+        /**
66
+         * Initialize the configuration by loading all the configuration from config file
67
+         */
68
+        public static function init(){
69
+            $logger = static::getLogger();
70
+            $logger->debug('Initialization of the configuration');
71
+            self::$config = & load_configurations();
72
+            self::setBaseUrlUsingServerVar();
73
+            if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
+                $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
+            }
76
+            $logger->info('Configuration initialized successfully');
77
+            $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
+        }
79 79
 
80
-		/**
81
-		 * Get the configuration item value
82
-		 * @param  string $item    the configuration item name to get
83
-		 * @param  mixed $default the default value to use if can not find the config item in the list
84
-		 * @return mixed          the config value if exist or the default value
85
-		 */
86
-		public static function get($item, $default = null){
87
-			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
89
-				return self::$config[$item];
90
-			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
-			return $default;
93
-		}
80
+        /**
81
+         * Get the configuration item value
82
+         * @param  string $item    the configuration item name to get
83
+         * @param  mixed $default the default value to use if can not find the config item in the list
84
+         * @return mixed          the config value if exist or the default value
85
+         */
86
+        public static function get($item, $default = null){
87
+            $logger = static::getLogger();
88
+            if(array_key_exists($item, self::$config)){
89
+                return self::$config[$item];
90
+            }
91
+            $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
+            return $default;
93
+        }
94 94
 
95
-		/**
96
-		 * Set the configuration item value
97
-		 * @param string $item  the config item name to set
98
-		 * @param mixed $value the config item value
99
-		 */
100
-		public static function set($item, $value){
101
-			self::$config[$item] = $value;
102
-		}
95
+        /**
96
+         * Set the configuration item value
97
+         * @param string $item  the config item name to set
98
+         * @param mixed $value the config item value
99
+         */
100
+        public static function set($item, $value){
101
+            self::$config[$item] = $value;
102
+        }
103 103
 
104
-		/**
105
-		 * Get all the configuration values
106
-		 * @return array the config values
107
-		 */
108
-		public static function getAll(){
109
-			return self::$config;
110
-		}
104
+        /**
105
+         * Get all the configuration values
106
+         * @return array the config values
107
+         */
108
+        public static function getAll(){
109
+            return self::$config;
110
+        }
111 111
 
112
-		/**
113
-		 * Set the configuration values bu merged with the existing configuration
114
-		 * @param array $config the config values to add in the configuration list
115
-		 */
116
-		public static function setAll(array $config = array()){
117
-			self::$config = array_merge(self::$config, $config);
118
-		}
112
+        /**
113
+         * Set the configuration values bu merged with the existing configuration
114
+         * @param array $config the config values to add in the configuration list
115
+         */
116
+        public static function setAll(array $config = array()){
117
+            self::$config = array_merge(self::$config, $config);
118
+        }
119 119
 
120
-		/**
121
-		 * Delete the configuration item in the list
122
-		 * @param  string $item the config item name to be deleted
123
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
-		 */
125
-		public static function delete($item){
126
-			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
129
-				unset(self::$config[$item]);
130
-				return true;
131
-			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
-				return false;
135
-			}
136
-		}
120
+        /**
121
+         * Delete the configuration item in the list
122
+         * @param  string $item the config item name to be deleted
123
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
+         */
125
+        public static function delete($item){
126
+            $logger = static::getLogger();
127
+            if(array_key_exists($item, self::$config)){
128
+                $logger->info('Delete config item ['.$item.']');
129
+                unset(self::$config[$item]);
130
+                return true;
131
+            }
132
+            else{
133
+                $logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
+                return false;
135
+            }
136
+        }
137 137
 
138
-		/**
139
-		 * Load the configuration file. This an alias to Loader::config()
140
-		 * @param  string $config the config name to be loaded
141
-		 */
142
-		public static function load($config){
143
-			Loader::config($config);
144
-		}
138
+        /**
139
+         * Load the configuration file. This an alias to Loader::config()
140
+         * @param  string $config the config name to be loaded
141
+         */
142
+        public static function load($config){
143
+            Loader::config($config);
144
+        }
145 145
 
146
-		/**
147
-		 * Set the configuration for "base_url" if is not set in the configuration
148
-		 */
149
-		private static function setBaseUrlUsingServerVar(){
150
-			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
153
-					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
-				}
155
-				$baseUrl = null;
156
-				$protocol = 'http';
157
-				if(is_https()){
158
-					$protocol = 'https';
159
-				}
160
-				$protocol .='://';
146
+        /**
147
+         * Set the configuration for "base_url" if is not set in the configuration
148
+         */
149
+        private static function setBaseUrlUsingServerVar(){
150
+            $logger = static::getLogger();
151
+            if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
+                if(ENVIRONMENT == 'production'){
153
+                    $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
+                }
155
+                $baseUrl = null;
156
+                $protocol = 'http';
157
+                if(is_https()){
158
+                    $protocol = 'https';
159
+                }
160
+                $protocol .='://';
161 161
 
162
-				if (isset($_SERVER['SERVER_ADDR'])){
163
-					$baseUrl = $_SERVER['SERVER_ADDR'];
164
-					//check if the server is running under IPv6
165
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
166
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
167
-					}
168
-					$serverPort = 80;
169
-					if (isset($_SERVER['SERVER_PORT'])) {
170
-						$serverPort = $_SERVER['SERVER_PORT'];
171
-					}
172
-					$port = '';
173
-					if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
174
-						$port = ':'.$serverPort;
175
-					}
176
-					$baseUrl = $protocol . $baseUrl . $port . substr(
177
-																		$_SERVER['SCRIPT_NAME'], 
178
-																		0, 
179
-																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
180
-																	);
181
-				}
182
-				else{
183
-					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
184
-					$baseUrl = 'http://localhost/';
185
-				}
186
-				self::set('base_url', $baseUrl);
187
-			}
188
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
189
-		}
190
-	}
162
+                if (isset($_SERVER['SERVER_ADDR'])){
163
+                    $baseUrl = $_SERVER['SERVER_ADDR'];
164
+                    //check if the server is running under IPv6
165
+                    if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
166
+                        $baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
167
+                    }
168
+                    $serverPort = 80;
169
+                    if (isset($_SERVER['SERVER_PORT'])) {
170
+                        $serverPort = $_SERVER['SERVER_PORT'];
171
+                    }
172
+                    $port = '';
173
+                    if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
174
+                        $port = ':'.$serverPort;
175
+                    }
176
+                    $baseUrl = $protocol . $baseUrl . $port . substr(
177
+                                                                        $_SERVER['SCRIPT_NAME'], 
178
+                                                                        0, 
179
+                                                                        strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
180
+                                                                    );
181
+                }
182
+                else{
183
+                    $logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
184
+                    $baseUrl = 'http://localhost/';
185
+                }
186
+                self::set('base_url', $baseUrl);
187
+            }
188
+            self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
189
+        }
190
+    }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		public static function getLogger(){
46
-			if(self::$logger == null){
45
+		public static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param object $logger the log object
58 58
 		 * @return object the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,39 +139,39 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156 156
 				$protocol = 'http';
157
-				if(is_https()){
157
+				if (is_https()) {
158 158
 					$protocol = 'https';
159 159
 				}
160
-				$protocol .='://';
160
+				$protocol .= '://';
161 161
 
162
-				if (isset($_SERVER['SERVER_ADDR'])){
162
+				if (isset($_SERVER['SERVER_ADDR'])) {
163 163
 					$baseUrl = $_SERVER['SERVER_ADDR'];
164 164
 					//check if the server is running under IPv6
165
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
166
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
165
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
166
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
167 167
 					}
168 168
 					$serverPort = 80;
169 169
 					if (isset($_SERVER['SERVER_PORT'])) {
170 170
 						$serverPort = $_SERVER['SERVER_PORT'];
171 171
 					}
172 172
 					$port = '';
173
-					if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
174
-						$port = ':'.$serverPort;
173
+					if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) {
174
+						$port = ':' . $serverPort;
175 175
 					}
176 176
 					$baseUrl = $protocol . $baseUrl . $port . substr(
177 177
 																		$_SERVER['SCRIPT_NAME'], 
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
180 180
 																	);
181 181
 				}
182
-				else{
182
+				else {
183 183
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
184 184
 					$baseUrl = 'http://localhost/';
185 185
 				}
186 186
 				self::set('base_url', $baseUrl);
187 187
 			}
188
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
188
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
189 189
 		}
190 190
 	}
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 3 patches
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -234,8 +234,7 @@  discard block
 block discarded – undo
234 234
                 //first check for CSRF
235 235
                 if (get_config('csrf_enable', false) && ! Security::validateCSRF()){
236 236
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
237
-                }
238
-                else{
237
+                } else{
239 238
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
240 239
                 }
241 240
             }
@@ -255,8 +254,7 @@  discard block
 block discarded – undo
255 254
             foreach ($this->getData() as $inputName => $inputVal) {
256 255
     			if(is_array($this->data[$inputName])){
257 256
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
258
-    			}
259
-    			else{
257
+    			} else{
260 258
     				$this->data[$inputName] = trim($this->data[$inputName]);
261 259
     			}
262 260
 
@@ -624,8 +622,7 @@  discard block
 block discarded – undo
624 622
                 if ($inputVal == '' && $callbackReturn == true) {
625 623
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
626 624
                 }
627
-            } 
628
-			else if($inputVal == '') {
625
+            } else if($inputVal == '') {
629 626
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
630 627
             }
631 628
         }
@@ -684,8 +681,7 @@  discard block
 block discarded – undo
684 681
                         $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual))));
685 682
                         continue;
686 683
                     }
687
-                } 
688
-				else{
684
+                } else{
689 685
                     if ($inputVal == $doNotEqual) {
690 686
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
691 687
                         continue;
Please login to merge, or discard this patch.
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
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
-     class FormValidation{
28
+        class FormValidation{
29 29
 		 
30 30
         /**
31 31
          * The form validation status
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
          */
61 61
         protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
62 62
         
63
-		/**
63
+        /**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             $this->logger =& class_loader('Log', 'classes');
101 101
             $this->logger->setLogger('Library::FormValidation');
102 102
            
103
-		   //Load form validation language message
103
+            //Load form validation language message
104 104
             Loader::lang('form_validation');
105 105
             $obj = & get_instance();
106 106
             $this->_errorsMessages  = array(
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
         /**
163 163
          * Set the form validation data
164 164
          * @param array $data the values to be validated
165
-		 *
165
+         *
166 166
          * @return FormValidation Current instance of object.
167 167
          */
168 168
         public function setData(array $data){
169 169
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
170 170
             $this->data = $data;
171
-			return $this;
171
+            return $this;
172 172
         }
173 173
 
174 174
         /**
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
             return $this->data;
180 180
         }
181 181
 
182
-		/**
183
-		* Get the validation function name to validate a rule
184
-		*
185
-		* @return string the function name
186
-		*/
182
+        /**
183
+         * Get the validation function name to validate a rule
184
+         *
185
+         * @return string the function name
186
+         */
187 187
         protected function _toCallCase($funcName, $prefix='_validate') {
188 188
             $funcName = strtolower($funcName);
189 189
             $finalFuncName = $prefix;
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
             $this->_forceFail = false;
254 254
 
255 255
             foreach ($this->getData() as $inputName => $inputVal) {
256
-    			if(is_array($this->data[$inputName])){
257
-    				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
258
-    			}
259
-    			else{
260
-    				$this->data[$inputName] = trim($this->data[$inputName]);
261
-    			}
256
+                if(is_array($this->data[$inputName])){
257
+                    $this->data[$inputName] = array_map('trim', $this->data[$inputName]);
258
+                }
259
+                else{
260
+                    $this->data[$inputName] = trim($this->data[$inputName]);
261
+                }
262 262
 
263 263
                 if (array_key_exists($inputName, $this->_rules)) {
264 264
                     foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
          *
275 275
          * @param string $inputField Name of the field or the data key to add a rule to
276 276
          * @param string $ruleSets PIPE seperated string of rules
277
-		 *
277
+         *
278 278
          * @return FormValidation Current instance of object.
279 279
          */
280 280
         public function setRule($inputField, $inputLabel, $ruleSets) {
@@ -288,8 +288,8 @@  discard block
 block discarded – undo
288 288
          * Takes an array of rules and uses setRule() to set them, accepts an array
289 289
          * of rule names rather than a pipe-delimited string as well.
290 290
          * @param array $ruleSets
291
-		 *
292
-		 * @return FormValidation Current instance of object.
291
+         *
292
+         * @return FormValidation Current instance of object.
293 293
          */
294 294
         public function setRules(array $ruleSets) {
295 295
             foreach ($ruleSets as $ruleSet) {
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
          * @param string $start Before block of errors gets displayed, HTML allowed.
312 312
          * @param string $end After the block of errors gets displayed, HTML allowed.
313 313
          *
314
-		 * @return FormValidation Current instance of object.
314
+         * @return FormValidation Current instance of object.
315 315
          */
316 316
         public function setErrorsDelimiter($start, $end) {
317 317
             $this->_allErrorsDelimiter[0] = $start;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
          * @param string $start Displayed before each error.
327 327
          * @param string $end Displayed after each error.
328 328
          * 
329
-		 * @return FormValidation Current instance of object.
329
+         * @return FormValidation Current instance of object.
330 330
          */
331 331
         public function setErrorDelimiter($start, $end) {
332 332
             $this->_eachErrorDelimiter[0] = $start;
@@ -334,21 +334,21 @@  discard block
 block discarded – undo
334 334
             return $this;
335 335
         }
336 336
 
337
-		/**
338
-		* Get the each errors delimiters
339
-		*
340
-		* @return array
341
-		*/
342
-    	public function getErrorDelimiter() {
337
+        /**
338
+         * Get the each errors delimiters
339
+         *
340
+         * @return array
341
+         */
342
+        public function getErrorDelimiter() {
343 343
             return $this->_eachErrorDelimiter;
344 344
         }
345 345
 
346
-		/**
347
-		* Get the all errors delimiters
348
-		*
349
-		* @return array
350
-		*/
351
-    	public function getErrorsDelimiter() {
346
+        /**
347
+         * Get the all errors delimiters
348
+         *
349
+         * @return array
350
+         */
351
+        public function getErrorsDelimiter() {
352 352
             return $this->_allErrorsDelimiter;
353 353
         }
354 354
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
          *
387 387
          * @param string $inputName The form input name or data key
388 388
          * @param string $errorMessage Error to display
389
-		 *
389
+         *
390 390
          * @return formValidation Current instance of the object
391 391
          */
392 392
         public function setCustomError($inputName, $errorMessage) {
@@ -423,17 +423,17 @@  discard block
 block discarded – undo
423 423
          *
424 424
          * @param boolean $limit number of error to display or return
425 425
          * @param boolean $echo Whether or not the values are to be returned or displayed
426
-		 *
426
+         *
427 427
          * @return string Errors formatted for output
428 428
          */
429 429
         public function displayErrors($limit = null, $echo = true) {
430 430
             list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter;
431 431
             list($errorStart, $errorEnd) = $this->_eachErrorDelimiter;
432 432
             $errorOutput = $errorsStart;
433
-    		$i = 0;
433
+            $i = 0;
434 434
             if (!empty($this->_errors)) {
435 435
                 foreach ($this->_errors as $fieldName => $error) {
436
-        	    	if ($i === $limit) { 
436
+                    if ($i === $limit) { 
437 437
                         break; 
438 438
                     }
439 439
                     $errorOutput .= $errorStart;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
          * Breaks up a PIPE seperated string of rules, and puts them into an array.
462 462
          *
463 463
          * @param string $ruleString String to be parsed.
464
-		 *
464
+         *
465 465
          * @return array Array of each value in original string.
466 466
          */
467 467
         protected function _parseRuleString($ruleString) {
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
475 475
                 preg_match($rule, $ruleString, $regexRule);
476 476
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
477
-                 if(!empty($regexRule[0])){
478
-                     $ruleSets[] = $regexRule[0];
479
-                 }
480
-                 $ruleStringRegex = explode('|', $ruleStringTemp);
477
+                    if(!empty($regexRule[0])){
478
+                        $ruleSets[] = $regexRule[0];
479
+                    }
480
+                    $ruleStringRegex = explode('|', $ruleStringTemp);
481 481
                 foreach ($ruleStringRegex as $rule) {
482 482
                     $rule = trim($rule);
483 483
                     if($rule){
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
                 } else {
494 494
                     $ruleSets[] = $ruleString;
495 495
                 }
496
-             }
496
+                }
497 497
             return $ruleSets;
498 498
         }
499 499
 
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
          * Returns whether or not a field obtains the rule "required".
502 502
          *
503 503
          * @param string $fieldName Field to check if required.
504
-		 *
504
+         *
505 505
          * @return boolean Whether or not the field is required.
506 506
          */
507 507
         protected function _fieldIsRequired($fieldName) {
@@ -536,13 +536,13 @@  discard block
 block discarded – undo
536 536
             return;
537 537
         }
538 538
 
539
-		/**
540
-		* Set error for the given field or key
541
-		*
542
-		* @param string $inputName the input or key name
543
-		* @param string $ruleName the rule name
544
-		* @param array|string $replacements
545
-		*/
539
+        /**
540
+         * Set error for the given field or key
541
+         *
542
+         * @param string $inputName the input or key name
543
+         * @param string $ruleName the rule name
544
+         * @param array|string $replacements
545
+         */
546 546
         protected function _setError($inputName, $ruleName, $replacements = array()) {
547 547
             $rulePhraseKeyParts = explode(',', $ruleName);
548 548
             $rulePhrase = null;
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
             }
560 560
             // Type cast to array in case it's a string
561 561
             $replacements = (array) $replacements;
562
-			$replacementCount = count($replacements);
562
+            $replacementCount = count($replacements);
563 563
             for ($i = 1; $i <= $replacementCount; $i++) {
564 564
                 $key = $i - 1;
565 565
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
@@ -577,11 +577,11 @@  discard block
 block discarded – undo
577 577
          *
578 578
          * @param type $inputArg
579 579
          * @param string $callbackFunc
580
-		 *
580
+         *
581 581
          * @return mixed
582 582
          */
583 583
         protected function _runCallback($inputArg, $callbackFunc) {
584
-			return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
584
+            return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
585 585
         }
586 586
 
587 587
         /**
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
          * arguments.
591 591
          *
592 592
          * @param string $callbackFunc
593
-		 *
593
+         *
594 594
          * @return mixed
595 595
          */
596 596
         protected function _runEmptyCallback($callbackFunc) {
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
          * Gets a specific label of a specific field input name.
602 602
          *
603 603
          * @param string $inputName
604
-		 *
604
+         *
605 605
          * @return string
606 606
          */
607 607
         protected function _getLabel($inputName) {
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
          * @param  string $ruleName  the rule name for this validation ("required")
615 615
          * @param  array  $ruleArgs  the rules argument
616 616
          */
617
-		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
617
+        protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
618 618
             $inputVal = $this->post($inputName);
619 619
             if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
620 620
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
@@ -622,8 +622,8 @@  discard block
 block discarded – undo
622 622
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
623 623
                 }
624 624
             } 
625
-			else if($inputVal == '') {
626
-				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
625
+            else if($inputVal == '') {
626
+                $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
627 627
             }
628 628
         }
629 629
 
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
          */
648 648
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
649 649
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
650
-				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
651
-				if(! $result){
652
-					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
653
-				}
650
+                $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
651
+                if(! $result){
652
+                    $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
653
+                }
654 654
             }
655 655
         }
656 656
 
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                         continue;
683 683
                     }
684 684
                 } 
685
-				else{
685
+                else{
686 686
                     if ($inputVal == $doNotEqual) {
687 687
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
688 688
                         continue;
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
          * @param  string $ruleName  the rule name for this validation ("less_than")
775 775
          * @param  array  $ruleArgs  the rules argument
776 776
          */
777
-    	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
777
+        protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
778 778
             $inputVal = $this->post($inputName);
779 779
             if ($inputVal >= $ruleArgs[1]) { 
780 780
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
          * @param  string $ruleName  the rule name for this validation ("greater_than")
791 791
          * @param  array  $ruleArgs  the rules argument
792 792
          */
793
-    	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
793
+        protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
794 794
             $inputVal = $this->post($inputName);
795 795
             if ($inputVal <= $ruleArgs[1]) {
796 796
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
          * @param  string $ruleName  the rule name for this validation ("numeric")
807 807
          * @param  array  $ruleArgs  the rules argument
808 808
          */
809
-    	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
809
+        protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
810 810
             $inputVal = $this->post($inputName);
811 811
             if (! is_numeric($inputVal)) {
812 812
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -822,18 +822,18 @@  discard block
 block discarded – undo
822 822
          * @param  string $ruleName  the rule name for this validation ("exists")
823 823
          * @param  array  $ruleArgs  the rules argument
824 824
          */
825
-		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
825
+        protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
826 826
             $inputVal = $this->post($inputName);
827
-    		if (! is_object($this->databaseInstance)){
827
+            if (! is_object($this->databaseInstance)){
828 828
                 $obj = & get_instance();
829 829
                 if(isset($obj->database)){
830 830
                     $this->databaseInstance = $obj->database;
831 831
                 } 
832 832
             }
833
-    		list($table, $column) = explode('.', $ruleArgs[1]);
834
-    		$this->databaseInstance->getQueryBuilder()->from($table)
835
-    			                                       ->where($column, $inputVal);
836
-    		$this->databaseInstance->get();
833
+            list($table, $column) = explode('.', $ruleArgs[1]);
834
+            $this->databaseInstance->getQueryBuilder()->from($table)
835
+                                                        ->where($column, $inputVal);
836
+            $this->databaseInstance->get();
837 837
             if ($this->databaseInstance->numRows() <= 0) {
838 838
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
839 839
                     return;
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
          * @param  string $ruleName  the rule name for this validation ("is_unique")
849 849
          * @param  array  $ruleArgs  the rules argument
850 850
          */
851
-    	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
851
+        protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
852 852
             $inputVal = $this->post($inputName);
853 853
             if (! is_object($this->databaseInstance)){
854 854
                 $obj = & get_instance();
@@ -856,11 +856,11 @@  discard block
 block discarded – undo
856 856
                     $this->databaseInstance = $obj->database;
857 857
                 } 
858 858
             }
859
-    		list($table, $column) = explode('.', $ruleArgs[1]);
860
-    		$this->databaseInstance->getQueryBuilder()->from($table)
861
-    			                                      ->where($column, $inputVal);
862
-    		$this->databaseInstance->get();
863
-    		if ($this->databaseInstance->numRows() > 0) {
859
+            list($table, $column) = explode('.', $ruleArgs[1]);
860
+            $this->databaseInstance->getQueryBuilder()->from($table)
861
+                                                        ->where($column, $inputVal);
862
+            $this->databaseInstance->get();
863
+            if ($this->databaseInstance->numRows() > 0) {
864 864
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
865 865
                     return;
866 866
                 }
@@ -874,25 +874,25 @@  discard block
 block discarded – undo
874 874
          * @param  string $ruleName  the rule name for this validation ("is_unique_update")
875 875
          * @param  array  $ruleArgs  the rules argument
876 876
          */
877
-    	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
877
+        protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
878 878
             $inputVal = $this->post($inputName);
879
-    		if (! is_object($this->databaseInstance)){
879
+            if (! is_object($this->databaseInstance)){
880 880
                 $obj = & get_instance();
881 881
                 if(isset($obj->database)){
882 882
                     $this->databaseInstance = $obj->database;
883 883
                 } 
884 884
             }
885
-    		$data = explode(',', $ruleArgs[1]);
886
-    		if(count($data) < 2){
887
-    			return;
888
-    		}
889
-    		list($table, $column) = explode('.', $data[0]);
890
-    		list($field, $val)    = explode('=', $data[1]);
891
-    		$this->databaseInstance->getQueryBuilder()->from($table)
892
-                                			          ->where($column, $inputVal)
893
-                                            		  ->where($field, '!=', trim($val));
885
+            $data = explode(',', $ruleArgs[1]);
886
+            if(count($data) < 2){
887
+                return;
888
+            }
889
+            list($table, $column) = explode('.', $data[0]);
890
+            list($field, $val)    = explode('=', $data[1]);
891
+            $this->databaseInstance->getQueryBuilder()->from($table)
892
+                                                        ->where($column, $inputVal)
893
+                                                        ->where($field, '!=', trim($val));
894 894
             $this->databaseInstance->get();
895
-    		if ($this->databaseInstance->numRows() > 0) {
895
+            if ($this->databaseInstance->numRows() > 0) {
896 896
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
897 897
                     return;
898 898
                 }
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
          */
909 909
         protected function _validateInList($inputName, $ruleName, array $ruleArgs) {
910 910
             $inputVal = $this->post($inputName);
911
-    		$list = explode(',', $ruleArgs[1]);
911
+            $list = explode(',', $ruleArgs[1]);
912 912
             $list = array_map('trim', $list);
913 913
             if (! in_array($inputVal, $list)) {
914 914
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
          */
927 927
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
928 928
             $inputVal = $this->post($inputName);
929
-    		$regex = $ruleArgs[1];
929
+            $regex = $ruleArgs[1];
930 930
             if (! preg_match($regex, $inputVal)) {
931 931
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
932 932
                     return;
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+     class FormValidation {
29 29
 		 
30 30
         /**
31 31
          * The form validation status
32 32
          * @var boolean
33 33
          */
34
-        protected $_success  = false;
34
+        protected $_success = false;
35 35
 
36 36
         /**
37 37
          * The list of errors messages
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
         protected $_errorsMessages = array();
41 41
         
42 42
         // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
43
+        protected $_rules = array();
44 44
         
45 45
         // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
46
+        protected $_errors = array();
47 47
         
48 48
         // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
49
+        protected $_labels = array();
50 50
         
51 51
         /**
52 52
          * The errors delimiters
53 53
          * @var array
54 54
          */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
55
+        protected $_allErrorsDelimiter = array('<div class="error">', '</div>');
56 56
 
57 57
         /**
58 58
          * The each error delimiter
59 59
          * @var array
60 60
          */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
61
+        protected $_eachErrorDelimiter = array('<p class="error">', '</p>');
62 62
         
63 63
 		/**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
67
-        protected $_forceFail            = false;
67
+        protected $_forceFail = false;
68 68
 
69 69
         /**
70 70
          * The list of the error messages overrides by the original
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
          * @return void
98 98
          */
99 99
         public function __construct() {
100
-            $this->logger =& class_loader('Log', 'classes');
100
+            $this->logger = & class_loader('Log', 'classes');
101 101
             $this->logger->setLogger('Library::FormValidation');
102 102
            
103 103
 		   //Load form validation language message
104 104
             Loader::lang('form_validation');
105 105
             $obj = & get_instance();
106
-            $this->_errorsMessages  = array(
106
+            $this->_errorsMessages = array(
107 107
                         'required'         => $obj->lang->get('fv_required'),
108 108
                         'min_length'       => $obj->lang->get('fv_min_length'),
109 109
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
          * Set the database instance
134 134
          * @param object $database the database instance
135 135
          */
136
-        public function setDatabase(Database $database){
136
+        public function setDatabase(Database $database) {
137 137
             $this->databaseInstance = $database;
138 138
             return $this;
139 139
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
          * Get the database instance
143 143
          * @return object the database instance
144 144
          */
145
-        public function getDatabase(){
145
+        public function getDatabase() {
146 146
             return $this->databaseInstance;
147 147
         }
148 148
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		 *
166 166
          * @return FormValidation Current instance of object.
167 167
          */
168
-        public function setData(array $data){
168
+        public function setData(array $data) {
169 169
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
170 170
             $this->data = $data;
171 171
 			return $this;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
          * Get the form validation data
176 176
          * @return array the form validation data to be validated
177 177
          */
178
-        public function getData(){
178
+        public function getData() {
179 179
             return $this->data;
180 180
         }
181 181
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		*
185 185
 		* @return string the function name
186 186
 		*/
187
-        protected function _toCallCase($funcName, $prefix='_validate') {
187
+        protected function _toCallCase($funcName, $prefix = '_validate') {
188 188
             $funcName = strtolower($funcName);
189 189
             $finalFuncName = $prefix;
190 190
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
209 209
          */
210 210
         public function canDoValidation() {
211
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
211
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
212 212
         }
213 213
 
214 214
         /**
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
          * Validate the CSRF 
229 229
          * @return void 
230 230
          */
231
-        protected function validateCSRF(){
232
-            if(get_instance()->request->method() == 'POST'){
231
+        protected function validateCSRF() {
232
+            if (get_instance()->request->method() == 'POST') {
233 233
                 $this->logger->debug('Check if CSRF is enabled in configuration');
234 234
                 //first check for CSRF
235
-                if (get_config('csrf_enable', false) && ! Security::validateCSRF()){
235
+                if (get_config('csrf_enable', false) && !Security::validateCSRF()) {
236 236
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
237 237
                 }
238
-                else{
238
+                else {
239 239
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
240 240
                 }
241 241
             }
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
             $this->_forceFail = false;
254 254
 
255 255
             foreach ($this->getData() as $inputName => $inputVal) {
256
-    			if(is_array($this->data[$inputName])){
256
+    			if (is_array($this->data[$inputName])) {
257 257
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
258 258
     			}
259
-    			else{
259
+    			else {
260 260
     				$this->data[$inputName] = trim($this->data[$inputName]);
261 261
     			}
262 262
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                     }
267 267
                 }
268 268
             }
269
-            $this->_success =  empty($this->_errors) && $this->_forceFail === false;
269
+            $this->_success = empty($this->_errors) && $this->_forceFail === false;
270 270
         }
271 271
 
272 272
         /**
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         public function setRule($inputField, $inputLabel, $ruleSets) {
281 281
             $this->_rules[$inputField] = $ruleSets;
282 282
             $this->_labels[$inputField] = $inputLabel;
283
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
283
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
284 284
             return $this;
285 285
         }
286 286
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
             }
445 445
             $errorOutput .= $errorsEnd;
446 446
             echo ($echo) ? $errorOutput : '';
447
-            return (! $echo) ? $errorOutput : null;
447
+            return (!$echo) ? $errorOutput : null;
448 448
         }
449 449
 
450 450
         /**
@@ -469,25 +469,25 @@  discard block
 block discarded – undo
469 469
             /*
470 470
             //////////////// hack for regex rule that can contain "|"
471 471
             */
472
-            if(strpos($ruleString, 'regex') !== false){
472
+            if (strpos($ruleString, 'regex') !== false) {
473 473
                 $regexRule = array();
474 474
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
475 475
                 preg_match($rule, $ruleString, $regexRule);
476 476
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
477
-                 if(!empty($regexRule[0])){
477
+                 if (!empty($regexRule[0])) {
478 478
                      $ruleSets[] = $regexRule[0];
479 479
                  }
480 480
                  $ruleStringRegex = explode('|', $ruleStringTemp);
481 481
                 foreach ($ruleStringRegex as $rule) {
482 482
                     $rule = trim($rule);
483
-                    if($rule){
483
+                    if ($rule) {
484 484
                         $ruleSets[] = $rule;
485 485
                     }
486 486
                 }
487 487
                  
488 488
             }
489 489
             /***********************************/
490
-            else{
490
+            else {
491 491
                 if (strpos($ruleString, '|') !== FALSE) {
492 492
                     $ruleSets = explode('|', $ruleString);
493 493
                 } else {
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
          * @return void
520 520
          */
521 521
         protected function _validateRule($inputName, $inputVal, $ruleName) {
522
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
522
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
523 523
             // Array to store args
524 524
             $ruleArgs = array();
525 525
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                 $key = $i - 1;
565 565
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
566 566
             }
567
-            if (! array_key_exists($inputName, $this->_errors)) {
567
+            if (!array_key_exists($inputName, $this->_errors)) {
568 568
                 $this->_errors[$inputName] = $rulePhrase;
569 569
             }
570 570
         }
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
          */
617 617
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
618 618
             $inputVal = $this->post($inputName);
619
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
619
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
620 620
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
621 621
                 if ($inputVal == '' && $callbackReturn == true) {
622 622
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
623 623
                 }
624 624
             } 
625
-			else if($inputVal == '') {
625
+			else if ($inputVal == '') {
626 626
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
627 627
             }
628 628
         }
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
649 649
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
650 650
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
651
-				if(! $result){
651
+				if (!$result) {
652 652
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
653 653
 				}
654 654
             }
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                         continue;
683 683
                     }
684 684
                 } 
685
-				else{
685
+				else {
686 686
                     if ($inputVal == $doNotEqual) {
687 687
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
688 688
                         continue;
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
          */
713 713
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
714 714
             $inputVal = $this->post($inputName);
715
-            if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
716
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
715
+            if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
716
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
717 717
                     return;
718 718
                 }
719 719
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
730 730
             $inputVal = $this->post($inputName);
731 731
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
732
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
732
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
733 733
                     return;
734 734
                 }
735 735
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
746 746
             $inputVal = $this->post($inputName);
747 747
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
748
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
748
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
749 749
                     return;
750 750
                 }
751 751
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
762 762
             $inputVal = $this->post($inputName);
763 763
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
764
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
764
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
765 765
                     return;
766 766
                 }
767 767
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
778 778
             $inputVal = $this->post($inputName);
779 779
             if ($inputVal >= $ruleArgs[1]) { 
780
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
780
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
781 781
                     return;
782 782
                 }
783 783
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
794 794
             $inputVal = $this->post($inputName);
795 795
             if ($inputVal <= $ruleArgs[1]) {
796
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
796
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
797 797
                     return;
798 798
                 }
799 799
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
          */
809 809
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
810 810
             $inputVal = $this->post($inputName);
811
-            if (! is_numeric($inputVal)) {
812
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
811
+            if (!is_numeric($inputVal)) {
812
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
813 813
                     return;
814 814
                 }
815 815
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -824,9 +824,9 @@  discard block
 block discarded – undo
824 824
          */
825 825
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
826 826
             $inputVal = $this->post($inputName);
827
-    		if (! is_object($this->databaseInstance)){
827
+    		if (!is_object($this->databaseInstance)) {
828 828
                 $obj = & get_instance();
829
-                if(isset($obj->database)){
829
+                if (isset($obj->database)) {
830 830
                     $this->databaseInstance = $obj->database;
831 831
                 } 
832 832
             }
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
     			                                       ->where($column, $inputVal);
836 836
     		$this->databaseInstance->get();
837 837
             if ($this->databaseInstance->numRows() <= 0) {
838
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
838
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
839 839
                     return;
840 840
                 }
841 841
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -850,9 +850,9 @@  discard block
 block discarded – undo
850 850
          */
851 851
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
852 852
             $inputVal = $this->post($inputName);
853
-            if (! is_object($this->databaseInstance)){
853
+            if (!is_object($this->databaseInstance)) {
854 854
                 $obj = & get_instance();
855
-                if(isset($obj->database)){
855
+                if (isset($obj->database)) {
856 856
                     $this->databaseInstance = $obj->database;
857 857
                 } 
858 858
             }
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
     			                                      ->where($column, $inputVal);
862 862
     		$this->databaseInstance->get();
863 863
     		if ($this->databaseInstance->numRows() > 0) {
864
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
864
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
865 865
                     return;
866 866
                 }
867 867
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -876,14 +876,14 @@  discard block
 block discarded – undo
876 876
          */
877 877
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
878 878
             $inputVal = $this->post($inputName);
879
-    		if (! is_object($this->databaseInstance)){
879
+    		if (!is_object($this->databaseInstance)) {
880 880
                 $obj = & get_instance();
881
-                if(isset($obj->database)){
881
+                if (isset($obj->database)) {
882 882
                     $this->databaseInstance = $obj->database;
883 883
                 } 
884 884
             }
885 885
     		$data = explode(',', $ruleArgs[1]);
886
-    		if(count($data) < 2){
886
+    		if (count($data) < 2) {
887 887
     			return;
888 888
     		}
889 889
     		list($table, $column) = explode('.', $data[0]);
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
                                             		  ->where($field, '!=', trim($val));
894 894
             $this->databaseInstance->get();
895 895
     		if ($this->databaseInstance->numRows() > 0) {
896
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
896
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
897 897
                     return;
898 898
                 }
899 899
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
             $inputVal = $this->post($inputName);
911 911
     		$list = explode(',', $ruleArgs[1]);
912 912
             $list = array_map('trim', $list);
913
-            if (! in_array($inputVal, $list)) {
914
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
913
+            if (!in_array($inputVal, $list)) {
914
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
915 915
                     return;
916 916
                 }
917 917
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -927,8 +927,8 @@  discard block
 block discarded – undo
927 927
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
928 928
             $inputVal = $this->post($inputName);
929 929
     		$regex = $ruleArgs[1];
930
-            if (! preg_match($regex, $inputVal)) {
931
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
930
+            if (!preg_match($regex, $inputVal)) {
931
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
932 932
                     return;
933 933
                 }
934 934
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.