Test Failed
Push — 1.0.0-dev ( dc6bfa...14bd99 )
by nguereza
02:55
created
tests/include/testsUtil.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	/**
4
-	* Function to test private & protected method
5
-	*/
6
-	function run_private_protected_method($object, $method, array $args = array()){
7
-		$r = new ReflectionClass(get_class($object));
8
-		$m = $r->getMethod($method);
9
-		$m->setAccessible(true);
10
-		return $m->invokeArgs($object, $args);
11
-	}
3
+    /**
4
+     * Function to test private & protected method
5
+     */
6
+    function run_private_protected_method($object, $method, array $args = array()){
7
+        $r = new ReflectionClass(get_class($object));
8
+        $m = $r->getMethod($method);
9
+        $m->setAccessible(true);
10
+        return $m->invokeArgs($object, $args);
11
+    }
12 12
     
13 13
     /**
14
-	* Function to return the correct database configuration
15
-	*/
14
+     * Function to return the correct database configuration
15
+     */
16 16
     function get_db_config(){
17 17
         return array(
18 18
                     'driver'    =>  'sqlite',
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 	/**
4 4
 	* Function to test private & protected method
5 5
 	*/
6
-	function run_private_protected_method($object, $method, array $args = array()){
6
+	function run_private_protected_method($object, $method, array $args = array()) {
7 7
 		$r = new ReflectionClass(get_class($object));
8 8
 		$m = $r->getMethod($method);
9 9
 		$m->setAccessible(true);
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     /**
14 14
 	* Function to return the correct database configuration
15 15
 	*/
16
-    function get_db_config(){
16
+    function get_db_config() {
17 17
         return array(
18 18
                     'driver'    =>  'sqlite',
19 19
                     'database'  =>  TESTS_PATH . 'assets/db_tests.db',
Please login to merge, or discard this patch.
tests/tnhfw/classes/DBSessionHandlerTest.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -1,222 +1,222 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class DBSessionHandlerTest extends TestCase
6
-	{	
5
+    class DBSessionHandlerTest extends TestCase
6
+    {	
7 7
 	
8
-		private $db = null;
8
+        private $db = null;
9 9
 		
10
-		private $model = null;
10
+        private $model = null;
11 11
 		
12
-		private $secret = 'bXlzZWNyZXQ';
12
+        private $secret = 'bXlzZWNyZXQ';
13 13
 		
14
-		private static $config = null;
14
+        private static $config = null;
15 15
 		
16
-		public function __construct(){
16
+        public function __construct(){
17 17
             $cfg = get_db_config();
18
-			$this->db = new Database($cfg);
18
+            $this->db = new Database($cfg);
19 19
             $qr = new DatabaseQueryRunner($this->db->getPdo());
20 20
             $qr->setBenchmark(new Benchmark());
21 21
             $qr->setDriver('sqlite');
22 22
             $this->db->setQueryRunner($qr);
23
-		}
23
+        }
24 24
 		
25
-		public static function setUpBeforeClass()
26
-		{
27
-			require APPS_MODEL_PATH . 'DBSessionModel.php';
28
-			self::$config = new Config();
29
-			self::$config->init();
30
-		}
25
+        public static function setUpBeforeClass()
26
+        {
27
+            require APPS_MODEL_PATH . 'DBSessionModel.php';
28
+            self::$config = new Config();
29
+            self::$config->init();
30
+        }
31 31
 		
32 32
 		
33
-		public static function tearDownAfterClass()
34
-		{
33
+        public static function tearDownAfterClass()
34
+        {
35 35
 			
36
-		}
36
+        }
37 37
 		
38
-		protected function setUp()
39
-		{
40
-			$this->model = new DBSessionModel($this->db);
38
+        protected function setUp()
39
+        {
40
+            $this->model = new DBSessionModel($this->db);
41 41
             //to prevent old data conflict
42
-			$this->model->truncate();
43
-		}
42
+            $this->model->truncate();
43
+        }
44 44
 
45
-		protected function tearDown()
46
-		{
47
-		}
45
+        protected function tearDown()
46
+        {
47
+        }
48 48
 
49 49
 		
50 50
 		
51
-		public function testUsingSessionConfiguration(){
52
-			//using value in the configuration
53
-			self::$config->set('session_save_path', 'DBSessionModel');
54
-			self::$config->set('session_secret', $this->secret);
55
-			$dbsh = new DBSessionHandler();
56
-			//assign Database instance manually
57
-			$o = &get_instance();
58
-			$o->database = $this->db;
59
-			
60
-			$this->assertTrue($dbsh->open(null, null));
61
-			$this->assertTrue($dbsh->close());
62
-			$this->assertNull($dbsh->read('foo'));
63
-			$this->assertTrue($dbsh->write('foo', '444'));
64
-			$this->assertNotEmpty($dbsh->read('foo'));
65
-			$this->assertEquals($dbsh->read('foo'), '444');
66
-			//do update of existing data
67
-			$this->assertTrue($dbsh->write('foo', '445'));
68
-			$this->assertEquals($dbsh->read('foo'), '445');	
69
-			$this->assertTrue($dbsh->destroy('foo'));
70
-			$this->assertNull($dbsh->read('foo'));
71
-			$this->assertTrue($dbsh->gc(13));
72
-			$encoded = $dbsh->encode('foo');
73
-			$this->assertNotEmpty($encoded);
74
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
75
-		}
76
-		
77
-		public function testWhenDataIsExpired(){
78
-			$dbsh = new DBSessionHandler($this->model);
79
-			$dbsh->setSessionSecret($this->secret);
80
-			
81
-			$this->assertTrue($dbsh->open(null, null));
82
-			$this->assertTrue($dbsh->write('foo', '444'));
83
-			$this->assertNotEmpty($dbsh->read('foo'));
84
-			$this->assertEquals($dbsh->read('foo'), '444');
85
-			//put it in expired
86
-			$this->model->update('foo', array('s_time' => 1234567));
87
-			$this->assertNull($dbsh->read('foo'));
88
-		}
89
-		
90
-		public function testWhenDataAlreadyExistDoUpdate(){
91
-			$dbsh = new DBSessionHandler($this->model);
92
-			$dbsh->setSessionSecret($this->secret);
93
-			
94
-			$this->assertTrue($dbsh->open(null, null));
95
-			$this->assertTrue($dbsh->write('foo', '444'));
96
-			$this->assertNotEmpty($dbsh->read('foo'));
97
-			$this->assertEquals($dbsh->read('foo'), '444');
98
-			//do update of existing data
99
-			$this->assertTrue($dbsh->write('foo', '445'));
100
-			$this->assertEquals($dbsh->read('foo'), '445');	
101
-		}
102
-		
103
-		public function testUsingCustomModelInstance(){
104
-			$dbsh = new DBSessionHandler($this->model);
105
-			$dbsh->setSessionSecret($this->secret);
106
-			
107
-			$this->assertTrue($dbsh->open(null, null));
108
-			$this->assertTrue($dbsh->close());
109
-			$this->assertNull($dbsh->read('foo'));
110
-			$this->assertTrue($dbsh->write('foo', '444'));
111
-			$this->assertNotEmpty($dbsh->read('foo'));
112
-			$this->assertEquals($dbsh->read('foo'), '444');
113
-			//put it in expired
114
-			$this->model->update('foo', array('s_time' => 1234567));
115
-			
116
-			$this->assertNull($dbsh->read('foo'));
117
-			$this->assertTrue($dbsh->write('foo', '444'));
118
-			
119
-			//do update of existing data
120
-			$this->assertTrue($dbsh->write('foo', '445'));
121
-			$this->assertEquals($dbsh->read('foo'), '445');	
122
-			$this->assertTrue($dbsh->destroy('foo'));
123
-			$this->assertNull($dbsh->read('foo'));
124
-			$this->assertTrue($dbsh->gc(13));
125
-			$encoded = $dbsh->encode('foo');
126
-			$this->assertNotEmpty($encoded);
127
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
128
-		}
129
-			
130
-			
131
-		public function testUsingCustomLogInstance(){
132
-			$dbsh = new DBSessionHandler($this->model, new Log());
133
-			$dbsh->setSessionSecret($this->secret);
134
-			
135
-			$this->assertTrue($dbsh->open(null, null));
136
-			$this->assertTrue($dbsh->close());
137
-			$this->assertNull($dbsh->read('foo'));
138
-			$this->assertTrue($dbsh->write('foo', '444'));
139
-			$this->assertNotEmpty($dbsh->read('foo'));
140
-			$this->assertEquals($dbsh->read('foo'), '444');
141
-			//put it in expired
142
-			$this->model->update('foo', array('s_time' => 1234567));
143
-			
144
-			$this->assertNull($dbsh->read('foo'));
145
-			$this->assertTrue($dbsh->write('foo', '444'));
146
-			
147
-			//do update of existing data
148
-			$this->assertTrue($dbsh->write('foo', '445'));
149
-			$this->assertEquals($dbsh->read('foo'), '445');	
150
-			$this->assertTrue($dbsh->destroy('foo'));
151
-			$this->assertNull($dbsh->read('foo'));
152
-			$this->assertTrue($dbsh->gc(13));
153
-			$encoded = $dbsh->encode('foo');
154
-			$this->assertNotEmpty($encoded);
155
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
156
-		}
157
-		
158
-		public function testUsingCustomLoaderInstance(){
159
-			$dbsh = new DBSessionHandler($this->model, null, new Loader());
160
-			$dbsh->setSessionSecret($this->secret);
161
-			
162
-			$this->assertTrue($dbsh->open(null, null));
163
-			$this->assertTrue($dbsh->close());
164
-			$this->assertNull($dbsh->read('foo'));
165
-			$this->assertTrue($dbsh->write('foo', '444'));
166
-			$this->assertNotEmpty($dbsh->read('foo'));
167
-			$this->assertEquals($dbsh->read('foo'), '444');
168
-			//put it in expired
169
-			$this->model->update('foo', array('s_time' => 1234567));
170
-			
171
-			$this->assertNull($dbsh->read('foo'));
172
-			$this->assertTrue($dbsh->write('foo', '444'));
173
-			
174
-			//do update of existing data
175
-			$this->assertTrue($dbsh->write('foo', '445'));
176
-			$this->assertEquals($dbsh->read('foo'), '445');	
177
-			$this->assertTrue($dbsh->destroy('foo'));
178
-			$this->assertNull($dbsh->read('foo'));
179
-			$this->assertTrue($dbsh->gc(13));
180
-			$encoded = $dbsh->encode('foo');
181
-			$this->assertNotEmpty($encoded);
182
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
183
-		}
184
-		
185
-		
186
-		public function testWhenModelInsanceIsNotSet(){
187
-			$dbsh = new DBSessionHandler(null, null, new Loader());
188
-			$dbsh->setSessionSecret($this->secret);
189
-			
190
-			$this->assertTrue($dbsh->open(null, null));
191
-			$this->assertTrue($dbsh->close());
192
-			$this->assertNull($dbsh->read('foo'));
193
-			$this->assertTrue($dbsh->write('foo', '444'));
194
-			$this->assertNotEmpty($dbsh->read('foo'));
195
-			$this->assertEquals($dbsh->read('foo'), '444');
196
-			//put it in expired
197
-			$this->model->update('foo', array('s_time' => 1234567));
198
-			
199
-			$this->assertNull($dbsh->read('foo'));
200
-			$this->assertTrue($dbsh->write('foo', '444'));
201
-			
202
-			//do update of existing data
203
-			$this->assertTrue($dbsh->write('tnh', '445'));
204
-			$this->assertTrue($dbsh->write('foo', '445'));
205
-			$this->assertEquals($dbsh->read('foo'), '445');	
206
-			$this->assertTrue($dbsh->destroy('foo'));
207
-			$this->assertNull($dbsh->read('foo'));
208
-			$this->assertTrue($dbsh->gc(13));
209
-			$encoded = $dbsh->encode('foo');
210
-			$this->assertNotEmpty($encoded);
211
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
212
-		}
213
-		
214
-		public function testWhenModelTableColumnsIsNotSet(){
215
-			//session table is empty
216
-			$this->model->setSessionTableColumns(array());
217
-			$dbsh = new DBSessionHandler($this->model);
218
-			$this->assertTrue($dbsh->open(null, null));
219
-		}
220
-		
221
-		
222
-	}
223 51
\ No newline at end of file
52
+        public function testUsingSessionConfiguration(){
53
+            //using value in the configuration
54
+            self::$config->set('session_save_path', 'DBSessionModel');
55
+            self::$config->set('session_secret', $this->secret);
56
+            $dbsh = new DBSessionHandler();
57
+            //assign Database instance manually
58
+            $o = &get_instance();
59
+            $o->database = $this->db;
60
+			
61
+            $this->assertTrue($dbsh->open(null, null));
62
+            $this->assertTrue($dbsh->close());
63
+            $this->assertNull($dbsh->read('foo'));
64
+            $this->assertTrue($dbsh->write('foo', '444'));
65
+            $this->assertNotEmpty($dbsh->read('foo'));
66
+            $this->assertEquals($dbsh->read('foo'), '444');
67
+            //do update of existing data
68
+            $this->assertTrue($dbsh->write('foo', '445'));
69
+            $this->assertEquals($dbsh->read('foo'), '445');	
70
+            $this->assertTrue($dbsh->destroy('foo'));
71
+            $this->assertNull($dbsh->read('foo'));
72
+            $this->assertTrue($dbsh->gc(13));
73
+            $encoded = $dbsh->encode('foo');
74
+            $this->assertNotEmpty($encoded);
75
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
76
+        }
77
+		
78
+        public function testWhenDataIsExpired(){
79
+            $dbsh = new DBSessionHandler($this->model);
80
+            $dbsh->setSessionSecret($this->secret);
81
+			
82
+            $this->assertTrue($dbsh->open(null, null));
83
+            $this->assertTrue($dbsh->write('foo', '444'));
84
+            $this->assertNotEmpty($dbsh->read('foo'));
85
+            $this->assertEquals($dbsh->read('foo'), '444');
86
+            //put it in expired
87
+            $this->model->update('foo', array('s_time' => 1234567));
88
+            $this->assertNull($dbsh->read('foo'));
89
+        }
90
+		
91
+        public function testWhenDataAlreadyExistDoUpdate(){
92
+            $dbsh = new DBSessionHandler($this->model);
93
+            $dbsh->setSessionSecret($this->secret);
94
+			
95
+            $this->assertTrue($dbsh->open(null, null));
96
+            $this->assertTrue($dbsh->write('foo', '444'));
97
+            $this->assertNotEmpty($dbsh->read('foo'));
98
+            $this->assertEquals($dbsh->read('foo'), '444');
99
+            //do update of existing data
100
+            $this->assertTrue($dbsh->write('foo', '445'));
101
+            $this->assertEquals($dbsh->read('foo'), '445');	
102
+        }
103
+		
104
+        public function testUsingCustomModelInstance(){
105
+            $dbsh = new DBSessionHandler($this->model);
106
+            $dbsh->setSessionSecret($this->secret);
107
+			
108
+            $this->assertTrue($dbsh->open(null, null));
109
+            $this->assertTrue($dbsh->close());
110
+            $this->assertNull($dbsh->read('foo'));
111
+            $this->assertTrue($dbsh->write('foo', '444'));
112
+            $this->assertNotEmpty($dbsh->read('foo'));
113
+            $this->assertEquals($dbsh->read('foo'), '444');
114
+            //put it in expired
115
+            $this->model->update('foo', array('s_time' => 1234567));
116
+			
117
+            $this->assertNull($dbsh->read('foo'));
118
+            $this->assertTrue($dbsh->write('foo', '444'));
119
+			
120
+            //do update of existing data
121
+            $this->assertTrue($dbsh->write('foo', '445'));
122
+            $this->assertEquals($dbsh->read('foo'), '445');	
123
+            $this->assertTrue($dbsh->destroy('foo'));
124
+            $this->assertNull($dbsh->read('foo'));
125
+            $this->assertTrue($dbsh->gc(13));
126
+            $encoded = $dbsh->encode('foo');
127
+            $this->assertNotEmpty($encoded);
128
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
129
+        }
130
+			
131
+			
132
+        public function testUsingCustomLogInstance(){
133
+            $dbsh = new DBSessionHandler($this->model, new Log());
134
+            $dbsh->setSessionSecret($this->secret);
135
+			
136
+            $this->assertTrue($dbsh->open(null, null));
137
+            $this->assertTrue($dbsh->close());
138
+            $this->assertNull($dbsh->read('foo'));
139
+            $this->assertTrue($dbsh->write('foo', '444'));
140
+            $this->assertNotEmpty($dbsh->read('foo'));
141
+            $this->assertEquals($dbsh->read('foo'), '444');
142
+            //put it in expired
143
+            $this->model->update('foo', array('s_time' => 1234567));
144
+			
145
+            $this->assertNull($dbsh->read('foo'));
146
+            $this->assertTrue($dbsh->write('foo', '444'));
147
+			
148
+            //do update of existing data
149
+            $this->assertTrue($dbsh->write('foo', '445'));
150
+            $this->assertEquals($dbsh->read('foo'), '445');	
151
+            $this->assertTrue($dbsh->destroy('foo'));
152
+            $this->assertNull($dbsh->read('foo'));
153
+            $this->assertTrue($dbsh->gc(13));
154
+            $encoded = $dbsh->encode('foo');
155
+            $this->assertNotEmpty($encoded);
156
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
157
+        }
158
+		
159
+        public function testUsingCustomLoaderInstance(){
160
+            $dbsh = new DBSessionHandler($this->model, null, new Loader());
161
+            $dbsh->setSessionSecret($this->secret);
162
+			
163
+            $this->assertTrue($dbsh->open(null, null));
164
+            $this->assertTrue($dbsh->close());
165
+            $this->assertNull($dbsh->read('foo'));
166
+            $this->assertTrue($dbsh->write('foo', '444'));
167
+            $this->assertNotEmpty($dbsh->read('foo'));
168
+            $this->assertEquals($dbsh->read('foo'), '444');
169
+            //put it in expired
170
+            $this->model->update('foo', array('s_time' => 1234567));
171
+			
172
+            $this->assertNull($dbsh->read('foo'));
173
+            $this->assertTrue($dbsh->write('foo', '444'));
174
+			
175
+            //do update of existing data
176
+            $this->assertTrue($dbsh->write('foo', '445'));
177
+            $this->assertEquals($dbsh->read('foo'), '445');	
178
+            $this->assertTrue($dbsh->destroy('foo'));
179
+            $this->assertNull($dbsh->read('foo'));
180
+            $this->assertTrue($dbsh->gc(13));
181
+            $encoded = $dbsh->encode('foo');
182
+            $this->assertNotEmpty($encoded);
183
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
184
+        }
185
+		
186
+		
187
+        public function testWhenModelInsanceIsNotSet(){
188
+            $dbsh = new DBSessionHandler(null, null, new Loader());
189
+            $dbsh->setSessionSecret($this->secret);
190
+			
191
+            $this->assertTrue($dbsh->open(null, null));
192
+            $this->assertTrue($dbsh->close());
193
+            $this->assertNull($dbsh->read('foo'));
194
+            $this->assertTrue($dbsh->write('foo', '444'));
195
+            $this->assertNotEmpty($dbsh->read('foo'));
196
+            $this->assertEquals($dbsh->read('foo'), '444');
197
+            //put it in expired
198
+            $this->model->update('foo', array('s_time' => 1234567));
199
+			
200
+            $this->assertNull($dbsh->read('foo'));
201
+            $this->assertTrue($dbsh->write('foo', '444'));
202
+			
203
+            //do update of existing data
204
+            $this->assertTrue($dbsh->write('tnh', '445'));
205
+            $this->assertTrue($dbsh->write('foo', '445'));
206
+            $this->assertEquals($dbsh->read('foo'), '445');	
207
+            $this->assertTrue($dbsh->destroy('foo'));
208
+            $this->assertNull($dbsh->read('foo'));
209
+            $this->assertTrue($dbsh->gc(13));
210
+            $encoded = $dbsh->encode('foo');
211
+            $this->assertNotEmpty($encoded);
212
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
213
+        }
214
+		
215
+        public function testWhenModelTableColumnsIsNotSet(){
216
+            //session table is empty
217
+            $this->model->setSessionTableColumns(array());
218
+            $dbsh = new DBSessionHandler($this->model);
219
+            $this->assertTrue($dbsh->open(null, null));
220
+        }
221
+		
222
+		
223
+    }
224 224
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 		
14 14
 		private static $config = null;
15 15
 		
16
-		public function __construct(){
16
+		public function __construct() {
17 17
             $cfg = get_db_config();
18 18
 			$this->db = new Database($cfg);
19 19
             $qr = new DatabaseQueryRunner($this->db->getPdo());
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 		
50 50
 		
51
-		public function testUsingSessionConfiguration(){
51
+		public function testUsingSessionConfiguration() {
52 52
 			//using value in the configuration
53 53
 			self::$config->set('session_save_path', 'DBSessionModel');
54 54
 			self::$config->set('session_secret', $this->secret);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
75 75
 		}
76 76
 		
77
-		public function testWhenDataIsExpired(){
77
+		public function testWhenDataIsExpired() {
78 78
 			$dbsh = new DBSessionHandler($this->model);
79 79
 			$dbsh->setSessionSecret($this->secret);
80 80
 			
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			$this->assertNull($dbsh->read('foo'));
88 88
 		}
89 89
 		
90
-		public function testWhenDataAlreadyExistDoUpdate(){
90
+		public function testWhenDataAlreadyExistDoUpdate() {
91 91
 			$dbsh = new DBSessionHandler($this->model);
92 92
 			$dbsh->setSessionSecret($this->secret);
93 93
 			
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			$this->assertEquals($dbsh->read('foo'), '445');	
101 101
 		}
102 102
 		
103
-		public function testUsingCustomModelInstance(){
103
+		public function testUsingCustomModelInstance() {
104 104
 			$dbsh = new DBSessionHandler($this->model);
105 105
 			$dbsh->setSessionSecret($this->secret);
106 106
 			
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		}
129 129
 			
130 130
 			
131
-		public function testUsingCustomLogInstance(){
131
+		public function testUsingCustomLogInstance() {
132 132
 			$dbsh = new DBSessionHandler($this->model, new Log());
133 133
 			$dbsh->setSessionSecret($this->secret);
134 134
 			
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
156 156
 		}
157 157
 		
158
-		public function testUsingCustomLoaderInstance(){
158
+		public function testUsingCustomLoaderInstance() {
159 159
 			$dbsh = new DBSessionHandler($this->model, null, new Loader());
160 160
 			$dbsh->setSessionSecret($this->secret);
161 161
 			
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		}
184 184
 		
185 185
 		
186
-		public function testWhenModelInsanceIsNotSet(){
186
+		public function testWhenModelInsanceIsNotSet() {
187 187
 			$dbsh = new DBSessionHandler(null, null, new Loader());
188 188
 			$dbsh->setSessionSecret($this->secret);
189 189
 			
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
212 212
 		}
213 213
 		
214
-		public function testWhenModelTableColumnsIsNotSet(){
214
+		public function testWhenModelTableColumnsIsNotSet() {
215 215
 			//session table is empty
216 216
 			$this->model->setSessionTableColumns(array());
217 217
 			$dbsh = new DBSessionHandler($this->model);
Please login to merge, or discard this patch.
tests/tnhfw/classes/database/DatabaseTest.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,41 +1,41 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class DatabaseTest extends TestCase
6
-	{	
5
+    class DatabaseTest extends TestCase
6
+    {	
7 7
 	
8
-		public static function setUpBeforeClass()
9
-		{
8
+        public static function setUpBeforeClass()
9
+        {
10 10
 		
11
-		}
11
+        }
12 12
 		
13
-		public static function tearDownAfterClass()
14
-		{
13
+        public static function tearDownAfterClass()
14
+        {
15 15
 			
16
-		}
16
+        }
17 17
 		
18
-		protected function setUp()
19
-		{
20
-		}
18
+        protected function setUp()
19
+        {
20
+        }
21 21
 
22
-		protected function tearDown()
23
-		{
24
-		}
22
+        protected function tearDown()
23
+        {
24
+        }
25 25
 		
26
-		public function testConnectToDatabaseSuccessfully()
27
-		{
26
+        public function testConnectToDatabaseSuccessfully()
27
+        {
28 28
             $cfg = get_db_config();
29 29
             $db = new Database($cfg, false);
30 30
             $isConnected = $db->connect();
31
-			$this->assertTrue($isConnected);
32
-		}
31
+            $this->assertTrue($isConnected);
32
+        }
33 33
         
34 34
         public function testCannotConnectToDatabase()
35
-		{
36
-             $db = new Database(array(), false);
37
-             $isConnected = $db->connect();
38
-			$this->assertFalse($isConnected);
39
-		}
35
+        {
36
+                $db = new Database(array(), false);
37
+                $isConnected = $db->connect();
38
+            $this->assertFalse($isConnected);
39
+        }
40 40
 
41
-	}
42 41
\ No newline at end of file
42
+    }
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
core/classes/Config.php 2 patches
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
-		private 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
+        private 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
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private 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/classes/Loader.php 3 patches
Indentation   +622 added lines, -622 removed lines patch added patch discarded remove patch
@@ -1,660 +1,660 @@
 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
-	*/
26
-	class Loader{
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 Loader{
27 27
 		
28
-		/**
29
-		 * List of loaded resources
30
-		 * @var array
31
-		 */
32
-		public static $loaded = array();
28
+        /**
29
+         * List of loaded resources
30
+         * @var array
31
+         */
32
+        public static $loaded = array();
33 33
 		
34
-		/**
35
-		 * The logger instance
36
-		 * @var object
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var object
37
+         */
38
+        private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
42
-			//add the resources already loaded during application bootstrap
43
-			//in the list to prevent duplicate or loading the resources again.
44
-			static::$loaded = class_loaded();
41
+        public function __construct(){
42
+            //add the resources already loaded during application bootstrap
43
+            //in the list to prevent duplicate or loading the resources again.
44
+            static::$loaded = class_loaded();
45 45
 			
46
-			//Load resources from autoload configuration
47
-			$this->loadResourcesFromAutoloadConfig();
48
-		}
46
+            //Load resources from autoload configuration
47
+            $this->loadResourcesFromAutoloadConfig();
48
+        }
49 49
 
50
-		/**
51
-		 * The signleton of the logger
52
-		 * @return object the Log instance
53
-		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				$logger = array();
57
-				$logger[0] =& class_loader('Log', 'classes');
58
-				$logger[0]->setLogger('Library::Loader');
59
-				self::$logger = $logger[0];
60
-			}
61
-			return self::$logger;			
62
-		}
50
+        /**
51
+         * The signleton of the logger
52
+         * @return object the Log instance
53
+         */
54
+        private static function getLogger(){
55
+            if(self::$logger == null){
56
+                $logger = array();
57
+                $logger[0] =& class_loader('Log', 'classes');
58
+                $logger[0]->setLogger('Library::Loader');
59
+                self::$logger = $logger[0];
60
+            }
61
+            return self::$logger;			
62
+        }
63 63
 
64
-		/**
65
-		 * Set the log instance for future use
66
-		 * @param object $logger the log object
67
-		 * @return object the log instance
68
-		 */
69
-		public static function setLogger($logger){
70
-			self::$logger = $logger;
71
-			return self::$logger;
72
-		}
64
+        /**
65
+         * Set the log instance for future use
66
+         * @param object $logger the log object
67
+         * @return object the log instance
68
+         */
69
+        public static function setLogger($logger){
70
+            self::$logger = $logger;
71
+            return self::$logger;
72
+        }
73 73
 
74 74
 		
75
-		/**
76
-		 * Load the model class
77
-		 *
78
-		 * @param  string $class    the class name to be loaded
79
-		 * @param  string $instance the name of the instance to use in super object
80
-		 *
81
-		 * @return void
82
-		 */
83
-		public static function model($class, $instance = null){
84
-			$logger = static::getLogger();
85
-			$class = str_ireplace('.php', '', $class);
86
-			$class = trim($class, '/\\');
87
-			$file = ucfirst($class).'.php';
88
-			$logger->debug('Loading model [' . $class . '] ...');
89
-			//************
90
-			if (! $instance){
91
-				$instance = self::getModelLibraryInstanceName($class);
92
-			}
93
-			//****************
94
-			if (isset(static::$loaded[$instance])){
95
-				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96
-				return;
97
-			}
98
-			$classFilePath = APPS_MODEL_PATH . $file;
99
-			//first check if this model is in the module
100
-			$logger->debug('Checking model [' . $class . '] from module list ...');
101
-			//check if the request class contains module name
102
-			$moduleInfo = self::getModuleInfoForModelLibrary($class);
103
-			$module = $moduleInfo['module'];
104
-			$class  = $moduleInfo['class'];
75
+        /**
76
+         * Load the model class
77
+         *
78
+         * @param  string $class    the class name to be loaded
79
+         * @param  string $instance the name of the instance to use in super object
80
+         *
81
+         * @return void
82
+         */
83
+        public static function model($class, $instance = null){
84
+            $logger = static::getLogger();
85
+            $class = str_ireplace('.php', '', $class);
86
+            $class = trim($class, '/\\');
87
+            $file = ucfirst($class).'.php';
88
+            $logger->debug('Loading model [' . $class . '] ...');
89
+            //************
90
+            if (! $instance){
91
+                $instance = self::getModelLibraryInstanceName($class);
92
+            }
93
+            //****************
94
+            if (isset(static::$loaded[$instance])){
95
+                $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96
+                return;
97
+            }
98
+            $classFilePath = APPS_MODEL_PATH . $file;
99
+            //first check if this model is in the module
100
+            $logger->debug('Checking model [' . $class . '] from module list ...');
101
+            //check if the request class contains module name
102
+            $moduleInfo = self::getModuleInfoForModelLibrary($class);
103
+            $module = $moduleInfo['module'];
104
+            $class  = $moduleInfo['class'];
105 105
 			
106
-			$moduleModelFilePath = Module::findModelFullPath($class, $module);
107
-			if ($moduleModelFilePath){
108
-				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
109
-				$classFilePath = $moduleModelFilePath;
110
-			}
111
-			else{
112
-				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113
-			}
114
-			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
-			if (file_exists($classFilePath)){
116
-				require_once $classFilePath;
117
-				if (class_exists($class)){
118
-					$c = new $class();
119
-					$obj = & get_instance();
120
-					$obj->{$instance} = $c;
121
-					static::$loaded[$instance] = $class;
122
-					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123
-				}
124
-				else{
125
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
126
-				}
127
-			}
128
-			else{
129
-				show_error('Unable to find the model [' . $class . ']');
130
-			}
131
-		}
106
+            $moduleModelFilePath = Module::findModelFullPath($class, $module);
107
+            if ($moduleModelFilePath){
108
+                $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
109
+                $classFilePath = $moduleModelFilePath;
110
+            }
111
+            else{
112
+                $logger->info('Cannot find model [' . $class . '] from modules using the default location');
113
+            }
114
+            $logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
+            if (file_exists($classFilePath)){
116
+                require_once $classFilePath;
117
+                if (class_exists($class)){
118
+                    $c = new $class();
119
+                    $obj = & get_instance();
120
+                    $obj->{$instance} = $c;
121
+                    static::$loaded[$instance] = $class;
122
+                    $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123
+                }
124
+                else{
125
+                    show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
126
+                }
127
+            }
128
+            else{
129
+                show_error('Unable to find the model [' . $class . ']');
130
+            }
131
+        }
132 132
 
133 133
 		
134
-		/**
135
-		 * Load the library class
136
-		 *
137
-		 * @param  string $class    the library class name to be loaded
138
-		 * @param  string $instance the instance name to use in super object
139
-		 * @param mixed $params the arguments to pass to the constructor
140
-		 *
141
-		 * @return void
142
-		 */
143
-		public static function library($class, $instance = null, array $params = array()){
144
-			$logger = static::getLogger();
145
-			$class = str_ireplace('.php', '', $class);
146
-			$class = trim($class, '/\\');
147
-			$file = ucfirst($class) .'.php';
148
-			$logger->debug('Loading library [' . $class . '] ...');
149
-			if (! $instance){
150
-				$instance = self::getModelLibraryInstanceName($class);
151
-			}
152
-			if (isset(static::$loaded[$instance])){
153
-				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154
-				return;
155
-			}
156
-			$obj = & get_instance();
157
-			//Check and load Database library
158
-			if (strtolower($class) == 'database'){
159
-				$logger->info('This is the Database library ...');
160
-				$obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161
-				static::$loaded[$instance] = $class;
162
-				$logger->info('Library Database loaded successfully.');
163
-				return;
164
-			}
165
-			$libraryFilePath = null;
166
-			$logger->debug('Check if this is a system library ...');
167
-			if (file_exists(CORE_LIBRARY_PATH . $file)){
168
-				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169
-				$class = ucfirst($class);
170
-				$logger->info('This library is a system library');
171
-			}
172
-			else{
173
-				$logger->info('This library is not a system library');	
174
-				//first check if this library is in the module
175
-				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176
-				//***************
177
-			}
178
-			if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
179
-				$libraryFilePath = LIBRARY_PATH . $file;
180
-			}
181
-			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
182
-			//*************************
183
-			self::loadLibrary($libraryFilePath, $class, $instance, $params);
184
-		}
134
+        /**
135
+         * Load the library class
136
+         *
137
+         * @param  string $class    the library class name to be loaded
138
+         * @param  string $instance the instance name to use in super object
139
+         * @param mixed $params the arguments to pass to the constructor
140
+         *
141
+         * @return void
142
+         */
143
+        public static function library($class, $instance = null, array $params = array()){
144
+            $logger = static::getLogger();
145
+            $class = str_ireplace('.php', '', $class);
146
+            $class = trim($class, '/\\');
147
+            $file = ucfirst($class) .'.php';
148
+            $logger->debug('Loading library [' . $class . '] ...');
149
+            if (! $instance){
150
+                $instance = self::getModelLibraryInstanceName($class);
151
+            }
152
+            if (isset(static::$loaded[$instance])){
153
+                $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154
+                return;
155
+            }
156
+            $obj = & get_instance();
157
+            //Check and load Database library
158
+            if (strtolower($class) == 'database'){
159
+                $logger->info('This is the Database library ...');
160
+                $obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161
+                static::$loaded[$instance] = $class;
162
+                $logger->info('Library Database loaded successfully.');
163
+                return;
164
+            }
165
+            $libraryFilePath = null;
166
+            $logger->debug('Check if this is a system library ...');
167
+            if (file_exists(CORE_LIBRARY_PATH . $file)){
168
+                $libraryFilePath = CORE_LIBRARY_PATH . $file;
169
+                $class = ucfirst($class);
170
+                $logger->info('This library is a system library');
171
+            }
172
+            else{
173
+                $logger->info('This library is not a system library');	
174
+                //first check if this library is in the module
175
+                $libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176
+                //***************
177
+            }
178
+            if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
179
+                $libraryFilePath = LIBRARY_PATH . $file;
180
+            }
181
+            $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
182
+            //*************************
183
+            self::loadLibrary($libraryFilePath, $class, $instance, $params);
184
+        }
185 185
 
186
-		/**
187
-		 * Load the helper
188
-		 *
189
-		 * @param  string $function the helper name to be loaded
190
-		 *
191
-		 * @return void
192
-		 */
193
-		public static function functions($function){
194
-			$logger = static::getLogger();
195
-			$function = str_ireplace('.php', '', $function);
196
-			$function = trim($function, '/\\');
197
-			$function = str_ireplace('function_', '', $function);
198
-			$file = 'function_'.$function.'.php';
199
-			$logger->debug('Loading helper [' . $function . '] ...');
200
-			if (isset(static::$loaded['function_' . $function])){
201
-				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202
-				return;
203
-			}
204
-			$functionFilePath = null;
205
-			//first check if this helper is in the module
206
-			$logger->debug('Checking helper [' . $function . '] from module list ...');
207
-			$moduleInfo = self::getModuleInfoForFunction($function);
208
-			$module    = $moduleInfo['module'];
209
-			$function  = $moduleInfo['function'];
210
-			if(! empty($moduleInfo['file'])){
211
-				$file = $moduleInfo['file'];
212
-			}
213
-			$moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
-			if ($moduleFunctionPath){
215
-				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
216
-				$functionFilePath = $moduleFunctionPath;
217
-			}
218
-			else{
219
-				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220
-			}
221
-			if (! $functionFilePath){
222
-				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
-				foreach($searchDir as $dir){
224
-					$filePath = $dir . $file;
225
-					if (file_exists($filePath)){
226
-						$functionFilePath = $filePath;
227
-						//is already found not to continue
228
-						break;
229
-					}
230
-				}
231
-			}
232
-			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
-			if ($functionFilePath){
234
-				require_once $functionFilePath;
235
-				static::$loaded['function_' . $function] = $functionFilePath;
236
-				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237
-			}
238
-			else{
239
-				show_error('Unable to find helper file [' . $file . ']');
240
-			}
241
-		}
186
+        /**
187
+         * Load the helper
188
+         *
189
+         * @param  string $function the helper name to be loaded
190
+         *
191
+         * @return void
192
+         */
193
+        public static function functions($function){
194
+            $logger = static::getLogger();
195
+            $function = str_ireplace('.php', '', $function);
196
+            $function = trim($function, '/\\');
197
+            $function = str_ireplace('function_', '', $function);
198
+            $file = 'function_'.$function.'.php';
199
+            $logger->debug('Loading helper [' . $function . '] ...');
200
+            if (isset(static::$loaded['function_' . $function])){
201
+                $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202
+                return;
203
+            }
204
+            $functionFilePath = null;
205
+            //first check if this helper is in the module
206
+            $logger->debug('Checking helper [' . $function . '] from module list ...');
207
+            $moduleInfo = self::getModuleInfoForFunction($function);
208
+            $module    = $moduleInfo['module'];
209
+            $function  = $moduleInfo['function'];
210
+            if(! empty($moduleInfo['file'])){
211
+                $file = $moduleInfo['file'];
212
+            }
213
+            $moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
+            if ($moduleFunctionPath){
215
+                $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
216
+                $functionFilePath = $moduleFunctionPath;
217
+            }
218
+            else{
219
+                $logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220
+            }
221
+            if (! $functionFilePath){
222
+                $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
+                foreach($searchDir as $dir){
224
+                    $filePath = $dir . $file;
225
+                    if (file_exists($filePath)){
226
+                        $functionFilePath = $filePath;
227
+                        //is already found not to continue
228
+                        break;
229
+                    }
230
+                }
231
+            }
232
+            $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
+            if ($functionFilePath){
234
+                require_once $functionFilePath;
235
+                static::$loaded['function_' . $function] = $functionFilePath;
236
+                $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237
+            }
238
+            else{
239
+                show_error('Unable to find helper file [' . $file . ']');
240
+            }
241
+        }
242 242
 
243
-		/**
244
-		 * Load the configuration file
245
-		 *
246
-		 * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
247
-		 *
248
-		 * @return void
249
-		 */
250
-		public static function config($filename){
251
-			$logger = static::getLogger();
252
-			$filename = str_ireplace('.php', '', $filename);
253
-			$filename = trim($filename, '/\\');
254
-			$filename = str_ireplace('config_', '', $filename);
255
-			$file = 'config_'.$filename.'.php';
256
-			$logger->debug('Loading configuration [' . $filename . '] ...');
257
-			if (isset(static::$loaded['config_' . $filename])){
258
-				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259
-				return;
260
-			}
261
-			$configFilePath = CONFIG_PATH . $file;
262
-			//first check if this config is in the module
263
-			$logger->debug('Checking config [' . $filename . '] from module list ...');
264
-			$moduleInfo = self::getModuleInfoForConfig($filename);
265
-			$module    = $moduleInfo['module'];
266
-			$filename  = $moduleInfo['filename'];
267
-			$moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
-			if ($moduleConfigPath){
269
-				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
270
-				$configFilePath = $moduleConfigPath;
271
-			}
272
-			else{
273
-				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274
-			}
275
-			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276
-			$config = array();
277
-			if (file_exists($configFilePath)){
278
-				require_once $configFilePath;
279
-				if (! empty($config) && is_array($config)){
280
-					Config::setAll($config);
281
-					static::$loaded['config_' . $filename] = $configFilePath;
282
-					$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
283
-					$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
284
-					unset($config);
285
-				}
286
-			}
287
-			else{
288
-				show_error('Unable to find config file ['. $configFilePath . ']');
289
-			}
290
-		}
243
+        /**
244
+         * Load the configuration file
245
+         *
246
+         * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
247
+         *
248
+         * @return void
249
+         */
250
+        public static function config($filename){
251
+            $logger = static::getLogger();
252
+            $filename = str_ireplace('.php', '', $filename);
253
+            $filename = trim($filename, '/\\');
254
+            $filename = str_ireplace('config_', '', $filename);
255
+            $file = 'config_'.$filename.'.php';
256
+            $logger->debug('Loading configuration [' . $filename . '] ...');
257
+            if (isset(static::$loaded['config_' . $filename])){
258
+                $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259
+                return;
260
+            }
261
+            $configFilePath = CONFIG_PATH . $file;
262
+            //first check if this config is in the module
263
+            $logger->debug('Checking config [' . $filename . '] from module list ...');
264
+            $moduleInfo = self::getModuleInfoForConfig($filename);
265
+            $module    = $moduleInfo['module'];
266
+            $filename  = $moduleInfo['filename'];
267
+            $moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
+            if ($moduleConfigPath){
269
+                $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
270
+                $configFilePath = $moduleConfigPath;
271
+            }
272
+            else{
273
+                $logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274
+            }
275
+            $logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276
+            $config = array();
277
+            if (file_exists($configFilePath)){
278
+                require_once $configFilePath;
279
+                if (! empty($config) && is_array($config)){
280
+                    Config::setAll($config);
281
+                    static::$loaded['config_' . $filename] = $configFilePath;
282
+                    $logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
283
+                    $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
284
+                    unset($config);
285
+                }
286
+            }
287
+            else{
288
+                show_error('Unable to find config file ['. $configFilePath . ']');
289
+            }
290
+        }
291 291
 
292 292
 
293
-		/**
294
-		 * Load the language
295
-		 *
296
-		 * @param  string $language the language name to be loaded
297
-		 *
298
-		 * @return void
299
-		 */
300
-		public static function lang($language){
301
-			$logger = static::getLogger();
302
-			$language = str_ireplace('.php', '', $language);
303
-			$language = trim($language, '/\\');
304
-			$language = str_ireplace('lang_', '', $language);
305
-			$file = 'lang_'.$language.'.php';
306
-			$logger->debug('Loading language [' . $language . '] ...');
307
-			if (isset(static::$loaded['lang_' . $language])){
308
-				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309
-				return;
310
-			}
311
-			//get the current language
312
-			$appLang = self::getAppLang();
313
-			$languageFilePath = null;
314
-			//first check if this language is in the module
315
-			$logger->debug('Checking language [' . $language . '] from module list ...');
316
-			$moduleInfo = self::getModuleInfoForLanguage($language);
317
-			$module    = $moduleInfo['module'];
318
-			$language  = $moduleInfo['language'];
319
-			if(! empty($moduleInfo['file'])){
320
-				$file = $moduleInfo['file'];
321
-			}
322
-			$moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
-			if ($moduleLanguagePath){
324
-				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
325
-				$languageFilePath = $moduleLanguagePath;
326
-			}
327
-			else{
328
-				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329
-			}
330
-			if (! $languageFilePath){
331
-				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
-				foreach($searchDir as $dir){
333
-					$filePath = $dir . $appLang . DS . $file;
334
-					if (file_exists($filePath)){
335
-						$languageFilePath = $filePath;
336
-						//already found no need continue
337
-						break;
338
-					}
339
-				}
340
-			}
341
-			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
342
-			self::loadLanguage($languageFilePath, $language);
343
-		}
293
+        /**
294
+         * Load the language
295
+         *
296
+         * @param  string $language the language name to be loaded
297
+         *
298
+         * @return void
299
+         */
300
+        public static function lang($language){
301
+            $logger = static::getLogger();
302
+            $language = str_ireplace('.php', '', $language);
303
+            $language = trim($language, '/\\');
304
+            $language = str_ireplace('lang_', '', $language);
305
+            $file = 'lang_'.$language.'.php';
306
+            $logger->debug('Loading language [' . $language . '] ...');
307
+            if (isset(static::$loaded['lang_' . $language])){
308
+                $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309
+                return;
310
+            }
311
+            //get the current language
312
+            $appLang = self::getAppLang();
313
+            $languageFilePath = null;
314
+            //first check if this language is in the module
315
+            $logger->debug('Checking language [' . $language . '] from module list ...');
316
+            $moduleInfo = self::getModuleInfoForLanguage($language);
317
+            $module    = $moduleInfo['module'];
318
+            $language  = $moduleInfo['language'];
319
+            if(! empty($moduleInfo['file'])){
320
+                $file = $moduleInfo['file'];
321
+            }
322
+            $moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
+            if ($moduleLanguagePath){
324
+                $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
325
+                $languageFilePath = $moduleLanguagePath;
326
+            }
327
+            else{
328
+                $logger->info('Cannot find language [' . $language . '] from modules using the default location');
329
+            }
330
+            if (! $languageFilePath){
331
+                $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
+                foreach($searchDir as $dir){
333
+                    $filePath = $dir . $appLang . DS . $file;
334
+                    if (file_exists($filePath)){
335
+                        $languageFilePath = $filePath;
336
+                        //already found no need continue
337
+                        break;
338
+                    }
339
+                }
340
+            }
341
+            $logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
342
+            self::loadLanguage($languageFilePath, $language);
343
+        }
344 344
 
345
-		/**
346
-		 * Return the current app language by default will use the value from cookie 
347
-		 * if can not found will use the default value from configuration
348
-		 * @return string the app language like "en", "fr"
349
-		 */
350
-		protected static function getAppLang(){
351
-			//determine the current language
352
-			$appLang = get_config('default_language');
353
-			//if the language exists in the cookie use it
354
-			$cfgKey = get_config('language_cookie_name');
355
-			$objCookie = & class_loader('Cookie');
356
-			$cookieLang = $objCookie->get($cfgKey);
357
-			if ($cookieLang){
358
-				$appLang = $cookieLang;
359
-			}
360
-			return $appLang;
361
-		}
362
-		/**
363
-		 * Get the module information for the model and library to load
364
-		 * @param  string $class the full class name like moduleName/className, className,
365
-		 * @return array        the module information
366
-		 * array(
367
-		 * 	'module'=> 'module_name'
368
-		 * 	'class' => 'class_name'
369
-		 * )
370
-		 */
371
-		protected static function getModuleInfoForModelLibrary($class){
372
-			$module = null;
373
-			$obj = & get_instance();
374
-			if (strpos($class, '/') !== false){
375
-				$path = explode('/', $class);
376
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
377
-					$module = $path[0];
378
-					$class = ucfirst($path[1]);
379
-				}
380
-			}
381
-			else{
382
-				$class = ucfirst($class);
383
-			}
384
-			if (! $module && !empty($obj->moduleName)){
385
-				$module = $obj->moduleName;
386
-			}
387
-			return array(
388
-						'class' => $class,
389
-						'module' => $module
390
-					);
391
-		}
345
+        /**
346
+         * Return the current app language by default will use the value from cookie 
347
+         * if can not found will use the default value from configuration
348
+         * @return string the app language like "en", "fr"
349
+         */
350
+        protected static function getAppLang(){
351
+            //determine the current language
352
+            $appLang = get_config('default_language');
353
+            //if the language exists in the cookie use it
354
+            $cfgKey = get_config('language_cookie_name');
355
+            $objCookie = & class_loader('Cookie');
356
+            $cookieLang = $objCookie->get($cfgKey);
357
+            if ($cookieLang){
358
+                $appLang = $cookieLang;
359
+            }
360
+            return $appLang;
361
+        }
362
+        /**
363
+         * Get the module information for the model and library to load
364
+         * @param  string $class the full class name like moduleName/className, className,
365
+         * @return array        the module information
366
+         * array(
367
+         * 	'module'=> 'module_name'
368
+         * 	'class' => 'class_name'
369
+         * )
370
+         */
371
+        protected static function getModuleInfoForModelLibrary($class){
372
+            $module = null;
373
+            $obj = & get_instance();
374
+            if (strpos($class, '/') !== false){
375
+                $path = explode('/', $class);
376
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
377
+                    $module = $path[0];
378
+                    $class = ucfirst($path[1]);
379
+                }
380
+            }
381
+            else{
382
+                $class = ucfirst($class);
383
+            }
384
+            if (! $module && !empty($obj->moduleName)){
385
+                $module = $obj->moduleName;
386
+            }
387
+            return array(
388
+                        'class' => $class,
389
+                        'module' => $module
390
+                    );
391
+        }
392 392
 
393
-		/**
394
-		 * Get the module information for the function to load
395
-		 * @param  string $function the function name like moduleName/functionName, functionName,
396
-		 * @return array        the module information
397
-		 * array(
398
-		 * 	'module'=> 'module_name'
399
-		 * 	'function' => 'function'
400
-		 * 	'file' => 'file'
401
-		 * )
402
-		 */
403
-		protected static function getModuleInfoForFunction($function){
404
-			$module = null;
405
-			$file = null;
406
-			$obj = & get_instance();
407
-			//check if the request class contains module name
408
-			if (strpos($function, '/') !== false){
409
-				$path = explode('/', $function);
410
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
411
-					$module = $path[0];
412
-					$function = 'function_' . $path[1];
413
-					$file = $path[0] . DS . $function.'.php';
414
-				}
415
-			}
416
-			if (! $module && !empty($obj->moduleName)){
417
-				$module = $obj->moduleName;
418
-			}
419
-			return array(
420
-						'function' => $function,
421
-						'module' => $module,
422
-						'file' => $file
423
-					);
424
-		}
393
+        /**
394
+         * Get the module information for the function to load
395
+         * @param  string $function the function name like moduleName/functionName, functionName,
396
+         * @return array        the module information
397
+         * array(
398
+         * 	'module'=> 'module_name'
399
+         * 	'function' => 'function'
400
+         * 	'file' => 'file'
401
+         * )
402
+         */
403
+        protected static function getModuleInfoForFunction($function){
404
+            $module = null;
405
+            $file = null;
406
+            $obj = & get_instance();
407
+            //check if the request class contains module name
408
+            if (strpos($function, '/') !== false){
409
+                $path = explode('/', $function);
410
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
411
+                    $module = $path[0];
412
+                    $function = 'function_' . $path[1];
413
+                    $file = $path[0] . DS . $function.'.php';
414
+                }
415
+            }
416
+            if (! $module && !empty($obj->moduleName)){
417
+                $module = $obj->moduleName;
418
+            }
419
+            return array(
420
+                        'function' => $function,
421
+                        'module' => $module,
422
+                        'file' => $file
423
+                    );
424
+        }
425 425
 
426
-		/**
427
-		 * Get the module information for the language to load
428
-		 * @param  string $language the language name like moduleName/languageName, languageName,
429
-		 * @return array        the module information
430
-		 * array(
431
-		 * 	'module'=> 'module_name'
432
-		 * 	'language' => 'language'
433
-		 * 	'file' => 'file'
434
-		 * )
435
-		 */
436
-		protected static function getModuleInfoForLanguage($language){
437
-			$module = null;
438
-			$file = null;
439
-			$obj = & get_instance();
440
-			//check if the request class contains module name
441
-			if (strpos($language, '/') !== false){
442
-				$path = explode('/', $language);
443
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
444
-					$module = $path[0];
445
-					$language = 'lang_' . $path[1] . '.php';
446
-					$file = $path[0] . DS .$language;
447
-				}
448
-			}
449
-			if (! $module && !empty($obj->moduleName)){
450
-				$module = $obj->moduleName;
451
-			}
452
-			return array(
453
-						'language' => $language,
454
-						'module' => $module,
455
-						'file' => $file
456
-					);
457
-		}
426
+        /**
427
+         * Get the module information for the language to load
428
+         * @param  string $language the language name like moduleName/languageName, languageName,
429
+         * @return array        the module information
430
+         * array(
431
+         * 	'module'=> 'module_name'
432
+         * 	'language' => 'language'
433
+         * 	'file' => 'file'
434
+         * )
435
+         */
436
+        protected static function getModuleInfoForLanguage($language){
437
+            $module = null;
438
+            $file = null;
439
+            $obj = & get_instance();
440
+            //check if the request class contains module name
441
+            if (strpos($language, '/') !== false){
442
+                $path = explode('/', $language);
443
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
444
+                    $module = $path[0];
445
+                    $language = 'lang_' . $path[1] . '.php';
446
+                    $file = $path[0] . DS .$language;
447
+                }
448
+            }
449
+            if (! $module && !empty($obj->moduleName)){
450
+                $module = $obj->moduleName;
451
+            }
452
+            return array(
453
+                        'language' => $language,
454
+                        'module' => $module,
455
+                        'file' => $file
456
+                    );
457
+        }
458 458
 
459 459
 
460
-		/**
461
-		 * Get the module information for the config to load
462
-		 * @param  string $filename the filename of the configuration file,
463
-		 * @return array        the module information
464
-		 * array(
465
-		 * 	'module'=> 'module_name'
466
-		 * 	'filename' => 'filename'
467
-		 * )
468
-		 */
469
-		protected static function getModuleInfoForConfig($filename){
470
-			$module = null;
471
-			$obj = & get_instance();
472
-			//check if the request class contains module name
473
-			if (strpos($filename, '/') !== false){
474
-				$path = explode('/', $filename);
475
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
476
-					$module = $path[0];
477
-					$filename = $path[1] . '.php';
478
-				}
479
-			}
480
-			if (! $module && !empty($obj->moduleName)){
481
-				$module = $obj->moduleName;
482
-			}
483
-			return array(
484
-						'filename' => $filename,
485
-						'module' => $module
486
-					);
487
-		}
460
+        /**
461
+         * Get the module information for the config to load
462
+         * @param  string $filename the filename of the configuration file,
463
+         * @return array        the module information
464
+         * array(
465
+         * 	'module'=> 'module_name'
466
+         * 	'filename' => 'filename'
467
+         * )
468
+         */
469
+        protected static function getModuleInfoForConfig($filename){
470
+            $module = null;
471
+            $obj = & get_instance();
472
+            //check if the request class contains module name
473
+            if (strpos($filename, '/') !== false){
474
+                $path = explode('/', $filename);
475
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
476
+                    $module = $path[0];
477
+                    $filename = $path[1] . '.php';
478
+                }
479
+            }
480
+            if (! $module && !empty($obj->moduleName)){
481
+                $module = $obj->moduleName;
482
+            }
483
+            return array(
484
+                        'filename' => $filename,
485
+                        'module' => $module
486
+                    );
487
+        }
488 488
 
489
-		/**
490
-		 * Get the name of model or library instance if is null
491
-		 * @param  string $class the class name to determine the instance
492
-		 * @return string        the instance name
493
-		 */
494
-		protected static function getModelLibraryInstanceName($class){
495
-			//for module
496
-			$instance = null;
497
-			if (strpos($class, '/') !== false){
498
-				$path = explode('/', $class);
499
-				if (isset($path[1])){
500
-					$instance = strtolower($path[1]);
501
-				}
502
-			}
503
-			else{
504
-				$instance = strtolower($class);
505
-			}
506
-			return $instance;
507
-		}
489
+        /**
490
+         * Get the name of model or library instance if is null
491
+         * @param  string $class the class name to determine the instance
492
+         * @return string        the instance name
493
+         */
494
+        protected static function getModelLibraryInstanceName($class){
495
+            //for module
496
+            $instance = null;
497
+            if (strpos($class, '/') !== false){
498
+                $path = explode('/', $class);
499
+                if (isset($path[1])){
500
+                    $instance = strtolower($path[1]);
501
+                }
502
+            }
503
+            else{
504
+                $instance = strtolower($class);
505
+            }
506
+            return $instance;
507
+        }
508 508
 
509
-		/**
510
-		 * Get the library file path using the module information
511
-		 * @param  string $class the class name
512
-		 * @return string|null        the library file path otherwise null will be returned
513
-		 */
514
-		protected static function getLibraryPathUsingModuleInfo($class){
515
-			$logger = static::getLogger();
516
-			$libraryFilePath = null;
517
-			$logger->debug('Checking library [' . $class . '] from module list ...');
518
-			$moduleInfo = self::getModuleInfoForModelLibrary($class);
519
-			$module = $moduleInfo['module'];
520
-			$class  = $moduleInfo['class'];
521
-			$moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
-			if ($moduleLibraryPath){
523
-				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
524
-				$libraryFilePath = $moduleLibraryPath;
525
-			}
526
-			else{
527
-				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528
-			}
529
-			return $libraryFilePath;
530
-		}
509
+        /**
510
+         * Get the library file path using the module information
511
+         * @param  string $class the class name
512
+         * @return string|null        the library file path otherwise null will be returned
513
+         */
514
+        protected static function getLibraryPathUsingModuleInfo($class){
515
+            $logger = static::getLogger();
516
+            $libraryFilePath = null;
517
+            $logger->debug('Checking library [' . $class . '] from module list ...');
518
+            $moduleInfo = self::getModuleInfoForModelLibrary($class);
519
+            $module = $moduleInfo['module'];
520
+            $class  = $moduleInfo['class'];
521
+            $moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
+            if ($moduleLibraryPath){
523
+                $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
524
+                $libraryFilePath = $moduleLibraryPath;
525
+            }
526
+            else{
527
+                $logger->info('Cannot find library [' . $class . '] from modules using the default location');
528
+            }
529
+            return $libraryFilePath;
530
+        }
531 531
 
532
-		/**
533
-		 * Load the library 
534
-		 * @param  string $libraryFilePath the file path of the library to load
535
-		 * @param  string $class           the class name
536
-		 * @param  string $instance        the instance
537
-		 * @param  array  $params          the parameter to use
538
-		 * @return void
539
-		 */
540
-		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
-			if ($libraryFilePath){
542
-				$logger = static::getLogger();
543
-				require_once $libraryFilePath;
544
-				if (class_exists($class)){
545
-					$c = $params ? new $class($params) : new $class();
546
-					$obj = & get_instance();
547
-					$obj->{$instance} = $c;
548
-					static::$loaded[$instance] = $class;
549
-					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550
-				}
551
-				else{
552
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
553
-				}
554
-			}
555
-			else{
556
-				show_error('Unable to find library class [' . $class . ']');
557
-			}
558
-		}
532
+        /**
533
+         * Load the library 
534
+         * @param  string $libraryFilePath the file path of the library to load
535
+         * @param  string $class           the class name
536
+         * @param  string $instance        the instance
537
+         * @param  array  $params          the parameter to use
538
+         * @return void
539
+         */
540
+        protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
+            if ($libraryFilePath){
542
+                $logger = static::getLogger();
543
+                require_once $libraryFilePath;
544
+                if (class_exists($class)){
545
+                    $c = $params ? new $class($params) : new $class();
546
+                    $obj = & get_instance();
547
+                    $obj->{$instance} = $c;
548
+                    static::$loaded[$instance] = $class;
549
+                    $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550
+                }
551
+                else{
552
+                    show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
553
+                }
554
+            }
555
+            else{
556
+                show_error('Unable to find library class [' . $class . ']');
557
+            }
558
+        }
559 559
 
560
-		/**
561
-		 * Load the language 
562
-		 * @param  string $languageFilePath the file path of the language to load
563
-		 * @param  string $language           the language name
564
-		 * @return void
565
-		 */
566
-		protected static function loadLanguage($languageFilePath, $language){
567
-			if ($languageFilePath){
568
-				$logger = static::getLogger();
569
-				$lang = array();
570
-				require_once $languageFilePath;
571
-				if (! empty($lang) && is_array($lang)){
572
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
573
-					//Note: may be here the class 'Lang' not yet loaded
574
-					$langObj =& class_loader('Lang', 'classes');
575
-					$langObj->addLangMessages($lang);
576
-					//free the memory
577
-					unset($lang);
578
-				}
579
-				static::$loaded['lang_' . $language] = $languageFilePath;
580
-				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581
-			}
582
-			else{
583
-				show_error('Unable to find language [' . $language . ']');
584
-			}
585
-		}
560
+        /**
561
+         * Load the language 
562
+         * @param  string $languageFilePath the file path of the language to load
563
+         * @param  string $language           the language name
564
+         * @return void
565
+         */
566
+        protected static function loadLanguage($languageFilePath, $language){
567
+            if ($languageFilePath){
568
+                $logger = static::getLogger();
569
+                $lang = array();
570
+                require_once $languageFilePath;
571
+                if (! empty($lang) && is_array($lang)){
572
+                    $logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
573
+                    //Note: may be here the class 'Lang' not yet loaded
574
+                    $langObj =& class_loader('Lang', 'classes');
575
+                    $langObj->addLangMessages($lang);
576
+                    //free the memory
577
+                    unset($lang);
578
+                }
579
+                static::$loaded['lang_' . $language] = $languageFilePath;
580
+                $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581
+            }
582
+            else{
583
+                show_error('Unable to find language [' . $language . ']');
584
+            }
585
+        }
586 586
 
587 587
 
588 588
 
589 589
 
590
-		/**
591
-		 * Get all the autoload using the configuration file
592
-		 * @return array
593
-		 */
594
-		private function getResourcesFromAutoloadConfig(){
595
-			$autoloads = array();
596
-			$autoloads['config']    = array();
597
-			$autoloads['languages'] = array();
598
-			$autoloads['libraries'] = array();
599
-			$autoloads['models']    = array();
600
-			$autoloads['functions'] = array();
601
-			//loading of the resources from autoload configuration file
602
-			if (file_exists(CONFIG_PATH . 'autoload.php')){
603
-				$autoload = array();
604
-				require_once CONFIG_PATH . 'autoload.php';
605
-				if (! empty($autoload) && is_array($autoload)){
606
-					$autoloads = array_merge($autoloads, $autoload);
607
-					unset($autoload);
608
-				}
609
-			}
610
-			//loading autoload configuration for modules
611
-			$modulesAutoloads = Module::getModulesAutoloadConfig();
612
-			if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
613
-				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
614
-			}
615
-			return $autoloads;
616
-		}
590
+        /**
591
+         * Get all the autoload using the configuration file
592
+         * @return array
593
+         */
594
+        private function getResourcesFromAutoloadConfig(){
595
+            $autoloads = array();
596
+            $autoloads['config']    = array();
597
+            $autoloads['languages'] = array();
598
+            $autoloads['libraries'] = array();
599
+            $autoloads['models']    = array();
600
+            $autoloads['functions'] = array();
601
+            //loading of the resources from autoload configuration file
602
+            if (file_exists(CONFIG_PATH . 'autoload.php')){
603
+                $autoload = array();
604
+                require_once CONFIG_PATH . 'autoload.php';
605
+                if (! empty($autoload) && is_array($autoload)){
606
+                    $autoloads = array_merge($autoloads, $autoload);
607
+                    unset($autoload);
608
+                }
609
+            }
610
+            //loading autoload configuration for modules
611
+            $modulesAutoloads = Module::getModulesAutoloadConfig();
612
+            if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
613
+                $autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
614
+            }
615
+            return $autoloads;
616
+        }
617 617
 
618
-		/**
619
-		 * Load the autoload configuration
620
-		 * @return void
621
-		 */
622
-		private function loadResourcesFromAutoloadConfig(){
623
-			$autoloads = array();
624
-			$autoloads['config']    = array();
625
-			$autoloads['languages'] = array();
626
-			$autoloads['libraries'] = array();
627
-			$autoloads['models']    = array();
628
-			$autoloads['functions'] = array();
618
+        /**
619
+         * Load the autoload configuration
620
+         * @return void
621
+         */
622
+        private function loadResourcesFromAutoloadConfig(){
623
+            $autoloads = array();
624
+            $autoloads['config']    = array();
625
+            $autoloads['languages'] = array();
626
+            $autoloads['libraries'] = array();
627
+            $autoloads['models']    = array();
628
+            $autoloads['functions'] = array();
629 629
 
630
-			$list = $this->getResourcesFromAutoloadConfig();
631
-			$autoloads = array_merge($autoloads, $list);
630
+            $list = $this->getResourcesFromAutoloadConfig();
631
+            $autoloads = array_merge($autoloads, $list);
632 632
 			
633
-			//config autoload
634
-			$this->loadAutoloadResourcesArray('config', $autoloads['config']);
633
+            //config autoload
634
+            $this->loadAutoloadResourcesArray('config', $autoloads['config']);
635 635
 			
636
-			//languages autoload
637
-			$this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
636
+            //languages autoload
637
+            $this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
638 638
 			
639
-			//libraries autoload
640
-			$this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
639
+            //libraries autoload
640
+            $this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
641 641
 
642
-			//models autoload
643
-			$this->loadAutoloadResourcesArray('model', $autoloads['models']);
642
+            //models autoload
643
+            $this->loadAutoloadResourcesArray('model', $autoloads['models']);
644 644
 			
645
-			//functions autoload
646
-			$this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
647
-		}
645
+            //functions autoload
646
+            $this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
647
+        }
648 648
 
649
-		/**
650
-		 * Load the resources autoload array
651
-		 * @param  string $method    this object method name to call
652
-		 * @param  array  $resources the resource to load
653
-		 * @return void            
654
-		 */
655
-		private function loadAutoloadResourcesArray($method, array $resources){
656
-			foreach ($resources as $name) {
657
-				$this->{$method}($name);
658
-			}
659
-		}
660
-	}
649
+        /**
650
+         * Load the resources autoload array
651
+         * @param  string $method    this object method name to call
652
+         * @param  array  $resources the resource to load
653
+         * @return void            
654
+         */
655
+        private function loadAutoloadResourcesArray($method, array $resources){
656
+            foreach ($resources as $name) {
657
+                $this->{$method}($name);
658
+            }
659
+        }
660
+    }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  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 Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 		 * The signleton of the logger
52 52
 		 * @return object the Log instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56 56
 				$logger = array();
57
-				$logger[0] =& class_loader('Log', 'classes');
57
+				$logger[0] = & class_loader('Log', 'classes');
58 58
 				$logger[0]->setLogger('Library::Loader');
59 59
 				self::$logger = $logger[0];
60 60
 			}
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		 * @param object $logger the log object
67 67
 		 * @return object the log instance
68 68
 		 */
69
-		public static function setLogger($logger){
69
+		public static function setLogger($logger) {
70 70
 			self::$logger = $logger;
71 71
 			return self::$logger;
72 72
 		}
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 		 *
81 81
 		 * @return void
82 82
 		 */
83
-		public static function model($class, $instance = null){
83
+		public static function model($class, $instance = null) {
84 84
 			$logger = static::getLogger();
85 85
 			$class = str_ireplace('.php', '', $class);
86 86
 			$class = trim($class, '/\\');
87
-			$file = ucfirst($class).'.php';
87
+			$file = ucfirst($class) . '.php';
88 88
 			$logger->debug('Loading model [' . $class . '] ...');
89 89
 			//************
90
-			if (! $instance){
90
+			if (!$instance) {
91 91
 				$instance = self::getModelLibraryInstanceName($class);
92 92
 			}
93 93
 			//****************
94
-			if (isset(static::$loaded[$instance])){
94
+			if (isset(static::$loaded[$instance])) {
95 95
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96 96
 				return;
97 97
 			}
@@ -104,28 +104,28 @@  discard block
 block discarded – undo
104 104
 			$class  = $moduleInfo['class'];
105 105
 			
106 106
 			$moduleModelFilePath = Module::findModelFullPath($class, $module);
107
-			if ($moduleModelFilePath){
108
-				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
107
+			if ($moduleModelFilePath) {
108
+				$logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it');
109 109
 				$classFilePath = $moduleModelFilePath;
110 110
 			}
111
-			else{
111
+			else {
112 112
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113 113
 			}
114 114
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
-			if (file_exists($classFilePath)){
115
+			if (file_exists($classFilePath)) {
116 116
 				require_once $classFilePath;
117
-				if (class_exists($class)){
117
+				if (class_exists($class)) {
118 118
 					$c = new $class();
119 119
 					$obj = & get_instance();
120 120
 					$obj->{$instance} = $c;
121 121
 					static::$loaded[$instance] = $class;
122 122
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123 123
 				}
124
-				else{
125
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
124
+				else {
125
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
126 126
 				}
127 127
 			}
128
-			else{
128
+			else {
129 129
 				show_error('Unable to find the model [' . $class . ']');
130 130
 			}
131 131
 		}
@@ -140,22 +140,22 @@  discard block
 block discarded – undo
140 140
 		 *
141 141
 		 * @return void
142 142
 		 */
143
-		public static function library($class, $instance = null, array $params = array()){
143
+		public static function library($class, $instance = null, array $params = array()) {
144 144
 			$logger = static::getLogger();
145 145
 			$class = str_ireplace('.php', '', $class);
146 146
 			$class = trim($class, '/\\');
147
-			$file = ucfirst($class) .'.php';
147
+			$file = ucfirst($class) . '.php';
148 148
 			$logger->debug('Loading library [' . $class . '] ...');
149
-			if (! $instance){
149
+			if (!$instance) {
150 150
 				$instance = self::getModelLibraryInstanceName($class);
151 151
 			}
152
-			if (isset(static::$loaded[$instance])){
152
+			if (isset(static::$loaded[$instance])) {
153 153
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154 154
 				return;
155 155
 			}
156 156
 			$obj = & get_instance();
157 157
 			//Check and load Database library
158
-			if (strtolower($class) == 'database'){
158
+			if (strtolower($class) == 'database') {
159 159
 				$logger->info('This is the Database library ...');
160 160
 				$obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161 161
 				static::$loaded[$instance] = $class;
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 			}
165 165
 			$libraryFilePath = null;
166 166
 			$logger->debug('Check if this is a system library ...');
167
-			if (file_exists(CORE_LIBRARY_PATH . $file)){
167
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
168 168
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169 169
 				$class = ucfirst($class);
170 170
 				$logger->info('This library is a system library');
171 171
 			}
172
-			else{
172
+			else {
173 173
 				$logger->info('This library is not a system library');	
174 174
 				//first check if this library is in the module
175 175
 				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176 176
 				//***************
177 177
 			}
178
-			if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
178
+			if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) {
179 179
 				$libraryFilePath = LIBRARY_PATH . $file;
180 180
 			}
181 181
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 		 *
191 191
 		 * @return void
192 192
 		 */
193
-		public static function functions($function){
193
+		public static function functions($function) {
194 194
 			$logger = static::getLogger();
195 195
 			$function = str_ireplace('.php', '', $function);
196 196
 			$function = trim($function, '/\\');
197 197
 			$function = str_ireplace('function_', '', $function);
198
-			$file = 'function_'.$function.'.php';
198
+			$file = 'function_' . $function . '.php';
199 199
 			$logger->debug('Loading helper [' . $function . '] ...');
200
-			if (isset(static::$loaded['function_' . $function])){
200
+			if (isset(static::$loaded['function_' . $function])) {
201 201
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202 202
 				return;
203 203
 			}
@@ -207,22 +207,22 @@  discard block
 block discarded – undo
207 207
 			$moduleInfo = self::getModuleInfoForFunction($function);
208 208
 			$module    = $moduleInfo['module'];
209 209
 			$function  = $moduleInfo['function'];
210
-			if(! empty($moduleInfo['file'])){
210
+			if (!empty($moduleInfo['file'])) {
211 211
 				$file = $moduleInfo['file'];
212 212
 			}
213 213
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
-			if ($moduleFunctionPath){
215
-				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
214
+			if ($moduleFunctionPath) {
215
+				$logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it');
216 216
 				$functionFilePath = $moduleFunctionPath;
217 217
 			}
218
-			else{
218
+			else {
219 219
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220 220
 			}
221
-			if (! $functionFilePath){
221
+			if (!$functionFilePath) {
222 222
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
-				foreach($searchDir as $dir){
223
+				foreach ($searchDir as $dir) {
224 224
 					$filePath = $dir . $file;
225
-					if (file_exists($filePath)){
225
+					if (file_exists($filePath)) {
226 226
 						$functionFilePath = $filePath;
227 227
 						//is already found not to continue
228 228
 						break;
@@ -230,12 +230,12 @@  discard block
 block discarded – undo
230 230
 				}
231 231
 			}
232 232
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
-			if ($functionFilePath){
233
+			if ($functionFilePath) {
234 234
 				require_once $functionFilePath;
235 235
 				static::$loaded['function_' . $function] = $functionFilePath;
236 236
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237 237
 			}
238
-			else{
238
+			else {
239 239
 				show_error('Unable to find helper file [' . $file . ']');
240 240
 			}
241 241
 		}
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
 		 *
248 248
 		 * @return void
249 249
 		 */
250
-		public static function config($filename){
250
+		public static function config($filename) {
251 251
 			$logger = static::getLogger();
252 252
 			$filename = str_ireplace('.php', '', $filename);
253 253
 			$filename = trim($filename, '/\\');
254 254
 			$filename = str_ireplace('config_', '', $filename);
255
-			$file = 'config_'.$filename.'.php';
255
+			$file = 'config_' . $filename . '.php';
256 256
 			$logger->debug('Loading configuration [' . $filename . '] ...');
257
-			if (isset(static::$loaded['config_' . $filename])){
257
+			if (isset(static::$loaded['config_' . $filename])) {
258 258
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259 259
 				return;
260 260
 			}
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 			$module    = $moduleInfo['module'];
266 266
 			$filename  = $moduleInfo['filename'];
267 267
 			$moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
-			if ($moduleConfigPath){
269
-				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
268
+			if ($moduleConfigPath) {
269
+				$logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it');
270 270
 				$configFilePath = $moduleConfigPath;
271 271
 			}
272
-			else{
272
+			else {
273 273
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274 274
 			}
275 275
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276 276
 			$config = array();
277
-			if (file_exists($configFilePath)){
277
+			if (file_exists($configFilePath)) {
278 278
 				require_once $configFilePath;
279
-				if (! empty($config) && is_array($config)){
279
+				if (!empty($config) && is_array($config)) {
280 280
 					Config::setAll($config);
281 281
 					static::$loaded['config_' . $filename] = $configFilePath;
282 282
 					$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 					unset($config);
285 285
 				}
286 286
 			}
287
-			else{
288
-				show_error('Unable to find config file ['. $configFilePath . ']');
287
+			else {
288
+				show_error('Unable to find config file [' . $configFilePath . ']');
289 289
 			}
290 290
 		}
291 291
 
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
 		 *
298 298
 		 * @return void
299 299
 		 */
300
-		public static function lang($language){
300
+		public static function lang($language) {
301 301
 			$logger = static::getLogger();
302 302
 			$language = str_ireplace('.php', '', $language);
303 303
 			$language = trim($language, '/\\');
304 304
 			$language = str_ireplace('lang_', '', $language);
305
-			$file = 'lang_'.$language.'.php';
305
+			$file = 'lang_' . $language . '.php';
306 306
 			$logger->debug('Loading language [' . $language . '] ...');
307
-			if (isset(static::$loaded['lang_' . $language])){
307
+			if (isset(static::$loaded['lang_' . $language])) {
308 308
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309 309
 				return;
310 310
 			}
@@ -316,22 +316,22 @@  discard block
 block discarded – undo
316 316
 			$moduleInfo = self::getModuleInfoForLanguage($language);
317 317
 			$module    = $moduleInfo['module'];
318 318
 			$language  = $moduleInfo['language'];
319
-			if(! empty($moduleInfo['file'])){
319
+			if (!empty($moduleInfo['file'])) {
320 320
 				$file = $moduleInfo['file'];
321 321
 			}
322 322
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
-			if ($moduleLanguagePath){
324
-				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
323
+			if ($moduleLanguagePath) {
324
+				$logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it');
325 325
 				$languageFilePath = $moduleLanguagePath;
326 326
 			}
327
-			else{
327
+			else {
328 328
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329 329
 			}
330
-			if (! $languageFilePath){
330
+			if (!$languageFilePath) {
331 331
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
-				foreach($searchDir as $dir){
332
+				foreach ($searchDir as $dir) {
333 333
 					$filePath = $dir . $appLang . DS . $file;
334
-					if (file_exists($filePath)){
334
+					if (file_exists($filePath)) {
335 335
 						$languageFilePath = $filePath;
336 336
 						//already found no need continue
337 337
 						break;
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 		 * if can not found will use the default value from configuration
348 348
 		 * @return string the app language like "en", "fr"
349 349
 		 */
350
-		protected static function getAppLang(){
350
+		protected static function getAppLang() {
351 351
 			//determine the current language
352 352
 			$appLang = get_config('default_language');
353 353
 			//if the language exists in the cookie use it
354 354
 			$cfgKey = get_config('language_cookie_name');
355 355
 			$objCookie = & class_loader('Cookie');
356 356
 			$cookieLang = $objCookie->get($cfgKey);
357
-			if ($cookieLang){
357
+			if ($cookieLang) {
358 358
 				$appLang = $cookieLang;
359 359
 			}
360 360
 			return $appLang;
@@ -368,20 +368,20 @@  discard block
 block discarded – undo
368 368
 		 * 	'class' => 'class_name'
369 369
 		 * )
370 370
 		 */
371
-		protected static function getModuleInfoForModelLibrary($class){
371
+		protected static function getModuleInfoForModelLibrary($class) {
372 372
 			$module = null;
373 373
 			$obj = & get_instance();
374
-			if (strpos($class, '/') !== false){
374
+			if (strpos($class, '/') !== false) {
375 375
 				$path = explode('/', $class);
376
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
376
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
377 377
 					$module = $path[0];
378 378
 					$class = ucfirst($path[1]);
379 379
 				}
380 380
 			}
381
-			else{
381
+			else {
382 382
 				$class = ucfirst($class);
383 383
 			}
384
-			if (! $module && !empty($obj->moduleName)){
384
+			if (!$module && !empty($obj->moduleName)) {
385 385
 				$module = $obj->moduleName;
386 386
 			}
387 387
 			return array(
@@ -400,20 +400,20 @@  discard block
 block discarded – undo
400 400
 		 * 	'file' => 'file'
401 401
 		 * )
402 402
 		 */
403
-		protected static function getModuleInfoForFunction($function){
403
+		protected static function getModuleInfoForFunction($function) {
404 404
 			$module = null;
405 405
 			$file = null;
406 406
 			$obj = & get_instance();
407 407
 			//check if the request class contains module name
408
-			if (strpos($function, '/') !== false){
408
+			if (strpos($function, '/') !== false) {
409 409
 				$path = explode('/', $function);
410
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
410
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
411 411
 					$module = $path[0];
412 412
 					$function = 'function_' . $path[1];
413
-					$file = $path[0] . DS . $function.'.php';
413
+					$file = $path[0] . DS . $function . '.php';
414 414
 				}
415 415
 			}
416
-			if (! $module && !empty($obj->moduleName)){
416
+			if (!$module && !empty($obj->moduleName)) {
417 417
 				$module = $obj->moduleName;
418 418
 			}
419 419
 			return array(
@@ -433,20 +433,20 @@  discard block
 block discarded – undo
433 433
 		 * 	'file' => 'file'
434 434
 		 * )
435 435
 		 */
436
-		protected static function getModuleInfoForLanguage($language){
436
+		protected static function getModuleInfoForLanguage($language) {
437 437
 			$module = null;
438 438
 			$file = null;
439 439
 			$obj = & get_instance();
440 440
 			//check if the request class contains module name
441
-			if (strpos($language, '/') !== false){
441
+			if (strpos($language, '/') !== false) {
442 442
 				$path = explode('/', $language);
443
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
443
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
444 444
 					$module = $path[0];
445 445
 					$language = 'lang_' . $path[1] . '.php';
446
-					$file = $path[0] . DS .$language;
446
+					$file = $path[0] . DS . $language;
447 447
 				}
448 448
 			}
449
-			if (! $module && !empty($obj->moduleName)){
449
+			if (!$module && !empty($obj->moduleName)) {
450 450
 				$module = $obj->moduleName;
451 451
 			}
452 452
 			return array(
@@ -466,18 +466,18 @@  discard block
 block discarded – undo
466 466
 		 * 	'filename' => 'filename'
467 467
 		 * )
468 468
 		 */
469
-		protected static function getModuleInfoForConfig($filename){
469
+		protected static function getModuleInfoForConfig($filename) {
470 470
 			$module = null;
471 471
 			$obj = & get_instance();
472 472
 			//check if the request class contains module name
473
-			if (strpos($filename, '/') !== false){
473
+			if (strpos($filename, '/') !== false) {
474 474
 				$path = explode('/', $filename);
475
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
475
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
476 476
 					$module = $path[0];
477 477
 					$filename = $path[1] . '.php';
478 478
 				}
479 479
 			}
480
-			if (! $module && !empty($obj->moduleName)){
480
+			if (!$module && !empty($obj->moduleName)) {
481 481
 				$module = $obj->moduleName;
482 482
 			}
483 483
 			return array(
@@ -491,16 +491,16 @@  discard block
 block discarded – undo
491 491
 		 * @param  string $class the class name to determine the instance
492 492
 		 * @return string        the instance name
493 493
 		 */
494
-		protected static function getModelLibraryInstanceName($class){
494
+		protected static function getModelLibraryInstanceName($class) {
495 495
 			//for module
496 496
 			$instance = null;
497
-			if (strpos($class, '/') !== false){
497
+			if (strpos($class, '/') !== false) {
498 498
 				$path = explode('/', $class);
499
-				if (isset($path[1])){
499
+				if (isset($path[1])) {
500 500
 					$instance = strtolower($path[1]);
501 501
 				}
502 502
 			}
503
-			else{
503
+			else {
504 504
 				$instance = strtolower($class);
505 505
 			}
506 506
 			return $instance;
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		 * @param  string $class the class name
512 512
 		 * @return string|null        the library file path otherwise null will be returned
513 513
 		 */
514
-		protected static function getLibraryPathUsingModuleInfo($class){
514
+		protected static function getLibraryPathUsingModuleInfo($class) {
515 515
 			$logger = static::getLogger();
516 516
 			$libraryFilePath = null;
517 517
 			$logger->debug('Checking library [' . $class . '] from module list ...');
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
 			$module = $moduleInfo['module'];
520 520
 			$class  = $moduleInfo['class'];
521 521
 			$moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
-			if ($moduleLibraryPath){
523
-				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
522
+			if ($moduleLibraryPath) {
523
+				$logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it');
524 524
 				$libraryFilePath = $moduleLibraryPath;
525 525
 			}
526
-			else{
526
+			else {
527 527
 				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528 528
 			}
529 529
 			return $libraryFilePath;
@@ -537,22 +537,22 @@  discard block
 block discarded – undo
537 537
 		 * @param  array  $params          the parameter to use
538 538
 		 * @return void
539 539
 		 */
540
-		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
-			if ($libraryFilePath){
540
+		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) {
541
+			if ($libraryFilePath) {
542 542
 				$logger = static::getLogger();
543 543
 				require_once $libraryFilePath;
544
-				if (class_exists($class)){
544
+				if (class_exists($class)) {
545 545
 					$c = $params ? new $class($params) : new $class();
546 546
 					$obj = & get_instance();
547 547
 					$obj->{$instance} = $c;
548 548
 					static::$loaded[$instance] = $class;
549 549
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550 550
 				}
551
-				else{
552
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
551
+				else {
552
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
553 553
 				}
554 554
 			}
555
-			else{
555
+			else {
556 556
 				show_error('Unable to find library class [' . $class . ']');
557 557
 			}
558 558
 		}
@@ -563,15 +563,15 @@  discard block
 block discarded – undo
563 563
 		 * @param  string $language           the language name
564 564
 		 * @return void
565 565
 		 */
566
-		protected static function loadLanguage($languageFilePath, $language){
567
-			if ($languageFilePath){
566
+		protected static function loadLanguage($languageFilePath, $language) {
567
+			if ($languageFilePath) {
568 568
 				$logger = static::getLogger();
569 569
 				$lang = array();
570 570
 				require_once $languageFilePath;
571
-				if (! empty($lang) && is_array($lang)){
572
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
571
+				if (!empty($lang) && is_array($lang)) {
572
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
573 573
 					//Note: may be here the class 'Lang' not yet loaded
574
-					$langObj =& class_loader('Lang', 'classes');
574
+					$langObj = & class_loader('Lang', 'classes');
575 575
 					$langObj->addLangMessages($lang);
576 576
 					//free the memory
577 577
 					unset($lang);
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 				static::$loaded['lang_' . $language] = $languageFilePath;
580 580
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581 581
 			}
582
-			else{
582
+			else {
583 583
 				show_error('Unable to find language [' . $language . ']');
584 584
 			}
585 585
 		}
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 		 * Get all the autoload using the configuration file
592 592
 		 * @return array
593 593
 		 */
594
-		private function getResourcesFromAutoloadConfig(){
594
+		private function getResourcesFromAutoloadConfig() {
595 595
 			$autoloads = array();
596 596
 			$autoloads['config']    = array();
597 597
 			$autoloads['languages'] = array();
@@ -599,17 +599,17 @@  discard block
 block discarded – undo
599 599
 			$autoloads['models']    = array();
600 600
 			$autoloads['functions'] = array();
601 601
 			//loading of the resources from autoload configuration file
602
-			if (file_exists(CONFIG_PATH . 'autoload.php')){
602
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
603 603
 				$autoload = array();
604 604
 				require_once CONFIG_PATH . 'autoload.php';
605
-				if (! empty($autoload) && is_array($autoload)){
605
+				if (!empty($autoload) && is_array($autoload)) {
606 606
 					$autoloads = array_merge($autoloads, $autoload);
607 607
 					unset($autoload);
608 608
 				}
609 609
 			}
610 610
 			//loading autoload configuration for modules
611 611
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
612
-			if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
612
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
613 613
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
614 614
 			}
615 615
 			return $autoloads;
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 		 * Load the autoload configuration
620 620
 		 * @return void
621 621
 		 */
622
-		private function loadResourcesFromAutoloadConfig(){
622
+		private function loadResourcesFromAutoloadConfig() {
623 623
 			$autoloads = array();
624 624
 			$autoloads['config']    = array();
625 625
 			$autoloads['languages'] = array();
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 		 * @param  array  $resources the resource to load
653 653
 		 * @return void            
654 654
 		 */
655
-		private function loadAutoloadResourcesArray($method, array $resources){
655
+		private function loadAutoloadResourcesArray($method, array $resources) {
656 656
 			foreach ($resources as $name) {
657 657
 				$this->{$method}($name);
658 658
 			}
Please login to merge, or discard this patch.
Braces   +15 added lines, -30 removed lines patch added patch discarded remove patch
@@ -107,8 +107,7 @@  discard block
 block discarded – undo
107 107
 			if ($moduleModelFilePath){
108 108
 				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
109 109
 				$classFilePath = $moduleModelFilePath;
110
-			}
111
-			else{
110
+			} else{
112 111
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113 112
 			}
114 113
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
@@ -120,12 +119,10 @@  discard block
 block discarded – undo
120 119
 					$obj->{$instance} = $c;
121 120
 					static::$loaded[$instance] = $class;
122 121
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123
-				}
124
-				else{
122
+				} else{
125 123
 					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
126 124
 				}
127
-			}
128
-			else{
125
+			} else{
129 126
 				show_error('Unable to find the model [' . $class . ']');
130 127
 			}
131 128
 		}
@@ -168,8 +165,7 @@  discard block
 block discarded – undo
168 165
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169 166
 				$class = ucfirst($class);
170 167
 				$logger->info('This library is a system library');
171
-			}
172
-			else{
168
+			} else{
173 169
 				$logger->info('This library is not a system library');	
174 170
 				//first check if this library is in the module
175 171
 				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
@@ -214,8 +210,7 @@  discard block
 block discarded – undo
214 210
 			if ($moduleFunctionPath){
215 211
 				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
216 212
 				$functionFilePath = $moduleFunctionPath;
217
-			}
218
-			else{
213
+			} else{
219 214
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220 215
 			}
221 216
 			if (! $functionFilePath){
@@ -234,8 +229,7 @@  discard block
 block discarded – undo
234 229
 				require_once $functionFilePath;
235 230
 				static::$loaded['function_' . $function] = $functionFilePath;
236 231
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237
-			}
238
-			else{
232
+			} else{
239 233
 				show_error('Unable to find helper file [' . $file . ']');
240 234
 			}
241 235
 		}
@@ -268,8 +262,7 @@  discard block
 block discarded – undo
268 262
 			if ($moduleConfigPath){
269 263
 				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
270 264
 				$configFilePath = $moduleConfigPath;
271
-			}
272
-			else{
265
+			} else{
273 266
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274 267
 			}
275 268
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
@@ -283,8 +276,7 @@  discard block
 block discarded – undo
283 276
 					$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
284 277
 					unset($config);
285 278
 				}
286
-			}
287
-			else{
279
+			} else{
288 280
 				show_error('Unable to find config file ['. $configFilePath . ']');
289 281
 			}
290 282
 		}
@@ -323,8 +315,7 @@  discard block
 block discarded – undo
323 315
 			if ($moduleLanguagePath){
324 316
 				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
325 317
 				$languageFilePath = $moduleLanguagePath;
326
-			}
327
-			else{
318
+			} else{
328 319
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329 320
 			}
330 321
 			if (! $languageFilePath){
@@ -377,8 +368,7 @@  discard block
 block discarded – undo
377 368
 					$module = $path[0];
378 369
 					$class = ucfirst($path[1]);
379 370
 				}
380
-			}
381
-			else{
371
+			} else{
382 372
 				$class = ucfirst($class);
383 373
 			}
384 374
 			if (! $module && !empty($obj->moduleName)){
@@ -499,8 +489,7 @@  discard block
 block discarded – undo
499 489
 				if (isset($path[1])){
500 490
 					$instance = strtolower($path[1]);
501 491
 				}
502
-			}
503
-			else{
492
+			} else{
504 493
 				$instance = strtolower($class);
505 494
 			}
506 495
 			return $instance;
@@ -522,8 +511,7 @@  discard block
 block discarded – undo
522 511
 			if ($moduleLibraryPath){
523 512
 				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
524 513
 				$libraryFilePath = $moduleLibraryPath;
525
-			}
526
-			else{
514
+			} else{
527 515
 				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528 516
 			}
529 517
 			return $libraryFilePath;
@@ -547,12 +535,10 @@  discard block
 block discarded – undo
547 535
 					$obj->{$instance} = $c;
548 536
 					static::$loaded[$instance] = $class;
549 537
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550
-				}
551
-				else{
538
+				} else{
552 539
 					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
553 540
 				}
554
-			}
555
-			else{
541
+			} else{
556 542
 				show_error('Unable to find library class [' . $class . ']');
557 543
 			}
558 544
 		}
@@ -578,8 +564,7 @@  discard block
 block discarded – undo
578 564
 				}
579 565
 				static::$loaded['lang_' . $language] = $languageFilePath;
580 566
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581
-			}
582
-			else{
567
+			} else{
583 568
 				show_error('Unable to find language [' . $language . ']');
584 569
 			}
585 570
 		}
Please login to merge, or discard this patch.
core/classes/Log.php 2 patches
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -1,297 +1,297 @@
 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 Log{
27
+    class Log{
28 28
 		
29
-		/**
30
-		 * The defined constante for Log level
31
-		 */
32
-		const NONE = 99999999;
33
-		const FATAL = 500;
34
-		const ERROR = 400;
35
-		const WARNING = 300;
36
-		const INFO = 200;
37
-		const DEBUG = 100;
38
-		const ALL = -99999999;
29
+        /**
30
+         * The defined constante for Log level
31
+         */
32
+        const NONE = 99999999;
33
+        const FATAL = 500;
34
+        const ERROR = 400;
35
+        const WARNING = 300;
36
+        const INFO = 200;
37
+        const DEBUG = 100;
38
+        const ALL = -99999999;
39 39
 
40
-		/**
41
-		 * The logger name
42
-		 * @var string
43
-		 */
44
-		private $logger = 'ROOT_LOGGER';
40
+        /**
41
+         * The logger name
42
+         * @var string
43
+         */
44
+        private $logger = 'ROOT_LOGGER';
45 45
 		
46
-		/**
47
-		 * List of valid log level to be checked for the configuration
48
-		 * @var array
49
-		 */
50
-		private static $validConfigLevel = array('off', 'none', 'fatal', 'error', 'warning', 'warn', 'info', 'debug', 'all');
46
+        /**
47
+         * List of valid log level to be checked for the configuration
48
+         * @var array
49
+         */
50
+        private static $validConfigLevel = array('off', 'none', 'fatal', 'error', 'warning', 'warn', 'info', 'debug', 'all');
51 51
 
52
-		/**
53
-		 * Create new Log instance
54
-		 */
55
-		public function __construct(){
56
-		}
52
+        /**
53
+         * Create new Log instance
54
+         */
55
+        public function __construct(){
56
+        }
57 57
 
58
-		/**
59
-		 * Set the logger to identify each message in the log
60
-		 * @param string $logger the logger name
61
-		 */
62
-		public  function setLogger($logger){
63
-			$this->logger = $logger;
64
-		}
58
+        /**
59
+         * Set the logger to identify each message in the log
60
+         * @param string $logger the logger name
61
+         */
62
+        public  function setLogger($logger){
63
+            $this->logger = $logger;
64
+        }
65 65
 
66
-		/**
67
-		 * Save the fatal message in the log
68
-		 * @see Log::writeLog for more detail
69
-		 * @param  string $message the log message to save
70
-		 */
71
-		public function fatal($message){
72
-			$this->writeLog($message, self::FATAL);
73
-		} 
66
+        /**
67
+         * Save the fatal message in the log
68
+         * @see Log::writeLog for more detail
69
+         * @param  string $message the log message to save
70
+         */
71
+        public function fatal($message){
72
+            $this->writeLog($message, self::FATAL);
73
+        } 
74 74
 		
75
-		/**
76
-		 * Save the error message in the log
77
-		 * @see Log::writeLog for more detail
78
-		 * @param  string $message the log message to save
79
-		 */
80
-		public function error($message){
81
-			$this->writeLog($message, self::ERROR);
82
-		} 
75
+        /**
76
+         * Save the error message in the log
77
+         * @see Log::writeLog for more detail
78
+         * @param  string $message the log message to save
79
+         */
80
+        public function error($message){
81
+            $this->writeLog($message, self::ERROR);
82
+        } 
83 83
 
84
-		/**
85
-		 * Save the warning message in the log
86
-		 * @see Log::writeLog for more detail
87
-		 * @param  string $message the log message to save
88
-		 */
89
-		public function warning($message){
90
-			$this->writeLog($message, self::WARNING);
91
-		} 
84
+        /**
85
+         * Save the warning message in the log
86
+         * @see Log::writeLog for more detail
87
+         * @param  string $message the log message to save
88
+         */
89
+        public function warning($message){
90
+            $this->writeLog($message, self::WARNING);
91
+        } 
92 92
 		
93
-		/**
94
-		 * Save the info message in the log
95
-		 * @see Log::writeLog for more detail
96
-		 * @param  string $message the log message to save
97
-		 */
98
-		public function info($message){
99
-			$this->writeLog($message, self::INFO);
100
-		} 
93
+        /**
94
+         * Save the info message in the log
95
+         * @see Log::writeLog for more detail
96
+         * @param  string $message the log message to save
97
+         */
98
+        public function info($message){
99
+            $this->writeLog($message, self::INFO);
100
+        } 
101 101
 		
102
-		/**
103
-		 * Save the debug message in the log
104
-		 * @see Log::writeLog for more detail
105
-		 * @param  string $message the log message to save
106
-		 */
107
-		public function debug($message){
108
-			$this->writeLog($message, self::DEBUG);
109
-		} 
102
+        /**
103
+         * Save the debug message in the log
104
+         * @see Log::writeLog for more detail
105
+         * @param  string $message the log message to save
106
+         */
107
+        public function debug($message){
108
+            $this->writeLog($message, self::DEBUG);
109
+        } 
110 110
 		
111 111
 		
112
-		/**
113
-		 * Save the log message
114
-		 * @param  string $message the log message to be saved
115
-		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116
-		 * to allow check the log level threshold.
117
-		 */
118
-		public function writeLog($message, $level = self::INFO){
119
-			$configLogLevel = get_config('log_level');
120
-			if(! $configLogLevel){
121
-				//so means no need log just stop here
122
-				return;
123
-			}
124
-			//check config log level
125
-			if(! self::isValidConfigLevel($configLogLevel)){
126
-				//NOTE: here need put the show_error() "logging" to false to prevent loop
127
-				show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128
-			}
112
+        /**
113
+         * Save the log message
114
+         * @param  string $message the log message to be saved
115
+         * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116
+         * to allow check the log level threshold.
117
+         */
118
+        public function writeLog($message, $level = self::INFO){
119
+            $configLogLevel = get_config('log_level');
120
+            if(! $configLogLevel){
121
+                //so means no need log just stop here
122
+                return;
123
+            }
124
+            //check config log level
125
+            if(! self::isValidConfigLevel($configLogLevel)){
126
+                //NOTE: here need put the show_error() "logging" to false to prevent loop
127
+                show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128
+            }
129 129
 			
130
-			//check if config log_logger_name and current log can save log data
131
-			if(! $this->canSaveLogDataForLogger()){
132
-				return;
133
-			}
130
+            //check if config log_logger_name and current log can save log data
131
+            if(! $this->canSaveLogDataForLogger()){
132
+                return;
133
+            }
134 134
 			
135
-			//if $level is not an integer
136
-			if(! is_numeric($level)){
137
-				$level = self::getLevelValue($level);
138
-			}
135
+            //if $level is not an integer
136
+            if(! is_numeric($level)){
137
+                $level = self::getLevelValue($level);
138
+            }
139 139
 			
140
-			//check if can logging regarding the log level config
141
-			$configLevel = self::getLevelValue($configLogLevel);
142
-			if($configLevel > $level){
143
-				//can't log
144
-				return;
145
-			}
146
-			//check log file and directory
147
-			$path = $this->checkAndSetLogFileDirectory();
148
-			//save the log data
149
-			$this->saveLogData($path, $level, $message);
150
-		}	
140
+            //check if can logging regarding the log level config
141
+            $configLevel = self::getLevelValue($configLogLevel);
142
+            if($configLevel > $level){
143
+                //can't log
144
+                return;
145
+            }
146
+            //check log file and directory
147
+            $path = $this->checkAndSetLogFileDirectory();
148
+            //save the log data
149
+            $this->saveLogData($path, $level, $message);
150
+        }	
151 151
 
152
-		/**
153
-		 * Save the log data into file
154
-		 * @param  string $path    the path of the log file
155
-		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
156
-		 * @param  string $message the log message to save
157
-		 * @return void
158
-		 */
159
-		protected function saveLogData($path, $level, $message){
160
-			//may be at this time helper user_agent not yet included
161
-			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
152
+        /**
153
+         * Save the log data into file
154
+         * @param  string $path    the path of the log file
155
+         * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
156
+         * @param  string $message the log message to save
157
+         * @return void
158
+         */
159
+        protected function saveLogData($path, $level, $message){
160
+            //may be at this time helper user_agent not yet included
161
+            require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
162 162
 			
163
-			///////////////////// date //////////////
164
-			$timestampWithMicro = microtime(true);
165
-			$microtime = sprintf('%06d', ($timestampWithMicro - floor($timestampWithMicro)) * 1000000);
166
-			$dateTime = new DateTime(date('Y-m-d H:i:s.' . $microtime, $timestampWithMicro));
167
-			$logDate = $dateTime->format('Y-m-d H:i:s.u'); 
168
-			//ip
169
-			$ip = get_ip();
163
+            ///////////////////// date //////////////
164
+            $timestampWithMicro = microtime(true);
165
+            $microtime = sprintf('%06d', ($timestampWithMicro - floor($timestampWithMicro)) * 1000000);
166
+            $dateTime = new DateTime(date('Y-m-d H:i:s.' . $microtime, $timestampWithMicro));
167
+            $logDate = $dateTime->format('Y-m-d H:i:s.u'); 
168
+            //ip
169
+            $ip = get_ip();
170 170
 			
171
-			//if $level is not an integer
172
-			if(! is_numeric($level)){
173
-				$level = self::getLevelValue($level);
174
-			}
171
+            //if $level is not an integer
172
+            if(! is_numeric($level)){
173
+                $level = self::getLevelValue($level);
174
+            }
175 175
 
176
-			//level name
177
-			$levelName = self::getLevelName($level);
176
+            //level name
177
+            $levelName = self::getLevelName($level);
178 178
 			
179
-			//debug info
180
-			$dtrace = debug_backtrace();
181
-			$fileInfo = $dtrace[0]['file'] == __FILE__ ? $dtrace[1] : $dtrace[0];
179
+            //debug info
180
+            $dtrace = debug_backtrace();
181
+            $fileInfo = $dtrace[0]['file'] == __FILE__ ? $dtrace[1] : $dtrace[0];
182 182
 			
183
-			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
184
-			$fp = fopen($path, 'a+');
185
-			if(is_resource($fp)){
186
-				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
187
-				fwrite($fp, $str);
188
-				fclose($fp);
189
-			}
190
-		}	
183
+            $str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
184
+            $fp = fopen($path, 'a+');
185
+            if(is_resource($fp)){
186
+                flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
187
+                fwrite($fp, $str);
188
+                fclose($fp);
189
+            }
190
+        }	
191 191
 
192
-		/**
193
-		 * Check if the current logger can save log data regarding the configuration
194
-		 * of logger filter
195
-		 * @return boolean
196
-		 */
197
-		protected function canSaveLogDataForLogger(){
198
-			if(! empty($this->logger)){
199
-				$configLoggersName = get_config('log_logger_name', array());
200
-				if (!empty($configLoggersName)) {
201
-					//for best comparaison put all string to lowercase
202
-					$configLoggersName = array_map('strtolower', $configLoggersName);
203
-					if(! in_array(strtolower($this->logger), $configLoggersName)){
204
-						return false;
205
-					}
206
-				}
207
-			}
208
-			return true;
209
-		}
192
+        /**
193
+         * Check if the current logger can save log data regarding the configuration
194
+         * of logger filter
195
+         * @return boolean
196
+         */
197
+        protected function canSaveLogDataForLogger(){
198
+            if(! empty($this->logger)){
199
+                $configLoggersName = get_config('log_logger_name', array());
200
+                if (!empty($configLoggersName)) {
201
+                    //for best comparaison put all string to lowercase
202
+                    $configLoggersName = array_map('strtolower', $configLoggersName);
203
+                    if(! in_array(strtolower($this->logger), $configLoggersName)){
204
+                        return false;
205
+                    }
206
+                }
207
+            }
208
+            return true;
209
+        }
210 210
 
211
-		/**
212
-		 * Check the file and directory 
213
-		 * @return string the log file path
214
-		 */
215
-		protected function checkAndSetLogFileDirectory(){
216
-			$logSavePath = get_config('log_save_path');
217
-			if(! $logSavePath){
218
-				$logSavePath = LOGS_PATH;
219
-			}
211
+        /**
212
+         * Check the file and directory 
213
+         * @return string the log file path
214
+         */
215
+        protected function checkAndSetLogFileDirectory(){
216
+            $logSavePath = get_config('log_save_path');
217
+            if(! $logSavePath){
218
+                $logSavePath = LOGS_PATH;
219
+            }
220 220
 			
221
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
222
-				//NOTE: here need put the show_error() "logging" to false to prevent loop
223
-				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
224
-			}
221
+            if(! is_dir($logSavePath) || !is_writable($logSavePath)){
222
+                //NOTE: here need put the show_error() "logging" to false to prevent loop
223
+                show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
224
+            }
225 225
 			
226
-			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
227
-			if(! file_exists($path)){
228
-				touch($path);
229
-			}
230
-			return $path;
231
-		}
226
+            $path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
227
+            if(! file_exists($path)){
228
+                touch($path);
229
+            }
230
+            return $path;
231
+        }
232 232
 		
233
-		/**
234
-		 * Check if the given log level is valid
235
-		 *
236
-		 * @param  string  $level the log level
237
-		 *
238
-		 * @return boolean        true if the given log level is valid, false if not
239
-		 */
240
-		protected static function isValidConfigLevel($level){
241
-			$level = strtolower($level);
242
-			return in_array($level, self::$validConfigLevel);
243
-		}
233
+        /**
234
+         * Check if the given log level is valid
235
+         *
236
+         * @param  string  $level the log level
237
+         *
238
+         * @return boolean        true if the given log level is valid, false if not
239
+         */
240
+        protected static function isValidConfigLevel($level){
241
+            $level = strtolower($level);
242
+            return in_array($level, self::$validConfigLevel);
243
+        }
244 244
 
245
-		/**
246
-		 * Get the log level number for the given level string
247
-		 * @param  string $level the log level in string format
248
-		 * 
249
-		 * @return int        the log level in integer format using the predefined constants
250
-		 */
251
-		protected static function getLevelValue($level){
252
-			$level = strtolower($level);
253
-			$levelMaps = array(
254
-				'fatal'   => self::FATAL,
255
-				'error'   => self::ERROR,
256
-				'warning' => self::WARNING,
257
-				'warn'    => self::WARNING,
258
-				'info'    => self::INFO,
259
-				'debug'   => self::DEBUG,
260
-				'all'     => self::ALL
261
-			);
262
-			//the default value is NONE, so means no need test for NONE
263
-			$value = self::NONE;
264
-			foreach ($levelMaps as $k => $v) {
265
-				if($level == $k){
266
-					$value = $v;
267
-					break;
268
-				}
269
-			}
270
-			return $value;
271
-		}
245
+        /**
246
+         * Get the log level number for the given level string
247
+         * @param  string $level the log level in string format
248
+         * 
249
+         * @return int        the log level in integer format using the predefined constants
250
+         */
251
+        protected static function getLevelValue($level){
252
+            $level = strtolower($level);
253
+            $levelMaps = array(
254
+                'fatal'   => self::FATAL,
255
+                'error'   => self::ERROR,
256
+                'warning' => self::WARNING,
257
+                'warn'    => self::WARNING,
258
+                'info'    => self::INFO,
259
+                'debug'   => self::DEBUG,
260
+                'all'     => self::ALL
261
+            );
262
+            //the default value is NONE, so means no need test for NONE
263
+            $value = self::NONE;
264
+            foreach ($levelMaps as $k => $v) {
265
+                if($level == $k){
266
+                    $value = $v;
267
+                    break;
268
+                }
269
+            }
270
+            return $value;
271
+        }
272 272
 
273
-		/**
274
-		 * Get the log level string for the given log level integer
275
-		 * @param  integer $level the log level in integer format
276
-		 * @return string        the log level in string format
277
-		 */
278
-		protected static function getLevelName($level){
279
-			$levelMaps = array(
280
-				self::FATAL   => 'FATAL',
281
-				self::ERROR   => 'ERROR',
282
-				self::WARNING => 'WARNING',
283
-				self::INFO    => 'INFO',
284
-				self::DEBUG   => 'DEBUG'
285
-			);
286
-			$value = '';
287
-			foreach ($levelMaps as $k => $v) {
288
-				if($level == $k){
289
-					$value = $v;
290
-					break;
291
-				}
292
-			}
293
-			//no need for ALL
294
-			return $value;
295
-		}
273
+        /**
274
+         * Get the log level string for the given log level integer
275
+         * @param  integer $level the log level in integer format
276
+         * @return string        the log level in string format
277
+         */
278
+        protected static function getLevelName($level){
279
+            $levelMaps = array(
280
+                self::FATAL   => 'FATAL',
281
+                self::ERROR   => 'ERROR',
282
+                self::WARNING => 'WARNING',
283
+                self::INFO    => 'INFO',
284
+                self::DEBUG   => 'DEBUG'
285
+            );
286
+            $value = '';
287
+            foreach ($levelMaps as $k => $v) {
288
+                if($level == $k){
289
+                    $value = $v;
290
+                    break;
291
+                }
292
+            }
293
+            //no need for ALL
294
+            return $value;
295
+        }
296 296
 
297
-	}
297
+    }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 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 Log{
27
+	class Log {
28 28
 		
29 29
 		/**
30 30
 		 * The defined constante for Log level
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 		/**
53 53
 		 * Create new Log instance
54 54
 		 */
55
-		public function __construct(){
55
+		public function __construct() {
56 56
 		}
57 57
 
58 58
 		/**
59 59
 		 * Set the logger to identify each message in the log
60 60
 		 * @param string $logger the logger name
61 61
 		 */
62
-		public  function setLogger($logger){
62
+		public  function setLogger($logger) {
63 63
 			$this->logger = $logger;
64 64
 		}
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 * @see Log::writeLog for more detail
69 69
 		 * @param  string $message the log message to save
70 70
 		 */
71
-		public function fatal($message){
71
+		public function fatal($message) {
72 72
 			$this->writeLog($message, self::FATAL);
73 73
 		} 
74 74
 		
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		 * @see Log::writeLog for more detail
78 78
 		 * @param  string $message the log message to save
79 79
 		 */
80
-		public function error($message){
80
+		public function error($message) {
81 81
 			$this->writeLog($message, self::ERROR);
82 82
 		} 
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		 * @see Log::writeLog for more detail
87 87
 		 * @param  string $message the log message to save
88 88
 		 */
89
-		public function warning($message){
89
+		public function warning($message) {
90 90
 			$this->writeLog($message, self::WARNING);
91 91
 		} 
92 92
 		
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * @see Log::writeLog for more detail
96 96
 		 * @param  string $message the log message to save
97 97
 		 */
98
-		public function info($message){
98
+		public function info($message) {
99 99
 			$this->writeLog($message, self::INFO);
100 100
 		} 
101 101
 		
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		 * @see Log::writeLog for more detail
105 105
 		 * @param  string $message the log message to save
106 106
 		 */
107
-		public function debug($message){
107
+		public function debug($message) {
108 108
 			$this->writeLog($message, self::DEBUG);
109 109
 		} 
110 110
 		
@@ -115,31 +115,31 @@  discard block
 block discarded – undo
115 115
 		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116 116
 		 * to allow check the log level threshold.
117 117
 		 */
118
-		public function writeLog($message, $level = self::INFO){
118
+		public function writeLog($message, $level = self::INFO) {
119 119
 			$configLogLevel = get_config('log_level');
120
-			if(! $configLogLevel){
120
+			if (!$configLogLevel) {
121 121
 				//so means no need log just stop here
122 122
 				return;
123 123
 			}
124 124
 			//check config log level
125
-			if(! self::isValidConfigLevel($configLogLevel)){
125
+			if (!self::isValidConfigLevel($configLogLevel)) {
126 126
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
127 127
 				show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128 128
 			}
129 129
 			
130 130
 			//check if config log_logger_name and current log can save log data
131
-			if(! $this->canSaveLogDataForLogger()){
131
+			if (!$this->canSaveLogDataForLogger()) {
132 132
 				return;
133 133
 			}
134 134
 			
135 135
 			//if $level is not an integer
136
-			if(! is_numeric($level)){
136
+			if (!is_numeric($level)) {
137 137
 				$level = self::getLevelValue($level);
138 138
 			}
139 139
 			
140 140
 			//check if can logging regarding the log level config
141 141
 			$configLevel = self::getLevelValue($configLogLevel);
142
-			if($configLevel > $level){
142
+			if ($configLevel > $level) {
143 143
 				//can't log
144 144
 				return;
145 145
 			}
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		 * @param  string $message the log message to save
157 157
 		 * @return void
158 158
 		 */
159
-		protected function saveLogData($path, $level, $message){
159
+		protected function saveLogData($path, $level, $message) {
160 160
 			//may be at this time helper user_agent not yet included
161 161
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
162 162
 			
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			$ip = get_ip();
170 170
 			
171 171
 			//if $level is not an integer
172
-			if(! is_numeric($level)){
172
+			if (!is_numeric($level)) {
173 173
 				$level = self::getLevelValue($level);
174 174
 			}
175 175
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 			
183 183
 			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
184 184
 			$fp = fopen($path, 'a+');
185
-			if(is_resource($fp)){
185
+			if (is_resource($fp)) {
186 186
 				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
187 187
 				fwrite($fp, $str);
188 188
 				fclose($fp);
@@ -194,13 +194,13 @@  discard block
 block discarded – undo
194 194
 		 * of logger filter
195 195
 		 * @return boolean
196 196
 		 */
197
-		protected function canSaveLogDataForLogger(){
198
-			if(! empty($this->logger)){
197
+		protected function canSaveLogDataForLogger() {
198
+			if (!empty($this->logger)) {
199 199
 				$configLoggersName = get_config('log_logger_name', array());
200 200
 				if (!empty($configLoggersName)) {
201 201
 					//for best comparaison put all string to lowercase
202 202
 					$configLoggersName = array_map('strtolower', $configLoggersName);
203
-					if(! in_array(strtolower($this->logger), $configLoggersName)){
203
+					if (!in_array(strtolower($this->logger), $configLoggersName)) {
204 204
 						return false;
205 205
 					}
206 206
 				}
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 		 * Check the file and directory 
213 213
 		 * @return string the log file path
214 214
 		 */
215
-		protected function checkAndSetLogFileDirectory(){
215
+		protected function checkAndSetLogFileDirectory() {
216 216
 			$logSavePath = get_config('log_save_path');
217
-			if(! $logSavePath){
217
+			if (!$logSavePath) {
218 218
 				$logSavePath = LOGS_PATH;
219 219
 			}
220 220
 			
221
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
221
+			if (!is_dir($logSavePath) || !is_writable($logSavePath)) {
222 222
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
223 223
 				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
224 224
 			}
225 225
 			
226 226
 			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
227
-			if(! file_exists($path)){
227
+			if (!file_exists($path)) {
228 228
 				touch($path);
229 229
 			}
230 230
 			return $path;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		 *
238 238
 		 * @return boolean        true if the given log level is valid, false if not
239 239
 		 */
240
-		protected static function isValidConfigLevel($level){
240
+		protected static function isValidConfigLevel($level) {
241 241
 			$level = strtolower($level);
242 242
 			return in_array($level, self::$validConfigLevel);
243 243
 		}
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 		 * 
249 249
 		 * @return int        the log level in integer format using the predefined constants
250 250
 		 */
251
-		protected static function getLevelValue($level){
251
+		protected static function getLevelValue($level) {
252 252
 			$level = strtolower($level);
253 253
 			$levelMaps = array(
254 254
 				'fatal'   => self::FATAL,
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			//the default value is NONE, so means no need test for NONE
263 263
 			$value = self::NONE;
264 264
 			foreach ($levelMaps as $k => $v) {
265
-				if($level == $k){
265
+				if ($level == $k) {
266 266
 					$value = $v;
267 267
 					break;
268 268
 				}
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		 * @param  integer $level the log level in integer format
276 276
 		 * @return string        the log level in string format
277 277
 		 */
278
-		protected static function getLevelName($level){
278
+		protected static function getLevelName($level) {
279 279
 			$levelMaps = array(
280 280
 				self::FATAL   => 'FATAL',
281 281
 				self::ERROR   => 'ERROR',
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 			);
286 286
 			$value = '';
287 287
 			foreach ($levelMaps as $k => $v) {
288
-				if($level == $k){
288
+				if ($level == $k) {
289 289
 					$value = $v;
290 290
 					break;
291 291
 				}
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryBuilder.php 2 patches
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/Database.php 3 patches
Indentation   +356 added lines, -356 removed lines patch added patch discarded remove patch
@@ -1,119 +1,119 @@  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 Database{
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 Database{
27 27
 	
28
-  	/**
29
-  	 * The PDO instance
30
-  	 * @var object
31
-  	*/
28
+        /**
29
+         * The PDO instance
30
+         * @var object
31
+         */
32 32
     private $pdo                 = null;
33 33
     
34
-  	/**
35
-  	 * The database name used for the application
36
-  	 * @var string
37
-  	*/
38
-	  private $databaseName        = null;
34
+        /**
35
+         * The database name used for the application
36
+         * @var string
37
+         */
38
+        private $databaseName        = null;
39 39
 	
40
-  	/**
41
-  	 * The number of rows returned by the last query
42
-  	 * @var int
43
-  	*/
40
+        /**
41
+         * The number of rows returned by the last query
42
+         * @var int
43
+         */
44 44
     private $numRows             = 0;
45 45
 	
46
-  	/**
47
-  	 * The last insert id for the primary key column that have auto increment or sequence
48
-  	 * @var mixed
49
-  	*/
46
+        /**
47
+         * The last insert id for the primary key column that have auto increment or sequence
48
+         * @var mixed
49
+         */
50 50
     private $insertId            = null;
51 51
 	
52
-  	/**
53
-  	 * The full SQL query statment after build for each command
54
-  	 * @var string
55
-  	*/
52
+        /**
53
+         * The full SQL query statment after build for each command
54
+         * @var string
55
+         */
56 56
     private $query               = null;
57 57
 	
58
-  	/**
59
-  	 * The result returned for the last query
60
-  	 * @var mixed
61
-  	*/
58
+        /**
59
+         * The result returned for the last query
60
+         * @var mixed
61
+         */
62 62
     private $result              = array();
63 63
 	
64
-  	/**
65
-  	 * The cache default time to live in second. 0 means no need to use the cache feature
66
-  	 * @var int
67
-  	*/
68
-  	private $cacheTtl             = 0;
64
+        /**
65
+         * The cache default time to live in second. 0 means no need to use the cache feature
66
+         * @var int
67
+         */
68
+        private $cacheTtl             = 0;
69 69
 	
70
-  	/**
71
-  	 * The cache current time to live. 0 means no need to use the cache feature
72
-  	 * @var int
73
-  	*/
70
+        /**
71
+         * The cache current time to live. 0 means no need to use the cache feature
72
+         * @var int
73
+         */
74 74
     private $temporaryCacheTtl   = 0;
75 75
 	
76
-  	/**
77
-  	 * The number of executed query for the current request
78
-  	 * @var int
79
-  	*/
76
+        /**
77
+         * The number of executed query for the current request
78
+         * @var int
79
+         */
80 80
     private $queryCount          = 0;
81 81
 	
82
-  	/**
83
-  	 * The default data to be used in the statments query INSERT, UPDATE
84
-  	 * @var array
85
-  	*/
82
+        /**
83
+         * The default data to be used in the statments query INSERT, UPDATE
84
+         * @var array
85
+         */
86 86
     private $data                = array();
87 87
 	
88
-  	/**
89
-  	 * The database configuration
90
-  	 * @var array
91
-  	*/
88
+        /**
89
+         * The database configuration
90
+         * @var array
91
+         */
92 92
     private $config              = array();
93 93
 	
94
-  	/**
95
-  	 * The logger instance
96
-  	 * @var object
97
-  	 */
94
+        /**
95
+         * The logger instance
96
+         * @var object
97
+         */
98 98
     private $logger              = null;
99 99
 
100 100
     /**
101
-    * The cache instance
102
-    * @var object
103
-    */
101
+     * The cache instance
102
+     * @var object
103
+     */
104 104
     private $cacheInstance       = null;
105 105
 
106 106
     
107
-  	/**
108
-    * The DatabaseQueryBuilder instance
109
-    * @var object
110
-    */
107
+        /**
108
+         * The DatabaseQueryBuilder instance
109
+         * @var object
110
+         */
111 111
     private $queryBuilder        = null;
112 112
     
113 113
     /**
114
-    * The DatabaseQueryRunner instance
115
-    * @var object
116
-    */
114
+     * The DatabaseQueryRunner instance
115
+     * @var object
116
+     */
117 117
     private $queryRunner         = null;
118 118
 
119 119
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         //Set Log instance to use
127 127
         $this->setLoggerFromParamOrCreate(null);
128 128
 		
129
-    		//Set DatabaseQueryBuilder instance to use
129
+            //Set DatabaseQueryBuilder instance to use
130 130
         $this->setDependencyInstanceFromParamOrCreate('queryBuilder', null, 'DatabaseQueryBuilder', 'classes/database');
131 131
        
132 132
         //Set DatabaseQueryRunner instance to use
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
      * @return bool 
145 145
      */
146 146
     public function connect(){
147
-      $config = $this->getDatabaseConfiguration();
148
-      if (! empty($config)){
147
+        $config = $this->getDatabaseConfiguration();
148
+        if (! empty($config)){
149 149
         try{
150 150
             $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']);
151 151
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
@@ -156,14 +156,14 @@  discard block
 block discarded – undo
156 156
             $this->updateQueryBuilderAndRunnerProperties();
157 157
 
158 158
             return true;
159
-          }
160
-          catch (PDOException $e){
159
+            }
160
+            catch (PDOException $e){
161 161
             $this->logger->fatal($e->getMessage());
162 162
             show_error('Cannot connect to Database.');
163 163
             return false;
164
-          }
165
-      }
166
-      return false;
164
+            }
165
+        }
166
+        return false;
167 167
     }
168 168
 
169 169
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @return int
173 173
      */
174 174
     public function numRows(){
175
-      return $this->numRows;
175
+        return $this->numRows;
176 176
     }
177 177
 
178 178
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      * @return mixed
181 181
      */
182 182
     public function insertId(){
183
-      return $this->insertId;
183
+        return $this->insertId;
184 184
     }
185 185
 
186 186
 
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
      * @return mixed       the query SQL string or the record result
192 192
      */
193 193
     public function get($returnSQLQueryOrResultType = false){
194
-      $this->queryBuilder->limit(1);
195
-      $query = $this->getAll(true);
196
-      if ($returnSQLQueryOrResultType === true){
194
+        $this->queryBuilder->limit(1);
195
+        $query = $this->getAll(true);
196
+        if ($returnSQLQueryOrResultType === true){
197 197
         return $query;
198
-      } else {
198
+        } else {
199 199
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
200
-      }
200
+        }
201 201
     }
202 202
 
203 203
     /**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
      * @return mixed       the query SQL string or the record result
208 208
      */
209 209
     public function getAll($returnSQLQueryOrResultType = false){
210
-	   $query = $this->queryBuilder->getQuery();
211
-	   if ($returnSQLQueryOrResultType === true){
212
-      	return $query;
213
-      }
214
-      return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
210
+        $query = $this->queryBuilder->getQuery();
211
+        if ($returnSQLQueryOrResultType === true){
212
+            return $query;
213
+        }
214
+        return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
215 215
     }
216 216
 
217 217
     /**
@@ -221,19 +221,19 @@  discard block
 block discarded – undo
221 221
      * @return mixed          the insert id of the new record or null
222 222
      */
223 223
     public function insert($data = array(), $escape = true){
224
-      if (empty($data) && ! empty($this->data)){
224
+        if (empty($data) && ! empty($this->data)){
225 225
         //as when using $this->setData() may be the data already escaped
226 226
         $escape = false;
227 227
         $data = $this->data;
228
-      }
229
-      $query = $this->queryBuilder->insert($data, $escape)->getQuery();
230
-      $result = $this->query($query);
231
-      if ($result){
228
+        }
229
+        $query = $this->queryBuilder->insert($data, $escape)->getQuery();
230
+        $result = $this->query($query);
231
+        if ($result){
232 232
         $this->insertId = $this->pdo->lastInsertId();
233
-		    //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
233
+            //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
234 234
         return ! ($this->insertId) ? true : $this->insertId;
235
-      }
236
-      return false;
235
+        }
236
+        return false;
237 237
     }
238 238
 
239 239
     /**
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
      * @return mixed          the update status
244 244
      */
245 245
     public function update($data = array(), $escape = true){
246
-      if (empty($data) && ! empty($this->data)){
246
+        if (empty($data) && ! empty($this->data)){
247 247
         //as when using $this->setData() may be the data already escaped
248 248
         $escape = false;
249 249
         $data = $this->data;
250
-      }
251
-      $query = $this->queryBuilder->update($data, $escape)->getQuery();
252
-      return $this->query($query);
250
+        }
251
+        $query = $this->queryBuilder->update($data, $escape)->getQuery();
252
+        return $this->query($query);
253 253
     }
254 254
 
255 255
     /**
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
      * @return mixed the delete status
258 258
      */
259 259
     public function delete(){
260
-		  $query = $this->queryBuilder->delete()->getQuery();
261
-    	return $this->query($query);
260
+            $query = $this->queryBuilder->delete()->getQuery();
261
+        return $this->query($query);
262 262
     }
263 263
 
264 264
     /**
@@ -267,17 +267,17 @@  discard block
 block discarded – undo
267 267
      * @return object        the current Database instance
268 268
      */
269 269
     public function setCache($ttl = 0){
270
-      $this->cacheTtl = $ttl;
271
-      $this->temporaryCacheTtl = $ttl;
272
-      return $this;
270
+        $this->cacheTtl = $ttl;
271
+        $this->temporaryCacheTtl = $ttl;
272
+        return $this;
273 273
     }
274 274
 	
275
-	/**
276
-	 * Enabled cache temporary for the current query not globally	
277
-	 * @param  integer $ttl the cache time to live in second
278
-	 * @return object        the current Database instance
279
-	 */
280
-  	public function cached($ttl = 0){
275
+    /**
276
+     * Enabled cache temporary for the current query not globally	
277
+     * @param  integer $ttl the cache time to live in second
278
+     * @return object        the current Database instance
279
+     */
280
+        public function cached($ttl = 0){
281 281
         $this->temporaryCacheTtl = $ttl;
282 282
         return $this;
283 283
     }
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
      * need escaped
291 291
      */
292 292
     public function escape($data, $escaped = true){
293
-      $data = trim($data);
294
-      if($escaped){
293
+        $data = trim($data);
294
+        if($escaped){
295 295
         return $this->pdo->quote($data);
296
-      }
297
-      return $data; 
296
+        }
297
+        return $data; 
298 298
     }
299 299
 
300 300
     /**
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      * @return int
303 303
      */
304 304
     public function queryCount(){
305
-      return $this->queryCount;
305
+        return $this->queryCount;
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 getQuery(){
313
-      return $this->query;
313
+        return $this->query;
314 314
     }
315 315
 
316 316
     /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      * @return string
319 319
      */
320 320
     public function getDatabaseName(){
321
-      return $this->databaseName;
321
+        return $this->databaseName;
322 322
     }
323 323
 
324 324
     /**
@@ -326,17 +326,17 @@  discard block
 block discarded – undo
326 326
      * @return object
327 327
      */
328 328
     public function getPdo(){
329
-      return $this->pdo;
329
+        return $this->pdo;
330 330
     }
331 331
 
332 332
     /**
333 333
      * Set the PDO instance
334 334
      * @param object $pdo the pdo object
335
-	 * @return object Database
335
+     * @return object Database
336 336
      */
337 337
     public function setPdo(PDO $pdo){
338
-      $this->pdo = $pdo;
339
-      return $this;
338
+        $this->pdo = $pdo;
339
+        return $this;
340 340
     }
341 341
 
342 342
 
@@ -345,44 +345,44 @@  discard block
 block discarded – undo
345 345
      * @return Log
346 346
      */
347 347
     public function getLogger(){
348
-      return $this->logger;
348
+        return $this->logger;
349 349
     }
350 350
 
351 351
     /**
352 352
      * Set the log instance
353 353
      * @param Log $logger the log object
354
-	 * @return object Database
354
+     * @return object Database
355 355
      */
356 356
     public function setLogger($logger){
357
-      $this->logger = $logger;
358
-      return $this;
357
+        $this->logger = $logger;
358
+        return $this;
359 359
     }
360 360
 
361
-     /**
362
-     * Return the cache instance
363
-     * @return CacheInterface
364
-     */
361
+        /**
362
+         * Return the cache instance
363
+         * @return CacheInterface
364
+         */
365 365
     public function getCacheInstance(){
366
-      return $this->cacheInstance;
366
+        return $this->cacheInstance;
367 367
     }
368 368
 
369 369
     /**
370 370
      * Set the cache instance
371 371
      * @param CacheInterface $cache the cache object
372
-	 * @return object Database
372
+     * @return object Database
373 373
      */
374 374
     public function setCacheInstance($cache){
375
-      $this->cacheInstance = $cache;
376
-      return $this;
375
+        $this->cacheInstance = $cache;
376
+        return $this;
377 377
     }
378 378
 	
379 379
 	
380
-	   /**
381
-     * Return the DatabaseQueryBuilder instance
382
-     * @return object DatabaseQueryBuilder
383
-     */
380
+        /**
381
+         * Return the DatabaseQueryBuilder instance
382
+         * @return object DatabaseQueryBuilder
383
+         */
384 384
     public function getQueryBuilder(){
385
-      return $this->queryBuilder;
385
+        return $this->queryBuilder;
386 386
     }
387 387
 
388 388
     /**
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
391 391
      */
392 392
     public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
393
-      $this->queryBuilder = $queryBuilder;
394
-      return $this;
393
+        $this->queryBuilder = $queryBuilder;
394
+        return $this;
395 395
     }
396 396
     
397 397
     /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @return object DatabaseQueryRunner
400 400
      */
401 401
     public function getQueryRunner(){
402
-      return $this->queryRunner;
402
+        return $this->queryRunner;
403 403
     }
404 404
 
405 405
     /**
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
      * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object
408 408
      */
409 409
     public function setQueryRunner(DatabaseQueryRunner $queryRunner){
410
-      $this->queryRunner = $queryRunner;
411
-      return $this;
410
+        $this->queryRunner = $queryRunner;
411
+        return $this;
412 412
     }
413 413
 
414 414
     /**
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @return array
417 417
      */
418 418
     public function getData(){
419
-      return $this->data;
419
+        return $this->data;
420 420
     }
421 421
 
422 422
     /**
@@ -427,62 +427,62 @@  discard block
 block discarded – undo
427 427
      * @return object        the current Database instance
428 428
      */
429 429
     public function setData($key, $value = null, $escape = true){
430
-  	  if (is_array($key)){
431
-    		foreach($key as $k => $v){
432
-    			$this->setData($k, $v, $escape);
433
-    		}	
434
-  	  } else {
430
+        if (is_array($key)){
431
+            foreach($key as $k => $v){
432
+                $this->setData($k, $v, $escape);
433
+            }	
434
+        } else {
435 435
         $this->data[$key] = $this->escape($value, $escape);
436
-  	  }
437
-      return $this;
436
+        }
437
+        return $this;
438 438
     }
439 439
 
440
-     /**
441
-     * Execute an SQL query
442
-     * @param  string  $query the query SQL string
443
-     * @param  boolean $returnAsList  indicate whether to return all record or just one row 
444
-     * @param  boolean $returnAsArray return the result as array or not
445
-     * @return mixed         the query result
446
-     */
440
+        /**
441
+         * Execute an SQL query
442
+         * @param  string  $query the query SQL string
443
+         * @param  boolean $returnAsList  indicate whether to return all record or just one row 
444
+         * @param  boolean $returnAsArray return the result as array or not
445
+         * @return mixed         the query result
446
+         */
447 447
     public function query($query, $returnAsList = true, $returnAsArray = false){
448
-      $this->reset();
449
-      $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
450
-      //If is the SELECT query
451
-      $isSqlSELECTQuery = stristr($this->query, 'SELECT');
448
+        $this->reset();
449
+        $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
450
+        //If is the SELECT query
451
+        $isSqlSELECTQuery = stristr($this->query, 'SELECT');
452 452
 
453
-      //cache expire time
454
-      $cacheExpire = $this->temporaryCacheTtl;
453
+        //cache expire time
454
+        $cacheExpire = $this->temporaryCacheTtl;
455 455
       
456
-      //return to the initial cache time
457
-      $this->temporaryCacheTtl = $this->cacheTtl;
456
+        //return to the initial cache time
457
+        $this->temporaryCacheTtl = $this->cacheTtl;
458 458
       
459
-      //config for cache
460
-      $cacheEnable = get_config('cache_enable');
459
+        //config for cache
460
+        $cacheEnable = get_config('cache_enable');
461 461
       
462
-      //the database cache content
463
-      $cacheContent = null;
462
+        //the database cache content
463
+        $cacheContent = null;
464 464
 
465
-      //if can use cache feature for this query
466
-      $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
465
+        //if can use cache feature for this query
466
+        $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
467 467
     
468
-      if ($dbCacheStatus && $isSqlSELECTQuery){
469
-          $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
470
-          $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
471
-      }
468
+        if ($dbCacheStatus && $isSqlSELECTQuery){
469
+            $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
470
+            $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
471
+        }
472 472
       
473
-      if (!$cacheContent){
474
-  	   	//count the number of query execution to server
473
+        if (!$cacheContent){
474
+                //count the number of query execution to server
475 475
         $this->queryCount++;
476 476
         
477 477
         $queryResult = $this->queryRunner->setQuery($query)
478
-                                          ->setReturnType($returnAsList)
479
-                                          ->setReturnAsArray($returnAsArray)
480
-                                          ->execute();
478
+                                            ->setReturnType($returnAsList)
479
+                                            ->setReturnAsArray($returnAsArray)
480
+                                            ->execute();
481 481
 
482 482
         if (!is_object($queryResult)){
483
-          $this->result = false;
484
-          $this->numRows = 0;
485
-          return $this->result;
483
+            $this->result = false;
484
+            $this->numRows = 0;
485
+            return $this->result;
486 486
         }
487 487
         $this->result  = $queryResult->getResult();
488 488
         $this->numRows = $queryResult->getNumRows();
@@ -490,72 +490,72 @@  discard block
 block discarded – undo
490 490
             $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray);
491 491
             $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire);
492 492
         }
493
-      } else if ($isSqlSELECTQuery){
494
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
495
-          $this->result = $cacheContent;
496
-          $this->numRows = count($this->result);
497
-      }
498
-      return $this->result;
499
-    }
500
-
501
-   /**
502
-    * Setting the database configuration using the configuration file and additional configuration from param
503
-    * @param array $overwriteConfig the additional configuration to overwrite with the existing one
504
-    * @param boolean $useConfigFile whether to use database configuration file
505
-    * @param boolean $autoConnect whether to connect to database after set the configuration
506
-	  * @return object Database
507
-    */
493
+        } else if ($isSqlSELECTQuery){
494
+            $this->logger->info('The result for query [' .$this->query. '] already cached use it');
495
+            $this->result = $cacheContent;
496
+            $this->numRows = count($this->result);
497
+        }
498
+        return $this->result;
499
+    }
500
+
501
+    /**
502
+     * Setting the database configuration using the configuration file and additional configuration from param
503
+     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
504
+     * @param boolean $useConfigFile whether to use database configuration file
505
+     * @param boolean $autoConnect whether to connect to database after set the configuration
506
+     * @return object Database
507
+     */
508 508
     public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){
509
-      $db = array();
510
-      if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
511
-          //here don't use require_once because somewhere user can create database instance directly
512
-          require CONFIG_PATH . 'database.php';
513
-      }
509
+        $db = array();
510
+        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
511
+            //here don't use require_once because somewhere user can create database instance directly
512
+            require CONFIG_PATH . 'database.php';
513
+        }
514 514
       
515
-      //merge with the parameter  
516
-      $db = array_merge($db, $overwriteConfig);
515
+        //merge with the parameter  
516
+        $db = array_merge($db, $overwriteConfig);
517 517
       
518
-      //get the default configuration
519
-      $config = $this->getDatabaseDefaultConfiguration();
518
+        //get the default configuration
519
+        $config = $this->getDatabaseDefaultConfiguration();
520 520
 		  
521
-    	$config = array_merge($config, $db);
522
-    	//determine the port using the hostname like localhost:3307
523
-      //hostname will be "localhost", and port "3307"
524
-      $p = explode(':', $config['hostname']);
525
-  	  if (count($p) >= 2){
526
-  		  $config['hostname'] = $p[0];
527
-  		  $config['port'] = $p[1];
528
-  		}
521
+        $config = array_merge($config, $db);
522
+        //determine the port using the hostname like localhost:3307
523
+        //hostname will be "localhost", and port "3307"
524
+        $p = explode(':', $config['hostname']);
525
+        if (count($p) >= 2){
526
+            $config['hostname'] = $p[0];
527
+            $config['port'] = $p[1];
528
+            }
529 529
 		
530
-		 $this->databaseName = $config['database'];
531
-		 $this->config = $config;
532
-		 $this->logger->info(
533
-								'The database configuration are listed below: ' 
534
-								. stringfy_vars(array_merge(
535
-															$this->config, 
536
-															array('password' => string_hidden($this->config['password']))
537
-												))
538
-							);
539
-  	  if($autoConnect){
540
-    		 //Now connect to the database
541
-    		 $this->connect();
542
-  		}
543
-		 return $this;
544
-    }
545
-
546
-    /**
547
-   * Return the database configuration
548
-   * @return array
549
-   */
530
+            $this->databaseName = $config['database'];
531
+            $this->config = $config;
532
+            $this->logger->info(
533
+                                'The database configuration are listed below: ' 
534
+                                . stringfy_vars(array_merge(
535
+                                                            $this->config, 
536
+                                                            array('password' => string_hidden($this->config['password']))
537
+                                                ))
538
+                            );
539
+        if($autoConnect){
540
+                //Now connect to the database
541
+                $this->connect();
542
+            }
543
+            return $this;
544
+    }
545
+
546
+    /**
547
+     * Return the database configuration
548
+     * @return array
549
+     */
550 550
     public  function getDatabaseConfiguration(){
551
-      return $this->config;
551
+        return $this->config;
552 552
     }
553 553
 
554 554
     /**
555 555
      * Close the connexion
556 556
      */
557 557
     public function close(){
558
-      $this->pdo = null;
558
+        $this->pdo = null;
559 559
     }
560 560
 
561 561
     /**
@@ -563,16 +563,16 @@  discard block
 block discarded – undo
563 563
      * @return array
564 564
      */
565 565
     protected function getDatabaseDefaultConfiguration(){
566
-      return array(
567
-              'driver' => 'mysql',
568
-              'username' => 'root',
569
-              'password' => '',
570
-              'database' => '',
571
-              'hostname' => 'localhost',
572
-              'charset' => 'utf8',
573
-              'collation' => 'utf8_general_ci',
574
-              'prefix' => '',
575
-              'port' => ''
566
+        return array(
567
+                'driver' => 'mysql',
568
+                'username' => 'root',
569
+                'password' => '',
570
+                'database' => '',
571
+                'hostname' => 'localhost',
572
+                'charset' => 'utf8',
573
+                'collation' => 'utf8_general_ci',
574
+                'prefix' => '',
575
+                'port' => ''
576 576
             );
577 577
     }
578 578
 
@@ -581,18 +581,18 @@  discard block
 block discarded – undo
581 581
      * @return void
582 582
      */
583 583
     protected function updateQueryBuilderAndRunnerProperties(){
584
-       //update queryBuilder with some properties needed
585
-     if (is_object($this->queryBuilder)){
584
+        //update queryBuilder with some properties needed
585
+        if (is_object($this->queryBuilder)){
586 586
         $this->queryBuilder->setDriver($this->config['driver'])
587
-                           ->setPrefix($this->config['prefix'])
588
-                           ->setPdo($this->pdo);
589
-     }
587
+                            ->setPrefix($this->config['prefix'])
588
+                            ->setPdo($this->pdo);
589
+        }
590 590
 
591
-      //update queryRunner with some properties needed
592
-     if (is_object($this->queryRunner)){
591
+        //update queryRunner with some properties needed
592
+        if (is_object($this->queryRunner)){
593 593
         $this->queryRunner->setDriver($this->config['driver'])
594
-                          ->setPdo($this->pdo);
595
-     }
594
+                            ->setPdo($this->pdo);
595
+        }
596 596
     }
597 597
 	
598 598
 
@@ -601,21 +601,21 @@  discard block
 block discarded – undo
601 601
      * @return string|null the DSN string or null if can not find it
602 602
      */
603 603
     protected function getDsnValueFromConfig(){
604
-      $dsn = null;
605
-      $config = $this->getDatabaseConfiguration();
606
-      if (! empty($config)){
604
+        $dsn = null;
605
+        $config = $this->getDatabaseConfiguration();
606
+        if (! empty($config)){
607 607
         $driver = $config['driver'];
608 608
         $driverDsnMap = array(
609
-                              'mysql'  => $this->getDsnValueForDriver('mysql'),
610
-                              'pgsql'  => $this->getDsnValueForDriver('pgsql'),
611
-                              'sqlite' => $this->getDsnValueForDriver('sqlite'),
612
-                              'oracle' => $this->getDsnValueForDriver('oracle')
613
-                              );
609
+                                'mysql'  => $this->getDsnValueForDriver('mysql'),
610
+                                'pgsql'  => $this->getDsnValueForDriver('pgsql'),
611
+                                'sqlite' => $this->getDsnValueForDriver('sqlite'),
612
+                                'oracle' => $this->getDsnValueForDriver('oracle')
613
+                                );
614 614
         if (isset($driverDsnMap[$driver])){
615
-          $dsn = $driverDsnMap[$driver];
615
+            $dsn = $driverDsnMap[$driver];
616 616
         }
617
-      }    
618
-      return $dsn;
617
+        }    
618
+        return $dsn;
619 619
     }
620 620
 
621 621
     /**
@@ -624,32 +624,32 @@  discard block
 block discarded – undo
624 624
      * @return string|null         the dsn name
625 625
      */
626 626
     protected function getDsnValueForDriver($driver){
627
-      $dsn = '';
628
-      $config = $this->getDatabaseConfiguration();
629
-      if (empty($config)){
627
+        $dsn = '';
628
+        $config = $this->getDatabaseConfiguration();
629
+        if (empty($config)){
630 630
         return null;
631
-      }
632
-      switch ($driver) {
631
+        }
632
+        switch ($driver) {
633 633
         case 'mysql':
634 634
         case 'pgsql':
635 635
           $port = '';
636
-          if (! empty($config['port'])) {
636
+            if (! empty($config['port'])) {
637 637
             $port = 'port=' . $config['port'] . ';';
638
-          }
639
-          $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
640
-          break;
638
+            }
639
+            $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
640
+            break;
641 641
         case 'sqlite':
642 642
           $dsn = 'sqlite:' . $config['database'];
643
-          break;
644
-          case 'oracle':
643
+            break;
644
+            case 'oracle':
645 645
           $port = '';
646
-          if (! empty($config['port'])) {
646
+            if (! empty($config['port'])) {
647 647
             $port = ':' . $config['port'];
648
-          }
649
-          $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
650
-          break;
651
-      }
652
-      return $dsn;
648
+            }
649
+            $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
650
+            break;
651
+        }
652
+        return $dsn;
653 653
     }
654 654
 
655 655
     /**
@@ -661,11 +661,11 @@  discard block
 block discarded – undo
661 661
     protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){
662 662
         $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray);
663 663
         if (! is_object($this->cacheInstance)){
664
-    			//can not call method with reference in argument
665
-    			//like $this->setCacheInstance(& get_instance()->cache);
666
-    			//use temporary variable
667
-    			$instance = & get_instance()->cache;
668
-    			$this->cacheInstance = $instance;
664
+                //can not call method with reference in argument
665
+                //like $this->setCacheInstance(& get_instance()->cache);
666
+                //use temporary variable
667
+                $instance = & get_instance()->cache;
668
+                $this->cacheInstance = $instance;
669 669
         }
670 670
         return $this->cacheInstance->get($cacheKey);
671 671
     }
@@ -677,80 +677,80 @@  discard block
 block discarded – undo
677 677
      * @param mixed $result the query result to save
678 678
      * @param int $expire the cache TTL
679 679
      */
680
-     protected function setCacheContentForQuery($query, $key, $result, $expire){
680
+        protected function setCacheContentForQuery($query, $key, $result, $expire){
681 681
         $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
682 682
         if (! is_object($this->cacheInstance)){
683
-  				//can not call method with reference in argument
684
-  				//like $this->setCacheInstance(& get_instance()->cache);
685
-  				//use temporary variable
686
-  				$instance = & get_instance()->cache;
687
-  				$this->cacheInstance = $instance;
688
-  			}
683
+                    //can not call method with reference in argument
684
+                    //like $this->setCacheInstance(& get_instance()->cache);
685
+                    //use temporary variable
686
+                    $instance = & get_instance()->cache;
687
+                    $this->cacheInstance = $instance;
688
+                }
689 689
         $this->cacheInstance->set($key, $result, $expire);
690
-     }
690
+        }
691 691
 
692 692
     
693
-	 /**
694
-     * Return the cache key for the given query
695
-     * @see Database::query
696
-     * 
697
-     *  @return string
698
-     */
693
+        /**
694
+         * Return the cache key for the given query
695
+         * @see Database::query
696
+         * 
697
+         *  @return string
698
+         */
699 699
     protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){
700
-      return md5($query . $returnAsList . $returnAsArray);
701
-    }
702
-
703
-     /**
704
-     * Set the dependencies instance using argument or create new instance if is null
705
-     * @param string $name this class property name.
706
-     * @param object $instance the instance. If is not null will use it
707
-     * otherwise will create new instance.
708
-     * @param string $loadClassName the name of class to load using class_loader function.
709
-     * @param string $loadClassPath the path of class to load using class_loader function.
710
-     *
711
-     * @return object this current instance
712
-     */
700
+        return md5($query . $returnAsList . $returnAsArray);
701
+    }
702
+
703
+        /**
704
+         * Set the dependencies instance using argument or create new instance if is null
705
+         * @param string $name this class property name.
706
+         * @param object $instance the instance. If is not null will use it
707
+         * otherwise will create new instance.
708
+         * @param string $loadClassName the name of class to load using class_loader function.
709
+         * @param string $loadClassPath the path of class to load using class_loader function.
710
+         *
711
+         * @return object this current instance
712
+         */
713 713
     protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
714
-      if ($instance !== null){
714
+        if ($instance !== null){
715 715
         $this->{$name} = $instance;
716 716
         return $this;
717
-      }
718
-      $this->{$name} =& class_loader($loadClassName, $loadClassePath);
719
-      return $this;
717
+        }
718
+        $this->{$name} =& class_loader($loadClassName, $loadClassePath);
719
+        return $this;
720 720
     }
721 721
     
722
-	   /**
723
-     * Set the Log instance using argument or create new instance
724
-     * @param object $logger the Log instance if not null
725
-     *
726
-     * @return object this current instance
727
-     */
722
+        /**
723
+         * Set the Log instance using argument or create new instance
724
+         * @param object $logger the Log instance if not null
725
+         *
726
+         * @return object this current instance
727
+         */
728 728
     protected function setLoggerFromParamOrCreate(Log $logger = null){
729
-      $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
730
-      if ($logger === null){
729
+        $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
730
+        if ($logger === null){
731 731
         $this->logger->setLogger('Library::Database');
732
-      }
733
-      return $this;
732
+        }
733
+        return $this;
734 734
     }
735 735
 	
736 736
     /**
737 737
      * Reset the database class attributs to the initail values before each query.
738 738
      */
739 739
     private function reset(){
740
-	   //query builder reset
741
-      $this->queryBuilder->reset();
742
-      $this->numRows  = 0;
743
-      $this->insertId = null;
744
-      $this->query    = null;
745
-      $this->result   = array();
746
-      $this->data     = array();
740
+        //query builder reset
741
+        $this->queryBuilder->reset();
742
+        $this->numRows  = 0;
743
+        $this->insertId = null;
744
+        $this->query    = null;
745
+        $this->result   = array();
746
+        $this->data     = array();
747 747
     }
748 748
 
749 749
     /**
750 750
      * The class destructor
751 751
      */
752 752
     public function __destruct(){
753
-      $this->pdo = null;
753
+        $this->pdo = null;
754 754
     }
755 755
 
756 756
 }
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -23,98 +23,98 @@  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 Database{
26
+  class Database {
27 27
 	
28 28
   	/**
29 29
   	 * The PDO instance
30 30
   	 * @var object
31 31
   	*/
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
   	/**
35 35
   	 * The database name used for the application
36 36
   	 * @var string
37 37
   	*/
38
-	  private $databaseName        = null;
38
+	  private $databaseName = null;
39 39
 	
40 40
   	/**
41 41
   	 * The number of rows returned by the last query
42 42
   	 * @var int
43 43
   	*/
44
-    private $numRows             = 0;
44
+    private $numRows = 0;
45 45
 	
46 46
   	/**
47 47
   	 * The last insert id for the primary key column that have auto increment or sequence
48 48
   	 * @var mixed
49 49
   	*/
50
-    private $insertId            = null;
50
+    private $insertId = null;
51 51
 	
52 52
   	/**
53 53
   	 * The full SQL query statment after build for each command
54 54
   	 * @var string
55 55
   	*/
56
-    private $query               = null;
56
+    private $query = null;
57 57
 	
58 58
   	/**
59 59
   	 * The result returned for the last query
60 60
   	 * @var mixed
61 61
   	*/
62
-    private $result              = array();
62
+    private $result = array();
63 63
 	
64 64
   	/**
65 65
   	 * The cache default time to live in second. 0 means no need to use the cache feature
66 66
   	 * @var int
67 67
   	*/
68
-  	private $cacheTtl             = 0;
68
+  	private $cacheTtl = 0;
69 69
 	
70 70
   	/**
71 71
   	 * The cache current time to live. 0 means no need to use the cache feature
72 72
   	 * @var int
73 73
   	*/
74
-    private $temporaryCacheTtl   = 0;
74
+    private $temporaryCacheTtl = 0;
75 75
 	
76 76
   	/**
77 77
   	 * The number of executed query for the current request
78 78
   	 * @var int
79 79
   	*/
80
-    private $queryCount          = 0;
80
+    private $queryCount = 0;
81 81
 	
82 82
   	/**
83 83
   	 * The default data to be used in the statments query INSERT, UPDATE
84 84
   	 * @var array
85 85
   	*/
86
-    private $data                = array();
86
+    private $data = array();
87 87
 	
88 88
   	/**
89 89
   	 * The database configuration
90 90
   	 * @var array
91 91
   	*/
92
-    private $config              = array();
92
+    private $config = array();
93 93
 	
94 94
   	/**
95 95
   	 * The logger instance
96 96
   	 * @var object
97 97
   	 */
98
-    private $logger              = null;
98
+    private $logger = null;
99 99
 
100 100
     /**
101 101
     * The cache instance
102 102
     * @var object
103 103
     */
104
-    private $cacheInstance       = null;
104
+    private $cacheInstance = null;
105 105
 
106 106
     
107 107
   	/**
108 108
     * The DatabaseQueryBuilder instance
109 109
     * @var object
110 110
     */
111
-    private $queryBuilder        = null;
111
+    private $queryBuilder = null;
112 112
     
113 113
     /**
114 114
     * The DatabaseQueryRunner instance
115 115
     * @var object
116 116
     */
117
-    private $queryRunner         = null;
117
+    private $queryRunner = null;
118 118
 
119 119
 
120 120
     /**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
123 123
      * @param boolean $autoConnect whether to connect to database automatically
124 124
      */
125
-    public function __construct($overwriteConfig = array(), $autoConnect = true){
125
+    public function __construct($overwriteConfig = array(), $autoConnect = true) {
126 126
         //Set Log instance to use
127 127
         $this->setLoggerFromParamOrCreate(null);
128 128
 		
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
      * This is used to connect to database
144 144
      * @return bool 
145 145
      */
146
-    public function connect(){
146
+    public function connect() {
147 147
       $config = $this->getDatabaseConfiguration();
148
-      if (! empty($config)){
149
-        try{
148
+      if (!empty($config)) {
149
+        try {
150 150
             $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']);
151 151
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
152 152
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 
158 158
             return true;
159 159
           }
160
-          catch (PDOException $e){
160
+          catch (PDOException $e) {
161 161
             $this->logger->fatal($e->getMessage());
162 162
             show_error('Cannot connect to Database.');
163 163
             return false;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * Return the number of rows returned by the current query
172 172
      * @return int
173 173
      */
174
-    public function numRows(){
174
+    public function numRows() {
175 175
       return $this->numRows;
176 176
     }
177 177
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      * Return the last insert id value
180 180
      * @return mixed
181 181
      */
182
-    public function insertId(){
182
+    public function insertId() {
183 183
       return $this->insertId;
184 184
     }
185 185
 
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
      * If is string will determine the result type "array" or "object"
191 191
      * @return mixed       the query SQL string or the record result
192 192
      */
193
-    public function get($returnSQLQueryOrResultType = false){
193
+    public function get($returnSQLQueryOrResultType = false) {
194 194
       $this->queryBuilder->limit(1);
195 195
       $query = $this->getAll(true);
196
-      if ($returnSQLQueryOrResultType === true){
196
+      if ($returnSQLQueryOrResultType === true) {
197 197
         return $query;
198 198
       } else {
199 199
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
      * If is string will determine the result type "array" or "object"
207 207
      * @return mixed       the query SQL string or the record result
208 208
      */
209
-    public function getAll($returnSQLQueryOrResultType = false){
209
+    public function getAll($returnSQLQueryOrResultType = false) {
210 210
 	   $query = $this->queryBuilder->getQuery();
211
-	   if ($returnSQLQueryOrResultType === true){
211
+	   if ($returnSQLQueryOrResultType === true) {
212 212
       	return $query;
213 213
       }
214 214
       return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
      * @param  boolean $escape  whether to escape or not the values
221 221
      * @return mixed          the insert id of the new record or null
222 222
      */
223
-    public function insert($data = array(), $escape = true){
224
-      if (empty($data) && ! empty($this->data)){
223
+    public function insert($data = array(), $escape = true) {
224
+      if (empty($data) && !empty($this->data)) {
225 225
         //as when using $this->setData() may be the data already escaped
226 226
         $escape = false;
227 227
         $data = $this->data;
228 228
       }
229 229
       $query = $this->queryBuilder->insert($data, $escape)->getQuery();
230 230
       $result = $this->query($query);
231
-      if ($result){
231
+      if ($result) {
232 232
         $this->insertId = $this->pdo->lastInsertId();
233 233
 		    //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
234
-        return ! ($this->insertId) ? true : $this->insertId;
234
+        return !($this->insertId) ? true : $this->insertId;
235 235
       }
236 236
       return false;
237 237
     }
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
      * @param  boolean $escape  whether to escape or not the values
243 243
      * @return mixed          the update status
244 244
      */
245
-    public function update($data = array(), $escape = true){
246
-      if (empty($data) && ! empty($this->data)){
245
+    public function update($data = array(), $escape = true) {
246
+      if (empty($data) && !empty($this->data)) {
247 247
         //as when using $this->setData() may be the data already escaped
248 248
         $escape = false;
249 249
         $data = $this->data;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      * Delete the record in database
257 257
      * @return mixed the delete status
258 258
      */
259
-    public function delete(){
259
+    public function delete() {
260 260
 		  $query = $this->queryBuilder->delete()->getQuery();
261 261
     	return $this->query($query);
262 262
     }
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      * @param integer $ttl the cache time to live in second
267 267
      * @return object        the current Database instance
268 268
      */
269
-    public function setCache($ttl = 0){
269
+    public function setCache($ttl = 0) {
270 270
       $this->cacheTtl = $ttl;
271 271
       $this->temporaryCacheTtl = $ttl;
272 272
       return $this;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 * @param  integer $ttl the cache time to live in second
278 278
 	 * @return object        the current Database instance
279 279
 	 */
280
-  	public function cached($ttl = 0){
280
+  	public function cached($ttl = 0) {
281 281
         $this->temporaryCacheTtl = $ttl;
282 282
         return $this;
283 283
     }
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
      * @return mixed       the data after escaped or the same data if no
290 290
      * need escaped
291 291
      */
292
-    public function escape($data, $escaped = true){
292
+    public function escape($data, $escaped = true) {
293 293
       $data = trim($data);
294
-      if($escaped){
294
+      if ($escaped) {
295 295
         return $this->pdo->quote($data);
296 296
       }
297 297
       return $data; 
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * Return the number query executed count for the current request
302 302
      * @return int
303 303
      */
304
-    public function queryCount(){
304
+    public function queryCount() {
305 305
       return $this->queryCount;
306 306
     }
307 307
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      * Return the current query SQL string
310 310
      * @return string
311 311
      */
312
-    public function getQuery(){
312
+    public function getQuery() {
313 313
       return $this->query;
314 314
     }
315 315
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      * Return the application database name
318 318
      * @return string
319 319
      */
320
-    public function getDatabaseName(){
320
+    public function getDatabaseName() {
321 321
       return $this->databaseName;
322 322
     }
323 323
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
      * Return the PDO instance
326 326
      * @return object
327 327
      */
328
-    public function getPdo(){
328
+    public function getPdo() {
329 329
       return $this->pdo;
330 330
     }
331 331
 
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
      * @param object $pdo the pdo object
335 335
 	 * @return object Database
336 336
      */
337
-    public function setPdo(PDO $pdo){
337
+    public function setPdo(PDO $pdo) {
338 338
       $this->pdo = $pdo;
339 339
       return $this;
340 340
     }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * Return the Log instance
345 345
      * @return Log
346 346
      */
347
-    public function getLogger(){
347
+    public function getLogger() {
348 348
       return $this->logger;
349 349
     }
350 350
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
      * @param Log $logger the log object
354 354
 	 * @return object Database
355 355
      */
356
-    public function setLogger($logger){
356
+    public function setLogger($logger) {
357 357
       $this->logger = $logger;
358 358
       return $this;
359 359
     }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * Return the cache instance
363 363
      * @return CacheInterface
364 364
      */
365
-    public function getCacheInstance(){
365
+    public function getCacheInstance() {
366 366
       return $this->cacheInstance;
367 367
     }
368 368
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      * @param CacheInterface $cache the cache object
372 372
 	 * @return object Database
373 373
      */
374
-    public function setCacheInstance($cache){
374
+    public function setCacheInstance($cache) {
375 375
       $this->cacheInstance = $cache;
376 376
       return $this;
377 377
     }
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
      * Return the DatabaseQueryBuilder instance
382 382
      * @return object DatabaseQueryBuilder
383 383
      */
384
-    public function getQueryBuilder(){
384
+    public function getQueryBuilder() {
385 385
       return $this->queryBuilder;
386 386
     }
387 387
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
      * Set the DatabaseQueryBuilder instance
390 390
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
391 391
      */
392
-    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
392
+    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) {
393 393
       $this->queryBuilder = $queryBuilder;
394 394
       return $this;
395 395
     }
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      * Return the DatabaseQueryRunner instance
399 399
      * @return object DatabaseQueryRunner
400 400
      */
401
-    public function getQueryRunner(){
401
+    public function getQueryRunner() {
402 402
       return $this->queryRunner;
403 403
     }
404 404
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
      * Set the DatabaseQueryRunner instance
407 407
      * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object
408 408
      */
409
-    public function setQueryRunner(DatabaseQueryRunner $queryRunner){
409
+    public function setQueryRunner(DatabaseQueryRunner $queryRunner) {
410 410
       $this->queryRunner = $queryRunner;
411 411
       return $this;
412 412
     }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
      * Return the data to be used for insert, update, etc.
416 416
      * @return array
417 417
      */
418
-    public function getData(){
418
+    public function getData() {
419 419
       return $this->data;
420 420
     }
421 421
 
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
      * @param boolean $escape whether to escape or not the $value
427 427
      * @return object        the current Database instance
428 428
      */
429
-    public function setData($key, $value = null, $escape = true){
430
-  	  if (is_array($key)){
431
-    		foreach($key as $k => $v){
429
+    public function setData($key, $value = null, $escape = true) {
430
+  	  if (is_array($key)) {
431
+    		foreach ($key as $k => $v) {
432 432
     			$this->setData($k, $v, $escape);
433 433
     		}	
434 434
   	  } else {
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      * @param  boolean $returnAsArray return the result as array or not
445 445
      * @return mixed         the query result
446 446
      */
447
-    public function query($query, $returnAsList = true, $returnAsArray = false){
447
+    public function query($query, $returnAsList = true, $returnAsArray = false) {
448 448
       $this->reset();
449 449
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
450 450
       //If is the SELECT query
@@ -465,12 +465,12 @@  discard block
 block discarded – undo
465 465
       //if can use cache feature for this query
466 466
       $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
467 467
     
468
-      if ($dbCacheStatus && $isSqlSELECTQuery){
468
+      if ($dbCacheStatus && $isSqlSELECTQuery) {
469 469
           $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
470 470
           $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
471 471
       }
472 472
       
473
-      if (!$cacheContent){
473
+      if (!$cacheContent) {
474 474
   	   	//count the number of query execution to server
475 475
         $this->queryCount++;
476 476
         
@@ -479,19 +479,19 @@  discard block
 block discarded – undo
479 479
                                           ->setReturnAsArray($returnAsArray)
480 480
                                           ->execute();
481 481
 
482
-        if (!is_object($queryResult)){
482
+        if (!is_object($queryResult)) {
483 483
           $this->result = false;
484 484
           $this->numRows = 0;
485 485
           return $this->result;
486 486
         }
487 487
         $this->result  = $queryResult->getResult();
488 488
         $this->numRows = $queryResult->getNumRows();
489
-        if ($isSqlSELECTQuery && $dbCacheStatus){
489
+        if ($isSqlSELECTQuery && $dbCacheStatus) {
490 490
             $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray);
491 491
             $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire);
492 492
         }
493
-      } else if ($isSqlSELECTQuery){
494
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
493
+      } else if ($isSqlSELECTQuery) {
494
+          $this->logger->info('The result for query [' . $this->query . '] already cached use it');
495 495
           $this->result = $cacheContent;
496 496
           $this->numRows = count($this->result);
497 497
       }
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
     * @param boolean $autoConnect whether to connect to database after set the configuration
506 506
 	  * @return object Database
507 507
     */
508
-    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){
508
+    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false) {
509 509
       $db = array();
510
-      if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
510
+      if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) {
511 511
           //here don't use require_once because somewhere user can create database instance directly
512 512
           require CONFIG_PATH . 'database.php';
513 513
       }
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
     	//determine the port using the hostname like localhost:3307
523 523
       //hostname will be "localhost", and port "3307"
524 524
       $p = explode(':', $config['hostname']);
525
-  	  if (count($p) >= 2){
525
+  	  if (count($p) >= 2) {
526 526
   		  $config['hostname'] = $p[0];
527 527
   		  $config['port'] = $p[1];
528 528
   		}
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 															array('password' => string_hidden($this->config['password']))
537 537
 												))
538 538
 							);
539
-  	  if($autoConnect){
539
+  	  if ($autoConnect) {
540 540
     		 //Now connect to the database
541 541
     		 $this->connect();
542 542
   		}
@@ -547,14 +547,14 @@  discard block
 block discarded – undo
547 547
    * Return the database configuration
548 548
    * @return array
549 549
    */
550
-    public  function getDatabaseConfiguration(){
550
+    public  function getDatabaseConfiguration() {
551 551
       return $this->config;
552 552
     }
553 553
 
554 554
     /**
555 555
      * Close the connexion
556 556
      */
557
-    public function close(){
557
+    public function close() {
558 558
       $this->pdo = null;
559 559
     }
560 560
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
      * Return the database default configuration
563 563
      * @return array
564 564
      */
565
-    protected function getDatabaseDefaultConfiguration(){
565
+    protected function getDatabaseDefaultConfiguration() {
566 566
       return array(
567 567
               'driver' => 'mysql',
568 568
               'username' => 'root',
@@ -580,16 +580,16 @@  discard block
 block discarded – undo
580 580
      * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties
581 581
      * @return void
582 582
      */
583
-    protected function updateQueryBuilderAndRunnerProperties(){
583
+    protected function updateQueryBuilderAndRunnerProperties() {
584 584
        //update queryBuilder with some properties needed
585
-     if (is_object($this->queryBuilder)){
585
+     if (is_object($this->queryBuilder)) {
586 586
         $this->queryBuilder->setDriver($this->config['driver'])
587 587
                            ->setPrefix($this->config['prefix'])
588 588
                            ->setPdo($this->pdo);
589 589
      }
590 590
 
591 591
       //update queryRunner with some properties needed
592
-     if (is_object($this->queryRunner)){
592
+     if (is_object($this->queryRunner)) {
593 593
         $this->queryRunner->setDriver($this->config['driver'])
594 594
                           ->setPdo($this->pdo);
595 595
      }
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
      * This method is used to get the PDO DSN string using the configured driver
601 601
      * @return string|null the DSN string or null if can not find it
602 602
      */
603
-    protected function getDsnValueFromConfig(){
603
+    protected function getDsnValueFromConfig() {
604 604
       $dsn = null;
605 605
       $config = $this->getDatabaseConfiguration();
606
-      if (! empty($config)){
606
+      if (!empty($config)) {
607 607
         $driver = $config['driver'];
608 608
         $driverDsnMap = array(
609 609
                               'mysql'  => $this->getDsnValueForDriver('mysql'),
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
                               'sqlite' => $this->getDsnValueForDriver('sqlite'),
612 612
                               'oracle' => $this->getDsnValueForDriver('oracle')
613 613
                               );
614
-        if (isset($driverDsnMap[$driver])){
614
+        if (isset($driverDsnMap[$driver])) {
615 615
           $dsn = $driverDsnMap[$driver];
616 616
         }
617 617
       }    
@@ -623,17 +623,17 @@  discard block
 block discarded – undo
623 623
      * @param  string $driver the driver name
624 624
      * @return string|null         the dsn name
625 625
      */
626
-    protected function getDsnValueForDriver($driver){
626
+    protected function getDsnValueForDriver($driver) {
627 627
       $dsn = '';
628 628
       $config = $this->getDatabaseConfiguration();
629
-      if (empty($config)){
629
+      if (empty($config)) {
630 630
         return null;
631 631
       }
632 632
       switch ($driver) {
633 633
         case 'mysql':
634 634
         case 'pgsql':
635 635
           $port = '';
636
-          if (! empty($config['port'])) {
636
+          if (!empty($config['port'])) {
637 637
             $port = 'port=' . $config['port'] . ';';
638 638
           }
639 639
           $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
@@ -643,10 +643,10 @@  discard block
 block discarded – undo
643 643
           break;
644 644
           case 'oracle':
645 645
           $port = '';
646
-          if (! empty($config['port'])) {
646
+          if (!empty($config['port'])) {
647 647
             $port = ':' . $config['port'];
648 648
           }
649
-          $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
649
+          $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
650 650
           break;
651 651
       }
652 652
       return $dsn;
@@ -658,9 +658,9 @@  discard block
 block discarded – undo
658 658
      *      
659 659
      * @return mixed
660 660
      */
661
-    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){
661
+    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) {
662 662
         $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray);
663
-        if (! is_object($this->cacheInstance)){
663
+        if (!is_object($this->cacheInstance)) {
664 664
     			//can not call method with reference in argument
665 665
     			//like $this->setCacheInstance(& get_instance()->cache);
666 666
     			//use temporary variable
@@ -677,9 +677,9 @@  discard block
 block discarded – undo
677 677
      * @param mixed $result the query result to save
678 678
      * @param int $expire the cache TTL
679 679
      */
680
-     protected function setCacheContentForQuery($query, $key, $result, $expire){
681
-        $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
682
-        if (! is_object($this->cacheInstance)){
680
+     protected function setCacheContentForQuery($query, $key, $result, $expire) {
681
+        $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
682
+        if (!is_object($this->cacheInstance)) {
683 683
   				//can not call method with reference in argument
684 684
   				//like $this->setCacheInstance(& get_instance()->cache);
685 685
   				//use temporary variable
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
      * 
697 697
      *  @return string
698 698
      */
699
-    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){
699
+    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) {
700 700
       return md5($query . $returnAsList . $returnAsArray);
701 701
     }
702 702
 
@@ -710,12 +710,12 @@  discard block
 block discarded – undo
710 710
      *
711 711
      * @return object this current instance
712 712
      */
713
-    protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
714
-      if ($instance !== null){
713
+    protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes') {
714
+      if ($instance !== null) {
715 715
         $this->{$name} = $instance;
716 716
         return $this;
717 717
       }
718
-      $this->{$name} =& class_loader($loadClassName, $loadClassePath);
718
+      $this->{$name} = & class_loader($loadClassName, $loadClassePath);
719 719
       return $this;
720 720
     }
721 721
     
@@ -725,9 +725,9 @@  discard block
 block discarded – undo
725 725
      *
726 726
      * @return object this current instance
727 727
      */
728
-    protected function setLoggerFromParamOrCreate(Log $logger = null){
728
+    protected function setLoggerFromParamOrCreate(Log $logger = null) {
729 729
       $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
730
-      if ($logger === null){
730
+      if ($logger === null) {
731 731
         $this->logger->setLogger('Library::Database');
732 732
       }
733 733
       return $this;
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
     /**
737 737
      * Reset the database class attributs to the initail values before each query.
738 738
      */
739
-    private function reset(){
739
+    private function reset() {
740 740
 	   //query builder reset
741 741
       $this->queryBuilder->reset();
742 742
       $this->numRows  = 0;
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
     /**
750 750
      * The class destructor
751 751
      */
752
-    public function __destruct(){
752
+    public function __destruct() {
753 753
       $this->pdo = null;
754 754
     }
755 755
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -156,8 +156,7 @@
 block discarded – undo
156 156
             $this->updateQueryBuilderAndRunnerProperties();
157 157
 
158 158
             return true;
159
-          }
160
-          catch (PDOException $e){
159
+          } catch (PDOException $e){
161 160
             $this->logger->fatal($e->getMessage());
162 161
             show_error('Cannot connect to Database.');
163 162
             return false;
Please login to merge, or discard this patch.
core/classes/Controller.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,146 +1,146 @@
 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 Controller{
27
+    class Controller{
28 28
 		
29
-		/**
30
-		 * The name of the module if this controller belong to an module
31
-		 * @var string
32
-		 */
33
-		public $moduleName = null;
29
+        /**
30
+         * The name of the module if this controller belong to an module
31
+         * @var string
32
+         */
33
+        public $moduleName = null;
34 34
 
35
-		/**
36
-		 * The singleton of the super object
37
-		 * @var Controller
38
-		 */
39
-		private static $instance;
35
+        /**
36
+         * The singleton of the super object
37
+         * @var Controller
38
+         */
39
+        private static $instance;
40 40
 
41
-		/**
42
-		 * The logger instance
43
-		 * @var Log
44
-		 */
45
-		protected $logger;
41
+        /**
42
+         * The logger instance
43
+         * @var Log
44
+         */
45
+        protected $logger;
46 46
 
47
-		/**
48
-		 * Class constructor
49
-		 * @param object $logger the Log instance to use if is null will create one
50
-		 */
51
-		public function __construct(Log $logger = null){
52
-			//setting the Log instance
53
-			$this->setLoggerFromParamOrCreateNewInstance($logger);
47
+        /**
48
+         * Class constructor
49
+         * @param object $logger the Log instance to use if is null will create one
50
+         */
51
+        public function __construct(Log $logger = null){
52
+            //setting the Log instance
53
+            $this->setLoggerFromParamOrCreateNewInstance($logger);
54 54
 			
55
-			//instance of the super object
56
-			self::$instance = & $this;
55
+            //instance of the super object
56
+            self::$instance = & $this;
57 57
 
58
-			//Load the resources loaded during the application bootstrap
59
-			$this->logger->debug('Adding the loaded classes to the super instance');
60
-			foreach (class_loaded() as $var => $class){
61
-				$this->$var =& class_loader($class);
62
-			}
58
+            //Load the resources loaded during the application bootstrap
59
+            $this->logger->debug('Adding the loaded classes to the super instance');
60
+            foreach (class_loaded() as $var => $class){
61
+                $this->$var =& class_loader($class);
62
+            }
63 63
 			
64
-			//set module using the router
65
-			$this->setModuleNameFromRouter();
64
+            //set module using the router
65
+            $this->setModuleNameFromRouter();
66 66
 
67
-			//load the required resources
68
-			$this->loadRequiredResources();
67
+            //load the required resources
68
+            $this->loadRequiredResources();
69 69
 			
70
-			//set the cache using the configuration
71
-			$this->setCacheFromParamOrConfig(null);
70
+            //set the cache using the configuration
71
+            $this->setCacheFromParamOrConfig(null);
72 72
 			
73
-			//set application session configuration
74
-			$this->logger->debug('Setting PHP application session handler');
75
-			set_session_config();
73
+            //set application session configuration
74
+            $this->logger->debug('Setting PHP application session handler');
75
+            set_session_config();
76 76
 
77
-			//dispatch the loaded instance of super controller event
78
-			$this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
79
-		}
77
+            //dispatch the loaded instance of super controller event
78
+            $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
79
+        }
80 80
 
81 81
 
82
-		/**
83
-		 * This is a very useful method it's used to get the super object instance
84
-		 * @return Controller the super object instance
85
-		 */
86
-		public static function &get_instance(){
87
-			return self::$instance;
88
-		}
82
+        /**
83
+         * This is a very useful method it's used to get the super object instance
84
+         * @return Controller the super object instance
85
+         */
86
+        public static function &get_instance(){
87
+            return self::$instance;
88
+        }
89 89
 
90
-		/**
91
-		 * This method is used to set the module name
92
-		 */
93
-		protected function setModuleNameFromRouter(){
94
-			//set the module using the router instance
95
-			if(isset($this->router) && $this->router->getModule()){
96
-				$this->moduleName = $this->router->getModule();
97
-			}
98
-		}
90
+        /**
91
+         * This method is used to set the module name
92
+         */
93
+        protected function setModuleNameFromRouter(){
94
+            //set the module using the router instance
95
+            if(isset($this->router) && $this->router->getModule()){
96
+                $this->moduleName = $this->router->getModule();
97
+            }
98
+        }
99 99
 
100
-		/**
101
-		 * Set the cache using the argument otherwise will use the configuration
102
-		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
103
-		 */
104
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
105
-			$this->logger->debug('Setting the cache handler instance');
106
-			//set cache handler instance
107
-			if(get_config('cache_enable', false)){
108
-				if ($cache !== null){
109
-					$this->cache = $cache;
110
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
111
-					$this->cache = $this->{strtolower(get_config('cache_handler'))};
112
-					unset($this->{strtolower(get_config('cache_handler'))});
113
-				} 
114
-			}
115
-		}
100
+        /**
101
+         * Set the cache using the argument otherwise will use the configuration
102
+         * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
103
+         */
104
+        protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
105
+            $this->logger->debug('Setting the cache handler instance');
106
+            //set cache handler instance
107
+            if(get_config('cache_enable', false)){
108
+                if ($cache !== null){
109
+                    $this->cache = $cache;
110
+                } else if (isset($this->{strtolower(get_config('cache_handler'))})){
111
+                    $this->cache = $this->{strtolower(get_config('cache_handler'))};
112
+                    unset($this->{strtolower(get_config('cache_handler'))});
113
+                } 
114
+            }
115
+        }
116 116
 
117
-		/**
118
-		 * Set the Log instance using argument or create new instance
119
-		 * @param object $logger the Log instance if not null
120
-		 */
121
-		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
122
-			if($logger !== null){
123
-	          $this->logger = $logger;
124
-	        }
125
-	        else{
126
-	            $this->logger =& class_loader('Log', 'classes');
127
-				$this->logger->setLogger('MainController');
128
-	        }
129
-		}
117
+        /**
118
+         * Set the Log instance using argument or create new instance
119
+         * @param object $logger the Log instance if not null
120
+         */
121
+        protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
122
+            if($logger !== null){
123
+                $this->logger = $logger;
124
+            }
125
+            else{
126
+                $this->logger =& class_loader('Log', 'classes');
127
+                $this->logger->setLogger('MainController');
128
+            }
129
+        }
130 130
 
131
-		/**
132
-		 * This method is used to load the required resources for framework to work
133
-		 * @return void 
134
-		 */
135
-		private function loadRequiredResources(){
136
-			$this->logger->debug('Loading the required classes into super instance');
137
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
138
-			$this->loader =& class_loader('Loader', 'classes');
139
-			$this->lang =& class_loader('Lang', 'classes');
140
-			$this->request =& class_loader('Request', 'classes');
141
-			//dispatch the request instance created event
142
-			$this->eventdispatcher->dispatch('REQUEST_CREATED');
143
-			$this->response =& class_loader('Response', 'classes', 'classes');
144
-		}
131
+        /**
132
+         * This method is used to load the required resources for framework to work
133
+         * @return void 
134
+         */
135
+        private function loadRequiredResources(){
136
+            $this->logger->debug('Loading the required classes into super instance');
137
+            $this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
138
+            $this->loader =& class_loader('Loader', 'classes');
139
+            $this->lang =& class_loader('Lang', 'classes');
140
+            $this->request =& class_loader('Request', 'classes');
141
+            //dispatch the request instance created event
142
+            $this->eventdispatcher->dispatch('REQUEST_CREATED');
143
+            $this->response =& class_loader('Response', 'classes', 'classes');
144
+        }
145 145
 
146
-	}
146
+    }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 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 Controller{
27
+	class Controller {
28 28
 		
29 29
 		/**
30 30
 		 * The name of the module if this controller belong to an module
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		 * Class constructor
49 49
 		 * @param object $logger the Log instance to use if is null will create one
50 50
 		 */
51
-		public function __construct(Log $logger = null){
51
+		public function __construct(Log $logger = null) {
52 52
 			//setting the Log instance
53 53
 			$this->setLoggerFromParamOrCreateNewInstance($logger);
54 54
 			
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 
58 58
 			//Load the resources loaded during the application bootstrap
59 59
 			$this->logger->debug('Adding the loaded classes to the super instance');
60
-			foreach (class_loaded() as $var => $class){
61
-				$this->$var =& class_loader($class);
60
+			foreach (class_loaded() as $var => $class) {
61
+				$this->$var = & class_loader($class);
62 62
 			}
63 63
 			
64 64
 			//set module using the router
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 		/**
91 91
 		 * This method is used to set the module name
92 92
 		 */
93
-		protected function setModuleNameFromRouter(){
93
+		protected function setModuleNameFromRouter() {
94 94
 			//set the module using the router instance
95
-			if(isset($this->router) && $this->router->getModule()){
95
+			if (isset($this->router) && $this->router->getModule()) {
96 96
 				$this->moduleName = $this->router->getModule();
97 97
 			}
98 98
 		}
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 		 * Set the cache using the argument otherwise will use the configuration
102 102
 		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
103 103
 		 */
104
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
104
+		protected function setCacheFromParamOrConfig(CacheInterface $cache = null) {
105 105
 			$this->logger->debug('Setting the cache handler instance');
106 106
 			//set cache handler instance
107
-			if(get_config('cache_enable', false)){
108
-				if ($cache !== null){
107
+			if (get_config('cache_enable', false)) {
108
+				if ($cache !== null) {
109 109
 					$this->cache = $cache;
110
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
110
+				} else if (isset($this->{strtolower(get_config('cache_handler'))})) {
111 111
 					$this->cache = $this->{strtolower(get_config('cache_handler'))};
112 112
 					unset($this->{strtolower(get_config('cache_handler'))});
113 113
 				} 
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 		 * Set the Log instance using argument or create new instance
119 119
 		 * @param object $logger the Log instance if not null
120 120
 		 */
121
-		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
122
-			if($logger !== null){
121
+		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
122
+			if ($logger !== null) {
123 123
 	          $this->logger = $logger;
124 124
 	        }
125
-	        else{
126
-	            $this->logger =& class_loader('Log', 'classes');
125
+	        else {
126
+	            $this->logger = & class_loader('Log', 'classes');
127 127
 				$this->logger->setLogger('MainController');
128 128
 	        }
129 129
 		}
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 		 * This method is used to load the required resources for framework to work
133 133
 		 * @return void 
134 134
 		 */
135
-		private function loadRequiredResources(){
135
+		private function loadRequiredResources() {
136 136
 			$this->logger->debug('Loading the required classes into super instance');
137
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
138
-			$this->loader =& class_loader('Loader', 'classes');
139
-			$this->lang =& class_loader('Lang', 'classes');
140
-			$this->request =& class_loader('Request', 'classes');
137
+			$this->eventdispatcher = & class_loader('EventDispatcher', 'classes');
138
+			$this->loader = & class_loader('Loader', 'classes');
139
+			$this->lang = & class_loader('Lang', 'classes');
140
+			$this->request = & class_loader('Request', 'classes');
141 141
 			//dispatch the request instance created event
142 142
 			$this->eventdispatcher->dispatch('REQUEST_CREATED');
143
-			$this->response =& class_loader('Response', 'classes', 'classes');
143
+			$this->response = & class_loader('Response', 'classes', 'classes');
144 144
 		}
145 145
 
146 146
 	}
Please login to merge, or discard this patch.