Test Failed
Push — 1.0.0-dev ( b5c6bf...f8836a )
by nguereza
04:02
created
tests/tnhfw/classes/DBSessionHandlerTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
 		
47 47
 		
48
-		public function testUsingSessionConfiguration(){
48
+		public function testUsingSessionConfiguration() {
49 49
 			$secret = 'bXlzZWNyZXQ';
50 50
 			//using value in the configuration
51 51
 			static::$config->set('session_save_path', 'DBSessionModel');
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
73 73
 		}
74 74
 		
75
-		public function testWhenDataIsExpired(){
75
+		public function testWhenDataIsExpired() {
76 76
 			$model = new DBSessionModel($this->db);
77 77
 			//to prevent old data conflict
78 78
 			$model->truncate();
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			$this->assertFalse($dbsh->read('foo'));
91 91
 		}
92 92
 		
93
-		public function testWhenDataAlreadyExistDoUpdate(){
93
+		public function testWhenDataAlreadyExistDoUpdate() {
94 94
 			$model = new DBSessionModel($this->db);
95 95
 			//to prevent old data conflict
96 96
 			$model->truncate();
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 			$this->assertEquals($dbsh->read('foo'), '445');	
109 109
 		}
110 110
 		
111
-		public function testUsingCustomModelInstance(){
111
+		public function testUsingCustomModelInstance() {
112 112
 			
113 113
 			$model = new DBSessionModel($this->db);
114 114
 			//to prevent old data conflict
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		}
143 143
 			
144 144
 			
145
-		public function testUsingCustomLogInstance(){
145
+		public function testUsingCustomLogInstance() {
146 146
 			$model = new DBSessionModel($this->db);
147 147
 			//to prevent old data conflict
148 148
 			$model->truncate();
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
175 175
 		}
176 176
 		
177
-		public function testUsingCustomLoaderInstance(){
177
+		public function testUsingCustomLoaderInstance() {
178 178
 			$model = new DBSessionModel($this->db);
179 179
 			//to prevent old data conflict
180 180
 			$model->truncate();
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
207 207
 		}
208 208
 		
209
-		public function testWhenModelInsanceIsNotSet(){
209
+		public function testWhenModelInsanceIsNotSet() {
210 210
 			$model = new DBSessionModel($this->db);
211 211
 			//to prevent old data conflict
212 212
 			$model->truncate();
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
239 239
 		}
240 240
 		
241
-		public function testWhenModelTableColumnsIsNotSet(){
241
+		public function testWhenModelTableColumnsIsNotSet() {
242 242
 			$model = new DBSessionModel($this->db);
243 243
 			//to prevent old data conflict
244 244
 			$model->truncate();
Please login to merge, or discard this patch.
tests/tnhfw/classes/SessionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 			$this->assertEquals('bar', Session::get('foo'));
31 31
 		}
32 32
 		
33
-		public function testExc(){
33
+		public function testExc() {
34 34
 			 //$this->expectException(InvalidArgumentException::class);
35 35
 		}
36 36
 	}
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
tests/hmvc/models/CoursModel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-	class CoursModel extends Model{
2
+	class CoursModel extends Model {
3 3
 		
4 4
 		protected $_table = 'specialite';
5 5
 		protected $validate = array(
Please login to merge, or discard this patch.
tests/hmvc/models/DBSessionModel.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	class DBSessionModel extends DBSessionHandlerModel{
2
+	class DBSessionModel extends DBSessionHandlerModel {
3 3
 		
4 4
 		protected $_table = 'ses';
5 5
 		protected $primary_key = 's_id';
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 			'skey' => 'usr_id' //VARCHAR(255) 
15 15
 		);
16 16
 		
17
-		public function deleteByTime($time){
17
+		public function deleteByTime($time) {
18 18
 			$this->_database->from($this->_table)
19 19
 						->where('s_time', '<', $time)
20 20
 						->delete();
21 21
 		}
22 22
 
23 23
 		
24
-		public function getKeyValue(){
24
+		public function getKeyValue() {
25 25
 			$user_id = 0;
26 26
 			return $user_id;
27 27
 		}
Please login to merge, or discard this patch.
tests/hmvc/models/ClasseModel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-	class ClasseModel extends Model{
2
+	class ClasseModel extends Model {
3 3
 		
4 4
 		protected $_table = 'classe';
5 5
 		protected $primary_key = 'cls_id';
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 3 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 	
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
@@ -76,27 +76,27 @@  discard block
 block discarded – undo
76 76
 		private $logger;
77 77
 
78 78
 		/**
79
-         * Instance of the Loader class
80
-         * @var Loader
81
-         */
82
-        protected $loader = null;
79
+		 * Instance of the Loader class
80
+		 * @var Loader
81
+		 */
82
+		protected $loader = null;
83 83
 
84 84
 		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
85 85
 			/**
86
-	         * instance of the Log class
87
-	         */
88
-	        if(is_object($logger)){
89
-	          $this->setLogger($logger);
90
-	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
93
-	            $this->logger->setLogger('Library::DBSessionHandler');
94
-	        }
95
-
96
-	        if(is_object($loader)){
97
-	          $this->setLoader($loader);
98
-	        }
99
-		    $this->OBJ = & get_instance();
86
+			 * instance of the Log class
87
+			 */
88
+			if(is_object($logger)){
89
+			  $this->setLogger($logger);
90
+			}
91
+			else{
92
+				$this->logger =& class_loader('Log', 'classes');
93
+				$this->logger->setLogger('Library::DBSessionHandler');
94
+			}
95
+
96
+			if(is_object($loader)){
97
+			  $this->setLoader($loader);
98
+			}
99
+			$this->OBJ = & get_instance();
100 100
 
101 101
 		    
102 102
 			if(is_object($modelInstance)){
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
 				$this->getLoader()->library('Browser'); 
200 200
 			}
201 201
 			else{
202
-            	Loader::functions('user_agent');
203
-            	Loader::library('Browser');
204
-            }
202
+				Loader::functions('user_agent');
203
+				Loader::library('Browser');
204
+			}
205 205
 			
206 206
 			$ip = get_ip();
207 207
 			$keyValue = $instance->getKeyValue();
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
 				$this->getLoader()->library('Browser'); 
240 240
 			}
241 241
 			else{
242
-            	Loader::functions('user_agent');
243
-            	Loader::library('Browser');
244
-            }
242
+				Loader::functions('user_agent');
243
+				Loader::library('Browser');
244
+			}
245 245
 
246 246
 			$ip = get_ip();
247 247
 			$keyValue = $instance->getKeyValue();
@@ -325,75 +325,75 @@  discard block
 block discarded – undo
325 325
 
326 326
 		
327 327
 		/**
328
-         * Return the loader instance
329
-         * @return Loader the loader instance
330
-         */
331
-        public function getLoader(){
332
-            return $this->loader;
333
-        }
334
-
335
-        /**
336
-         * set the loader instance for future use
337
-         * @param Loader $loader the loader object
338
-         */
339
-         public function setLoader($loader){
340
-            $this->loader = $loader;
341
-            return $this;
342
-        }
343
-
344
-        /**
345
-         * Return the model instance
346
-         * @return DBSessionHandlerModel the model instance
347
-         */
348
-        public function getModelInstance(){
349
-            return $this->modelInstanceName;
350
-        }
351
-
352
-        /**
353
-         * set the model instance for future use
354
-         * @param DBSessionHandlerModel $modelInstance the model object
355
-         */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
357
-            $this->modelInstanceName = $modelInstance;
358
-            return $this;
359
-        }
360
-
361
-        /**
362
-	     * Return the Log instance
363
-	     * @return Log
364
-	     */
365
-	    public function getLogger(){
366
-	      return $this->logger;
367
-	    }
368
-
369
-	    /**
370
-	     * Set the log instance
371
-	     * @param Log $logger the log object
372
-	     */
373
-	    public function setLogger(Log $logger){
374
-	      $this->logger = $logger;
375
-	      return $this;
376
-	    }
377
-
378
-	    /**
379
-	     * Set the model instance using the configuration for session
380
-	     */
381
-	    private function setModelInstanceFromConfig(){
382
-	    	$modelName = get_config('session_save_path');
328
+		 * Return the loader instance
329
+		 * @return Loader the loader instance
330
+		 */
331
+		public function getLoader(){
332
+			return $this->loader;
333
+		}
334
+
335
+		/**
336
+		 * set the loader instance for future use
337
+		 * @param Loader $loader the loader object
338
+		 */
339
+		 public function setLoader($loader){
340
+			$this->loader = $loader;
341
+			return $this;
342
+		}
343
+
344
+		/**
345
+		 * Return the model instance
346
+		 * @return DBSessionHandlerModel the model instance
347
+		 */
348
+		public function getModelInstance(){
349
+			return $this->modelInstanceName;
350
+		}
351
+
352
+		/**
353
+		 * set the model instance for future use
354
+		 * @param DBSessionHandlerModel $modelInstance the model object
355
+		 */
356
+		 public function setModelInstance(DBSessionHandlerModel $modelInstance){
357
+			$this->modelInstanceName = $modelInstance;
358
+			return $this;
359
+		}
360
+
361
+		/**
362
+		 * Return the Log instance
363
+		 * @return Log
364
+		 */
365
+		public function getLogger(){
366
+		  return $this->logger;
367
+		}
368
+
369
+		/**
370
+		 * Set the log instance
371
+		 * @param Log $logger the log object
372
+		 */
373
+		public function setLogger(Log $logger){
374
+		  $this->logger = $logger;
375
+		  return $this;
376
+		}
377
+
378
+		/**
379
+		 * Set the model instance using the configuration for session
380
+		 */
381
+		private function setModelInstanceFromConfig(){
382
+			$modelName = get_config('session_save_path');
383 383
 			$this->logger->info('The database session model: ' . $modelName);
384 384
 			if($this->getLoader()){
385 385
 				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386 386
 			}
387 387
 			//@codeCoverageIgnoreStart
388 388
 			else{
389
-            	Loader::model($modelName, 'dbsessionhandlerinstance'); 
390
-            }
391
-            if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
389
+				Loader::model($modelName, 'dbsessionhandlerinstance'); 
390
+			}
391
+			if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392 392
 				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
393 393
 			}  
394 394
 			//@codeCoverageIgnoreEnd
395 395
 			
396 396
 			//set model instance
397 397
 			$this->setModelInstance($this->OBJ->dbsessionhandlerinstance);
398
-	    }
398
+		}
399 399
 	}
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
 	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
30
+	if (!interface_exists('SessionHandlerInterface')) {
31 31
 		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
 	}
33 33
 
34
-	class DBSessionHandler implements SessionHandlerInterface{
34
+	class DBSessionHandler implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -81,25 +81,25 @@  discard block
 block discarded – undo
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
84
+		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) {
85 85
 			/**
86 86
 	         * instance of the Log class
87 87
 	         */
88
-	        if(is_object($logger)){
88
+	        if (is_object($logger)) {
89 89
 	          $this->setLogger($logger);
90 90
 	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
91
+	        else {
92
+	            $this->logger = & class_loader('Log', 'classes');
93 93
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 94
 	        }
95 95
 
96
-	        if(is_object($loader)){
96
+	        if (is_object($loader)) {
97 97
 	          $this->setLoader($loader);
98 98
 	        }
99 99
 		    $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
102
+			if (is_object($modelInstance)) {
103 103
 				$this->setModelInstance($modelInstance);
104 104
 			}
105 105
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		 * Set the session secret used to encrypt the data in database 
109 109
 		 * @param string $secret the base64 string secret
110 110
 		 */
111
-		public function setSessionSecret($secret){
111
+		public function setSessionSecret($secret) {
112 112
 			$this->sessionSecret = $secret;
113 113
 			return $this;
114 114
 		}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Return the session secret
118 118
 		 * @return string 
119 119
 		 */
120
-		public function getSessionSecret(){
120
+		public function getSessionSecret() {
121 121
 			return $this->sessionSecret;
122 122
 		}
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * Set the initializer vector for openssl 
127 127
 		 * @param string $key the session secret used
128 128
 		 */
129
-		public function setInitializerVector($key){
129
+		public function setInitializerVector($key) {
130 130
 			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131 131
 			$key = base64_decode($key);
132 132
 			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * Return the initializer vector
138 138
 		 * @return string 
139 139
 		 */
140
-		public function getInitializerVector(){
140
+		public function getInitializerVector() {
141 141
 			return $this->iv;
142 142
 		}
143 143
 
@@ -147,16 +147,16 @@  discard block
 block discarded – undo
147 147
 		 * @param  string $sessionName the session name
148 148
 		 * @return boolean 
149 149
 		 */
150
-		public function open($savePath, $sessionName){
150
+		public function open($savePath, $sessionName) {
151 151
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152 152
 			//try to check if session secret is set before
153
-			if(! $this->getSessionSecret()){
153
+			if (!$this->getSessionSecret()) {
154 154
 				$secret = get_config('session_secret', false);
155 155
 				$this->setSessionSecret($secret);
156 156
 			}
157 157
 			$this->logger->info('Session secret: ' . $this->getSessionSecret());
158 158
 
159
-			if(! $this->getModelInstance()){
159
+			if (!$this->getModelInstance()) {
160 160
 				$this->setModelInstanceFromConfig();
161 161
 			}
162 162
 			$this->setInitializerVector($this->getSessionSecret());
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 			//set session tables columns
165 165
 			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
166 166
 
167
-			if(empty($this->sessionTableColumns)){
167
+			if (empty($this->sessionTableColumns)) {
168 168
 				show_error('The session handler is "database" but the table columns not set');
169 169
 			}
170 170
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		 * Close the session
181 181
 		 * @return boolean
182 182
 		 */
183
-		public function close(){
183
+		public function close() {
184 184
 			$this->logger->debug('Closing database session handler');
185 185
 			return true;
186 186
 		}
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
 		 * @param  string $sid the session id to use
191 191
 		 * @return mixed      the session data in serialiaze format
192 192
 		 */
193
-		public function read($sid){
193
+		public function read($sid) {
194 194
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
195 195
 			$instance = $this->getModelInstance();
196 196
 			$columns = $this->sessionTableColumns;
197
-			if($this->getLoader()){
197
+			if ($this->getLoader()) {
198 198
 				$this->getLoader()->functions('user_agent'); 
199 199
 				$this->getLoader()->library('Browser'); 
200 200
 			}
201
-			else{
201
+			else {
202 202
             	Loader::functions('user_agent');
203 203
             	Loader::library('Browser');
204 204
             }
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 			$ip = get_ip();
207 207
 			$keyValue = $instance->getKeyValue();
208 208
 			$host = @gethostbyaddr($ip) or null;
209
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
209
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
210 210
 			
211 211
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
-			if($data && isset($data->{$columns['sdata']})){
212
+			if ($data && isset($data->{$columns['sdata']})) {
213 213
 				//checking inactivity 
214 214
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
215
-				if($data->{$columns['stime']} < $timeInactivity){
215
+				if ($data->{$columns['stime']} < $timeInactivity) {
216 216
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217 217
 					$this->destroy($sid);
218 218
 					return false;
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
 		 * @param  mixed $data the session data to save in serialize format
230 230
 		 * @return boolean 
231 231
 		 */
232
-		public function write($sid, $data){
232
+		public function write($sid, $data) {
233 233
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234 234
 			$instance = $this->getModelInstance();
235 235
 			$columns = $this->sessionTableColumns;
236 236
 
237
-			if($this->getLoader()){
237
+			if ($this->getLoader()) {
238 238
 				$this->getLoader()->functions('user_agent'); 
239 239
 				$this->getLoader()->library('Browser'); 
240 240
 			}
241
-			else{
241
+			else {
242 242
             	Loader::functions('user_agent');
243 243
             	Loader::library('Browser');
244 244
             }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			$ip = get_ip();
247 247
 			$keyValue = $instance->getKeyValue();
248 248
 			$host = @gethostbyaddr($ip) or null;
249
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
249
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
250 250
 			$data = $this->encode($data);
251 251
 			$params = array(
252 252
 							$columns['sid'] => $sid,
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
 						);
260 260
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261 261
 			$exists = $instance->get($sid);
262
-			if($exists){
262
+			if ($exists) {
263 263
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264 264
 				//update
265 265
 				unset($params[$columns['sid']]);
266 266
 				$instance->update($sid, $params);
267 267
 			}
268
-			else{
268
+			else {
269 269
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270 270
 				$instance->insert($params);
271 271
 			}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		 * @param  string $sid the session id value
279 279
 		 * @return boolean
280 280
 		 */
281
-		public function destroy($sid){
281
+		public function destroy($sid) {
282 282
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
283 283
 			$instance = $this->modelInstanceName;
284 284
 			$instance->delete($sid);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		 * @param  ineteger $maxLifetime the max lifetime
291 291
 		 * @return boolean
292 292
 		 */
293
-		public function gc($maxLifetime){
293
+		public function gc($maxLifetime) {
294 294
 			$instance = $this->modelInstanceName;
295 295
 			$time = time() - $maxLifetime;
296 296
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 		 * @param  mixed $data the session data to encode
304 304
 		 * @return mixed the encoded session data
305 305
 		 */
306
-		public function encode($data){
306
+		public function encode($data) {
307 307
 			$key = base64_decode($this->sessionSecret);
308
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
308
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309 309
 			$output = base64_encode($dataEncrypted);
310 310
 			return $output;
311 311
 		}
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		 * @param  mixed $data the data to decode
317 317
 		 * @return mixed       the decoded data
318 318
 		 */
319
-		public function decode($data){
319
+		public function decode($data) {
320 320
 			$key = base64_decode($this->sessionSecret);
321 321
 			$data = base64_decode($data);
322 322
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
          * Return the loader instance
329 329
          * @return Loader the loader instance
330 330
          */
331
-        public function getLoader(){
331
+        public function getLoader() {
332 332
             return $this->loader;
333 333
         }
334 334
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
          * set the loader instance for future use
337 337
          * @param Loader $loader the loader object
338 338
          */
339
-         public function setLoader($loader){
339
+         public function setLoader($loader) {
340 340
             $this->loader = $loader;
341 341
             return $this;
342 342
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
          * Return the model instance
346 346
          * @return DBSessionHandlerModel the model instance
347 347
          */
348
-        public function getModelInstance(){
348
+        public function getModelInstance() {
349 349
             return $this->modelInstanceName;
350 350
         }
351 351
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
          * set the model instance for future use
354 354
          * @param DBSessionHandlerModel $modelInstance the model object
355 355
          */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
356
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
357 357
             $this->modelInstanceName = $modelInstance;
358 358
             return $this;
359 359
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	     * Return the Log instance
363 363
 	     * @return Log
364 364
 	     */
365
-	    public function getLogger(){
365
+	    public function getLogger() {
366 366
 	      return $this->logger;
367 367
 	    }
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	     * Set the log instance
371 371
 	     * @param Log $logger the log object
372 372
 	     */
373
-	    public function setLogger(Log $logger){
373
+	    public function setLogger(Log $logger) {
374 374
 	      $this->logger = $logger;
375 375
 	      return $this;
376 376
 	    }
@@ -378,18 +378,18 @@  discard block
 block discarded – undo
378 378
 	    /**
379 379
 	     * Set the model instance using the configuration for session
380 380
 	     */
381
-	    private function setModelInstanceFromConfig(){
381
+	    private function setModelInstanceFromConfig() {
382 382
 	    	$modelName = get_config('session_save_path');
383 383
 			$this->logger->info('The database session model: ' . $modelName);
384
-			if($this->getLoader()){
384
+			if ($this->getLoader()) {
385 385
 				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386 386
 			}
387 387
 			//@codeCoverageIgnoreStart
388
-			else{
388
+			else {
389 389
             	Loader::model($modelName, 'dbsessionhandlerinstance'); 
390 390
             }
391
-            if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
391
+            if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) {
392
+				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
393 393
 			}  
394 394
 			//@codeCoverageIgnoreEnd
395 395
 			
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
 	         */
88 88
 	        if(is_object($logger)){
89 89
 	          $this->setLogger($logger);
90
-	        }
91
-	        else{
90
+	        } else{
92 91
 	            $this->logger =& class_loader('Log', 'classes');
93 92
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 93
 	        }
@@ -197,8 +196,7 @@  discard block
 block discarded – undo
197 196
 			if($this->getLoader()){
198 197
 				$this->getLoader()->functions('user_agent'); 
199 198
 				$this->getLoader()->library('Browser'); 
200
-			}
201
-			else{
199
+			} else{
202 200
             	Loader::functions('user_agent');
203 201
             	Loader::library('Browser');
204 202
             }
@@ -237,8 +235,7 @@  discard block
 block discarded – undo
237 235
 			if($this->getLoader()){
238 236
 				$this->getLoader()->functions('user_agent'); 
239 237
 				$this->getLoader()->library('Browser'); 
240
-			}
241
-			else{
238
+			} else{
242 239
             	Loader::functions('user_agent');
243 240
             	Loader::library('Browser');
244 241
             }
@@ -264,8 +261,7 @@  discard block
 block discarded – undo
264 261
 				//update
265 262
 				unset($params[$columns['sid']]);
266 263
 				$instance->update($sid, $params);
267
-			}
268
-			else{
264
+			} else{
269 265
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270 266
 				$instance->insert($params);
271 267
 			}
Please login to merge, or discard this patch.
core/classes/model/Model.php 3 patches
Indentation   +934 added lines, -934 removed lines patch added patch discarded remove patch
@@ -1,595 +1,595 @@  discard block
 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
-
27
-
28
-    /**
29
-     * A base model with a series of CRUD functions (powered by CI's query builder),
30
-     * validation-in-model support, event callbacks and more.
31
-     *
32
-     * @link http://github.com/jamierumbelow/codeigniter-base-model
33
-     * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34
-     */
35
-
36
-    class Model{
37
-
38
-        /* --------------------------------------------------------------
2
+	defined('ROOT_PATH') || exit('Access denied');
3
+	/**
4
+	 * TNH Framework
5
+	 *
6
+	 * A simple PHP framework using HMVC architecture
7
+	 *
8
+	 * This content is released under the GNU GPL License (GPL)
9
+	 *
10
+	 * Copyright (C) 2017 Tony NGUEREZA
11
+	 *
12
+	 * This program is free software; you can redistribute it and/or
13
+	 * modify it under the terms of the GNU General Public License
14
+	 * as published by the Free Software Foundation; either version 3
15
+	 * of the License, or (at your option) any later version.
16
+	 *
17
+	 * This program is distributed in the hope that it will be useful,
18
+	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+	 * GNU General Public License for more details.
21
+	 *
22
+	 * You should have received a copy of the GNU General Public License
23
+	 * along with this program; if not, write to the Free Software
24
+	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+	 */
26
+
27
+
28
+	/**
29
+	 * A base model with a series of CRUD functions (powered by CI's query builder),
30
+	 * validation-in-model support, event callbacks and more.
31
+	 *
32
+	 * @link http://github.com/jamierumbelow/codeigniter-base-model
33
+	 * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34
+	 */
35
+
36
+	class Model{
37
+
38
+		/* --------------------------------------------------------------
39 39
          * VARIABLES
40 40
          * ------------------------------------------------------------ */
41 41
 
42
-        /**
43
-         * This model's default database table. Automatically
44
-         * guessed by pluralising the model name.
45
-         */
46
-        protected $_table;
47
-
48
-        /**
49
-         * The database connection object. Will be set to the default
50
-         * connection. This allows individual models to use different DBs
51
-         * without overwriting the global database connection.
52
-         */
53
-        protected $_database;
54
-
55
-        /**
56
-         * This model's default primary key or unique identifier.
57
-         * Used by the get(), update() and delete() functions.
58
-         */
59
-        protected $primary_key = 'id';
60
-
61
-        /**
62
-         * Support for soft deletes and this model's 'deleted' key
63
-         */
64
-        protected $soft_delete = false;
65
-        protected $soft_delete_key = 'is_deleted';
66
-        protected $_temporary_with_deleted = FALSE;
67
-        protected $_temporary_only_deleted = FALSE;
68
-
69
-        /**
70
-         * The various callbacks available to the model. Each are
71
-         * simple lists of method names (methods will be run on $this).
72
-         */
73
-        protected $before_create = array();
74
-        protected $after_create = array();
75
-        protected $before_update = array();
76
-        protected $after_update = array();
77
-        protected $before_get = array();
78
-        protected $after_get = array();
79
-        protected $before_delete = array();
80
-        protected $after_delete = array();
81
-
82
-        protected $callback_parameters = array();
83
-
84
-        /**
85
-         * Protected, non-modifiable attributes
86
-         */
87
-        protected $protected_attributes = array();
88
-
89
-        /**
90
-         * Relationship arrays. Use flat strings for defaults or string
91
-         * => array to customise the class name and primary key
92
-         */
93
-        protected $belongs_to = array();
94
-        protected $has_many = array();
95
-
96
-        protected $_with = array();
97
-
98
-        /**
99
-         * An array of validation rules. This needs to be the same format
100
-         * as validation rules passed to the FormValidation library.
101
-         */
102
-        protected $validate = array();
103
-
104
-        /**
105
-         * Optionally skip the validation. Used in conjunction with
106
-         * skip_validation() to skip data validation for any future calls.
107
-         */
108
-        protected $skip_validation = FALSE;
109
-
110
-        /**
111
-         * By default we return our results as objects. If we need to override
112
-         * this, we can, or, we could use the `as_array()` and `as_object()` scopes.
113
-         */
114
-        protected $return_type = 'object';
115
-        protected $_temporary_return_type = NULL;
42
+		/**
43
+		 * This model's default database table. Automatically
44
+		 * guessed by pluralising the model name.
45
+		 */
46
+		protected $_table;
47
+
48
+		/**
49
+		 * The database connection object. Will be set to the default
50
+		 * connection. This allows individual models to use different DBs
51
+		 * without overwriting the global database connection.
52
+		 */
53
+		protected $_database;
54
+
55
+		/**
56
+		 * This model's default primary key or unique identifier.
57
+		 * Used by the get(), update() and delete() functions.
58
+		 */
59
+		protected $primary_key = 'id';
60
+
61
+		/**
62
+		 * Support for soft deletes and this model's 'deleted' key
63
+		 */
64
+		protected $soft_delete = false;
65
+		protected $soft_delete_key = 'is_deleted';
66
+		protected $_temporary_with_deleted = FALSE;
67
+		protected $_temporary_only_deleted = FALSE;
68
+
69
+		/**
70
+		 * The various callbacks available to the model. Each are
71
+		 * simple lists of method names (methods will be run on $this).
72
+		 */
73
+		protected $before_create = array();
74
+		protected $after_create = array();
75
+		protected $before_update = array();
76
+		protected $after_update = array();
77
+		protected $before_get = array();
78
+		protected $after_get = array();
79
+		protected $before_delete = array();
80
+		protected $after_delete = array();
81
+
82
+		protected $callback_parameters = array();
83
+
84
+		/**
85
+		 * Protected, non-modifiable attributes
86
+		 */
87
+		protected $protected_attributes = array();
88
+
89
+		/**
90
+		 * Relationship arrays. Use flat strings for defaults or string
91
+		 * => array to customise the class name and primary key
92
+		 */
93
+		protected $belongs_to = array();
94
+		protected $has_many = array();
95
+
96
+		protected $_with = array();
97
+
98
+		/**
99
+		 * An array of validation rules. This needs to be the same format
100
+		 * as validation rules passed to the FormValidation library.
101
+		 */
102
+		protected $validate = array();
103
+
104
+		/**
105
+		 * Optionally skip the validation. Used in conjunction with
106
+		 * skip_validation() to skip data validation for any future calls.
107
+		 */
108
+		protected $skip_validation = FALSE;
109
+
110
+		/**
111
+		 * By default we return our results as objects. If we need to override
112
+		 * this, we can, or, we could use the `as_array()` and `as_object()` scopes.
113
+		 */
114
+		protected $return_type = 'object';
115
+		protected $_temporary_return_type = NULL;
116 116
     	
117 117
     	
118
-    	/**
118
+		/**
119 119
     		The database cache time 
120
-    	*/
121
-    	protected $dbCacheTime = 0;
122
-
123
-        /**
124
-         * Instance of the Loader class
125
-         * @var Loader
126
-         */
127
-        protected $loaderInstance = null;
128
-
129
-        /**
130
-         * Instance of the FormValidation library
131
-         * @var FormValidation
132
-         */
133
-        protected $formValidationInstance = null;
134
-
135
-        /* --------------------------------------------------------------
120
+		 */
121
+		protected $dbCacheTime = 0;
122
+
123
+		/**
124
+		 * Instance of the Loader class
125
+		 * @var Loader
126
+		 */
127
+		protected $loaderInstance = null;
128
+
129
+		/**
130
+		 * Instance of the FormValidation library
131
+		 * @var FormValidation
132
+		 */
133
+		protected $formValidationInstance = null;
134
+
135
+		/* --------------------------------------------------------------
136 136
          * GENERIC METHODS
137 137
          * ------------------------------------------------------------ */
138 138
 
139
-        /**
140
-         * Initialise the model, tie into the CodeIgniter superobject and
141
-         * try our best to guess the table name.
142
-         */
143
-        public function __construct(Database $db = null){
144
-            if(is_object($db)){
145
-                $this->setDatabaseInstance($db);
146
-            }
147
-            else{
148
-                $obj = & get_instance();
149
-        		if(isset($obj->database) && is_object($obj->database)){
150
-                    /**
151
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152
-                    * to prevent duplication
153
-                    */
154
-        			$this->setDatabaseInstance(clone $obj->database);
155
-                }
156
-            }
157
-
158
-            array_unshift($this->before_create, 'protect_attributes');
159
-            array_unshift($this->before_update, 'protect_attributes');
160
-            $this->_temporary_return_type = $this->return_type;
161
-        }
162
-
163
-        /* --------------------------------------------------------------
139
+		/**
140
+		 * Initialise the model, tie into the CodeIgniter superobject and
141
+		 * try our best to guess the table name.
142
+		 */
143
+		public function __construct(Database $db = null){
144
+			if(is_object($db)){
145
+				$this->setDatabaseInstance($db);
146
+			}
147
+			else{
148
+				$obj = & get_instance();
149
+				if(isset($obj->database) && is_object($obj->database)){
150
+					/**
151
+					 * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152
+					 * to prevent duplication
153
+					 */
154
+					$this->setDatabaseInstance(clone $obj->database);
155
+				}
156
+			}
157
+
158
+			array_unshift($this->before_create, 'protect_attributes');
159
+			array_unshift($this->before_update, 'protect_attributes');
160
+			$this->_temporary_return_type = $this->return_type;
161
+		}
162
+
163
+		/* --------------------------------------------------------------
164 164
          * CRUD INTERFACE
165 165
          * ------------------------------------------------------------ */
166 166
 
167
-        /**
168
-         * Fetch a single record based on the primary key. Returns an object.
169
-         */
170
-        public function get($primary_value)
171
-        {
172
-    		return $this->get_by($this->primary_key, $primary_value);
173
-        }
174
-
175
-        /**
176
-         * Fetch a single record based on an arbitrary WHERE call. Can be
177
-         * any valid value to $this->_database->where().
178
-         */
179
-        public function get_by()
180
-        {
181
-            $where = func_get_args();
182
-
183
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184
-            {
185
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
186
-            }
187
-
188
-    		$this->_set_where($where);
189
-
190
-            $this->trigger('before_get');
167
+		/**
168
+		 * Fetch a single record based on the primary key. Returns an object.
169
+		 */
170
+		public function get($primary_value)
171
+		{
172
+			return $this->get_by($this->primary_key, $primary_value);
173
+		}
174
+
175
+		/**
176
+		 * Fetch a single record based on an arbitrary WHERE call. Can be
177
+		 * any valid value to $this->_database->where().
178
+		 */
179
+		public function get_by()
180
+		{
181
+			$where = func_get_args();
182
+
183
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184
+			{
185
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
186
+			}
187
+
188
+			$this->_set_where($where);
189
+
190
+			$this->trigger('before_get');
191 191
 			$type = $this->_temporary_return_type == 'array' ? 'array':false;
192
-            $row = $this->_database->from($this->_table)->get($type);
193
-            $this->_temporary_return_type = $this->return_type;
194
-            $row = $this->trigger('after_get', $row);
195
-            $this->_with = array();
196
-            return $row;
197
-        }
198
-
199
-        /**
200
-         * Fetch an array of records based on an array of primary values.
201
-         */
202
-        public function get_many($values)
203
-        {
204
-            $this->_database->in($this->primary_key, $values);
205
-            return $this->get_all();
206
-        }
207
-
208
-        /**
209
-         * Fetch an array of records based on an arbitrary WHERE call.
210
-         */
211
-        public function get_many_by()
212
-        {
213
-            $where = func_get_args();
214
-            $this->_set_where($where);
215
-            return $this->get_all();
216
-        }
217
-
218
-        /**
219
-         * Fetch all the records in the table. Can be used as a generic call
220
-         * to $this->_database->get() with scoped methods.
221
-         */
222
-        public function get_all()
223
-        {
224
-            $this->trigger('before_get');
225
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226
-            {
227
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
228
-            }
192
+			$row = $this->_database->from($this->_table)->get($type);
193
+			$this->_temporary_return_type = $this->return_type;
194
+			$row = $this->trigger('after_get', $row);
195
+			$this->_with = array();
196
+			return $row;
197
+		}
198
+
199
+		/**
200
+		 * Fetch an array of records based on an array of primary values.
201
+		 */
202
+		public function get_many($values)
203
+		{
204
+			$this->_database->in($this->primary_key, $values);
205
+			return $this->get_all();
206
+		}
207
+
208
+		/**
209
+		 * Fetch an array of records based on an arbitrary WHERE call.
210
+		 */
211
+		public function get_many_by()
212
+		{
213
+			$where = func_get_args();
214
+			$this->_set_where($where);
215
+			return $this->get_all();
216
+		}
217
+
218
+		/**
219
+		 * Fetch all the records in the table. Can be used as a generic call
220
+		 * to $this->_database->get() with scoped methods.
221
+		 */
222
+		public function get_all()
223
+		{
224
+			$this->trigger('before_get');
225
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226
+			{
227
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
228
+			}
229 229
 			$type = $this->_temporary_return_type == 'array' ? 'array':false;
230
-            $result = $this->_database->from($this->_table)->getAll($type);
231
-            $this->_temporary_return_type = $this->return_type;
232
-
233
-            foreach ($result as $key => &$row)
234
-            {
235
-                $row = $this->trigger('after_get', $row, ($key == count($result) - 1));
236
-            }
237
-            $this->_with = array();
238
-            return $result;
239
-        }
240
-
241
-        /**
242
-         * Insert a new row into the table. $data should be an associative array
243
-         * of data to be inserted. Returns newly created ID.
244
-         */
245
-        public function insert($data = array(), $skip_validation = FALSE, $escape = true)
246
-        {
247
-            if ($skip_validation === FALSE)
248
-            {
249
-                $data = $this->validate($data);
250
-            }
251
-
252
-            if ($data !== FALSE)
253
-            {
254
-                $data = $this->trigger('before_create', $data);
255
-                $this->_database->from($this->_table)->insert($data, $escape);
256
-                $insert_id = $this->_database->insertId();
257
-                $this->trigger('after_create', $insert_id);
258
-                return $insert_id;
259
-            }
260
-            else
261
-            {
262
-                return FALSE;
263
-            }
264
-        }
265
-
266
-        /**
267
-         * Insert multiple rows into the table. Returns an array of multiple IDs.
268
-         */
269
-        public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
270
-        {
271
-            $ids = array();
272
-            foreach ($data as $key => $row)
273
-            {
274
-                $ids[] = $this->insert($row, $skip_validation, $escape);
275
-            }
276
-            return $ids;
277
-        }
278
-
279
-        /**
280
-         * Updated a record based on the primary value.
281
-         */
282
-        public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
283
-        {
284
-            $data = $this->trigger('before_update', $data);
285
-            if ($skip_validation === FALSE)
286
-            {
287
-                $data = $this->validate($data);
288
-            }
289
-
290
-            if ($data !== FALSE)
291
-            {
292
-                $result = $this->_database->where($this->primary_key, $primary_value)
293
-                                   ->from($this->_table)
294
-                                   ->update($data, $escape);
295
-                $this->trigger('after_update', array($data, $result));
296
-                return $result;
297
-            }
298
-            else
299
-            {
300
-                return FALSE;
301
-            }
302
-        }
303
-
304
-        /**
305
-         * Update many records, based on an array of primary values.
306
-         */
307
-        public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
308
-        {
309
-            $data = $this->trigger('before_update', $data);
310
-            if ($skip_validation === FALSE)
311
-            {
312
-                $data = $this->validate($data);
313
-            }
314
-            if ($data !== FALSE)
315
-            {
316
-                $result = $this->_database->in($this->primary_key, $primary_values)
317
-                                   ->from($this->_table)
318
-                                   ->update($data, $escape);
319
-                $this->trigger('after_update', array($data, $result));
320
-                return $result;
321
-            }
322
-            else
323
-            {
324
-                return FALSE;
325
-            }
326
-        }
327
-
328
-        /**
329
-         * Updated a record based on an arbitrary WHERE clause.
330
-         */
331
-        public function update_by()
332
-        {
333
-            $args = func_get_args();
334
-            $data = array();
335
-            if(count($args) == 2){
336
-                if(is_array($args[1])){
337
-                    $data = array_pop($args);
338
-                }
339
-            }
340
-            else if(count($args) == 3){
341
-                if(is_array($args[2])){
342
-                    $data = array_pop($args);
343
-                }
344
-            }
345
-            $data = $this->trigger('before_update', $data);
346
-            if ($this->validate($data) !== FALSE)
347
-            {
348
-                $this->_set_where($args);
349
-                $result = $this->_database->from($this->_table)->update($data);
350
-                $this->trigger('after_update', array($data, $result));
351
-                return $result;
352
-            }
353
-            else
354
-            {
355
-                return FALSE;
356
-            }
357
-        }
358
-
359
-        /**
360
-         * Update all records
361
-         */
362
-        public function update_all($data = array(), $escape = true)
363
-        {
364
-            $data = $this->trigger('before_update', $data);
365
-            $result = $this->_database->from($this->_table)->update($data, $escape);
366
-            $this->trigger('after_update', array($data, $result));
367
-            return $result;
368
-        }
369
-
370
-        /**
371
-         * Delete a row from the table by the primary value
372
-         */
373
-        public function delete($id)
374
-        {
375
-            $this->trigger('before_delete', $id);
376
-            $this->_database->where($this->primary_key, $id);
377
-            if ($this->soft_delete)
378
-            {
379
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
380
-            }
381
-            else
382
-            {
383
-                $result = $this->_database->from($this->_table)->delete();
384
-            }
385
-
386
-            $this->trigger('after_delete', $result);
387
-            return $result;
388
-        }
389
-
390
-        /**
391
-         * Delete a row from the database table by an arbitrary WHERE clause
392
-         */
393
-        public function delete_by()
394
-        {
395
-            $where = func_get_args();
396
-    	    $where = $this->trigger('before_delete', $where);
397
-            $this->_set_where($where);
398
-            if ($this->soft_delete)
399
-            {
400
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
401
-            }
402
-            else
403
-            {
404
-                $result = $this->_database->from($this->_table)->delete();
405
-            }
406
-            $this->trigger('after_delete', $result);
407
-            return $result;
408
-        }
409
-
410
-        /**
411
-         * Delete many rows from the database table by multiple primary values
412
-         */
413
-        public function delete_many($primary_values)
414
-        {
415
-            $primary_values = $this->trigger('before_delete', $primary_values);
416
-            $this->_database->in($this->primary_key, $primary_values);
417
-            if ($this->soft_delete)
418
-            {
419
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
420
-            }
421
-            else
422
-            {
423
-                $result = $this->_database->from($this->_table)->delete();
424
-            }
425
-            $this->trigger('after_delete', $result);
426
-            return $result;
427
-        }
428
-
429
-
430
-        /**
431
-         * Truncates the table
432
-         */
433
-        public function truncate()
434
-        {
435
-            $result = $this->_database->from($this->_table)->delete();
436
-            return $result;
437
-        }
438
-
439
-        /* --------------------------------------------------------------
230
+			$result = $this->_database->from($this->_table)->getAll($type);
231
+			$this->_temporary_return_type = $this->return_type;
232
+
233
+			foreach ($result as $key => &$row)
234
+			{
235
+				$row = $this->trigger('after_get', $row, ($key == count($result) - 1));
236
+			}
237
+			$this->_with = array();
238
+			return $result;
239
+		}
240
+
241
+		/**
242
+		 * Insert a new row into the table. $data should be an associative array
243
+		 * of data to be inserted. Returns newly created ID.
244
+		 */
245
+		public function insert($data = array(), $skip_validation = FALSE, $escape = true)
246
+		{
247
+			if ($skip_validation === FALSE)
248
+			{
249
+				$data = $this->validate($data);
250
+			}
251
+
252
+			if ($data !== FALSE)
253
+			{
254
+				$data = $this->trigger('before_create', $data);
255
+				$this->_database->from($this->_table)->insert($data, $escape);
256
+				$insert_id = $this->_database->insertId();
257
+				$this->trigger('after_create', $insert_id);
258
+				return $insert_id;
259
+			}
260
+			else
261
+			{
262
+				return FALSE;
263
+			}
264
+		}
265
+
266
+		/**
267
+		 * Insert multiple rows into the table. Returns an array of multiple IDs.
268
+		 */
269
+		public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
270
+		{
271
+			$ids = array();
272
+			foreach ($data as $key => $row)
273
+			{
274
+				$ids[] = $this->insert($row, $skip_validation, $escape);
275
+			}
276
+			return $ids;
277
+		}
278
+
279
+		/**
280
+		 * Updated a record based on the primary value.
281
+		 */
282
+		public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
283
+		{
284
+			$data = $this->trigger('before_update', $data);
285
+			if ($skip_validation === FALSE)
286
+			{
287
+				$data = $this->validate($data);
288
+			}
289
+
290
+			if ($data !== FALSE)
291
+			{
292
+				$result = $this->_database->where($this->primary_key, $primary_value)
293
+								   ->from($this->_table)
294
+								   ->update($data, $escape);
295
+				$this->trigger('after_update', array($data, $result));
296
+				return $result;
297
+			}
298
+			else
299
+			{
300
+				return FALSE;
301
+			}
302
+		}
303
+
304
+		/**
305
+		 * Update many records, based on an array of primary values.
306
+		 */
307
+		public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
308
+		{
309
+			$data = $this->trigger('before_update', $data);
310
+			if ($skip_validation === FALSE)
311
+			{
312
+				$data = $this->validate($data);
313
+			}
314
+			if ($data !== FALSE)
315
+			{
316
+				$result = $this->_database->in($this->primary_key, $primary_values)
317
+								   ->from($this->_table)
318
+								   ->update($data, $escape);
319
+				$this->trigger('after_update', array($data, $result));
320
+				return $result;
321
+			}
322
+			else
323
+			{
324
+				return FALSE;
325
+			}
326
+		}
327
+
328
+		/**
329
+		 * Updated a record based on an arbitrary WHERE clause.
330
+		 */
331
+		public function update_by()
332
+		{
333
+			$args = func_get_args();
334
+			$data = array();
335
+			if(count($args) == 2){
336
+				if(is_array($args[1])){
337
+					$data = array_pop($args);
338
+				}
339
+			}
340
+			else if(count($args) == 3){
341
+				if(is_array($args[2])){
342
+					$data = array_pop($args);
343
+				}
344
+			}
345
+			$data = $this->trigger('before_update', $data);
346
+			if ($this->validate($data) !== FALSE)
347
+			{
348
+				$this->_set_where($args);
349
+				$result = $this->_database->from($this->_table)->update($data);
350
+				$this->trigger('after_update', array($data, $result));
351
+				return $result;
352
+			}
353
+			else
354
+			{
355
+				return FALSE;
356
+			}
357
+		}
358
+
359
+		/**
360
+		 * Update all records
361
+		 */
362
+		public function update_all($data = array(), $escape = true)
363
+		{
364
+			$data = $this->trigger('before_update', $data);
365
+			$result = $this->_database->from($this->_table)->update($data, $escape);
366
+			$this->trigger('after_update', array($data, $result));
367
+			return $result;
368
+		}
369
+
370
+		/**
371
+		 * Delete a row from the table by the primary value
372
+		 */
373
+		public function delete($id)
374
+		{
375
+			$this->trigger('before_delete', $id);
376
+			$this->_database->where($this->primary_key, $id);
377
+			if ($this->soft_delete)
378
+			{
379
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
380
+			}
381
+			else
382
+			{
383
+				$result = $this->_database->from($this->_table)->delete();
384
+			}
385
+
386
+			$this->trigger('after_delete', $result);
387
+			return $result;
388
+		}
389
+
390
+		/**
391
+		 * Delete a row from the database table by an arbitrary WHERE clause
392
+		 */
393
+		public function delete_by()
394
+		{
395
+			$where = func_get_args();
396
+			$where = $this->trigger('before_delete', $where);
397
+			$this->_set_where($where);
398
+			if ($this->soft_delete)
399
+			{
400
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
401
+			}
402
+			else
403
+			{
404
+				$result = $this->_database->from($this->_table)->delete();
405
+			}
406
+			$this->trigger('after_delete', $result);
407
+			return $result;
408
+		}
409
+
410
+		/**
411
+		 * Delete many rows from the database table by multiple primary values
412
+		 */
413
+		public function delete_many($primary_values)
414
+		{
415
+			$primary_values = $this->trigger('before_delete', $primary_values);
416
+			$this->_database->in($this->primary_key, $primary_values);
417
+			if ($this->soft_delete)
418
+			{
419
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
420
+			}
421
+			else
422
+			{
423
+				$result = $this->_database->from($this->_table)->delete();
424
+			}
425
+			$this->trigger('after_delete', $result);
426
+			return $result;
427
+		}
428
+
429
+
430
+		/**
431
+		 * Truncates the table
432
+		 */
433
+		public function truncate()
434
+		{
435
+			$result = $this->_database->from($this->_table)->delete();
436
+			return $result;
437
+		}
438
+
439
+		/* --------------------------------------------------------------
440 440
          * RELATIONSHIPS
441 441
          * ------------------------------------------------------------ */
442 442
 
443
-        public function with($relationship)
444
-        {
445
-            $this->_with[] = $relationship;
446
-            if (!in_array('relate', $this->after_get))
447
-            {
448
-                $this->after_get[] = 'relate';
449
-            }
450
-            return $this;
451
-        }
452
-
453
-        public function relate($row)
454
-        {
455
-    		if (empty($row))
456
-            {
457
-    		    return $row;
458
-            }
459
-
460
-            foreach ($this->belongs_to as $key => $value)
461
-            {
462
-                if (is_string($value))
463
-                {
464
-                    $relationship = $value;
465
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
466
-                }
467
-                else
468
-                {
469
-                    $relationship = $key;
470
-                    $options = $value;
471
-                }
472
-
473
-                if (in_array($relationship, $this->_with))
474
-                {
475
-                    if(is_object($this->loaderInstance)){
476
-                        $this->loaderInstance->model($options['model'], $relationship . '_model');
477
-                    }
478
-                    else{
479
-                        Loader::model($options['model'], $relationship . '_model');    
480
-                    }
481
-                    if (is_object($row))
482
-                    {
483
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
484
-                    }
485
-                    else
486
-                    {
487
-                        $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
488
-                    }
489
-                }
490
-            }
491
-
492
-            foreach ($this->has_many as $key => $value)
493
-            {
494
-                if (is_string($value))
495
-                {
496
-                    $relationship = $value;
497
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
498
-                }
499
-                else
500
-                {
501
-                    $relationship = $key;
502
-                    $options = $value;
503
-                }
504
-
505
-                if (in_array($relationship, $this->_with))
506
-                {
507
-                    if(is_object($this->loaderInstance)){
508
-                        $this->loaderInstance->model($options['model'], $relationship . '_model');
509
-                    }
510
-                    else{
511
-                        Loader::model($options['model'], $relationship . '_model');    
512
-                    }
513
-                    if (is_object($row))
514
-                    {
515
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
516
-                    }
517
-                    else
518
-                    {
519
-                        $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
520
-                    }
521
-                }
522
-            }
523
-            return $row;
524
-        }
525
-
526
-        /* --------------------------------------------------------------
443
+		public function with($relationship)
444
+		{
445
+			$this->_with[] = $relationship;
446
+			if (!in_array('relate', $this->after_get))
447
+			{
448
+				$this->after_get[] = 'relate';
449
+			}
450
+			return $this;
451
+		}
452
+
453
+		public function relate($row)
454
+		{
455
+			if (empty($row))
456
+			{
457
+				return $row;
458
+			}
459
+
460
+			foreach ($this->belongs_to as $key => $value)
461
+			{
462
+				if (is_string($value))
463
+				{
464
+					$relationship = $value;
465
+					$options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
466
+				}
467
+				else
468
+				{
469
+					$relationship = $key;
470
+					$options = $value;
471
+				}
472
+
473
+				if (in_array($relationship, $this->_with))
474
+				{
475
+					if(is_object($this->loaderInstance)){
476
+						$this->loaderInstance->model($options['model'], $relationship . '_model');
477
+					}
478
+					else{
479
+						Loader::model($options['model'], $relationship . '_model');    
480
+					}
481
+					if (is_object($row))
482
+					{
483
+						$row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
484
+					}
485
+					else
486
+					{
487
+						$row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
488
+					}
489
+				}
490
+			}
491
+
492
+			foreach ($this->has_many as $key => $value)
493
+			{
494
+				if (is_string($value))
495
+				{
496
+					$relationship = $value;
497
+					$options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
498
+				}
499
+				else
500
+				{
501
+					$relationship = $key;
502
+					$options = $value;
503
+				}
504
+
505
+				if (in_array($relationship, $this->_with))
506
+				{
507
+					if(is_object($this->loaderInstance)){
508
+						$this->loaderInstance->model($options['model'], $relationship . '_model');
509
+					}
510
+					else{
511
+						Loader::model($options['model'], $relationship . '_model');    
512
+					}
513
+					if (is_object($row))
514
+					{
515
+						$row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
516
+					}
517
+					else
518
+					{
519
+						$row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
520
+					}
521
+				}
522
+			}
523
+			return $row;
524
+		}
525
+
526
+		/* --------------------------------------------------------------
527 527
          * UTILITY METHODS
528 528
          * ------------------------------------------------------------ */
529 529
 
530
-        /**
531
-         * Retrieve and generate a form_dropdown friendly array
532
-         */
533
-        public function dropdown()
534
-        {
535
-            $args = func_get_args();
536
-            if(count($args) == 2)
537
-            {
538
-                list($key, $value) = $args;
539
-            }
540
-            else
541
-            {
542
-                $key = $this->primary_key;
543
-                $value = $args[0];
544
-            }
545
-            $this->trigger('before_dropdown', array( $key, $value ));
546
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
547
-            {
548
-                $this->_database->where($this->soft_delete_key, FALSE);
549
-            }
550
-            $result = $this->_database->select(array($key, $value))
551
-                               ->from($this->_table)
552
-                               ->getAll();
553
-            $options = array();
554
-            foreach ($result as $row)
555
-            {
556
-                $options[$row->{$key}] = $row->{$value};
557
-            }
558
-            $options = $this->trigger('after_dropdown', $options);
559
-            return $options;
560
-        }
561
-
562
-        /**
563
-         * Fetch a count of rows based on an arbitrary WHERE call.
564
-         */
565
-        public function count_by()
566
-        {
567
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
568
-            {
569
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
570
-            }
571
-            $where = func_get_args();
572
-            $this->_set_where($where);
573
-            $this->_database->from($this->_table)->getAll();
574
-            return $this->_database->numRows();
575
-        }
576
-
577
-        /**
578
-         * Fetch a total count of rows, disregarding any previous conditions
579
-         */
580
-        public function count_all()
581
-        {
582
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
583
-            {
584
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
585
-            }
586
-            $this->_database->from($this->_table)->getAll();
587
-            return $this->_database->numRows();
588
-        }
530
+		/**
531
+		 * Retrieve and generate a form_dropdown friendly array
532
+		 */
533
+		public function dropdown()
534
+		{
535
+			$args = func_get_args();
536
+			if(count($args) == 2)
537
+			{
538
+				list($key, $value) = $args;
539
+			}
540
+			else
541
+			{
542
+				$key = $this->primary_key;
543
+				$value = $args[0];
544
+			}
545
+			$this->trigger('before_dropdown', array( $key, $value ));
546
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
547
+			{
548
+				$this->_database->where($this->soft_delete_key, FALSE);
549
+			}
550
+			$result = $this->_database->select(array($key, $value))
551
+							   ->from($this->_table)
552
+							   ->getAll();
553
+			$options = array();
554
+			foreach ($result as $row)
555
+			{
556
+				$options[$row->{$key}] = $row->{$value};
557
+			}
558
+			$options = $this->trigger('after_dropdown', $options);
559
+			return $options;
560
+		}
561
+
562
+		/**
563
+		 * Fetch a count of rows based on an arbitrary WHERE call.
564
+		 */
565
+		public function count_by()
566
+		{
567
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
568
+			{
569
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
570
+			}
571
+			$where = func_get_args();
572
+			$this->_set_where($where);
573
+			$this->_database->from($this->_table)->getAll();
574
+			return $this->_database->numRows();
575
+		}
576
+
577
+		/**
578
+		 * Fetch a total count of rows, disregarding any previous conditions
579
+		 */
580
+		public function count_all()
581
+		{
582
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
583
+			{
584
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
585
+			}
586
+			$this->_database->from($this->_table)->getAll();
587
+			return $this->_database->numRows();
588
+		}
589 589
 		
590 590
 		/**
591
-		* Enabled cache temporary
592
-		*/
591
+		 * Enabled cache temporary
592
+		 */
593 593
 		public function cached($ttl = 0){
594 594
 		  if($ttl > 0){
595 595
 			$this->_database = $this->_database->cached($ttl);
@@ -597,390 +597,390 @@  discard block
 block discarded – undo
597 597
 		  return $this;
598 598
 		}
599 599
 
600
-        /**
601
-         * Tell the class to skip the insert validation
602
-         */
603
-        public function skip_validation()
604
-        {
605
-            $this->skip_validation = TRUE;
606
-            return $this;
607
-        }
608
-
609
-        /**
610
-         * Get the skip validation status
611
-         */
612
-        public function get_skip_validation()
613
-        {
614
-            return $this->skip_validation;
615
-        }
616
-
617
-        /**
618
-         * Return the next auto increment of the table. Only tested on MySQL.
619
-         */
620
-        public function get_next_id()
621
-        {
622
-            return (int) $this->_database->select('AUTO_INCREMENT')
623
-                ->from('information_schema.TABLES')
624
-                ->where('TABLE_NAME', $this->_table)
625
-                ->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT;
626
-        }
627
-
628
-        /**
629
-         * Getter for the table name
630
-         */
631
-        public function table()
632
-        {
633
-            return $this->_table;
634
-        }
635
-
636
-        /* --------------------------------------------------------------
600
+		/**
601
+		 * Tell the class to skip the insert validation
602
+		 */
603
+		public function skip_validation()
604
+		{
605
+			$this->skip_validation = TRUE;
606
+			return $this;
607
+		}
608
+
609
+		/**
610
+		 * Get the skip validation status
611
+		 */
612
+		public function get_skip_validation()
613
+		{
614
+			return $this->skip_validation;
615
+		}
616
+
617
+		/**
618
+		 * Return the next auto increment of the table. Only tested on MySQL.
619
+		 */
620
+		public function get_next_id()
621
+		{
622
+			return (int) $this->_database->select('AUTO_INCREMENT')
623
+				->from('information_schema.TABLES')
624
+				->where('TABLE_NAME', $this->_table)
625
+				->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT;
626
+		}
627
+
628
+		/**
629
+		 * Getter for the table name
630
+		 */
631
+		public function table()
632
+		{
633
+			return $this->_table;
634
+		}
635
+
636
+		/* --------------------------------------------------------------
637 637
          * GLOBAL SCOPES
638 638
          * ------------------------------------------------------------ */
639 639
 
640
-        /**
641
-         * Return the next call as an array rather than an object
642
-         */
643
-        public function as_array()
644
-        {
645
-            $this->_temporary_return_type = 'array';
646
-            return $this;
647
-        }
648
-
649
-        /**
650
-         * Return the next call as an object rather than an array
651
-         */
652
-        public function as_object()
653
-        {
654
-            $this->_temporary_return_type = 'object';
655
-            return $this;
656
-        }
657
-
658
-        /**
659
-         * Don't care about soft deleted rows on the next call
660
-         */
661
-        public function with_deleted()
662
-        {
663
-            $this->_temporary_with_deleted = TRUE;
664
-            return $this;
665
-        }
666
-
667
-        /**
668
-         * Only get deleted rows on the next call
669
-         */
670
-        public function only_deleted()
671
-        {
672
-            $this->_temporary_only_deleted = TRUE;
673
-            return $this;
674
-        }
675
-
676
-        /* --------------------------------------------------------------
640
+		/**
641
+		 * Return the next call as an array rather than an object
642
+		 */
643
+		public function as_array()
644
+		{
645
+			$this->_temporary_return_type = 'array';
646
+			return $this;
647
+		}
648
+
649
+		/**
650
+		 * Return the next call as an object rather than an array
651
+		 */
652
+		public function as_object()
653
+		{
654
+			$this->_temporary_return_type = 'object';
655
+			return $this;
656
+		}
657
+
658
+		/**
659
+		 * Don't care about soft deleted rows on the next call
660
+		 */
661
+		public function with_deleted()
662
+		{
663
+			$this->_temporary_with_deleted = TRUE;
664
+			return $this;
665
+		}
666
+
667
+		/**
668
+		 * Only get deleted rows on the next call
669
+		 */
670
+		public function only_deleted()
671
+		{
672
+			$this->_temporary_only_deleted = TRUE;
673
+			return $this;
674
+		}
675
+
676
+		/* --------------------------------------------------------------
677 677
          * OBSERVERS
678 678
          * ------------------------------------------------------------ */
679 679
 
680
-        /**
681
-         * MySQL DATETIME created_at and updated_at
682
-         */
683
-        public function created_at($row)
684
-        {
685
-            if (is_object($row))
686
-            {
687
-                $row->created_at = date('Y-m-d H:i:s');
688
-            }
689
-            else
690
-            {
691
-                $row['created_at'] = date('Y-m-d H:i:s');
692
-            }
693
-
694
-            return $row;
695
-        }
696
-
697
-        public function updated_at($row)
698
-        {
699
-            if (is_object($row))
700
-            {
701
-                $row->updated_at = date('Y-m-d H:i:s');
702
-            }
703
-            else
704
-            {
705
-                $row['updated_at'] = date('Y-m-d H:i:s');
706
-            }
707
-            return $row;
708
-        }
709
-
710
-        /**
711
-         * Serialises data for you automatically, allowing you to pass
712
-         * through objects and let it handle the serialisation in the background
713
-         */
714
-        public function serialize($row)
715
-        {
716
-            foreach ($this->callback_parameters as $column)
717
-            {
718
-                $row[$column] = serialize($row[$column]);
719
-            }
720
-            return $row;
721
-        }
722
-
723
-        public function unserialize($row)
724
-        {
725
-            foreach ($this->callback_parameters as $column)
726
-            {
727
-                if (is_array($row))
728
-                {
729
-                    $row[$column] = unserialize($row[$column]);
730
-                }
731
-                else
732
-                {
733
-                    $row->$column = unserialize($row->$column);
734
-                }
735
-            }
736
-            return $row;
737
-        }
738
-
739
-        /**
740
-         * Protect attributes by removing them from $row array
741
-         */
742
-        public function protect_attributes($row)
743
-        {
744
-            foreach ($this->protected_attributes as $attr)
745
-            {
746
-                if (is_object($row))
747
-                {
680
+		/**
681
+		 * MySQL DATETIME created_at and updated_at
682
+		 */
683
+		public function created_at($row)
684
+		{
685
+			if (is_object($row))
686
+			{
687
+				$row->created_at = date('Y-m-d H:i:s');
688
+			}
689
+			else
690
+			{
691
+				$row['created_at'] = date('Y-m-d H:i:s');
692
+			}
693
+
694
+			return $row;
695
+		}
696
+
697
+		public function updated_at($row)
698
+		{
699
+			if (is_object($row))
700
+			{
701
+				$row->updated_at = date('Y-m-d H:i:s');
702
+			}
703
+			else
704
+			{
705
+				$row['updated_at'] = date('Y-m-d H:i:s');
706
+			}
707
+			return $row;
708
+		}
709
+
710
+		/**
711
+		 * Serialises data for you automatically, allowing you to pass
712
+		 * through objects and let it handle the serialisation in the background
713
+		 */
714
+		public function serialize($row)
715
+		{
716
+			foreach ($this->callback_parameters as $column)
717
+			{
718
+				$row[$column] = serialize($row[$column]);
719
+			}
720
+			return $row;
721
+		}
722
+
723
+		public function unserialize($row)
724
+		{
725
+			foreach ($this->callback_parameters as $column)
726
+			{
727
+				if (is_array($row))
728
+				{
729
+					$row[$column] = unserialize($row[$column]);
730
+				}
731
+				else
732
+				{
733
+					$row->$column = unserialize($row->$column);
734
+				}
735
+			}
736
+			return $row;
737
+		}
738
+
739
+		/**
740
+		 * Protect attributes by removing them from $row array
741
+		 */
742
+		public function protect_attributes($row)
743
+		{
744
+			foreach ($this->protected_attributes as $attr)
745
+			{
746
+				if (is_object($row))
747
+				{
748 748
 					if(isset($row->$attr)){
749 749
 						unset($row->$attr);
750 750
 					}
751
-                }
752
-                else
753
-                {
751
+				}
752
+				else
753
+				{
754 754
 					if(isset($row[$attr])){
755 755
 						unset($row[$attr]);
756 756
 					}
757
-                }
758
-            }
759
-            return $row;
760
-        }
757
+				}
758
+			}
759
+			return $row;
760
+		}
761 761
 		
762 762
 		 /**
763
-         * Return the database instance
764
-         * @return Database the database instance
765
-         */
766
-        public function getDatabaseInstance(){
767
-            return $this->_database;
768
-        }
769
-
770
-        /**
771
-         * set the Database instance for future use
772
-         * @param Database $db the database object
773
-         */
774
-         public function setDatabaseInstance($db){
775
-            $this->_database = $db;
776
-            if($this->dbCacheTime > 0){
777
-                $this->_database->setCache($this->dbCacheTime);
778
-            }
779
-            return $this;
780
-        }
781
-
782
-        /**
783
-         * Return the loader instance
784
-         * @return Loader the loader instance
785
-         */
786
-        public function getLoader(){
787
-            return $this->loaderInstance;
788
-        }
789
-
790
-        /**
791
-         * set the loader instance for future use
792
-         * @param Loader $loader the loader object
793
-         */
794
-         public function setLoader($loader){
795
-            $this->loaderInstance = $loader;
796
-            return $this;
797
-        }
798
-
799
-        /**
800
-         * Return the FormValidation instance
801
-         * @return FormValidation the form validation instance
802
-         */
803
-        public function getFormValidation(){
804
-            return $this->formValidationInstance;
805
-        }
806
-
807
-        /**
808
-         * set the form validation instance for future use
809
-         * @param FormValidation $fv the form validation object
810
-         */
811
-         public function setFormValidation($fv){
812
-            $this->formValidationInstance = $fv;
813
-            return $this;
814
-        }
815
-
816
-        /* --------------------------------------------------------------
763
+		  * Return the database instance
764
+		  * @return Database the database instance
765
+		  */
766
+		public function getDatabaseInstance(){
767
+			return $this->_database;
768
+		}
769
+
770
+		/**
771
+		 * set the Database instance for future use
772
+		 * @param Database $db the database object
773
+		 */
774
+		 public function setDatabaseInstance($db){
775
+			$this->_database = $db;
776
+			if($this->dbCacheTime > 0){
777
+				$this->_database->setCache($this->dbCacheTime);
778
+			}
779
+			return $this;
780
+		}
781
+
782
+		/**
783
+		 * Return the loader instance
784
+		 * @return Loader the loader instance
785
+		 */
786
+		public function getLoader(){
787
+			return $this->loaderInstance;
788
+		}
789
+
790
+		/**
791
+		 * set the loader instance for future use
792
+		 * @param Loader $loader the loader object
793
+		 */
794
+		 public function setLoader($loader){
795
+			$this->loaderInstance = $loader;
796
+			return $this;
797
+		}
798
+
799
+		/**
800
+		 * Return the FormValidation instance
801
+		 * @return FormValidation the form validation instance
802
+		 */
803
+		public function getFormValidation(){
804
+			return $this->formValidationInstance;
805
+		}
806
+
807
+		/**
808
+		 * set the form validation instance for future use
809
+		 * @param FormValidation $fv the form validation object
810
+		 */
811
+		 public function setFormValidation($fv){
812
+			$this->formValidationInstance = $fv;
813
+			return $this;
814
+		}
815
+
816
+		/* --------------------------------------------------------------
817 817
          * QUERY BUILDER DIRECT ACCESS METHODS
818 818
          * ------------------------------------------------------------ */
819 819
 
820
-        /**
821
-         * A wrapper to $this->_database->orderBy()
822
-         */
823
-        public function order_by($criteria, $order = 'ASC')
824
-        {
825
-            if ( is_array($criteria) )
826
-            {
827
-                foreach ($criteria as $key => $value)
828
-                {
829
-                    $this->_database->orderBy($key, $value);
830
-                }
831
-            }
832
-            else
833
-            {
834
-                $this->_database->orderBy($criteria, $order);
835
-            }
836
-            return $this;
837
-        }
838
-
839
-        /**
840
-         * A wrapper to $this->_database->limit()
841
-         */
842
-        public function limit($offset = 0, $limit = 10)
843
-        {
844
-            $this->_database->limit($offset, $limit);
845
-            return $this;
846
-        }
847
-
848
-        /* --------------------------------------------------------------
820
+		/**
821
+		 * A wrapper to $this->_database->orderBy()
822
+		 */
823
+		public function order_by($criteria, $order = 'ASC')
824
+		{
825
+			if ( is_array($criteria) )
826
+			{
827
+				foreach ($criteria as $key => $value)
828
+				{
829
+					$this->_database->orderBy($key, $value);
830
+				}
831
+			}
832
+			else
833
+			{
834
+				$this->_database->orderBy($criteria, $order);
835
+			}
836
+			return $this;
837
+		}
838
+
839
+		/**
840
+		 * A wrapper to $this->_database->limit()
841
+		 */
842
+		public function limit($offset = 0, $limit = 10)
843
+		{
844
+			$this->_database->limit($offset, $limit);
845
+			return $this;
846
+		}
847
+
848
+		/* --------------------------------------------------------------
849 849
          * INTERNAL METHODS
850 850
          * ------------------------------------------------------------ */
851 851
 
852
-        /**
853
-         * Trigger an event and call its observers. Pass through the event name
854
-         * (which looks for an instance variable $this->event_name), an array of
855
-         * parameters to pass through and an optional 'last in interation' boolean
856
-         */
857
-        protected function trigger($event, $data = FALSE, $last = TRUE)
858
-        {
859
-            if (isset($this->$event) && is_array($this->$event))
860
-            {
861
-                foreach ($this->$event as $method)
862
-                {
863
-                    if (strpos($method, '('))
864
-                    {
865
-                        preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
866
-
867
-                        $method = $matches[1];
868
-                        $this->callback_parameters = explode(',', $matches[3]);
869
-                    }
870
-                    $data = call_user_func_array(array($this, $method), array($data, $last));
871
-                }
872
-            }
873
-            return $data;
874
-        }
875
-
876
-        /**
877
-         * Run validation on the passed data
878
-         */
879
-        protected function validate(array $data)
880
-        {
881
-            if($this->skip_validation)
882
-            {
883
-                return $data;
884
-            }
885
-            if(!empty($this->validate))
886
-            {
887
-                $fv = null;
888
-                if(is_object($this->formValidationInstance)){
889
-                    $fv = $this->formValidationInstance;
890
-                }
891
-                else{
892
-                    Loader::library('FormValidation');
893
-                    $fv = $this->formvalidation;
894
-                    $this->setFormValidation($fv);
895
-                }
896
-                if(is_array($this->validate))
897
-                {
898
-                    $fv->setData($data);
899
-                    $fv->setRules($this->validate);
900
-
901
-                    if ($fv->run())
902
-                    {
903
-                        return $data;
904
-                    }
905
-                    else
906
-                    {
907
-                        return FALSE;
908
-                    }
909
-                }
910
-                else {
911
-                    return $data;
912
-                }
913
-            }
914
-            else
915
-            {
916
-                return $data;
917
-            }
918
-        }
919
-
920
-
921
-        /**
922
-         * Set WHERE parameters, cleverly
923
-         */
924
-        protected function _set_where($params)
925
-        {
926
-            if (count($params) == 1 && is_array($params[0]))
927
-            {
928
-                foreach ($params[0] as $field => $filter)
929
-                {
930
-                    if (is_array($filter))
931
-                    {
932
-                        $this->_database->in($field, $filter);
933
-                    }
934
-                    else
935
-                    {
936
-                        if (is_int($field))
937
-                        {
938
-                            $this->_database->where($filter);
939
-                        }
940
-                        else
941
-                        {
942
-                            $this->_database->where($field, $filter);
943
-                        }
944
-                    }
945
-                }
946
-            }
947
-            else if (count($params) == 1)
948
-            {
949
-                $this->_database->where($params[0]);
950
-            }
951
-        	else if(count($params) == 2)
952
-    		{
953
-                if (is_array($params[1]))
954
-                {
955
-                    $this->_database->in($params[0], $params[1]);
956
-                }
957
-                else
958
-                {
959
-                    $this->_database->where($params[0], $params[1]);
960
-                }
961
-    		}
962
-    		else if(count($params) == 3)
963
-    		{
964
-    			$this->_database->where($params[0], $params[1], $params[2]);
965
-    		}
966
-            else
967
-            {
968
-                if (is_array($params[1]))
969
-                {
970
-                    $this->_database->in($params[0], $params[1]);
971
-                }
972
-                else
973
-                {
974
-                    $this->_database->where($params[0], $params[1]);
975
-                }
976
-            }
977
-        }
978
-
979
-        /**
852
+		/**
853
+		 * Trigger an event and call its observers. Pass through the event name
854
+		 * (which looks for an instance variable $this->event_name), an array of
855
+		 * parameters to pass through and an optional 'last in interation' boolean
856
+		 */
857
+		protected function trigger($event, $data = FALSE, $last = TRUE)
858
+		{
859
+			if (isset($this->$event) && is_array($this->$event))
860
+			{
861
+				foreach ($this->$event as $method)
862
+				{
863
+					if (strpos($method, '('))
864
+					{
865
+						preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
866
+
867
+						$method = $matches[1];
868
+						$this->callback_parameters = explode(',', $matches[3]);
869
+					}
870
+					$data = call_user_func_array(array($this, $method), array($data, $last));
871
+				}
872
+			}
873
+			return $data;
874
+		}
875
+
876
+		/**
877
+		 * Run validation on the passed data
878
+		 */
879
+		protected function validate(array $data)
880
+		{
881
+			if($this->skip_validation)
882
+			{
883
+				return $data;
884
+			}
885
+			if(!empty($this->validate))
886
+			{
887
+				$fv = null;
888
+				if(is_object($this->formValidationInstance)){
889
+					$fv = $this->formValidationInstance;
890
+				}
891
+				else{
892
+					Loader::library('FormValidation');
893
+					$fv = $this->formvalidation;
894
+					$this->setFormValidation($fv);
895
+				}
896
+				if(is_array($this->validate))
897
+				{
898
+					$fv->setData($data);
899
+					$fv->setRules($this->validate);
900
+
901
+					if ($fv->run())
902
+					{
903
+						return $data;
904
+					}
905
+					else
906
+					{
907
+						return FALSE;
908
+					}
909
+				}
910
+				else {
911
+					return $data;
912
+				}
913
+			}
914
+			else
915
+			{
916
+				return $data;
917
+			}
918
+		}
919
+
920
+
921
+		/**
922
+		 * Set WHERE parameters, cleverly
923
+		 */
924
+		protected function _set_where($params)
925
+		{
926
+			if (count($params) == 1 && is_array($params[0]))
927
+			{
928
+				foreach ($params[0] as $field => $filter)
929
+				{
930
+					if (is_array($filter))
931
+					{
932
+						$this->_database->in($field, $filter);
933
+					}
934
+					else
935
+					{
936
+						if (is_int($field))
937
+						{
938
+							$this->_database->where($filter);
939
+						}
940
+						else
941
+						{
942
+							$this->_database->where($field, $filter);
943
+						}
944
+					}
945
+				}
946
+			}
947
+			else if (count($params) == 1)
948
+			{
949
+				$this->_database->where($params[0]);
950
+			}
951
+			else if(count($params) == 2)
952
+			{
953
+				if (is_array($params[1]))
954
+				{
955
+					$this->_database->in($params[0], $params[1]);
956
+				}
957
+				else
958
+				{
959
+					$this->_database->where($params[0], $params[1]);
960
+				}
961
+			}
962
+			else if(count($params) == 3)
963
+			{
964
+				$this->_database->where($params[0], $params[1], $params[2]);
965
+			}
966
+			else
967
+			{
968
+				if (is_array($params[1]))
969
+				{
970
+					$this->_database->in($params[0], $params[1]);
971
+				}
972
+				else
973
+				{
974
+					$this->_database->where($params[0], $params[1]);
975
+				}
976
+			}
977
+		}
978
+
979
+		/**
980 980
             Shortcut to controller
981
-        */
982
-        public function __get($key){
983
-            return get_instance()->{$key};
984
-        }
981
+		 */
982
+		public function __get($key){
983
+			return get_instance()->{$key};
984
+		}
985 985
 
986
-    }
986
+	}
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34 34
      */
35 35
 
36
-    class Model{
36
+    class Model {
37 37
 
38 38
         /* --------------------------------------------------------------
39 39
          * VARIABLES
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
          * Initialise the model, tie into the CodeIgniter superobject and
141 141
          * try our best to guess the table name.
142 142
          */
143
-        public function __construct(Database $db = null){
144
-            if(is_object($db)){
143
+        public function __construct(Database $db = null) {
144
+            if (is_object($db)) {
145 145
                 $this->setDatabaseInstance($db);
146 146
             }
147
-            else{
147
+            else {
148 148
                 $obj = & get_instance();
149
-        		if(isset($obj->database) && is_object($obj->database)){
149
+        		if (isset($obj->database) && is_object($obj->database)) {
150 150
                     /**
151 151
                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152 152
                     * to prevent duplication
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 
183 183
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184 184
             {
185
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
185
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
186 186
             }
187 187
 
188 188
     		$this->_set_where($where);
189 189
 
190 190
             $this->trigger('before_get');
191
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
191
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
192 192
             $row = $this->_database->from($this->_table)->get($type);
193 193
             $this->_temporary_return_type = $this->return_type;
194 194
             $row = $this->trigger('after_get', $row);
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
             $this->trigger('before_get');
225 225
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226 226
             {
227
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
227
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
228 228
             }
229
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
229
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
230 230
             $result = $this->_database->from($this->_table)->getAll($type);
231 231
             $this->_temporary_return_type = $this->return_type;
232 232
 
@@ -332,13 +332,13 @@  discard block
 block discarded – undo
332 332
         {
333 333
             $args = func_get_args();
334 334
             $data = array();
335
-            if(count($args) == 2){
336
-                if(is_array($args[1])){
335
+            if (count($args) == 2) {
336
+                if (is_array($args[1])) {
337 337
                     $data = array_pop($args);
338 338
                 }
339 339
             }
340
-            else if(count($args) == 3){
341
-                if(is_array($args[2])){
340
+            else if (count($args) == 3) {
341
+                if (is_array($args[2])) {
342 342
                     $data = array_pop($args);
343 343
                 }
344 344
             }
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
             $this->_database->where($this->primary_key, $id);
377 377
             if ($this->soft_delete)
378 378
             {
379
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
379
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
380 380
             }
381 381
             else
382 382
             {
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
             $this->_set_where($where);
398 398
             if ($this->soft_delete)
399 399
             {
400
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
400
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
401 401
             }
402 402
             else
403 403
             {
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
             $this->_database->in($this->primary_key, $primary_values);
417 417
             if ($this->soft_delete)
418 418
             {
419
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
419
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
420 420
             }
421 421
             else
422 422
             {
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
                 if (is_string($value))
463 463
                 {
464 464
                     $relationship = $value;
465
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
465
+                    $options = array('primary_key' => $value . '_id', 'model' => $value . '_model');
466 466
                 }
467 467
                 else
468 468
                 {
@@ -472,10 +472,10 @@  discard block
 block discarded – undo
472 472
 
473 473
                 if (in_array($relationship, $this->_with))
474 474
                 {
475
-                    if(is_object($this->loaderInstance)){
475
+                    if (is_object($this->loaderInstance)) {
476 476
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
477 477
                     }
478
-                    else{
478
+                    else {
479 479
                         Loader::model($options['model'], $relationship . '_model');    
480 480
                     }
481 481
                     if (is_object($row))
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
                 if (is_string($value))
495 495
                 {
496 496
                     $relationship = $value;
497
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
497
+                    $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model');
498 498
                 }
499 499
                 else
500 500
                 {
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
 
505 505
                 if (in_array($relationship, $this->_with))
506 506
                 {
507
-                    if(is_object($this->loaderInstance)){
507
+                    if (is_object($this->loaderInstance)) {
508 508
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
509 509
                     }
510
-                    else{
510
+                    else {
511 511
                         Loader::model($options['model'], $relationship . '_model');    
512 512
                     }
513 513
                     if (is_object($row))
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
         public function dropdown()
534 534
         {
535 535
             $args = func_get_args();
536
-            if(count($args) == 2)
536
+            if (count($args) == 2)
537 537
             {
538 538
                 list($key, $value) = $args;
539 539
             }
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
                 $key = $this->primary_key;
543 543
                 $value = $args[0];
544 544
             }
545
-            $this->trigger('before_dropdown', array( $key, $value ));
545
+            $this->trigger('before_dropdown', array($key, $value));
546 546
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
547 547
             {
548 548
                 $this->_database->where($this->soft_delete_key, FALSE);
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
         {
567 567
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
568 568
             {
569
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
569
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
570 570
             }
571 571
             $where = func_get_args();
572 572
             $this->_set_where($where);
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
         {
582 582
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
583 583
             {
584
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
584
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
585 585
             }
586 586
             $this->_database->from($this->_table)->getAll();
587 587
             return $this->_database->numRows();
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 		/**
591 591
 		* Enabled cache temporary
592 592
 		*/
593
-		public function cached($ttl = 0){
594
-		  if($ttl > 0){
593
+		public function cached($ttl = 0) {
594
+		  if ($ttl > 0) {
595 595
 			$this->_database = $this->_database->cached($ttl);
596 596
 		  }
597 597
 		  return $this;
@@ -745,13 +745,13 @@  discard block
 block discarded – undo
745 745
             {
746 746
                 if (is_object($row))
747 747
                 {
748
-					if(isset($row->$attr)){
748
+					if (isset($row->$attr)) {
749 749
 						unset($row->$attr);
750 750
 					}
751 751
                 }
752 752
                 else
753 753
                 {
754
-					if(isset($row[$attr])){
754
+					if (isset($row[$attr])) {
755 755
 						unset($row[$attr]);
756 756
 					}
757 757
                 }
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
          * Return the database instance
764 764
          * @return Database the database instance
765 765
          */
766
-        public function getDatabaseInstance(){
766
+        public function getDatabaseInstance() {
767 767
             return $this->_database;
768 768
         }
769 769
 
@@ -771,9 +771,9 @@  discard block
 block discarded – undo
771 771
          * set the Database instance for future use
772 772
          * @param Database $db the database object
773 773
          */
774
-         public function setDatabaseInstance($db){
774
+         public function setDatabaseInstance($db) {
775 775
             $this->_database = $db;
776
-            if($this->dbCacheTime > 0){
776
+            if ($this->dbCacheTime > 0) {
777 777
                 $this->_database->setCache($this->dbCacheTime);
778 778
             }
779 779
             return $this;
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
          * Return the loader instance
784 784
          * @return Loader the loader instance
785 785
          */
786
-        public function getLoader(){
786
+        public function getLoader() {
787 787
             return $this->loaderInstance;
788 788
         }
789 789
 
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
          * set the loader instance for future use
792 792
          * @param Loader $loader the loader object
793 793
          */
794
-         public function setLoader($loader){
794
+         public function setLoader($loader) {
795 795
             $this->loaderInstance = $loader;
796 796
             return $this;
797 797
         }
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
          * Return the FormValidation instance
801 801
          * @return FormValidation the form validation instance
802 802
          */
803
-        public function getFormValidation(){
803
+        public function getFormValidation() {
804 804
             return $this->formValidationInstance;
805 805
         }
806 806
 
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
          * set the form validation instance for future use
809 809
          * @param FormValidation $fv the form validation object
810 810
          */
811
-         public function setFormValidation($fv){
811
+         public function setFormValidation($fv) {
812 812
             $this->formValidationInstance = $fv;
813 813
             return $this;
814 814
         }
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
          */
823 823
         public function order_by($criteria, $order = 'ASC')
824 824
         {
825
-            if ( is_array($criteria) )
825
+            if (is_array($criteria))
826 826
             {
827 827
                 foreach ($criteria as $key => $value)
828 828
                 {
@@ -878,22 +878,22 @@  discard block
 block discarded – undo
878 878
          */
879 879
         protected function validate(array $data)
880 880
         {
881
-            if($this->skip_validation)
881
+            if ($this->skip_validation)
882 882
             {
883 883
                 return $data;
884 884
             }
885
-            if(!empty($this->validate))
885
+            if (!empty($this->validate))
886 886
             {
887 887
                 $fv = null;
888
-                if(is_object($this->formValidationInstance)){
888
+                if (is_object($this->formValidationInstance)) {
889 889
                     $fv = $this->formValidationInstance;
890 890
                 }
891
-                else{
891
+                else {
892 892
                     Loader::library('FormValidation');
893 893
                     $fv = $this->formvalidation;
894 894
                     $this->setFormValidation($fv);
895 895
                 }
896
-                if(is_array($this->validate))
896
+                if (is_array($this->validate))
897 897
                 {
898 898
                     $fv->setData($data);
899 899
                     $fv->setRules($this->validate);
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
             {
949 949
                 $this->_database->where($params[0]);
950 950
             }
951
-        	else if(count($params) == 2)
951
+        	else if (count($params) == 2)
952 952
     		{
953 953
                 if (is_array($params[1]))
954 954
                 {
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
                     $this->_database->where($params[0], $params[1]);
960 960
                 }
961 961
     		}
962
-    		else if(count($params) == 3)
962
+    		else if (count($params) == 3)
963 963
     		{
964 964
     			$this->_database->where($params[0], $params[1], $params[2]);
965 965
     		}
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
         /**
980 980
             Shortcut to controller
981 981
         */
982
-        public function __get($key){
982
+        public function __get($key) {
983 983
             return get_instance()->{$key};
984 984
         }
985 985
 
Please login to merge, or discard this patch.
Braces   +33 added lines, -66 removed lines patch added patch discarded remove patch
@@ -143,8 +143,7 @@  discard block
 block discarded – undo
143 143
         public function __construct(Database $db = null){
144 144
             if(is_object($db)){
145 145
                 $this->setDatabaseInstance($db);
146
-            }
147
-            else{
146
+            } else{
148 147
                 $obj = & get_instance();
149 148
         		if(isset($obj->database) && is_object($obj->database)){
150 149
                     /**
@@ -256,8 +255,7 @@  discard block
 block discarded – undo
256 255
                 $insert_id = $this->_database->insertId();
257 256
                 $this->trigger('after_create', $insert_id);
258 257
                 return $insert_id;
259
-            }
260
-            else
258
+            } else
261 259
             {
262 260
                 return FALSE;
263 261
             }
@@ -294,8 +292,7 @@  discard block
 block discarded – undo
294 292
                                    ->update($data, $escape);
295 293
                 $this->trigger('after_update', array($data, $result));
296 294
                 return $result;
297
-            }
298
-            else
295
+            } else
299 296
             {
300 297
                 return FALSE;
301 298
             }
@@ -318,8 +315,7 @@  discard block
 block discarded – undo
318 315
                                    ->update($data, $escape);
319 316
                 $this->trigger('after_update', array($data, $result));
320 317
                 return $result;
321
-            }
322
-            else
318
+            } else
323 319
             {
324 320
                 return FALSE;
325 321
             }
@@ -336,8 +332,7 @@  discard block
 block discarded – undo
336 332
                 if(is_array($args[1])){
337 333
                     $data = array_pop($args);
338 334
                 }
339
-            }
340
-            else if(count($args) == 3){
335
+            } else if(count($args) == 3){
341 336
                 if(is_array($args[2])){
342 337
                     $data = array_pop($args);
343 338
                 }
@@ -349,8 +344,7 @@  discard block
 block discarded – undo
349 344
                 $result = $this->_database->from($this->_table)->update($data);
350 345
                 $this->trigger('after_update', array($data, $result));
351 346
                 return $result;
352
-            }
353
-            else
347
+            } else
354 348
             {
355 349
                 return FALSE;
356 350
             }
@@ -377,8 +371,7 @@  discard block
 block discarded – undo
377 371
             if ($this->soft_delete)
378 372
             {
379 373
                 $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
380
-            }
381
-            else
374
+            } else
382 375
             {
383 376
                 $result = $this->_database->from($this->_table)->delete();
384 377
             }
@@ -398,8 +391,7 @@  discard block
 block discarded – undo
398 391
             if ($this->soft_delete)
399 392
             {
400 393
                 $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
401
-            }
402
-            else
394
+            } else
403 395
             {
404 396
                 $result = $this->_database->from($this->_table)->delete();
405 397
             }
@@ -417,8 +409,7 @@  discard block
 block discarded – undo
417 409
             if ($this->soft_delete)
418 410
             {
419 411
                 $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
420
-            }
421
-            else
412
+            } else
422 413
             {
423 414
                 $result = $this->_database->from($this->_table)->delete();
424 415
             }
@@ -463,8 +454,7 @@  discard block
 block discarded – undo
463 454
                 {
464 455
                     $relationship = $value;
465 456
                     $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
466
-                }
467
-                else
457
+                } else
468 458
                 {
469 459
                     $relationship = $key;
470 460
                     $options = $value;
@@ -474,15 +464,13 @@  discard block
 block discarded – undo
474 464
                 {
475 465
                     if(is_object($this->loaderInstance)){
476 466
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
477
-                    }
478
-                    else{
467
+                    } else{
479 468
                         Loader::model($options['model'], $relationship . '_model');    
480 469
                     }
481 470
                     if (is_object($row))
482 471
                     {
483 472
                         $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
484
-                    }
485
-                    else
473
+                    } else
486 474
                     {
487 475
                         $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
488 476
                     }
@@ -495,8 +483,7 @@  discard block
 block discarded – undo
495 483
                 {
496 484
                     $relationship = $value;
497 485
                     $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
498
-                }
499
-                else
486
+                } else
500 487
                 {
501 488
                     $relationship = $key;
502 489
                     $options = $value;
@@ -506,15 +493,13 @@  discard block
 block discarded – undo
506 493
                 {
507 494
                     if(is_object($this->loaderInstance)){
508 495
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
509
-                    }
510
-                    else{
496
+                    } else{
511 497
                         Loader::model($options['model'], $relationship . '_model');    
512 498
                     }
513 499
                     if (is_object($row))
514 500
                     {
515 501
                         $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
516
-                    }
517
-                    else
502
+                    } else
518 503
                     {
519 504
                         $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
520 505
                     }
@@ -536,8 +521,7 @@  discard block
 block discarded – undo
536 521
             if(count($args) == 2)
537 522
             {
538 523
                 list($key, $value) = $args;
539
-            }
540
-            else
524
+            } else
541 525
             {
542 526
                 $key = $this->primary_key;
543 527
                 $value = $args[0];
@@ -685,8 +669,7 @@  discard block
 block discarded – undo
685 669
             if (is_object($row))
686 670
             {
687 671
                 $row->created_at = date('Y-m-d H:i:s');
688
-            }
689
-            else
672
+            } else
690 673
             {
691 674
                 $row['created_at'] = date('Y-m-d H:i:s');
692 675
             }
@@ -699,8 +682,7 @@  discard block
 block discarded – undo
699 682
             if (is_object($row))
700 683
             {
701 684
                 $row->updated_at = date('Y-m-d H:i:s');
702
-            }
703
-            else
685
+            } else
704 686
             {
705 687
                 $row['updated_at'] = date('Y-m-d H:i:s');
706 688
             }
@@ -727,8 +709,7 @@  discard block
 block discarded – undo
727 709
                 if (is_array($row))
728 710
                 {
729 711
                     $row[$column] = unserialize($row[$column]);
730
-                }
731
-                else
712
+                } else
732 713
                 {
733 714
                     $row->$column = unserialize($row->$column);
734 715
                 }
@@ -748,8 +729,7 @@  discard block
 block discarded – undo
748 729
 					if(isset($row->$attr)){
749 730
 						unset($row->$attr);
750 731
 					}
751
-                }
752
-                else
732
+                } else
753 733
                 {
754 734
 					if(isset($row[$attr])){
755 735
 						unset($row[$attr]);
@@ -828,8 +808,7 @@  discard block
 block discarded – undo
828 808
                 {
829 809
                     $this->_database->orderBy($key, $value);
830 810
                 }
831
-            }
832
-            else
811
+            } else
833 812
             {
834 813
                 $this->_database->orderBy($criteria, $order);
835 814
             }
@@ -887,8 +866,7 @@  discard block
 block discarded – undo
887 866
                 $fv = null;
888 867
                 if(is_object($this->formValidationInstance)){
889 868
                     $fv = $this->formValidationInstance;
890
-                }
891
-                else{
869
+                } else{
892 870
                     Loader::library('FormValidation');
893 871
                     $fv = $this->formvalidation;
894 872
                     $this->setFormValidation($fv);
@@ -901,17 +879,14 @@  discard block
 block discarded – undo
901 879
                     if ($fv->run())
902 880
                     {
903 881
                         return $data;
904
-                    }
905
-                    else
882
+                    } else
906 883
                     {
907 884
                         return FALSE;
908 885
                     }
909
-                }
910
-                else {
886
+                } else {
911 887
                     return $data;
912 888
                 }
913
-            }
914
-            else
889
+            } else
915 890
             {
916 891
                 return $data;
917 892
             }
@@ -930,46 +905,38 @@  discard block
 block discarded – undo
930 905
                     if (is_array($filter))
931 906
                     {
932 907
                         $this->_database->in($field, $filter);
933
-                    }
934
-                    else
908
+                    } else
935 909
                     {
936 910
                         if (is_int($field))
937 911
                         {
938 912
                             $this->_database->where($filter);
939
-                        }
940
-                        else
913
+                        } else
941 914
                         {
942 915
                             $this->_database->where($field, $filter);
943 916
                         }
944 917
                     }
945 918
                 }
946
-            }
947
-            else if (count($params) == 1)
919
+            } else if (count($params) == 1)
948 920
             {
949 921
                 $this->_database->where($params[0]);
950
-            }
951
-        	else if(count($params) == 2)
922
+            } else if(count($params) == 2)
952 923
     		{
953 924
                 if (is_array($params[1]))
954 925
                 {
955 926
                     $this->_database->in($params[0], $params[1]);
956
-                }
957
-                else
927
+                } else
958 928
                 {
959 929
                     $this->_database->where($params[0], $params[1]);
960 930
                 }
961
-    		}
962
-    		else if(count($params) == 3)
931
+    		} else if(count($params) == 3)
963 932
     		{
964 933
     			$this->_database->where($params[0], $params[1], $params[2]);
965
-    		}
966
-            else
934
+    		} else
967 935
             {
968 936
                 if (is_array($params[1]))
969 937
                 {
970 938
                     $this->_database->in($params[0], $params[1]);
971
-                }
972
-                else
939
+                } else
973 940
                 {
974 941
                     $this->_database->where($params[0], $params[1]);
975 942
                 }
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 3 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 
27 27
 	class FileCache implements CacheInterface{
28 28
 		
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47
-	         * instance of the Log class
48
-	         */
49
-	        if(is_object($logger)){
50
-	          $this->logger = $logger;
51
-	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
54
-	            $this->logger->setLogger('Library::FileCache');
55
-	        }
47
+			 * instance of the Log class
48
+			 */
49
+			if(is_object($logger)){
50
+			  $this->logger = $logger;
51
+			}
52
+			else{
53
+				$this->logger =& class_loader('Log', 'classes');
54
+				$this->logger->setLogger('Library::FileCache');
55
+			}
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58 58
 			if(! extension_loaded('zlib')){
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
83
-		    flock($handle, LOCK_SH);
84
-		    $data = file_get_contents($filePath);
85
-      		fclose($handle);
86
-      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
-		         // If unserializing somehow didn't work out, we'll delete the file
90
-		         unlink($filePath);
91
-		         return false;
92
-	      	}
93
-	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
-		        // Unlinking when the file was expired
96
-		        unlink($filePath);
97
-		        return false;
98
-		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
-		     	return $data['data'];
102
-		     }
83
+			flock($handle, LOCK_SH);
84
+			$data = file_get_contents($filePath);
85
+	  		fclose($handle);
86
+	  		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
+	  		if (! $data) {
88
+	  			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
+				 // If unserializing somehow didn't work out, we'll delete the file
90
+				 unlink($filePath);
91
+				 return false;
92
+		  	}
93
+		  	if (time() > $data['expire']) {
94
+		  		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
+				// Unlinking when the file was expired
96
+				unlink($filePath);
97
+				return false;
98
+			 }
99
+			 else{
100
+			 	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
+			 	return $data['data'];
102
+			 }
103 103
 			return false;
104 104
 		}
105 105
 
@@ -122,25 +122,25 @@  discard block
 block discarded – undo
122 122
 			}
123 123
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
124 124
 			//Serializing along with the TTL
125
-		    $cacheData = serialize(array(
125
+			$cacheData = serialize(array(
126 126
 									'mtime' => time(),
127 127
 									'expire' => $expire,
128 128
 									'data' => $data,
129 129
 									'ttl' => $ttl
130 130
 									)
131 131
 								);		   
132
-		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
133
-		    if(! $result){
134
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
135
-		    	fclose($handle);
136
-		    	return false;
137
-		    }
138
-		    else{
139
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
140
-		    	fclose($handle);
132
+			$result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
133
+			if(! $result){
134
+				$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
135
+				fclose($handle);
136
+				return false;
137
+			}
138
+			else{
139
+				$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
140
+				fclose($handle);
141 141
 				chmod($filePath, 0640);
142 142
 				return true;
143
-		    }
143
+			}
144 144
 		}	
145 145
 
146 146
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 			}
161 161
 			else{
162 162
 				$this->logger->info('Found cache file [' .$filePath. '] remove it');
163
-	      		@unlink($filePath);
163
+		  		@unlink($filePath);
164 164
 				return true;
165 165
 			}
166 166
 		}
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 			}
184 184
 			else{
185 185
 				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
186
-	      		$data = file_get_contents($filePath);
186
+		  		$data = file_get_contents($filePath);
187 187
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
188 188
 				if(! $data){
189 189
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
@@ -223,17 +223,17 @@  discard block
 block discarded – undo
223 223
 				foreach ($list as $file) {
224 224
 					$this->logger->debug('Processing the cache file [' . $file . ']');
225 225
 					$data = file_get_contents($file);
226
-		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
227
-		      		if(! $data){
228
-		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
229
-		      		}
230
-		      		else if(time() > $data['expire']){
231
-		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
232
-		      			@unlink($file);
233
-		      		}
234
-		      		else{
235
-		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
236
-		      		}
226
+			  		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
227
+			  		if(! $data){
228
+			  			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
229
+			  		}
230
+			  		else if(time() > $data['expire']){
231
+			  			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
232
+			  			@unlink($file);
233
+			  		}
234
+			  		else{
235
+			  			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
236
+			  		}
237 237
 				}
238 238
 			}
239 239
 		}	
@@ -256,19 +256,19 @@  discard block
 block discarded – undo
256 256
 			}
257 257
 		}
258 258
 	
259
-	    /**
260
-	     * @return boolean
261
-	     */
262
-	    public function isCompressCacheData(){
263
-	        return $this->compressCacheData;
264
-	    }
259
+		/**
260
+		 * @return boolean
261
+		 */
262
+		public function isCompressCacheData(){
263
+			return $this->compressCacheData;
264
+		}
265 265
 
266
-	    /**
267
-	     * @param boolean $compressCacheData
268
-	     *
269
-	     * @return self
270
-	     */
271
-	    public function setCompressCacheData($status = true){
266
+		/**
267
+		 * @param boolean $compressCacheData
268
+		 *
269
+		 * @return self
270
+		 */
271
+		public function setCompressCacheData($status = true){
272 272
 			//if Zlib extension is not loaded set compressCacheData to false
273 273
 			if($status === true && ! extension_loaded('zlib')){
274 274
 				
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 				$this->compressCacheData = $status;
280 280
 			}
281 281
 			return $this;
282
-	    }
282
+		}
283 283
 		
284 284
 		/**
285 285
 		 * Check whether the cache feature for the handle is supported
@@ -291,28 +291,28 @@  discard block
 block discarded – undo
291 291
 		}
292 292
 
293 293
 		/**
294
-	     * Return the Log instance
295
-	     * @return Log
296
-	     */
297
-	    public function getLogger(){
298
-	      return $this->logger;
299
-	    }
294
+		 * Return the Log instance
295
+		 * @return Log
296
+		 */
297
+		public function getLogger(){
298
+		  return $this->logger;
299
+		}
300 300
 
301
-	    /**
302
-	     * Set the log instance
303
-	     * @param Log $logger the log object
304
-	     */
305
-	    public function setLogger(Log $logger){
306
-	      $this->logger = $logger;
307
-	      return $this;
308
-	    }
301
+		/**
302
+		 * Set the log instance
303
+		 * @param Log $logger the log object
304
+		 */
305
+		public function setLogger(Log $logger){
306
+		  $this->logger = $logger;
307
+		  return $this;
308
+		}
309 309
 		
310 310
 		/**
311
-		* Get the cache file full path for the given key
312
-		*
313
-		* @param $key the cache item key
314
-		* @return string the full cache file path for this key
315
-		*/
311
+		 * Get the cache file full path for the given key
312
+		 *
313
+		 * @param $key the cache item key
314
+		 * @return string the full cache file path for this key
315
+		 */
316 316
 		private function getFilePath($key){
317 317
 			return CACHE_PATH . md5($key) . '.cache';
318 318
 		}
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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 FileCache implements CacheInterface{
27
+	class FileCache implements CacheInterface {
28 28
 		
29 29
 		/**
30 30
 		 * Whether to enable compression of the cache data file.
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 		private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
42
+		public function __construct(Log $logger = null) {
43
+			if (!$this->isSupported()) {
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47 47
 	         * instance of the Log class
48 48
 	         */
49
-	        if(is_object($logger)){
49
+	        if (is_object($logger)) {
50 50
 	          $this->logger = $logger;
51 51
 	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
52
+	        else {
53
+	            $this->logger = & class_loader('Log', 'classes');
54 54
 	            $this->logger->setLogger('Library::FileCache');
55 55
 	        }
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
58
+			if (!extension_loaded('zlib')) {
59 59
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60 60
 				$this->compressCacheData = false;
61 61
 			}
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 		 * @param  string $key the key to identify the cache data
67 67
 		 * @return mixed      the cache data if exists else return false
68 68
 		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
69
+		public function get($key) {
70
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
71 71
 			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
72
+			if (!file_exists($filePath)) {
73
+				$this->logger->info('No cache file found for the key [' . $key . '], return false');
74 74
 				return false;
75 75
 			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if( ! $handle){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
76
+			$this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid');
77
+			$handle = fopen($filePath, 'r');
78
+			if (!$handle) {
79
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 		    $data = file_get_contents($filePath);
85 85
       		fclose($handle);
86 86
       		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
87
+      		if (!$data) {
88
+      			$this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false');
89 89
 		         // If unserializing somehow didn't work out, we'll delete the file
90 90
 		         unlink($filePath);
91 91
 		         return false;
92 92
 	      	}
93 93
 	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
94
+	      		$this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']');
95 95
 		        // Unlinking when the file was expired
96 96
 		        unlink($filePath);
97 97
 		        return false;
98 98
 		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
99
+		     else {
100
+		     	$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101 101
 		     	return $data['data'];
102 102
 		     }
103 103
 			return false;
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
 		 * @param integer $ttl  the cache life time
112 112
 		 * @return boolean true if success otherwise will return false
113 113
 		 */
114
-		public function set($key, $data, $ttl = 0){
114
+		public function set($key, $data, $ttl = 0) {
115 115
 			$expire = time() + $ttl;
116
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
117 117
 			$filePath = $this->getFilePath($key);
118
-			$handle = fopen($filePath,'w');
119
-			if( ! $handle){
120
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
118
+			$handle = fopen($filePath, 'w');
119
+			if (!$handle) {
120
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
121 121
 				return false;
122 122
 			}
123 123
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 									)
131 131
 								);		   
132 132
 		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
133
-		    if(! $result){
134
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
133
+		    if (!$result) {
134
+		    	$this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false');
135 135
 		    	fclose($handle);
136 136
 		    	return false;
137 137
 		    }
138
-		    else{
139
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
138
+		    else {
139
+		    	$this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']');
140 140
 		    	fclose($handle);
141 141
 				chmod($filePath, 0640);
142 142
 				return true;
@@ -150,16 +150,16 @@  discard block
 block discarded – undo
150 150
 		 * @return boolean      true if the cache is delete, false if can't delete 
151 151
 		 * the cache or the cache with the given key not exist
152 152
 		 */
153
-		public function delete($key){
154
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
153
+		public function delete($key) {
154
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
155 155
 			$filePath = $this->getFilePath($key);
156
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
157
-			if(! file_exists($filePath)){
156
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
157
+			if (!file_exists($filePath)) {
158 158
 				$this->logger->info('This cache file does not exists skipping');
159 159
 				return false;
160 160
 			}
161
-			else{
162
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
161
+			else {
162
+				$this->logger->info('Found cache file [' . $filePath . '] remove it');
163 163
 	      		@unlink($filePath);
164 164
 				return true;
165 165
 			}
@@ -173,25 +173,25 @@  discard block
 block discarded – undo
173 173
 		 * 'expire' => expiration time of the cache (Unix timestamp),
174 174
 		 * 'ttl' => the time to live of the cache in second
175 175
 		 */
176
-		public function getInfo($key){
177
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
176
+		public function getInfo($key) {
177
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
178 178
 			$filePath = $this->getFilePath($key);
179
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
180
-			if(! file_exists($filePath)){
179
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
180
+			if (!file_exists($filePath)) {
181 181
 				$this->logger->info('This cache file does not exists skipping');
182 182
 				return false;
183 183
 			}
184
-			else{
185
-				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
184
+			else {
185
+				$this->logger->info('Found cache file [' . $filePath . '] check the validity');
186 186
 	      		$data = file_get_contents($filePath);
187 187
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
188
-				if(! $data){
188
+				if (!$data) {
189 189
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
190 190
 					return false;
191 191
 				}
192
-				else{
192
+				else {
193 193
 					$this->logger->info('This cache data is OK check for expire');
194
-					if(isset($data['expire']) && $data['expire'] > time()){
194
+					if (isset($data['expire']) && $data['expire'] > time()) {
195 195
 						$this->logger->info('This cache not yet expired return cache informations');
196 196
 						$info = array(
197 197
 							'mtime' => $data['mtime'],
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 							);
201 201
 						return $info;
202 202
 					}
203
-					else{
203
+					else {
204 204
 						$this->logger->info('This cache already expired return false');
205 205
 						return false;
206 206
 					}
@@ -212,26 +212,26 @@  discard block
 block discarded – undo
212 212
 		/**
213 213
 		 * Used to delete expired cache data
214 214
 		 */
215
-		public function deleteExpiredCache(){
215
+		public function deleteExpiredCache() {
216 216
 			$this->logger->debug('Deleting of expired cache files');
217 217
 			$list = glob(CACHE_PATH . '*.cache');
218
-			if(! $list){
218
+			if (!$list) {
219 219
 				$this->logger->info('No cache files were found skipping');
220 220
 			}
221
-			else{
221
+			else {
222 222
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
223 223
 				foreach ($list as $file) {
224 224
 					$this->logger->debug('Processing the cache file [' . $file . ']');
225 225
 					$data = file_get_contents($file);
226 226
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
227
-		      		if(! $data){
227
+		      		if (!$data) {
228 228
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
229 229
 		      		}
230
-		      		else if(time() > $data['expire']){
230
+		      		else if (time() > $data['expire']) {
231 231
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
232 232
 		      			@unlink($file);
233 233
 		      		}
234
-		      		else{
234
+		      		else {
235 235
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
236 236
 		      		}
237 237
 				}
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
 		/**
242 242
 		 * Remove all file from cache folder
243 243
 		 */
244
-		public function clean(){
244
+		public function clean() {
245 245
 			$this->logger->debug('Deleting of all cache files');
246 246
 			$list = glob(CACHE_PATH . '*.cache');
247
-			if(! $list){
247
+			if (!$list) {
248 248
 				$this->logger->info('No cache files were found skipping');
249 249
 			}
250
-			else{
250
+			else {
251 251
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
252 252
 				foreach ($list as $file) {
253 253
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	    /**
260 260
 	     * @return boolean
261 261
 	     */
262
-	    public function isCompressCacheData(){
262
+	    public function isCompressCacheData() {
263 263
 	        return $this->compressCacheData;
264 264
 	    }
265 265
 
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
 	     *
269 269
 	     * @return self
270 270
 	     */
271
-	    public function setCompressCacheData($status = true){
271
+	    public function setCompressCacheData($status = true) {
272 272
 			//if Zlib extension is not loaded set compressCacheData to false
273
-			if($status === true && ! extension_loaded('zlib')){
273
+			if ($status === true && !extension_loaded('zlib')) {
274 274
 				
275 275
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
276 276
 				$this->compressCacheData = false;
277 277
 			}
278
-			else{
278
+			else {
279 279
 				$this->compressCacheData = $status;
280 280
 			}
281 281
 			return $this;
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 		 *
287 287
 		 * @return bool
288 288
 		 */
289
-		public function isSupported(){
289
+		public function isSupported() {
290 290
 			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
291 291
 		}
292 292
 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	     * Return the Log instance
295 295
 	     * @return Log
296 296
 	     */
297
-	    public function getLogger(){
297
+	    public function getLogger() {
298 298
 	      return $this->logger;
299 299
 	    }
300 300
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	     * Set the log instance
303 303
 	     * @param Log $logger the log object
304 304
 	     */
305
-	    public function setLogger(Log $logger){
305
+	    public function setLogger(Log $logger) {
306 306
 	      $this->logger = $logger;
307 307
 	      return $this;
308 308
 	    }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 		* @param $key the cache item key
314 314
 		* @return string the full cache file path for this key
315 315
 		*/
316
-		private function getFilePath($key){
316
+		private function getFilePath($key) {
317 317
 			return CACHE_PATH . md5($key) . '.cache';
318 318
 		}
319 319
 	}
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -48,8 +48,7 @@  discard block
 block discarded – undo
48 48
 	         */
49 49
 	        if(is_object($logger)){
50 50
 	          $this->logger = $logger;
51
-	        }
52
-	        else{
51
+	        } else{
53 52
 	            $this->logger =& class_loader('Log', 'classes');
54 53
 	            $this->logger->setLogger('Library::FileCache');
55 54
 	        }
@@ -95,8 +94,7 @@  discard block
 block discarded – undo
95 94
 		        // Unlinking when the file was expired
96 95
 		        unlink($filePath);
97 96
 		        return false;
98
-		     }
99
-		     else{
97
+		     } else{
100 98
 		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101 99
 		     	return $data['data'];
102 100
 		     }
@@ -134,8 +132,7 @@  discard block
 block discarded – undo
134 132
 		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
135 133
 		    	fclose($handle);
136 134
 		    	return false;
137
-		    }
138
-		    else{
135
+		    } else{
139 136
 		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
140 137
 		    	fclose($handle);
141 138
 				chmod($filePath, 0640);
@@ -157,8 +154,7 @@  discard block
 block discarded – undo
157 154
 			if(! file_exists($filePath)){
158 155
 				$this->logger->info('This cache file does not exists skipping');
159 156
 				return false;
160
-			}
161
-			else{
157
+			} else{
162 158
 				$this->logger->info('Found cache file [' .$filePath. '] remove it');
163 159
 	      		@unlink($filePath);
164 160
 				return true;
@@ -180,16 +176,14 @@  discard block
 block discarded – undo
180 176
 			if(! file_exists($filePath)){
181 177
 				$this->logger->info('This cache file does not exists skipping');
182 178
 				return false;
183
-			}
184
-			else{
179
+			} else{
185 180
 				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
186 181
 	      		$data = file_get_contents($filePath);
187 182
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
188 183
 				if(! $data){
189 184
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
190 185
 					return false;
191
-				}
192
-				else{
186
+				} else{
193 187
 					$this->logger->info('This cache data is OK check for expire');
194 188
 					if(isset($data['expire']) && $data['expire'] > time()){
195 189
 						$this->logger->info('This cache not yet expired return cache informations');
@@ -199,8 +193,7 @@  discard block
 block discarded – undo
199 193
 							'ttl' => $data['ttl']
200 194
 							);
201 195
 						return $info;
202
-					}
203
-					else{
196
+					} else{
204 197
 						$this->logger->info('This cache already expired return false');
205 198
 						return false;
206 199
 					}
@@ -217,8 +210,7 @@  discard block
 block discarded – undo
217 210
 			$list = glob(CACHE_PATH . '*.cache');
218 211
 			if(! $list){
219 212
 				$this->logger->info('No cache files were found skipping');
220
-			}
221
-			else{
213
+			} else{
222 214
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
223 215
 				foreach ($list as $file) {
224 216
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -226,12 +218,10 @@  discard block
 block discarded – undo
226 218
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
227 219
 		      		if(! $data){
228 220
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
229
-		      		}
230
-		      		else if(time() > $data['expire']){
221
+		      		} else if(time() > $data['expire']){
231 222
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
232 223
 		      			@unlink($file);
233
-		      		}
234
-		      		else{
224
+		      		} else{
235 225
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
236 226
 		      		}
237 227
 				}
@@ -246,8 +236,7 @@  discard block
 block discarded – undo
246 236
 			$list = glob(CACHE_PATH . '*.cache');
247 237
 			if(! $list){
248 238
 				$this->logger->info('No cache files were found skipping');
249
-			}
250
-			else{
239
+			} else{
251 240
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
252 241
 				foreach ($list as $file) {
253 242
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -274,8 +263,7 @@  discard block
 block discarded – undo
274 263
 				
275 264
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
276 265
 				$this->compressCacheData = false;
277
-			}
278
-			else{
266
+			} else{
279 267
 				$this->compressCacheData = $status;
280 268
 			}
281 269
 			return $this;
Please login to merge, or discard this patch.
core/classes/cache/ApcCache.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * You should have received a copy of the GNU General Public License
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
25
+	 */
26 26
 	
27 27
 	class ApcCache implements CacheInterface{
28 28
 
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 			}
40 40
 
41 41
 			/**
42
-	         * instance of the Log class
43
-	         */
44
-	        if(is_object($logger)){
45
-	          $this->logger = $logger;
46
-	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
49
-	            $this->logger->setLogger('Library::ApcCache');
50
-	        }
42
+			 * instance of the Log class
43
+			 */
44
+			if(is_object($logger)){
45
+			  $this->logger = $logger;
46
+			}
47
+			else{
48
+				$this->logger =& class_loader('Log', 'classes');
49
+				$this->logger->setLogger('Library::ApcCache');
50
+			}
51 51
 		}
52 52
 
53 53
 		/**
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88 88
 			$result = apc_store($key, $data, $ttl);
89 89
 			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
-		    	return false;
92
-		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95
-		    	return true;
96
-		    }
90
+				$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91
+				return false;
92
+			}
93
+			else{
94
+				$this->logger->info('Cache data saved for the key ['. $key .']');
95
+				return true;
96
+			}
97 97
 		}
98 98
 
99 99
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 			}
113 113
 			else{
114 114
 				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
-	      		return apc_delete($key);
115
+		  		return apc_delete($key);
116 116
 			}
117 117
 			return false;
118 118
 		}
@@ -178,28 +178,28 @@  discard block
 block discarded – undo
178 178
 		}
179 179
 
180 180
 		/**
181
-	     * Return the Log instance
182
-	     * @return Log
183
-	     */
184
-	    public function getLogger(){
185
-	      return $this->logger;
186
-	    }
181
+		 * Return the Log instance
182
+		 * @return Log
183
+		 */
184
+		public function getLogger(){
185
+		  return $this->logger;
186
+		}
187 187
 
188
-	    /**
189
-	     * Set the log instance
190
-	     * @param Log $logger the log object
191
-	     */
192
-	    public function setLogger(Log $logger){
193
-	      $this->logger = $logger;
194
-	      return $this;
195
-	    }
188
+		/**
189
+		 * Set the log instance
190
+		 * @param Log $logger the log object
191
+		 */
192
+		public function setLogger(Log $logger){
193
+		  $this->logger = $logger;
194
+		  return $this;
195
+		}
196 196
 		
197 197
 		/**
198
-		* Return the array of cache information
199
-		*
200
-		* @param string $key the cache key to get the cache information 
201
-		* @return array
202
-		*/
198
+		 * Return the array of cache information
199
+		 *
200
+		 * @param string $key the cache key to get the cache information 
201
+		 * @return array
202
+		 */
203 203
 		private function _getCacheInfo($key){
204 204
 			$caches = apc_cache_info('user');
205 205
 			if(! empty($caches['cache_list'])){
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 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 ApcCache implements CacheInterface{
27
+	class ApcCache implements CacheInterface {
28 28
 
29 29
 		/**
30 30
 		 * The logger instance
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
 		private $logger;
34 34
 		
35 35
 		
36
-		public function __construct(Log $logger = null){
37
-			if(! $this->isSupported()){
36
+		public function __construct(Log $logger = null) {
37
+			if (!$this->isSupported()) {
38 38
 				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39 39
 			}
40 40
 
41 41
 			/**
42 42
 	         * instance of the Log class
43 43
 	         */
44
-	        if(is_object($logger)){
44
+	        if (is_object($logger)) {
45 45
 	          $this->logger = $logger;
46 46
 	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
47
+	        else {
48
+	            $this->logger = & class_loader('Log', 'classes');
49 49
 	            $this->logger->setLogger('Library::ApcCache');
50 50
 	        }
51 51
 		}
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 		 * @param  string $key the key to identify the cache data
56 56
 		 * @return mixed      the cache data if exists else return false
57 57
 		 */
58
-		public function get($key){
59
-			$this->logger->debug('Getting cache data for key ['. $key .']');
58
+		public function get($key) {
59
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
60 60
 			$success = false;
61 61
 			$data = apc_fetch($key, $success);
62
-			if($success === false){
63
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
62
+			if ($success === false) {
63
+				$this->logger->info('No cache found for the key [' . $key . '], return false');
64 64
 				return false;
65 65
 			}
66
-			else{
66
+			else {
67 67
 				$cacheInfo = $this->_getCacheInfo($key);
68 68
 				$expire = time();
69
-				if($cacheInfo){
69
+				if ($cacheInfo) {
70 70
 					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71 71
 				}
72
-				$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
72
+				$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73 73
 				return $data;
74 74
 			}
75 75
 		}
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 		 * @param integer $ttl  the cache life time
83 83
 		 * @return boolean true if success otherwise will return false
84 84
 		 */
85
-		public function set($key, $data, $ttl = 0){
85
+		public function set($key, $data, $ttl = 0) {
86 86
 			$expire = time() + $ttl;
87
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
87
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88 88
 			$result = apc_store($key, $data, $ttl);
89
-			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
89
+			if ($result === false) {
90
+		    	$this->logger->error('Can not write cache data for the key [' . $key . '], return false');
91 91
 		    	return false;
92 92
 		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
93
+		    else {
94
+		    	$this->logger->info('Cache data saved for the key [' . $key . ']');
95 95
 		    	return true;
96 96
 		    }
97 97
 		}
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 		 * @return boolean      true if the cache is deleted, false if can't delete 
104 104
 		 * the cache or the cache with the given key not exist
105 105
 		 */
106
-		public function delete($key){
107
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
106
+		public function delete($key) {
107
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
108 108
 			$cacheInfo = $this->_getCacheInfo($key);
109
-			if($cacheInfo === false){
109
+			if ($cacheInfo === false) {
110 110
 				$this->logger->info('This cache data does not exists skipping');
111 111
 				return false;
112 112
 			}
113
-			else{
114
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
113
+			else {
114
+				$this->logger->info('Found cache data for the key [' . $key . '] remove it');
115 115
 	      		return apc_delete($key);
116 116
 			}
117 117
 			return false;
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 		 * 'expire' => expiration time of the cache (Unix timestamp),
126 126
 		 * 'ttl' => the time to live of the cache in second
127 127
 		 */
128
-		public function getInfo($key){
129
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
128
+		public function getInfo($key) {
129
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
130 130
 			$cacheInfos = $this->_getCacheInfo($key);
131
-			if($cacheInfos){
131
+			if ($cacheInfos) {
132 132
 				$data = array(
133 133
 							'mtime' => $cacheInfos['creation_time'],
134 134
 							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 							);
137 137
 				return $data;
138 138
 			}
139
-			else{
139
+			else {
140 140
 				$this->logger->info('This cache does not exists skipping');
141 141
 				return false;
142 142
 			}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		/**
147 147
 		 * Used to delete expired cache data
148 148
 		 */
149
-		public function deleteExpiredCache(){
149
+		public function deleteExpiredCache() {
150 150
 			//for APC[u] is done automatically
151 151
 			return true;
152 152
 		}
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
 		/**
155 155
 		 * Remove all cache data
156 156
 		 */
157
-		public function clean(){
157
+		public function clean() {
158 158
 			$this->logger->debug('Deleting of all cache data');
159 159
 			$cacheInfos = apc_cache_info('user');
160
-			if(empty($cacheInfos['cache_list'])){
160
+			if (empty($cacheInfos['cache_list'])) {
161 161
 				$this->logger->info('No cache data were found skipping');
162 162
 				return false;
163 163
 			}
164
-			else{
164
+			else {
165 165
 				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
166 166
 				return apc_clear_cache('user');
167 167
 			}
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		 *
174 174
 		 * @return bool
175 175
 		 */
176
-		public function isSupported(){
176
+		public function isSupported() {
177 177
 			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
178 178
 		}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	     * Return the Log instance
182 182
 	     * @return Log
183 183
 	     */
184
-	    public function getLogger(){
184
+	    public function getLogger() {
185 185
 	      return $this->logger;
186 186
 	    }
187 187
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	     * Set the log instance
190 190
 	     * @param Log $logger the log object
191 191
 	     */
192
-	    public function setLogger(Log $logger){
192
+	    public function setLogger(Log $logger) {
193 193
 	      $this->logger = $logger;
194 194
 	      return $this;
195 195
 	    }
@@ -200,12 +200,12 @@  discard block
 block discarded – undo
200 200
 		* @param string $key the cache key to get the cache information 
201 201
 		* @return array
202 202
 		*/
203
-		private function _getCacheInfo($key){
203
+		private function _getCacheInfo($key) {
204 204
 			$caches = apc_cache_info('user');
205
-			if(! empty($caches['cache_list'])){
205
+			if (!empty($caches['cache_list'])) {
206 206
 				$cacheLists = $caches['cache_list'];
207
-				foreach ($cacheLists as $c){
208
-					if(isset($c['info']) && $c['info'] === $key){
207
+				foreach ($cacheLists as $c) {
208
+					if (isset($c['info']) && $c['info'] === $key) {
209 209
 						return $c;
210 210
 					}
211 211
 				}
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -43,8 +43,7 @@  discard block
 block discarded – undo
43 43
 	         */
44 44
 	        if(is_object($logger)){
45 45
 	          $this->logger = $logger;
46
-	        }
47
-	        else{
46
+	        } else{
48 47
 	            $this->logger =& class_loader('Log', 'classes');
49 48
 	            $this->logger->setLogger('Library::ApcCache');
50 49
 	        }
@@ -62,8 +61,7 @@  discard block
 block discarded – undo
62 61
 			if($success === false){
63 62
 				$this->logger->info('No cache found for the key ['. $key .'], return false');
64 63
 				return false;
65
-			}
66
-			else{
64
+			} else{
67 65
 				$cacheInfo = $this->_getCacheInfo($key);
68 66
 				$expire = time();
69 67
 				if($cacheInfo){
@@ -89,8 +87,7 @@  discard block
 block discarded – undo
89 87
 			if($result === false){
90 88
 		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
91 89
 		    	return false;
92
-		    }
93
-		    else{
90
+		    } else{
94 91
 		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95 92
 		    	return true;
96 93
 		    }
@@ -109,8 +106,7 @@  discard block
 block discarded – undo
109 106
 			if($cacheInfo === false){
110 107
 				$this->logger->info('This cache data does not exists skipping');
111 108
 				return false;
112
-			}
113
-			else{
109
+			} else{
114 110
 				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115 111
 	      		return apc_delete($key);
116 112
 			}
@@ -135,8 +131,7 @@  discard block
 block discarded – undo
135 131
 							'ttl' => $cacheInfos['ttl']
136 132
 							);
137 133
 				return $data;
138
-			}
139
-			else{
134
+			} else{
140 135
 				$this->logger->info('This cache does not exists skipping');
141 136
 				return false;
142 137
 			}
@@ -160,8 +155,7 @@  discard block
 block discarded – undo
160 155
 			if(empty($cacheInfos['cache_list'])){
161 156
 				$this->logger->info('No cache data were found skipping');
162 157
 				return false;
163
-			}
164
-			else{
158
+			} else{
165 159
 				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
166 160
 				return apc_clear_cache('user');
167 161
 			}
Please login to merge, or discard this patch.