Test Setup Failed
Branch 1.0.0-dev (6506b5)
by nguereza
05:54
created
core/classes/cache/CacheInterface.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 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
 	interface CacheInterface{
28 28
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 	
27
-	interface CacheInterface{
27
+	interface CacheInterface {
28 28
 
29 29
 		/**
30 30
 		 * This is used to get the cache data using the key
Please login to merge, or discard this patch.
core/classes/cache/ApcCache.php 3 patches
Indentation   +14 added lines, -14 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
 
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 			$logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
91 91
 			$result = apc_store($key, $data, $ttl);
92 92
 			if($result === false){
93
-		    	$logger->error('Can not write cache data for the key ['. $key .'], return false');
94
-		    	return false;
95
-		    }
96
-		    else{
97
-		    	$logger->info('Cache data saved for the key ['. $key .']');
98
-		    	return true;
99
-		    }
93
+				$logger->error('Can not write cache data for the key ['. $key .'], return false');
94
+				return false;
95
+			}
96
+			else{
97
+				$logger->info('Cache data saved for the key ['. $key .']');
98
+				return true;
99
+			}
100 100
 		}
101 101
 
102 102
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			else{
118 118
 				$logger->info('Found cache data for the key [' .$key. '] remove it');
119
-	      		return apc_delete($key);
119
+		  		return apc_delete($key);
120 120
 			}
121 121
 			return false;
122 122
 		}
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 		
186 186
 		/**
187
-		* Return the array of cache information
188
-		*
189
-		* @param string $key the cache key to get the cache information 
190
-		* @return array
191
-		*/
187
+		 * Return the array of cache information
188
+		 *
189
+		 * @param string $key the cache key to get the cache information 
190
+		 * @return array
191
+		 */
192 192
 		private function _getCacheInfo($key){
193 193
 			$caches = apc_cache_info('user');
194 194
 			if(! empty($caches['cache_list'])){
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 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,8 +33,8 @@  discard block
 block discarded – undo
33 33
 		private static $logger;
34 34
 		
35 35
 		
36
-		public function __construct(){
37
-			if(! $this->isSupported()){
36
+		public function __construct() {
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
 		}
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 		 * Get the logger singleton instance
44 44
 		 * @return Log the logger instance
45 45
 		 */
46
-		private static function getLogger(){
47
-			if(static::$logger == null){
48
-				static::$logger[0] =& class_loader('Log', 'classes');
46
+		private static function getLogger() {
47
+			if (static::$logger == null) {
48
+				static::$logger[0] = & class_loader('Log', 'classes');
49 49
 				static::$logger[0]->setLogger('Library::ApcCache');
50 50
 			}
51 51
 			return static::$logger[0];
@@ -56,22 +56,22 @@  discard block
 block discarded – undo
56 56
 		 * @param  string $key the key to identify the cache data
57 57
 		 * @return mixed      the cache data if exists else return false
58 58
 		 */
59
-		public function get($key){
59
+		public function get($key) {
60 60
 			$logger = static::getLogger();
61
-			$logger->debug('Getting cache data for key ['. $key .']');
61
+			$logger->debug('Getting cache data for key [' . $key . ']');
62 62
 			$success = false;
63 63
 			$data = apc_fetch($key, $success);
64
-			if($success === false){
65
-				$logger->info('No cache found for the key ['. $key .'], return false');
64
+			if ($success === false) {
65
+				$logger->info('No cache found for the key [' . $key . '], return false');
66 66
 				return false;
67 67
 			}
68
-			else{
68
+			else {
69 69
 				$cacheInfo = $this->_getCacheInfo($key);
70 70
 				$expire = time();
71
-				if($cacheInfo){
71
+				if ($cacheInfo) {
72 72
 					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
73 73
 				}
74
-				$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) . ']');
74
+				$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) . ']');
75 75
 				return $data;
76 76
 			}
77 77
 		}
@@ -84,17 +84,17 @@  discard block
 block discarded – undo
84 84
 		 * @param integer $ttl  the cache life time
85 85
 		 * @return boolean true if success otherwise will return false
86 86
 		 */
87
-		public function set($key, $data, $ttl = 0){
87
+		public function set($key, $data, $ttl = 0) {
88 88
 			$logger = static::getLogger();
89 89
 			$expire = time() + $ttl;
90
-			$logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
90
+			$logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
91 91
 			$result = apc_store($key, $data, $ttl);
92
-			if($result === false){
93
-		    	$logger->error('Can not write cache data for the key ['. $key .'], return false');
92
+			if ($result === false) {
93
+		    	$logger->error('Can not write cache data for the key [' . $key . '], return false');
94 94
 		    	return false;
95 95
 		    }
96
-		    else{
97
-		    	$logger->info('Cache data saved for the key ['. $key .']');
96
+		    else {
97
+		    	$logger->info('Cache data saved for the key [' . $key . ']');
98 98
 		    	return true;
99 99
 		    }
100 100
 		}
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
 		 * @return boolean      true if the cache is deleted, false if can't delete 
107 107
 		 * the cache or the cache with the given key not exist
108 108
 		 */
109
-		public function delete($key){
109
+		public function delete($key) {
110 110
 			$logger = static::getLogger();
111
-			$logger->debug('Deleting of cache data for key [' .$key. ']');
111
+			$logger->debug('Deleting of cache data for key [' . $key . ']');
112 112
 			$cacheInfo = $this->_getCacheInfo($key);
113
-			if($cacheInfo === false){
113
+			if ($cacheInfo === false) {
114 114
 				$logger->info('This cache data does not exists skipping');
115 115
 				return false;
116 116
 			}
117
-			else{
118
-				$logger->info('Found cache data for the key [' .$key. '] remove it');
117
+			else {
118
+				$logger->info('Found cache data for the key [' . $key . '] remove it');
119 119
 	      		return apc_delete($key);
120 120
 			}
121 121
 			return false;
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 		 * 'expire' => expiration time of the cache (Unix timestamp),
130 130
 		 * 'ttl' => the time to live of the cache in second
131 131
 		 */
132
-		public function getInfo($key){
132
+		public function getInfo($key) {
133 133
 			$logger = static::getLogger();
134
-			$logger->debug('Getting of cache info for key [' .$key. ']');
134
+			$logger->debug('Getting of cache info for key [' . $key . ']');
135 135
 			$cacheInfos = $this->_getCacheInfo($key);
136
-			if($cacheInfos){
136
+			if ($cacheInfos) {
137 137
 				$data = array(
138 138
 							'mtime' => $cacheInfos['creation_time'],
139 139
 							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 							);
142 142
 				return $data;
143 143
 			}
144
-			else{
144
+			else {
145 145
 				$logger->info('This cache does not exists skipping');
146 146
 				return false;
147 147
 			}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		/**
152 152
 		 * Used to delete expired cache data
153 153
 		 */
154
-		public function deleteExpiredCache(){
154
+		public function deleteExpiredCache() {
155 155
 			//for APC[u] is done automatically
156 156
 			return true;
157 157
 		}
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
 		/**
160 160
 		 * Remove all cache data
161 161
 		 */
162
-		public function clean(){
162
+		public function clean() {
163 163
 			$logger = static::getLogger();
164 164
 			$logger->debug('Deleting of all cache data');
165 165
 			$cacheInfos = apc_cache_info('user');
166
-			if(empty($cacheInfos['cache_list'])){
166
+			if (empty($cacheInfos['cache_list'])) {
167 167
 				$logger->info('No cache data were found skipping');
168 168
 				return false;
169 169
 			}
170
-			else{
170
+			else {
171 171
 				$logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
172 172
 				return apc_clear_cache('user');
173 173
 			}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		 *
180 180
 		 * @return bool
181 181
 		 */
182
-		public function isSupported(){
182
+		public function isSupported() {
183 183
 			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
184 184
 		}
185 185
 		
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
 		* @param string $key the cache key to get the cache information 
190 190
 		* @return array
191 191
 		*/
192
-		private function _getCacheInfo($key){
192
+		private function _getCacheInfo($key) {
193 193
 			$caches = apc_cache_info('user');
194
-			if(! empty($caches['cache_list'])){
194
+			if (!empty($caches['cache_list'])) {
195 195
 				$cacheLists = $caches['cache_list'];
196
-				foreach ($cacheLists as $c){
197
-					if(isset($c['info']) && $c['info'] === $key){
196
+				foreach ($cacheLists as $c) {
197
+					if (isset($c['info']) && $c['info'] === $key) {
198 198
 						return $c;
199 199
 					}
200 200
 				}
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@  discard block
 block discarded – undo
64 64
 			if($success === false){
65 65
 				$logger->info('No cache found for the key ['. $key .'], return false');
66 66
 				return false;
67
-			}
68
-			else{
67
+			} else{
69 68
 				$cacheInfo = $this->_getCacheInfo($key);
70 69
 				$expire = time();
71 70
 				if($cacheInfo){
@@ -92,8 +91,7 @@  discard block
 block discarded – undo
92 91
 			if($result === false){
93 92
 		    	$logger->error('Can not write cache data for the key ['. $key .'], return false');
94 93
 		    	return false;
95
-		    }
96
-		    else{
94
+		    } else{
97 95
 		    	$logger->info('Cache data saved for the key ['. $key .']');
98 96
 		    	return true;
99 97
 		    }
@@ -113,8 +111,7 @@  discard block
 block discarded – undo
113 111
 			if($cacheInfo === false){
114 112
 				$logger->info('This cache data does not exists skipping');
115 113
 				return false;
116
-			}
117
-			else{
114
+			} else{
118 115
 				$logger->info('Found cache data for the key [' .$key. '] remove it');
119 116
 	      		return apc_delete($key);
120 117
 			}
@@ -140,8 +137,7 @@  discard block
 block discarded – undo
140 137
 							'ttl' => $cacheInfos['ttl']
141 138
 							);
142 139
 				return $data;
143
-			}
144
-			else{
140
+			} else{
145 141
 				$logger->info('This cache does not exists skipping');
146 142
 				return false;
147 143
 			}
@@ -166,8 +162,7 @@  discard block
 block discarded – undo
166 162
 			if(empty($cacheInfos['cache_list'])){
167 163
 				$logger->info('No cache data were found skipping');
168 164
 				return false;
169
-			}
170
-			else{
165
+			} else{
171 166
 				$logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
172 167
 				return apc_clear_cache('user');
173 168
 			}
Please login to merge, or discard this patch.
core/classes/model/Model.php 3 patches
Indentation   +858 added lines, -858 removed lines patch added patch discarded remove patch
@@ -1,572 +1,572 @@  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
-    abstract 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
+	abstract 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 CI's global $this->db 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 Form_validation 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 CI's global $this->db 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 Form_validation 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;
120
+		 */
121
+		protected $dbCacheTime = 0;
122 122
 
123
-        /* --------------------------------------------------------------
123
+		/* --------------------------------------------------------------
124 124
          * GENERIC METHODS
125 125
          * ------------------------------------------------------------ */
126 126
 
127
-        /**
128
-         * Initialise the model, tie into the CodeIgniter superobject and
129
-         * try our best to guess the table name.
130
-         */
131
-        public function __construct(){
132
-            $obj = & get_instance();
133
-    		if(!isset($obj->database)){
134
-    			show_error('You must load the database library before to use the model class');
135
-            }
136
-            /**
137
-             * NOTE: Need use "clone" because some Model need have the personal instance of the database library
138
-             * to prevent duplication
139
-             */
140
-    		$this->_database = clone $obj->database;
127
+		/**
128
+		 * Initialise the model, tie into the CodeIgniter superobject and
129
+		 * try our best to guess the table name.
130
+		 */
131
+		public function __construct(){
132
+			$obj = & get_instance();
133
+			if(!isset($obj->database)){
134
+				show_error('You must load the database library before to use the model class');
135
+			}
136
+			/**
137
+			 * NOTE: Need use "clone" because some Model need have the personal instance of the database library
138
+			 * to prevent duplication
139
+			 */
140
+			$this->_database = clone $obj->database;
141 141
     				
142
-            array_unshift($this->before_create, 'protect_attributes');
143
-            array_unshift($this->before_update, 'protect_attributes');
144
-            $this->_temporary_return_type = $this->return_type;
145
-            if($this->dbCacheTime > 0){
146
-                $this->_database->setCache($this->dbCacheTime);
147
-            }
148
-        }
149
-
150
-        /* --------------------------------------------------------------
142
+			array_unshift($this->before_create, 'protect_attributes');
143
+			array_unshift($this->before_update, 'protect_attributes');
144
+			$this->_temporary_return_type = $this->return_type;
145
+			if($this->dbCacheTime > 0){
146
+				$this->_database->setCache($this->dbCacheTime);
147
+			}
148
+		}
149
+
150
+		/* --------------------------------------------------------------
151 151
          * CRUD INTERFACE
152 152
          * ------------------------------------------------------------ */
153 153
 
154
-        /**
155
-         * Fetch a single record based on the primary key. Returns an object.
156
-         */
157
-        public function get($primary_value)
158
-        {
159
-    		return $this->get_by($this->primary_key, $primary_value);
160
-        }
161
-
162
-        /**
163
-         * Fetch a single record based on an arbitrary WHERE call. Can be
164
-         * any valid value to $this->_database->where().
165
-         */
166
-        public function get_by()
167
-        {
168
-            $where = func_get_args();
169
-
170
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
171
-            {
172
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
173
-            }
174
-
175
-    		$this->_set_where($where);
176
-
177
-            $this->trigger('before_get');
154
+		/**
155
+		 * Fetch a single record based on the primary key. Returns an object.
156
+		 */
157
+		public function get($primary_value)
158
+		{
159
+			return $this->get_by($this->primary_key, $primary_value);
160
+		}
161
+
162
+		/**
163
+		 * Fetch a single record based on an arbitrary WHERE call. Can be
164
+		 * any valid value to $this->_database->where().
165
+		 */
166
+		public function get_by()
167
+		{
168
+			$where = func_get_args();
169
+
170
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
171
+			{
172
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
173
+			}
174
+
175
+			$this->_set_where($where);
176
+
177
+			$this->trigger('before_get');
178 178
 			$type = $this->_temporary_return_type == 'array' ? 'array':false;
179
-            $row = $this->_database->from($this->_table)->get($type);
180
-            $this->_temporary_return_type = $this->return_type;
181
-            $row = $this->trigger('after_get', $row);
182
-            $this->_with = array();
183
-            return $row;
184
-        }
185
-
186
-        /**
187
-         * Fetch an array of records based on an array of primary values.
188
-         */
189
-        public function get_many($values)
190
-        {
191
-            $this->_database->in($this->primary_key, $values);
192
-            return $this->get_all();
193
-        }
194
-
195
-        /**
196
-         * Fetch an array of records based on an arbitrary WHERE call.
197
-         */
198
-        public function get_many_by()
199
-        {
200
-            $where = func_get_args();
201
-            $this->_set_where($where);
202
-            return $this->get_all();
203
-        }
204
-
205
-        /**
206
-         * Fetch all the records in the table. Can be used as a generic call
207
-         * to $this->_database->get() with scoped methods.
208
-         */
209
-        public function get_all()
210
-        {
211
-            $this->trigger('before_get');
212
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
213
-            {
214
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
215
-            }
179
+			$row = $this->_database->from($this->_table)->get($type);
180
+			$this->_temporary_return_type = $this->return_type;
181
+			$row = $this->trigger('after_get', $row);
182
+			$this->_with = array();
183
+			return $row;
184
+		}
185
+
186
+		/**
187
+		 * Fetch an array of records based on an array of primary values.
188
+		 */
189
+		public function get_many($values)
190
+		{
191
+			$this->_database->in($this->primary_key, $values);
192
+			return $this->get_all();
193
+		}
194
+
195
+		/**
196
+		 * Fetch an array of records based on an arbitrary WHERE call.
197
+		 */
198
+		public function get_many_by()
199
+		{
200
+			$where = func_get_args();
201
+			$this->_set_where($where);
202
+			return $this->get_all();
203
+		}
204
+
205
+		/**
206
+		 * Fetch all the records in the table. Can be used as a generic call
207
+		 * to $this->_database->get() with scoped methods.
208
+		 */
209
+		public function get_all()
210
+		{
211
+			$this->trigger('before_get');
212
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
213
+			{
214
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
215
+			}
216 216
 			$type = $this->_temporary_return_type == 'array' ? 'array':false;
217
-            $result = $this->_database->from($this->_table)->getAll($type);
218
-            $this->_temporary_return_type = $this->return_type;
219
-
220
-            foreach ($result as $key => &$row)
221
-            {
222
-                $row = $this->trigger('after_get', $row, ($key == count($result) - 1));
223
-            }
224
-            $this->_with = array();
225
-            return $result;
226
-        }
227
-
228
-        /**
229
-         * Insert a new row into the table. $data should be an associative array
230
-         * of data to be inserted. Returns newly created ID.
231
-         */
232
-        public function insert($data = array(), $skip_validation = FALSE, $escape = true)
233
-        {
234
-            if ($skip_validation === FALSE)
235
-            {
236
-                $data = $this->validate($data);
237
-            }
238
-
239
-            if ($data !== FALSE)
240
-            {
241
-                $data = $this->trigger('before_create', $data);
242
-                $this->_database->from($this->_table)->insert($data, $escape);
243
-                $insert_id = $this->_database->insertId();
244
-                $this->trigger('after_create', $insert_id);
245
-                return $insert_id;
246
-            }
247
-            else
248
-            {
249
-                return FALSE;
250
-            }
251
-        }
252
-
253
-        /**
254
-         * Insert multiple rows into the table. Returns an array of multiple IDs.
255
-         */
256
-        public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
257
-        {
258
-            $ids = array();
259
-            foreach ($data as $key => $row)
260
-            {
261
-                $ids[] = $this->insert($row, $skip_validation, $escape);
262
-            }
263
-            return $ids;
264
-        }
265
-
266
-        /**
267
-         * Updated a record based on the primary value.
268
-         */
269
-        public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
270
-        {
271
-            $data = $this->trigger('before_update', $data);
272
-            if ($skip_validation === FALSE)
273
-            {
274
-                $data = $this->validate($data);
275
-            }
276
-
277
-            if ($data !== FALSE)
278
-            {
279
-                $result = $this->_database->where($this->primary_key, $primary_value)
280
-                                   ->from($this->_table)
281
-                                   ->update($data, $escape);
282
-                $this->trigger('after_update', array($data, $result));
283
-                return $result;
284
-            }
285
-            else
286
-            {
287
-                return FALSE;
288
-            }
289
-        }
290
-
291
-        /**
292
-         * Update many records, based on an array of primary values.
293
-         */
294
-        public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
295
-        {
296
-            $data = $this->trigger('before_update', $data);
297
-            if ($skip_validation === FALSE)
298
-            {
299
-                $data = $this->validate($data);
300
-            }
301
-            if ($data !== FALSE)
302
-            {
303
-                $result = $this->_database->in($this->primary_key, $primary_values)
304
-                                   ->from($this->_table)
305
-                                   ->update($data, $escape);
306
-                $this->trigger('after_update', array($data, $result));
307
-                return $result;
308
-            }
309
-            else
310
-            {
311
-                return FALSE;
312
-            }
313
-        }
314
-
315
-        /**
316
-         * Updated a record based on an arbitrary WHERE clause.
317
-         */
318
-        public function update_by()
319
-        {
320
-            $args = func_get_args();
321
-            $data = array();
322
-            if(count($args) == 2){
323
-                if(is_array($args[1])){
324
-                    $data = array_pop($args);
325
-                }
326
-            }
327
-            else if(count($args) == 3){
328
-                if(is_array($args[2])){
329
-                    $data = array_pop($args);
330
-                }
331
-            }
332
-            $data = $this->trigger('before_update', $data);
333
-            if ($this->validate($data) !== FALSE)
334
-            {
335
-                $this->_set_where($args);
336
-                $result = $this->_database->from($this->_table)->update($data);
337
-                $this->trigger('after_update', array($data, $result));
338
-                return $result;
339
-            }
340
-            else
341
-            {
342
-                return FALSE;
343
-            }
344
-        }
345
-
346
-        /**
347
-         * Update all records
348
-         */
349
-        public function update_all($data = array(), $escape = true)
350
-        {
351
-            $data = $this->trigger('before_update', $data);
352
-            $result = $this->_database->from($this->_table)->update($data, $escape);
353
-            $this->trigger('after_update', array($data, $result));
354
-            return $result;
355
-        }
356
-
357
-        /**
358
-         * Delete a row from the table by the primary value
359
-         */
360
-        public function delete($id)
361
-        {
362
-            $this->trigger('before_delete', $id);
363
-            $this->_database->where($this->primary_key, $id);
364
-            if ($this->soft_delete)
365
-            {
366
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
367
-            }
368
-            else
369
-            {
370
-                $result = $this->_database->from($this->_table)->delete();
371
-            }
372
-
373
-            $this->trigger('after_delete', $result);
374
-            return $result;
375
-        }
376
-
377
-        /**
378
-         * Delete a row from the database table by an arbitrary WHERE clause
379
-         */
380
-        public function delete_by()
381
-        {
382
-            $where = func_get_args();
383
-    	    $where = $this->trigger('before_delete', $where);
384
-            $this->_set_where($where);
385
-            if ($this->soft_delete)
386
-            {
387
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
388
-            }
389
-            else
390
-            {
391
-                $result = $this->_database->from($this->_table)->delete();
392
-            }
393
-            $this->trigger('after_delete', $result);
394
-            return $result;
395
-        }
396
-
397
-        /**
398
-         * Delete many rows from the database table by multiple primary values
399
-         */
400
-        public function delete_many($primary_values)
401
-        {
402
-            $primary_values = $this->trigger('before_delete', $primary_values);
403
-            $this->_database->in($this->primary_key, $primary_values);
404
-            if ($this->soft_delete)
405
-            {
406
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
407
-            }
408
-            else
409
-            {
410
-                $result = $this->_database->from($this->_table)->delete();
411
-            }
412
-            $this->trigger('after_delete', $result);
413
-            return $result;
414
-        }
415
-
416
-
417
-        /**
418
-         * Truncates the table
419
-         */
420
-        public function truncate()
421
-        {
422
-            $result = $this->_database->from($this->_table)->delete();
423
-            return $result;
424
-        }
425
-
426
-        /* --------------------------------------------------------------
217
+			$result = $this->_database->from($this->_table)->getAll($type);
218
+			$this->_temporary_return_type = $this->return_type;
219
+
220
+			foreach ($result as $key => &$row)
221
+			{
222
+				$row = $this->trigger('after_get', $row, ($key == count($result) - 1));
223
+			}
224
+			$this->_with = array();
225
+			return $result;
226
+		}
227
+
228
+		/**
229
+		 * Insert a new row into the table. $data should be an associative array
230
+		 * of data to be inserted. Returns newly created ID.
231
+		 */
232
+		public function insert($data = array(), $skip_validation = FALSE, $escape = true)
233
+		{
234
+			if ($skip_validation === FALSE)
235
+			{
236
+				$data = $this->validate($data);
237
+			}
238
+
239
+			if ($data !== FALSE)
240
+			{
241
+				$data = $this->trigger('before_create', $data);
242
+				$this->_database->from($this->_table)->insert($data, $escape);
243
+				$insert_id = $this->_database->insertId();
244
+				$this->trigger('after_create', $insert_id);
245
+				return $insert_id;
246
+			}
247
+			else
248
+			{
249
+				return FALSE;
250
+			}
251
+		}
252
+
253
+		/**
254
+		 * Insert multiple rows into the table. Returns an array of multiple IDs.
255
+		 */
256
+		public function insert_many($data = array(), $skip_validation = FALSE, $escape = true)
257
+		{
258
+			$ids = array();
259
+			foreach ($data as $key => $row)
260
+			{
261
+				$ids[] = $this->insert($row, $skip_validation, $escape);
262
+			}
263
+			return $ids;
264
+		}
265
+
266
+		/**
267
+		 * Updated a record based on the primary value.
268
+		 */
269
+		public function update($primary_value, $data = array(), $skip_validation = FALSE, $escape = true)
270
+		{
271
+			$data = $this->trigger('before_update', $data);
272
+			if ($skip_validation === FALSE)
273
+			{
274
+				$data = $this->validate($data);
275
+			}
276
+
277
+			if ($data !== FALSE)
278
+			{
279
+				$result = $this->_database->where($this->primary_key, $primary_value)
280
+								   ->from($this->_table)
281
+								   ->update($data, $escape);
282
+				$this->trigger('after_update', array($data, $result));
283
+				return $result;
284
+			}
285
+			else
286
+			{
287
+				return FALSE;
288
+			}
289
+		}
290
+
291
+		/**
292
+		 * Update many records, based on an array of primary values.
293
+		 */
294
+		public function update_many($primary_values, $data = array(), $skip_validation = FALSE, $escape = true)
295
+		{
296
+			$data = $this->trigger('before_update', $data);
297
+			if ($skip_validation === FALSE)
298
+			{
299
+				$data = $this->validate($data);
300
+			}
301
+			if ($data !== FALSE)
302
+			{
303
+				$result = $this->_database->in($this->primary_key, $primary_values)
304
+								   ->from($this->_table)
305
+								   ->update($data, $escape);
306
+				$this->trigger('after_update', array($data, $result));
307
+				return $result;
308
+			}
309
+			else
310
+			{
311
+				return FALSE;
312
+			}
313
+		}
314
+
315
+		/**
316
+		 * Updated a record based on an arbitrary WHERE clause.
317
+		 */
318
+		public function update_by()
319
+		{
320
+			$args = func_get_args();
321
+			$data = array();
322
+			if(count($args) == 2){
323
+				if(is_array($args[1])){
324
+					$data = array_pop($args);
325
+				}
326
+			}
327
+			else if(count($args) == 3){
328
+				if(is_array($args[2])){
329
+					$data = array_pop($args);
330
+				}
331
+			}
332
+			$data = $this->trigger('before_update', $data);
333
+			if ($this->validate($data) !== FALSE)
334
+			{
335
+				$this->_set_where($args);
336
+				$result = $this->_database->from($this->_table)->update($data);
337
+				$this->trigger('after_update', array($data, $result));
338
+				return $result;
339
+			}
340
+			else
341
+			{
342
+				return FALSE;
343
+			}
344
+		}
345
+
346
+		/**
347
+		 * Update all records
348
+		 */
349
+		public function update_all($data = array(), $escape = true)
350
+		{
351
+			$data = $this->trigger('before_update', $data);
352
+			$result = $this->_database->from($this->_table)->update($data, $escape);
353
+			$this->trigger('after_update', array($data, $result));
354
+			return $result;
355
+		}
356
+
357
+		/**
358
+		 * Delete a row from the table by the primary value
359
+		 */
360
+		public function delete($id)
361
+		{
362
+			$this->trigger('before_delete', $id);
363
+			$this->_database->where($this->primary_key, $id);
364
+			if ($this->soft_delete)
365
+			{
366
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
367
+			}
368
+			else
369
+			{
370
+				$result = $this->_database->from($this->_table)->delete();
371
+			}
372
+
373
+			$this->trigger('after_delete', $result);
374
+			return $result;
375
+		}
376
+
377
+		/**
378
+		 * Delete a row from the database table by an arbitrary WHERE clause
379
+		 */
380
+		public function delete_by()
381
+		{
382
+			$where = func_get_args();
383
+			$where = $this->trigger('before_delete', $where);
384
+			$this->_set_where($where);
385
+			if ($this->soft_delete)
386
+			{
387
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
388
+			}
389
+			else
390
+			{
391
+				$result = $this->_database->from($this->_table)->delete();
392
+			}
393
+			$this->trigger('after_delete', $result);
394
+			return $result;
395
+		}
396
+
397
+		/**
398
+		 * Delete many rows from the database table by multiple primary values
399
+		 */
400
+		public function delete_many($primary_values)
401
+		{
402
+			$primary_values = $this->trigger('before_delete', $primary_values);
403
+			$this->_database->in($this->primary_key, $primary_values);
404
+			if ($this->soft_delete)
405
+			{
406
+				$result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
407
+			}
408
+			else
409
+			{
410
+				$result = $this->_database->from($this->_table)->delete();
411
+			}
412
+			$this->trigger('after_delete', $result);
413
+			return $result;
414
+		}
415
+
416
+
417
+		/**
418
+		 * Truncates the table
419
+		 */
420
+		public function truncate()
421
+		{
422
+			$result = $this->_database->from($this->_table)->delete();
423
+			return $result;
424
+		}
425
+
426
+		/* --------------------------------------------------------------
427 427
          * RELATIONSHIPS
428 428
          * ------------------------------------------------------------ */
429 429
 
430
-        public function with($relationship)
431
-        {
432
-            $this->_with[] = $relationship;
433
-            if (!in_array('relate', $this->after_get))
434
-            {
435
-                $this->after_get[] = 'relate';
436
-            }
437
-            return $this;
438
-        }
439
-
440
-        public function relate($row)
441
-        {
442
-    		if (empty($row))
443
-            {
444
-    		    return $row;
445
-            }
446
-
447
-            foreach ($this->belongs_to as $key => $value)
448
-            {
449
-                if (is_string($value))
450
-                {
451
-                    $relationship = $value;
452
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
453
-                }
454
-                else
455
-                {
456
-                    $relationship = $key;
457
-                    $options = $value;
458
-                }
459
-
460
-                if (in_array($relationship, $this->_with))
461
-                {
462
-                    Loader::model($options['model'], $relationship . '_model');
463
-                    if (is_object($row))
464
-                    {
465
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
466
-                    }
467
-                    else
468
-                    {
469
-                        $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
470
-                    }
471
-                }
472
-            }
473
-
474
-            foreach ($this->has_many as $key => $value)
475
-            {
476
-                if (is_string($value))
477
-                {
478
-                    $relationship = $value;
479
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
480
-                }
481
-                else
482
-                {
483
-                    $relationship = $key;
484
-                    $options = $value;
485
-                }
486
-
487
-                if (in_array($relationship, $this->_with))
488
-                {
489
-                    Loader::model($options['model'], $relationship . '_model');
490
-                    if (is_object($row))
491
-                    {
492
-                        $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
493
-                    }
494
-                    else
495
-                    {
496
-                        $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
497
-                    }
498
-                }
499
-            }
500
-            return $row;
501
-        }
502
-
503
-        /* --------------------------------------------------------------
430
+		public function with($relationship)
431
+		{
432
+			$this->_with[] = $relationship;
433
+			if (!in_array('relate', $this->after_get))
434
+			{
435
+				$this->after_get[] = 'relate';
436
+			}
437
+			return $this;
438
+		}
439
+
440
+		public function relate($row)
441
+		{
442
+			if (empty($row))
443
+			{
444
+				return $row;
445
+			}
446
+
447
+			foreach ($this->belongs_to as $key => $value)
448
+			{
449
+				if (is_string($value))
450
+				{
451
+					$relationship = $value;
452
+					$options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
453
+				}
454
+				else
455
+				{
456
+					$relationship = $key;
457
+					$options = $value;
458
+				}
459
+
460
+				if (in_array($relationship, $this->_with))
461
+				{
462
+					Loader::model($options['model'], $relationship . '_model');
463
+					if (is_object($row))
464
+					{
465
+						$row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
466
+					}
467
+					else
468
+					{
469
+						$row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
470
+					}
471
+				}
472
+			}
473
+
474
+			foreach ($this->has_many as $key => $value)
475
+			{
476
+				if (is_string($value))
477
+				{
478
+					$relationship = $value;
479
+					$options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
480
+				}
481
+				else
482
+				{
483
+					$relationship = $key;
484
+					$options = $value;
485
+				}
486
+
487
+				if (in_array($relationship, $this->_with))
488
+				{
489
+					Loader::model($options['model'], $relationship . '_model');
490
+					if (is_object($row))
491
+					{
492
+						$row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
493
+					}
494
+					else
495
+					{
496
+						$row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
497
+					}
498
+				}
499
+			}
500
+			return $row;
501
+		}
502
+
503
+		/* --------------------------------------------------------------
504 504
          * UTILITY METHODS
505 505
          * ------------------------------------------------------------ */
506 506
 
507
-        /**
508
-         * Retrieve and generate a form_dropdown friendly array
509
-         */
510
-        public function dropdown()
511
-        {
512
-            $args = func_get_args();
513
-            if(count($args) == 2)
514
-            {
515
-                list($key, $value) = $args;
516
-            }
517
-            else
518
-            {
519
-                $key = $this->primary_key;
520
-                $value = $args[0];
521
-            }
522
-            $this->trigger('before_dropdown', array( $key, $value ));
523
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
524
-            {
525
-                $this->_database->where($this->soft_delete_key, FALSE);
526
-            }
527
-            $result = $this->_database->select(array($key, $value))
528
-                               ->from($this->_table)
529
-                               ->getAll();
530
-            $options = array();
531
-            foreach ($result as $row)
532
-            {
533
-                $options[$row->{$key}] = $row->{$value};
534
-            }
535
-            $options = $this->trigger('after_dropdown', $options);
536
-            return $options;
537
-        }
538
-
539
-        /**
540
-         * Fetch a count of rows based on an arbitrary WHERE call.
541
-         */
542
-        public function count_by()
543
-        {
544
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
545
-            {
546
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
547
-            }
548
-            $where = func_get_args();
549
-            $this->_set_where($where);
550
-            $this->_database->from($this->_table)->getAll();
551
-            return $this->_database->numRows();
552
-        }
553
-
554
-        /**
555
-         * Fetch a total count of rows, disregarding any previous conditions
556
-         */
557
-        public function count_all()
558
-        {
559
-            if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
560
-            {
561
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
562
-            }
563
-            $this->_database->from($this->_table)->getAll();
564
-            return $this->_database->numRows();
565
-        }
507
+		/**
508
+		 * Retrieve and generate a form_dropdown friendly array
509
+		 */
510
+		public function dropdown()
511
+		{
512
+			$args = func_get_args();
513
+			if(count($args) == 2)
514
+			{
515
+				list($key, $value) = $args;
516
+			}
517
+			else
518
+			{
519
+				$key = $this->primary_key;
520
+				$value = $args[0];
521
+			}
522
+			$this->trigger('before_dropdown', array( $key, $value ));
523
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
524
+			{
525
+				$this->_database->where($this->soft_delete_key, FALSE);
526
+			}
527
+			$result = $this->_database->select(array($key, $value))
528
+							   ->from($this->_table)
529
+							   ->getAll();
530
+			$options = array();
531
+			foreach ($result as $row)
532
+			{
533
+				$options[$row->{$key}] = $row->{$value};
534
+			}
535
+			$options = $this->trigger('after_dropdown', $options);
536
+			return $options;
537
+		}
538
+
539
+		/**
540
+		 * Fetch a count of rows based on an arbitrary WHERE call.
541
+		 */
542
+		public function count_by()
543
+		{
544
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
545
+			{
546
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
547
+			}
548
+			$where = func_get_args();
549
+			$this->_set_where($where);
550
+			$this->_database->from($this->_table)->getAll();
551
+			return $this->_database->numRows();
552
+		}
553
+
554
+		/**
555
+		 * Fetch a total count of rows, disregarding any previous conditions
556
+		 */
557
+		public function count_all()
558
+		{
559
+			if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
560
+			{
561
+				$this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
562
+			}
563
+			$this->_database->from($this->_table)->getAll();
564
+			return $this->_database->numRows();
565
+		}
566 566
 		
567 567
 		/**
568
-		* Enabled cache temporary
569
-		*/
568
+		 * Enabled cache temporary
569
+		 */
570 570
 		public function cached($ttl = 0){
571 571
 		  if($ttl > 0){
572 572
 			$this->_database = $this->_database->cached($ttl);
@@ -574,339 +574,339 @@  discard block
 block discarded – undo
574 574
 		  return $this;
575 575
 		}
576 576
 
577
-        /**
578
-         * Tell the class to skip the insert validation
579
-         */
580
-        public function skip_validation()
581
-        {
582
-            $this->skip_validation = TRUE;
583
-            return $this;
584
-        }
585
-
586
-        /**
587
-         * Get the skip validation status
588
-         */
589
-        public function get_skip_validation()
590
-        {
591
-            return $this->skip_validation;
592
-        }
593
-
594
-        /**
595
-         * Return the next auto increment of the table. Only tested on MySQL.
596
-         */
597
-        public function get_next_id()
598
-        {
599
-            return (int) $this->_database->select('AUTO_INCREMENT')
600
-                ->from('information_schema.TABLES')
601
-                ->where('TABLE_NAME', $this->_table)
602
-                ->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT;
603
-        }
604
-
605
-        /**
606
-         * Getter for the table name
607
-         */
608
-        public function table()
609
-        {
610
-            return $this->_table;
611
-        }
612
-
613
-        /* --------------------------------------------------------------
577
+		/**
578
+		 * Tell the class to skip the insert validation
579
+		 */
580
+		public function skip_validation()
581
+		{
582
+			$this->skip_validation = TRUE;
583
+			return $this;
584
+		}
585
+
586
+		/**
587
+		 * Get the skip validation status
588
+		 */
589
+		public function get_skip_validation()
590
+		{
591
+			return $this->skip_validation;
592
+		}
593
+
594
+		/**
595
+		 * Return the next auto increment of the table. Only tested on MySQL.
596
+		 */
597
+		public function get_next_id()
598
+		{
599
+			return (int) $this->_database->select('AUTO_INCREMENT')
600
+				->from('information_schema.TABLES')
601
+				->where('TABLE_NAME', $this->_table)
602
+				->where('TABLE_SCHEMA', $this->_database->getDatabaseName())->get()->AUTO_INCREMENT;
603
+		}
604
+
605
+		/**
606
+		 * Getter for the table name
607
+		 */
608
+		public function table()
609
+		{
610
+			return $this->_table;
611
+		}
612
+
613
+		/* --------------------------------------------------------------
614 614
          * GLOBAL SCOPES
615 615
          * ------------------------------------------------------------ */
616 616
 
617
-        /**
618
-         * Return the next call as an array rather than an object
619
-         */
620
-        public function as_array()
621
-        {
622
-            $this->_temporary_return_type = 'array';
623
-            return $this;
624
-        }
625
-
626
-        /**
627
-         * Return the next call as an object rather than an array
628
-         */
629
-        public function as_object()
630
-        {
631
-            $this->_temporary_return_type = 'object';
632
-            return $this;
633
-        }
634
-
635
-        /**
636
-         * Don't care about soft deleted rows on the next call
637
-         */
638
-        public function with_deleted()
639
-        {
640
-            $this->_temporary_with_deleted = TRUE;
641
-            return $this;
642
-        }
643
-
644
-        /**
645
-         * Only get deleted rows on the next call
646
-         */
647
-        public function only_deleted()
648
-        {
649
-            $this->_temporary_only_deleted = TRUE;
650
-            return $this;
651
-        }
652
-
653
-        /* --------------------------------------------------------------
617
+		/**
618
+		 * Return the next call as an array rather than an object
619
+		 */
620
+		public function as_array()
621
+		{
622
+			$this->_temporary_return_type = 'array';
623
+			return $this;
624
+		}
625
+
626
+		/**
627
+		 * Return the next call as an object rather than an array
628
+		 */
629
+		public function as_object()
630
+		{
631
+			$this->_temporary_return_type = 'object';
632
+			return $this;
633
+		}
634
+
635
+		/**
636
+		 * Don't care about soft deleted rows on the next call
637
+		 */
638
+		public function with_deleted()
639
+		{
640
+			$this->_temporary_with_deleted = TRUE;
641
+			return $this;
642
+		}
643
+
644
+		/**
645
+		 * Only get deleted rows on the next call
646
+		 */
647
+		public function only_deleted()
648
+		{
649
+			$this->_temporary_only_deleted = TRUE;
650
+			return $this;
651
+		}
652
+
653
+		/* --------------------------------------------------------------
654 654
          * OBSERVERS
655 655
          * ------------------------------------------------------------ */
656 656
 
657
-        /**
658
-         * MySQL DATETIME created_at and updated_at
659
-         */
660
-        public function created_at($row)
661
-        {
662
-            if (is_object($row))
663
-            {
664
-                $row->created_at = date('Y-m-d H:i:s');
665
-            }
666
-            else
667
-            {
668
-                $row['created_at'] = date('Y-m-d H:i:s');
669
-            }
670
-
671
-            return $row;
672
-        }
673
-
674
-        public function updated_at($row)
675
-        {
676
-            if (is_object($row))
677
-            {
678
-                $row->updated_at = date('Y-m-d H:i:s');
679
-            }
680
-            else
681
-            {
682
-                $row['updated_at'] = date('Y-m-d H:i:s');
683
-            }
684
-            return $row;
685
-        }
686
-
687
-        /**
688
-         * Serialises data for you automatically, allowing you to pass
689
-         * through objects and let it handle the serialisation in the background
690
-         */
691
-        public function serialize($row)
692
-        {
693
-            foreach ($this->callback_parameters as $column)
694
-            {
695
-                $row[$column] = serialize($row[$column]);
696
-            }
697
-            return $row;
698
-        }
699
-
700
-        public function unserialize($row)
701
-        {
702
-            foreach ($this->callback_parameters as $column)
703
-            {
704
-                if (is_array($row))
705
-                {
706
-                    $row[$column] = unserialize($row[$column]);
707
-                }
708
-                else
709
-                {
710
-                    $row->$column = unserialize($row->$column);
711
-                }
712
-            }
713
-            return $row;
714
-        }
715
-
716
-        /**
717
-         * Protect attributes by removing them from $row array
718
-         */
719
-        public function protect_attributes($row)
720
-        {
721
-            foreach ($this->protected_attributes as $attr)
722
-            {
723
-                if (is_object($row))
724
-                {
657
+		/**
658
+		 * MySQL DATETIME created_at and updated_at
659
+		 */
660
+		public function created_at($row)
661
+		{
662
+			if (is_object($row))
663
+			{
664
+				$row->created_at = date('Y-m-d H:i:s');
665
+			}
666
+			else
667
+			{
668
+				$row['created_at'] = date('Y-m-d H:i:s');
669
+			}
670
+
671
+			return $row;
672
+		}
673
+
674
+		public function updated_at($row)
675
+		{
676
+			if (is_object($row))
677
+			{
678
+				$row->updated_at = date('Y-m-d H:i:s');
679
+			}
680
+			else
681
+			{
682
+				$row['updated_at'] = date('Y-m-d H:i:s');
683
+			}
684
+			return $row;
685
+		}
686
+
687
+		/**
688
+		 * Serialises data for you automatically, allowing you to pass
689
+		 * through objects and let it handle the serialisation in the background
690
+		 */
691
+		public function serialize($row)
692
+		{
693
+			foreach ($this->callback_parameters as $column)
694
+			{
695
+				$row[$column] = serialize($row[$column]);
696
+			}
697
+			return $row;
698
+		}
699
+
700
+		public function unserialize($row)
701
+		{
702
+			foreach ($this->callback_parameters as $column)
703
+			{
704
+				if (is_array($row))
705
+				{
706
+					$row[$column] = unserialize($row[$column]);
707
+				}
708
+				else
709
+				{
710
+					$row->$column = unserialize($row->$column);
711
+				}
712
+			}
713
+			return $row;
714
+		}
715
+
716
+		/**
717
+		 * Protect attributes by removing them from $row array
718
+		 */
719
+		public function protect_attributes($row)
720
+		{
721
+			foreach ($this->protected_attributes as $attr)
722
+			{
723
+				if (is_object($row))
724
+				{
725 725
 					if(isset($row->$attr)){
726 726
 						unset($row->$attr);
727 727
 					}
728
-                }
729
-                else
730
-                {
728
+				}
729
+				else
730
+				{
731 731
 					if(isset($row[$attr])){
732 732
 						unset($row[$attr]);
733 733
 					}
734
-                }
735
-            }
736
-            return $row;
737
-        }
734
+				}
735
+			}
736
+			return $row;
737
+		}
738 738
 		
739 739
 		 /**
740
-         * Return the database instance
741
-         * @return Database the database instance
742
-         */
743
-        public function getDatabaseInstance(){
744
-            return $this->_database;
745
-        }
746
-
747
-        /* --------------------------------------------------------------
740
+		  * Return the database instance
741
+		  * @return Database the database instance
742
+		  */
743
+		public function getDatabaseInstance(){
744
+			return $this->_database;
745
+		}
746
+
747
+		/* --------------------------------------------------------------
748 748
          * QUERY BUILDER DIRECT ACCESS METHODS
749 749
          * ------------------------------------------------------------ */
750 750
 
751
-        /**
752
-         * A wrapper to $this->_database->orderBy()
753
-         */
754
-        public function order_by($criteria, $order = 'ASC')
755
-        {
756
-            if ( is_array($criteria) )
757
-            {
758
-                foreach ($criteria as $key => $value)
759
-                {
760
-                    $this->_database->orderBy($key, $value);
761
-                }
762
-            }
763
-            else
764
-            {
765
-                $this->_database->orderBy($criteria, $order);
766
-            }
767
-            return $this;
768
-        }
769
-
770
-        /**
771
-         * A wrapper to $this->_database->limit()
772
-         */
773
-        public function limit($offset = 0, $limit = 10)
774
-        {
775
-            $this->_database->limit($offset, $limit);
776
-            return $this;
777
-        }
778
-
779
-        /* --------------------------------------------------------------
751
+		/**
752
+		 * A wrapper to $this->_database->orderBy()
753
+		 */
754
+		public function order_by($criteria, $order = 'ASC')
755
+		{
756
+			if ( is_array($criteria) )
757
+			{
758
+				foreach ($criteria as $key => $value)
759
+				{
760
+					$this->_database->orderBy($key, $value);
761
+				}
762
+			}
763
+			else
764
+			{
765
+				$this->_database->orderBy($criteria, $order);
766
+			}
767
+			return $this;
768
+		}
769
+
770
+		/**
771
+		 * A wrapper to $this->_database->limit()
772
+		 */
773
+		public function limit($offset = 0, $limit = 10)
774
+		{
775
+			$this->_database->limit($offset, $limit);
776
+			return $this;
777
+		}
778
+
779
+		/* --------------------------------------------------------------
780 780
          * INTERNAL METHODS
781 781
          * ------------------------------------------------------------ */
782 782
 
783
-        /**
784
-         * Trigger an event and call its observers. Pass through the event name
785
-         * (which looks for an instance variable $this->event_name), an array of
786
-         * parameters to pass through and an optional 'last in interation' boolean
787
-         */
788
-        protected function trigger($event, $data = FALSE, $last = TRUE)
789
-        {
790
-            if (isset($this->$event) && is_array($this->$event))
791
-            {
792
-                foreach ($this->$event as $method)
793
-                {
794
-                    if (strpos($method, '('))
795
-                    {
796
-                        preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
797
-
798
-                        $method = $matches[1];
799
-                        $this->callback_parameters = explode(',', $matches[3]);
800
-                    }
801
-                    $data = call_user_func_array(array($this, $method), array($data, $last));
802
-                }
803
-            }
804
-            return $data;
805
-        }
806
-
807
-        /**
808
-         * Run validation on the passed data
809
-         */
810
-        protected function validate(array $data)
811
-        {
812
-            if($this->skip_validation)
813
-            {
814
-                return $data;
815
-            }
816
-            if(!empty($this->validate))
817
-            {
818
-                foreach($data as $key => $val)
819
-                {
820
-                    $_POST[$key] = $val;
821
-                }
822
-                Loader::library('FormValidation');
823
-                if(is_array($this->validate))
824
-                {
825
-                    $this->formvalidation->setRules($this->validate);
826
-
827
-                    if ($this->formvalidation->run())
828
-                    {
829
-                        return $data;
830
-                    }
831
-                    else
832
-                    {
833
-                        return FALSE;
834
-                    }
835
-                }
836
-                else {
837
-                    return $data;
838
-                }
839
-            }
840
-            else
841
-            {
842
-                return $data;
843
-            }
844
-        }
845
-
846
-
847
-        /**
848
-         * Set WHERE parameters, cleverly
849
-         */
850
-        protected function _set_where($params)
851
-        {
852
-            if (count($params) == 1 && is_array($params[0]))
853
-            {
854
-                foreach ($params[0] as $field => $filter)
855
-                {
856
-                    if (is_array($filter))
857
-                    {
858
-                        $this->_database->in($field, $filter);
859
-                    }
860
-                    else
861
-                    {
862
-                        if (is_int($field))
863
-                        {
864
-                            $this->_database->where($filter);
865
-                        }
866
-                        else
867
-                        {
868
-                            $this->_database->where($field, $filter);
869
-                        }
870
-                    }
871
-                }
872
-            }
873
-            else if (count($params) == 1)
874
-            {
875
-                $this->_database->where($params[0]);
876
-            }
877
-        	else if(count($params) == 2)
878
-    		{
879
-                if (is_array($params[1]))
880
-                {
881
-                    $this->_database->in($params[0], $params[1]);
882
-                }
883
-                else
884
-                {
885
-                    $this->_database->where($params[0], $params[1]);
886
-                }
887
-    		}
888
-    		else if(count($params) == 3)
889
-    		{
890
-    			$this->_database->where($params[0], $params[1], $params[2]);
891
-    		}
892
-            else
893
-            {
894
-                if (is_array($params[1]))
895
-                {
896
-                    $this->_database->in($params[0], $params[1]);
897
-                }
898
-                else
899
-                {
900
-                    $this->_database->where($params[0], $params[1]);
901
-                }
902
-            }
903
-        }
904
-
905
-        /**
783
+		/**
784
+		 * Trigger an event and call its observers. Pass through the event name
785
+		 * (which looks for an instance variable $this->event_name), an array of
786
+		 * parameters to pass through and an optional 'last in interation' boolean
787
+		 */
788
+		protected function trigger($event, $data = FALSE, $last = TRUE)
789
+		{
790
+			if (isset($this->$event) && is_array($this->$event))
791
+			{
792
+				foreach ($this->$event as $method)
793
+				{
794
+					if (strpos($method, '('))
795
+					{
796
+						preg_match('/([a-zA-Z0-9\_\-]+)(\(([a-zA-Z0-9\_\-\., ]+)\))?/', $method, $matches);
797
+
798
+						$method = $matches[1];
799
+						$this->callback_parameters = explode(',', $matches[3]);
800
+					}
801
+					$data = call_user_func_array(array($this, $method), array($data, $last));
802
+				}
803
+			}
804
+			return $data;
805
+		}
806
+
807
+		/**
808
+		 * Run validation on the passed data
809
+		 */
810
+		protected function validate(array $data)
811
+		{
812
+			if($this->skip_validation)
813
+			{
814
+				return $data;
815
+			}
816
+			if(!empty($this->validate))
817
+			{
818
+				foreach($data as $key => $val)
819
+				{
820
+					$_POST[$key] = $val;
821
+				}
822
+				Loader::library('FormValidation');
823
+				if(is_array($this->validate))
824
+				{
825
+					$this->formvalidation->setRules($this->validate);
826
+
827
+					if ($this->formvalidation->run())
828
+					{
829
+						return $data;
830
+					}
831
+					else
832
+					{
833
+						return FALSE;
834
+					}
835
+				}
836
+				else {
837
+					return $data;
838
+				}
839
+			}
840
+			else
841
+			{
842
+				return $data;
843
+			}
844
+		}
845
+
846
+
847
+		/**
848
+		 * Set WHERE parameters, cleverly
849
+		 */
850
+		protected function _set_where($params)
851
+		{
852
+			if (count($params) == 1 && is_array($params[0]))
853
+			{
854
+				foreach ($params[0] as $field => $filter)
855
+				{
856
+					if (is_array($filter))
857
+					{
858
+						$this->_database->in($field, $filter);
859
+					}
860
+					else
861
+					{
862
+						if (is_int($field))
863
+						{
864
+							$this->_database->where($filter);
865
+						}
866
+						else
867
+						{
868
+							$this->_database->where($field, $filter);
869
+						}
870
+					}
871
+				}
872
+			}
873
+			else if (count($params) == 1)
874
+			{
875
+				$this->_database->where($params[0]);
876
+			}
877
+			else if(count($params) == 2)
878
+			{
879
+				if (is_array($params[1]))
880
+				{
881
+					$this->_database->in($params[0], $params[1]);
882
+				}
883
+				else
884
+				{
885
+					$this->_database->where($params[0], $params[1]);
886
+				}
887
+			}
888
+			else if(count($params) == 3)
889
+			{
890
+				$this->_database->where($params[0], $params[1], $params[2]);
891
+			}
892
+			else
893
+			{
894
+				if (is_array($params[1]))
895
+				{
896
+					$this->_database->in($params[0], $params[1]);
897
+				}
898
+				else
899
+				{
900
+					$this->_database->where($params[0], $params[1]);
901
+				}
902
+			}
903
+		}
904
+
905
+		/**
906 906
             Shortcut to controller
907
-        */
908
-        public function __get($key){
909
-            return get_instance()->{$key};
910
-        }
907
+		 */
908
+		public function __get($key){
909
+			return get_instance()->{$key};
910
+		}
911 911
 
912
-    }
912
+	}
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 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
-    abstract class Model{
36
+    abstract class Model {
37 37
 
38 38
         /* --------------------------------------------------------------
39 39
          * VARIABLES
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
          * Initialise the model, tie into the CodeIgniter superobject and
129 129
          * try our best to guess the table name.
130 130
          */
131
-        public function __construct(){
131
+        public function __construct() {
132 132
             $obj = & get_instance();
133
-    		if(!isset($obj->database)){
133
+    		if (!isset($obj->database)) {
134 134
     			show_error('You must load the database library before to use the model class');
135 135
             }
136 136
             /**
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             array_unshift($this->before_create, 'protect_attributes');
143 143
             array_unshift($this->before_update, 'protect_attributes');
144 144
             $this->_temporary_return_type = $this->return_type;
145
-            if($this->dbCacheTime > 0){
145
+            if ($this->dbCacheTime > 0) {
146 146
                 $this->_database->setCache($this->dbCacheTime);
147 147
             }
148 148
         }
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
 
170 170
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
171 171
             {
172
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
172
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
173 173
             }
174 174
 
175 175
     		$this->_set_where($where);
176 176
 
177 177
             $this->trigger('before_get');
178
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
178
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
179 179
             $row = $this->_database->from($this->_table)->get($type);
180 180
             $this->_temporary_return_type = $this->return_type;
181 181
             $row = $this->trigger('after_get', $row);
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
             $this->trigger('before_get');
212 212
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
213 213
             {
214
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
214
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
215 215
             }
216
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
216
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
217 217
             $result = $this->_database->from($this->_table)->getAll($type);
218 218
             $this->_temporary_return_type = $this->return_type;
219 219
 
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
         {
320 320
             $args = func_get_args();
321 321
             $data = array();
322
-            if(count($args) == 2){
323
-                if(is_array($args[1])){
322
+            if (count($args) == 2) {
323
+                if (is_array($args[1])) {
324 324
                     $data = array_pop($args);
325 325
                 }
326 326
             }
327
-            else if(count($args) == 3){
328
-                if(is_array($args[2])){
327
+            else if (count($args) == 3) {
328
+                if (is_array($args[2])) {
329 329
                     $data = array_pop($args);
330 330
                 }
331 331
             }
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
             $this->_database->where($this->primary_key, $id);
364 364
             if ($this->soft_delete)
365 365
             {
366
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
366
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
367 367
             }
368 368
             else
369 369
             {
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
             $this->_set_where($where);
385 385
             if ($this->soft_delete)
386 386
             {
387
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
387
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
388 388
             }
389 389
             else
390 390
             {
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
             $this->_database->in($this->primary_key, $primary_values);
404 404
             if ($this->soft_delete)
405 405
             {
406
-                $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
406
+                $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE));
407 407
             }
408 408
             else
409 409
             {
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
                 if (is_string($value))
450 450
                 {
451 451
                     $relationship = $value;
452
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
452
+                    $options = array('primary_key' => $value . '_id', 'model' => $value . '_model');
453 453
                 }
454 454
                 else
455 455
                 {
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
                 if (is_string($value))
477 477
                 {
478 478
                     $relationship = $value;
479
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
479
+                    $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model');
480 480
                 }
481 481
                 else
482 482
                 {
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
         public function dropdown()
511 511
         {
512 512
             $args = func_get_args();
513
-            if(count($args) == 2)
513
+            if (count($args) == 2)
514 514
             {
515 515
                 list($key, $value) = $args;
516 516
             }
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
                 $key = $this->primary_key;
520 520
                 $value = $args[0];
521 521
             }
522
-            $this->trigger('before_dropdown', array( $key, $value ));
522
+            $this->trigger('before_dropdown', array($key, $value));
523 523
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
524 524
             {
525 525
                 $this->_database->where($this->soft_delete_key, FALSE);
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
         {
544 544
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
545 545
             {
546
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
546
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
547 547
             }
548 548
             $where = func_get_args();
549 549
             $this->_set_where($where);
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
         {
559 559
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
560 560
             {
561
-                $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
561
+                $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
562 562
             }
563 563
             $this->_database->from($this->_table)->getAll();
564 564
             return $this->_database->numRows();
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
 		/**
568 568
 		* Enabled cache temporary
569 569
 		*/
570
-		public function cached($ttl = 0){
571
-		  if($ttl > 0){
570
+		public function cached($ttl = 0) {
571
+		  if ($ttl > 0) {
572 572
 			$this->_database = $this->_database->cached($ttl);
573 573
 		  }
574 574
 		  return $this;
@@ -722,13 +722,13 @@  discard block
 block discarded – undo
722 722
             {
723 723
                 if (is_object($row))
724 724
                 {
725
-					if(isset($row->$attr)){
725
+					if (isset($row->$attr)) {
726 726
 						unset($row->$attr);
727 727
 					}
728 728
                 }
729 729
                 else
730 730
                 {
731
-					if(isset($row[$attr])){
731
+					if (isset($row[$attr])) {
732 732
 						unset($row[$attr]);
733 733
 					}
734 734
                 }
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
          * Return the database instance
741 741
          * @return Database the database instance
742 742
          */
743
-        public function getDatabaseInstance(){
743
+        public function getDatabaseInstance() {
744 744
             return $this->_database;
745 745
         }
746 746
 
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
          */
754 754
         public function order_by($criteria, $order = 'ASC')
755 755
         {
756
-            if ( is_array($criteria) )
756
+            if (is_array($criteria))
757 757
             {
758 758
                 foreach ($criteria as $key => $value)
759 759
                 {
@@ -809,18 +809,18 @@  discard block
 block discarded – undo
809 809
          */
810 810
         protected function validate(array $data)
811 811
         {
812
-            if($this->skip_validation)
812
+            if ($this->skip_validation)
813 813
             {
814 814
                 return $data;
815 815
             }
816
-            if(!empty($this->validate))
816
+            if (!empty($this->validate))
817 817
             {
818
-                foreach($data as $key => $val)
818
+                foreach ($data as $key => $val)
819 819
                 {
820 820
                     $_POST[$key] = $val;
821 821
                 }
822 822
                 Loader::library('FormValidation');
823
-                if(is_array($this->validate))
823
+                if (is_array($this->validate))
824 824
                 {
825 825
                     $this->formvalidation->setRules($this->validate);
826 826
 
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
             {
875 875
                 $this->_database->where($params[0]);
876 876
             }
877
-        	else if(count($params) == 2)
877
+        	else if (count($params) == 2)
878 878
     		{
879 879
                 if (is_array($params[1]))
880 880
                 {
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
                     $this->_database->where($params[0], $params[1]);
886 886
                 }
887 887
     		}
888
-    		else if(count($params) == 3)
888
+    		else if (count($params) == 3)
889 889
     		{
890 890
     			$this->_database->where($params[0], $params[1], $params[2]);
891 891
     		}
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
         /**
906 906
             Shortcut to controller
907 907
         */
908
-        public function __get($key){
908
+        public function __get($key) {
909 909
             return get_instance()->{$key};
910 910
         }
911 911
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -58 removed lines patch added patch discarded remove patch
@@ -243,8 +243,7 @@  discard block
 block discarded – undo
243 243
                 $insert_id = $this->_database->insertId();
244 244
                 $this->trigger('after_create', $insert_id);
245 245
                 return $insert_id;
246
-            }
247
-            else
246
+            } else
248 247
             {
249 248
                 return FALSE;
250 249
             }
@@ -281,8 +280,7 @@  discard block
 block discarded – undo
281 280
                                    ->update($data, $escape);
282 281
                 $this->trigger('after_update', array($data, $result));
283 282
                 return $result;
284
-            }
285
-            else
283
+            } else
286 284
             {
287 285
                 return FALSE;
288 286
             }
@@ -305,8 +303,7 @@  discard block
 block discarded – undo
305 303
                                    ->update($data, $escape);
306 304
                 $this->trigger('after_update', array($data, $result));
307 305
                 return $result;
308
-            }
309
-            else
306
+            } else
310 307
             {
311 308
                 return FALSE;
312 309
             }
@@ -323,8 +320,7 @@  discard block
 block discarded – undo
323 320
                 if(is_array($args[1])){
324 321
                     $data = array_pop($args);
325 322
                 }
326
-            }
327
-            else if(count($args) == 3){
323
+            } else if(count($args) == 3){
328 324
                 if(is_array($args[2])){
329 325
                     $data = array_pop($args);
330 326
                 }
@@ -336,8 +332,7 @@  discard block
 block discarded – undo
336 332
                 $result = $this->_database->from($this->_table)->update($data);
337 333
                 $this->trigger('after_update', array($data, $result));
338 334
                 return $result;
339
-            }
340
-            else
335
+            } else
341 336
             {
342 337
                 return FALSE;
343 338
             }
@@ -364,8 +359,7 @@  discard block
 block discarded – undo
364 359
             if ($this->soft_delete)
365 360
             {
366 361
                 $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
367
-            }
368
-            else
362
+            } else
369 363
             {
370 364
                 $result = $this->_database->from($this->_table)->delete();
371 365
             }
@@ -385,8 +379,7 @@  discard block
 block discarded – undo
385 379
             if ($this->soft_delete)
386 380
             {
387 381
                 $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
388
-            }
389
-            else
382
+            } else
390 383
             {
391 384
                 $result = $this->_database->from($this->_table)->delete();
392 385
             }
@@ -404,8 +397,7 @@  discard block
 block discarded – undo
404 397
             if ($this->soft_delete)
405 398
             {
406 399
                 $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE ));
407
-            }
408
-            else
400
+            } else
409 401
             {
410 402
                 $result = $this->_database->from($this->_table)->delete();
411 403
             }
@@ -450,8 +442,7 @@  discard block
 block discarded – undo
450 442
                 {
451 443
                     $relationship = $value;
452 444
                     $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
453
-                }
454
-                else
445
+                } else
455 446
                 {
456 447
                     $relationship = $key;
457 448
                     $options = $value;
@@ -463,8 +454,7 @@  discard block
 block discarded – undo
463 454
                     if (is_object($row))
464 455
                     {
465 456
                         $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
466
-                    }
467
-                    else
457
+                    } else
468 458
                     {
469 459
                         $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
470 460
                     }
@@ -477,8 +467,7 @@  discard block
 block discarded – undo
477 467
                 {
478 468
                     $relationship = $value;
479 469
                     $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
480
-                }
481
-                else
470
+                } else
482 471
                 {
483 472
                     $relationship = $key;
484 473
                     $options = $value;
@@ -490,8 +479,7 @@  discard block
 block discarded – undo
490 479
                     if (is_object($row))
491 480
                     {
492 481
                         $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
493
-                    }
494
-                    else
482
+                    } else
495 483
                     {
496 484
                         $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
497 485
                     }
@@ -513,8 +501,7 @@  discard block
 block discarded – undo
513 501
             if(count($args) == 2)
514 502
             {
515 503
                 list($key, $value) = $args;
516
-            }
517
-            else
504
+            } else
518 505
             {
519 506
                 $key = $this->primary_key;
520 507
                 $value = $args[0];
@@ -662,8 +649,7 @@  discard block
 block discarded – undo
662 649
             if (is_object($row))
663 650
             {
664 651
                 $row->created_at = date('Y-m-d H:i:s');
665
-            }
666
-            else
652
+            } else
667 653
             {
668 654
                 $row['created_at'] = date('Y-m-d H:i:s');
669 655
             }
@@ -676,8 +662,7 @@  discard block
 block discarded – undo
676 662
             if (is_object($row))
677 663
             {
678 664
                 $row->updated_at = date('Y-m-d H:i:s');
679
-            }
680
-            else
665
+            } else
681 666
             {
682 667
                 $row['updated_at'] = date('Y-m-d H:i:s');
683 668
             }
@@ -704,8 +689,7 @@  discard block
 block discarded – undo
704 689
                 if (is_array($row))
705 690
                 {
706 691
                     $row[$column] = unserialize($row[$column]);
707
-                }
708
-                else
692
+                } else
709 693
                 {
710 694
                     $row->$column = unserialize($row->$column);
711 695
                 }
@@ -725,8 +709,7 @@  discard block
 block discarded – undo
725 709
 					if(isset($row->$attr)){
726 710
 						unset($row->$attr);
727 711
 					}
728
-                }
729
-                else
712
+                } else
730 713
                 {
731 714
 					if(isset($row[$attr])){
732 715
 						unset($row[$attr]);
@@ -759,8 +742,7 @@  discard block
 block discarded – undo
759 742
                 {
760 743
                     $this->_database->orderBy($key, $value);
761 744
                 }
762
-            }
763
-            else
745
+            } else
764 746
             {
765 747
                 $this->_database->orderBy($criteria, $order);
766 748
             }
@@ -827,17 +809,14 @@  discard block
 block discarded – undo
827 809
                     if ($this->formvalidation->run())
828 810
                     {
829 811
                         return $data;
830
-                    }
831
-                    else
812
+                    } else
832 813
                     {
833 814
                         return FALSE;
834 815
                     }
835
-                }
836
-                else {
816
+                } else {
837 817
                     return $data;
838 818
                 }
839
-            }
840
-            else
819
+            } else
841 820
             {
842 821
                 return $data;
843 822
             }
@@ -856,46 +835,38 @@  discard block
 block discarded – undo
856 835
                     if (is_array($filter))
857 836
                     {
858 837
                         $this->_database->in($field, $filter);
859
-                    }
860
-                    else
838
+                    } else
861 839
                     {
862 840
                         if (is_int($field))
863 841
                         {
864 842
                             $this->_database->where($filter);
865
-                        }
866
-                        else
843
+                        } else
867 844
                         {
868 845
                             $this->_database->where($field, $filter);
869 846
                         }
870 847
                     }
871 848
                 }
872
-            }
873
-            else if (count($params) == 1)
849
+            } else if (count($params) == 1)
874 850
             {
875 851
                 $this->_database->where($params[0]);
876
-            }
877
-        	else if(count($params) == 2)
852
+            } else if(count($params) == 2)
878 853
     		{
879 854
                 if (is_array($params[1]))
880 855
                 {
881 856
                     $this->_database->in($params[0], $params[1]);
882
-                }
883
-                else
857
+                } else
884 858
                 {
885 859
                     $this->_database->where($params[0], $params[1]);
886 860
                 }
887
-    		}
888
-    		else if(count($params) == 3)
861
+    		} else if(count($params) == 3)
889 862
     		{
890 863
     			$this->_database->where($params[0], $params[1], $params[2]);
891
-    		}
892
-            else
864
+    		} else
893 865
             {
894 866
                 if (is_array($params[1]))
895 867
                 {
896 868
                     $this->_database->in($params[0], $params[1]);
897
-                }
898
-                else
869
+                } else
899 870
                 {
900 871
                     $this->_database->where($params[0], $params[1]);
901 872
                 }
Please login to merge, or discard this patch.
core/classes/model/DBSessionHandlerModel.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 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
 	 * DB session handler class
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@
 block discarded – undo
45 45
 		 */
46 46
 		protected $sessionTableColumns = array();
47 47
 
48
-		public function __construct(){
48
+		public function __construct() {
49 49
 			parent::__construct();
50 50
 		}
51 51
 
52
-		public function getSessionTableColumns(){
52
+		public function getSessionTableColumns() {
53 53
 			return $this->sessionTableColumns;
54 54
 		}
55 55
 
Please login to merge, or discard this patch.
core/classes/Url.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 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
 	class Url{
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Url{
28
+	class Url {
29 29
 
30 30
 		/**
31 31
 		 * Return the link using base_url config without front controller "index.php"
32 32
 		 * @param  string $path the link path or full URL
33 33
 		 * @return string the full link URL
34 34
 		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
35
+		public static function base_url($path = '') {
36
+			if (is_url($path)) {
37 37
 				return $path;
38 38
 			}
39 39
 			return get_config('base_url') . $path;
@@ -44,26 +44,26 @@  discard block
 block discarded – undo
44 44
 		 * @param  string $path the link path or full URL
45 45
 		 * @return string the full link URL
46 46
 		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
47
+		public static function site_url($path = '') {
48
+			if (is_url($path)) {
49 49
 				return $path;
50 50
 			}
51 51
 			$path = rtrim($path, '/');
52 52
 			$baseUrl = get_config('base_url');
53 53
 			$frontController = get_config('front_controller');
54 54
 			$url = $baseUrl;
55
-			if($frontController){
55
+			if ($frontController) {
56 56
 				$url .= $frontController . '/';
57 57
 			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
58
+			if (($suffix = get_config('url_suffix')) && $path) {
59
+				if (strpos($path, '?') !== false) {
60 60
 					$query = explode('?', $path);
61 61
 					$query[0] = str_ireplace($suffix, '', $query[0]);
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65 65
 				}
66
-				else{
66
+				else {
67 67
 					$path .= $suffix;
68 68
 				}
69 69
 			}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 		 * Return the current site URL
75 75
 		 * @return string
76 76
 		 */
77
-		public static function current(){
77
+		public static function current() {
78 78
 			$current = '/';
79 79
 			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
80
+			if ($requestUri) {
81 81
 				$current = $requestUri;
82 82
 			}
83 83
 			return static::domain() . $current;
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91 91
 		 * @return string the friendly generated text
92 92
 		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
93
+		public static function title($str = null, $separator = '-', $lowercase = true) {
94 94
 			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
95
+			$from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ');
96
+			$to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n');
97 97
 			$str = str_replace($from, $to, $str);
98 98
 			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99 99
 			$str = str_replace('--', $separator, $str);
100 100
 			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
101
+			if (substr($str, -1) == $separator) {
102 102
 				$str = substr($str, 0, -1);
103 103
 			}
104
-			if($lowercase){
104
+			if ($lowercase) {
105 105
 				$str = strtolower($str);
106 106
 			}
107 107
 			return $str;
@@ -111,36 +111,36 @@  discard block
 block discarded – undo
111 111
 		 * Get the current application domain with protocol
112 112
 		 * @return string the domain name
113 113
 		 */
114
-		public static function domain(){
114
+		public static function domain() {
115 115
 			$obj = & get_instance();
116 116
 			$domain = 'localhost';
117 117
 			$port = $obj->request->server('SERVER_PORT');
118 118
 			$protocol = is_https() ? 'https' : 'http';
119 119
 			
120
-			if($obj->request->server('HTTP_HOST')){
120
+			if ($obj->request->server('HTTP_HOST')) {
121 121
 				$domain = $obj->request->server('HTTP_HOST');
122 122
 			}
123
-			else if($obj->request->server('SERVER_NAME')){
123
+			else if ($obj->request->server('SERVER_NAME')) {
124 124
 				$domain = $obj->request->server('SERVER_NAME');
125 125
 			}
126
-			else if($obj->request->server('SERVER_ADDR')){
126
+			else if ($obj->request->server('SERVER_ADDR')) {
127 127
 				$domain = $obj->request->server('SERVER_ADDR');
128 128
 			}
129
-			if($port && (is_https() && $port != 443 || !is_https() && $port != 80)){
129
+			if ($port && (is_https() && $port != 443 || !is_https() && $port != 80)) {
130 130
 				//some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end
131 131
 				//of the domain like https://my.domain.com:787
132
-				if(is_https() && $port != 80){
133
-					$domain .= ':'.$port;
132
+				if (is_https() && $port != 80) {
133
+					$domain .= ':' . $port;
134 134
 				}
135 135
 			}
136
-			return $protocol.'://'.$domain;
136
+			return $protocol . '://' . $domain;
137 137
 		}
138 138
 
139 139
 		/**
140 140
 		 * Get the current request query string
141 141
 		 * @return string
142 142
 		 */
143
-		public static function queryString(){
143
+		public static function queryString() {
144 144
 			return get_instance()->request->server('QUERY_STRING');
145 145
 		}
146 146
 	}
147 147
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@  discard block
 block discarded – undo
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65
-				}
66
-				else{
65
+				} else{
67 66
 					$path .= $suffix;
68 67
 				}
69 68
 			}
@@ -119,11 +118,9 @@  discard block
 block discarded – undo
119 118
 			
120 119
 			if($obj->request->server('HTTP_HOST')){
121 120
 				$domain = $obj->request->server('HTTP_HOST');
122
-			}
123
-			else if($obj->request->server('SERVER_NAME')){
121
+			} else if($obj->request->server('SERVER_NAME')){
124 122
 				$domain = $obj->request->server('SERVER_NAME');
125
-			}
126
-			else if($obj->request->server('SERVER_ADDR')){
123
+			} else if($obj->request->server('SERVER_ADDR')){
127 124
 				$domain = $obj->request->server('SERVER_ADDR');
128 125
 			}
129 126
 			if($port && (is_https() && $port != 443 || !is_https() && $port != 80)){
Please login to merge, or discard this patch.
core/classes/Session.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 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
 	class Session{
27 27
 		
28 28
 		/**
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Session{
26
+	class Session {
27 27
 		
28 28
 		/**
29 29
 		 * The session flash key to use
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 		 * Get the logger singleton instance
42 42
 		 * @return Log the logger instance
43 43
 		 */
44
-		private static function getLogger(){
45
-			if(static::$logger == null){
46
-				static::$logger[0] =& class_loader('Log', 'classes');
44
+		private static function getLogger() {
45
+			if (static::$logger == null) {
46
+				static::$logger[0] = & class_loader('Log', 'classes');
47 47
 				static::$logger[0]->setLogger('Library::Session');
48 48
 			}
49 49
 			return static::$logger[0];
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
 		 * @param  mixed $default the default value to use if can not find the session item in the list
56 56
 		 * @return mixed          the session value if exist or the default value
57 57
 		 */
58
-		public static function get($item, $default = null){
58
+		public static function get($item, $default = null) {
59 59
 			$logger = static::getLogger();
60
-			$logger->debug('Getting session data for item [' .$item. '] ...');
61
-			if(array_key_exists($item, $_SESSION)){
60
+			$logger->debug('Getting session data for item [' . $item . '] ...');
61
+			if (array_key_exists($item, $_SESSION)) {
62 62
 				$logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
63 63
 				return $_SESSION[$item];
64 64
 			}
65
-			$logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']');
65
+			$logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']');
66 66
 			return $default;
67 67
 		}
68 68
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		 * @param string $item  the session item name to set
72 72
 		 * @param mixed $value the session item value
73 73
 		 */
74
-		public static function set($item, $value){
74
+		public static function set($item, $value) {
75 75
 			$logger = static::getLogger();
76 76
 			$logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
77 77
 			$_SESSION[$item] = $value;
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the session flash item in the list
84 84
 		 * @return mixed          the session flash value if exist or the default value
85 85
 		 */
86
-		public static function getFlash($item, $default = null){
86
+		public static function getFlash($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
88
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
89 89
 			$return = array_key_exists($key, $_SESSION) ?
90 90
 			($_SESSION[$key]) : $default;
91
-			if(array_key_exists($key, $_SESSION)){
91
+			if (array_key_exists($key, $_SESSION)) {
92 92
 				unset($_SESSION[$key]);
93 93
 			}
94
-			else{
95
-				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
94
+			else {
95
+				$logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']');
96 96
 			}
97 97
 			return $return;
98 98
 		}
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 		 * @param  string  $item the session flash item name
103 103
 		 * @return boolean 
104 104
 		 */
105
-		public static function hasFlash($item){
106
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
105
+		public static function hasFlash($item) {
106
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
107 107
 			return array_key_exists($key, $_SESSION);
108 108
 		}
109 109
 
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 		 * @param string $item  the session flash item name to set
113 113
 		 * @param mixed $value the session flash item value
114 114
 		 */
115
-		public static function setFlash($item, $value){
116
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
115
+		public static function setFlash($item, $value) {
116
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
117 117
 			$_SESSION[$key] = $value;
118 118
 		}
119 119
 
@@ -121,14 +121,14 @@  discard block
 block discarded – undo
121 121
 		 * Clear the session item in the list
122 122
 		 * @param  string $item the session item name to be deleted
123 123
 		 */
124
-		public static function clear($item){
124
+		public static function clear($item) {
125 125
 			$logger = static::getLogger();
126
-			if(array_key_exists($item, $_SESSION)){
127
-				$logger->info('Deleting of session for item ['.$item.' ]');
126
+			if (array_key_exists($item, $_SESSION)) {
127
+				$logger->info('Deleting of session for item [' . $item . ' ]');
128 128
 				unset($_SESSION[$item]);
129 129
 			}
130
-			else{
131
-				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
130
+			else {
131
+				$logger->warning('Session item [' . $item . '] to be deleted does not exists');
132 132
 			}
133 133
 		}
134 134
 		
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 		 * Clear the session flash item in the list
137 137
 		 * @param  string $item the session flash item name to be deleted
138 138
 		 */
139
-		public static function clearFlash($item){
139
+		public static function clearFlash($item) {
140 140
 			$logger = static::getLogger();
141
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
142
-			if(array_key_exists($key, $_SESSION)){
143
-				$logger->info('Delete session flash for item ['.$item.']');
141
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
142
+			if (array_key_exists($key, $_SESSION)) {
143
+				$logger->info('Delete session flash for item [' . $item . ']');
144 144
 				unset($_SESSION[$item]);
145 145
 			}
146
-			else{
147
-				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
146
+			else {
147
+				$logger->warning('Dession flash item [' . $item . '] to be deleted does not exists');
148 148
 			}
149 149
 		}
150 150
 
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 		 * @param  string  $item the session item name
154 154
 		 * @return boolean 
155 155
 		 */
156
-		public static function exists($item){
156
+		public static function exists($item) {
157 157
 			return array_key_exists($item, $_SESSION);
158 158
 		}
159 159
 
160 160
 		/**
161 161
 		 * Destroy all session data values
162 162
 		 */
163
-		public static function clearAll(){
163
+		public static function clearAll() {
164 164
 			session_unset();
165 165
 			session_destroy();
166 166
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 			($_SESSION[$key]) : $default;
91 91
 			if(array_key_exists($key, $_SESSION)){
92 92
 				unset($_SESSION[$key]);
93
-			}
94
-			else{
93
+			} else{
95 94
 				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
96 95
 			}
97 96
 			return $return;
@@ -126,8 +125,7 @@  discard block
 block discarded – undo
126 125
 			if(array_key_exists($item, $_SESSION)){
127 126
 				$logger->info('Deleting of session for item ['.$item.' ]');
128 127
 				unset($_SESSION[$item]);
129
-			}
130
-			else{
128
+			} else{
131 129
 				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
132 130
 			}
133 131
 		}
@@ -142,8 +140,7 @@  discard block
 block discarded – undo
142 140
 			if(array_key_exists($key, $_SESSION)){
143 141
 				$logger->info('Delete session flash for item ['.$item.']');
144 142
 				unset($_SESSION[$item]);
145
-			}
146
-			else{
143
+			} else{
147 144
 				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
148 145
 			}
149 146
 		}
Please login to merge, or discard this patch.
core/classes/Router.php 3 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,23 +22,23 @@  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 Router {
28 28
 		
29 29
 		/**
30
-		* @var array $pattern: The list of URIs to validate against
31
-		*/
30
+		 * @var array $pattern: The list of URIs to validate against
31
+		 */
32 32
 		private $pattern = array();
33 33
 
34 34
 		/**
35
-		* @var array $callback: The list of callback to call
36
-		*/
35
+		 * @var array $callback: The list of callback to call
36
+		 */
37 37
 		private $callback = array();
38 38
 
39 39
 		/**
40
-		* @var string $uriTrim: The char to remove from the URIs
41
-		*/
40
+		 * @var string $uriTrim: The char to remove from the URIs
41
+		 */
42 42
 		protected $uriTrim = '/\^$';
43 43
 
44 44
 		/**
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 		 */
95 95
 		public function __construct(){
96 96
 			$this->logger =& class_loader('Log', 'classes');
97
-	        $this->logger->setLogger('Library::Router');
98
-	        $routesPath = CONFIG_PATH . 'routes.php';
99
-	        $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...');
97
+			$this->logger->setLogger('Library::Router');
98
+			$routesPath = CONFIG_PATH . 'routes.php';
99
+			$this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...');
100 100
 			if(file_exists($routesPath)){
101 101
 				 $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it');
102 102
 				require_once $routesPath;
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 		}
148 148
 
149 149
 		/**
150
-		* Add the URI and callback to the list of URIs to validate
151
-		*
152
-		* @param string $uri the request URI
153
-		* @param object $callback the callback function
154
-		*/
150
+		 * Add the URI and callback to the list of URIs to validate
151
+		 *
152
+		 * @param string $uri the request URI
153
+		 * @param object $callback the callback function
154
+		 */
155 155
 		public function add($uri, $callback) {
156 156
 			$uri = trim($uri, $this->uriTrim);
157 157
 			if(in_array($uri, $this->pattern)){
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -92,39 +92,39 @@  discard block
 block discarded – undo
92 92
 		/**
93 93
 		 * Construct the new Router instance
94 94
 		 */
95
-		public function __construct(){
96
-			$this->logger =& class_loader('Log', 'classes');
95
+		public function __construct() {
96
+			$this->logger = & class_loader('Log', 'classes');
97 97
 	        $this->logger->setLogger('Library::Router');
98 98
 	        $routesPath = CONFIG_PATH . 'routes.php';
99 99
 	        $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...');
100
-			if(file_exists($routesPath)){
101
-				 $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it');
100
+			if (file_exists($routesPath)) {
101
+				 $this->logger->info('Found routes configuration file --> ' . $routesPath . ' now load it');
102 102
 				require_once $routesPath;
103
-				if(! empty($route) && is_array($route)){
103
+				if (!empty($route) && is_array($route)) {
104 104
 					$this->routes = $route;
105 105
 					unset($route);
106 106
 				}
107
-				else{
107
+				else {
108 108
 					show_error('No routing configuration found in [' . $routesPath . ']');
109 109
 				}
110 110
 			}
111
-			else{
111
+			else {
112 112
 				show_error('Unable to find the routes configuration file [' . $routesPath . ']');
113 113
 			}
114 114
 			
115 115
 			//loading routes for module
116 116
 			$this->logger->debug('Loading of modules routes ... ');
117 117
 			$modulesRoutes = Module::getModulesRoutes();
118
-			if($modulesRoutes && is_array($modulesRoutes)){
118
+			if ($modulesRoutes && is_array($modulesRoutes)) {
119 119
 				$this->routes = array_merge($this->routes, $modulesRoutes);
120 120
 				$this->logger->info('Routes for all modules loaded successfully');
121 121
 			}
122
-			else{
122
+			else {
123 123
 				$this->logger->info('No routes found for all modules skipping.');
124 124
 			}
125 125
 			$this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes));
126 126
 
127
-			foreach($this->routes as $pattern => $callback){
127
+			foreach ($this->routes as $pattern => $callback) {
128 128
 				$this->add($pattern, $callback);
129 129
 			}
130 130
 			
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
 			$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
133 133
 			$this->logger->debug('Check if URL suffix is enabled in the configuration');
134 134
 			//remove url suffix from the request URI
135
-			if($suffix = get_config('url_suffix')){
136
-				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
135
+			if ($suffix = get_config('url_suffix')) {
136
+				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
137 137
 				$uri = str_ireplace($suffix, '', $uri);
138 138
 			}
139
-			else{
139
+			else {
140 140
 				$this->logger->info('URL suffix is not enabled in the configuration');
141 141
 			}
142
-			if(strpos($uri, '?') !== false){
142
+			if (strpos($uri, '?') !== false) {
143 143
 				$uri = substr($uri, 0, strpos($uri, '?'));
144 144
 			}
145 145
 			$uri = trim($uri, $this->uriTrim);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 		*/
155 155
 		public function add($uri, $callback) {
156 156
 			$uri = trim($uri, $this->uriTrim);
157
-			if(in_array($uri, $this->pattern)){
157
+			if (in_array($uri, $this->pattern)) {
158 158
 				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
159 159
 			}
160 160
 			$this->pattern[] = $uri;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		 * Get the module name
166 166
 		 * @return string
167 167
 		 */
168
-		public function getModule(){
168
+		public function getModule() {
169 169
 			return $this->module;
170 170
 		}
171 171
 		
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		 * Get the controller name
174 174
 		 * @return string
175 175
 		 */
176
-		public function getController(){
176
+		public function getController() {
177 177
 			return $this->controller;
178 178
 		}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		 * Get the controller file path
182 182
 		 * @return string
183 183
 		 */
184
-		public function getControllerPath(){
184
+		public function getControllerPath() {
185 185
 			return $this->controllerPath;
186 186
 		}
187 187
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		 * Get the controller method
190 190
 		 * @return string
191 191
 		 */
192
-		public function getMethod(){
192
+		public function getMethod() {
193 193
 			return $this->method;
194 194
 		}
195 195
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 		 * Get the request arguments
198 198
 		 * @return array
199 199
 		 */
200
-		public function getArgs(){
200
+		public function getArgs() {
201 201
 			return $this->args;
202 202
 		}
203 203
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 		 * Get the URL segments array
206 206
 		 * @return array
207 207
 		 */
208
-		public function getSegments(){
208
+		public function getSegments() {
209 209
 			return $this->segments;
210 210
 		}
211 211
 
@@ -214,27 +214,27 @@  discard block
 block discarded – undo
214 214
 		 * otherwise send 404 error.
215 215
 		 */
216 216
 		public function run() {
217
-			$benchmark =& class_loader('Benchmark');
217
+			$benchmark = & class_loader('Benchmark');
218 218
 			$benchmark->mark('ROUTING_PROCESS_START');
219 219
 			$this->logger->debug('Routing process start ...');
220 220
 			$segment = $this->segments;
221 221
 			$baseUrl = get_config('base_url');
222 222
 			//check if the app is not in DOCUMENT_ROOT
223
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){
223
+			if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) {
224 224
 				array_shift($segment);
225 225
 				$this->segments = $segment;
226 226
 			}
227 227
 			$this->logger->debug('Check if the request URI contains the front controller');
228
-			if(isset($segment[0]) && $segment[0] == SELF){
228
+			if (isset($segment[0]) && $segment[0] == SELF) {
229 229
 				$this->logger->info('The request URI contains the front controller');
230 230
 				array_shift($segment);
231 231
 				$this->segments = $segment;
232 232
 			}
233
-			else{
233
+			else {
234 234
 				$this->logger->info('The request URI does not contain the front controller');
235 235
 			}
236 236
 			$uri = implode('/', $segment);
237
-			$this->logger->info('The final Request URI is [' . $uri . ']' );
237
+			$this->logger->info('The final Request URI is [' . $uri . ']');
238 238
 			//generic routes
239 239
 			$pattern = array(':num', ':alpha', ':alnum', ':any');
240 240
 			$replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*');
@@ -248,20 +248,20 @@  discard block
 block discarded – undo
248 248
 					array_shift($args);
249 249
 					//check if this contains an module
250 250
 					$moduleControllerMethod = explode('#', $this->callback[$index]);
251
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
252
-						$this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']');
251
+					if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
252
+						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
253 253
 						$this->module = $moduleControllerMethod[0];
254 254
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
255 255
 					}
256
-					else{
256
+					else {
257 257
 						$this->logger->info('The current request does not use the module');
258 258
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
259 259
 					}
260
-					if(is_array($moduleControllerMethod)){
261
-						if(isset($moduleControllerMethod[0])){
260
+					if (is_array($moduleControllerMethod)) {
261
+						if (isset($moduleControllerMethod[0])) {
262 262
 							$this->controller = $moduleControllerMethod[0];	
263 263
 						}
264
-						if(isset($moduleControllerMethod[1])){
264
+						if (isset($moduleControllerMethod[1])) {
265 265
 							$this->method = $moduleControllerMethod[1];
266 266
 						}
267 267
 						$this->args = $args;
@@ -271,73 +271,73 @@  discard block
 block discarded – undo
271 271
 				}
272 272
 			}
273 273
 			//first if the controller is not set and the module is set use the module name as the controller
274
-			if(! $this->getController() && $this->getModule()){
274
+			if (!$this->getController() && $this->getModule()) {
275 275
 				$this->logger->info('After loop in predefined routes configuration, the module name is set but the controller is not set, so we will use module as the controller');
276 276
 				$this->controller = $this->getModule();
277 277
 			}
278 278
 			//if can not determine the module/controller/method via the defined routes configuration we will use
279 279
 			//the URL like http://domain.com/module/controller/method/arg1/arg2
280
-			if(! $this->getController()){
280
+			if (!$this->getController()) {
281 281
 				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
282 282
 				$nbSegment = count($segment);
283 283
 				//if segment is null so means no need to perform
284
-				if($nbSegment > 0){
284
+				if ($nbSegment > 0) {
285 285
 					//get the module list
286 286
 					$modules = Module::getModuleList();
287 287
 					//first check if no module
288
-					if(! $modules){
288
+					if (!$modules) {
289 289
 						$this->logger->info('No module was loaded will skip the module checking');
290 290
 						//the application don't use module
291 291
 						//controller
292
-						if(isset($segment[0])){
292
+						if (isset($segment[0])) {
293 293
 							$this->controller = $segment[0];
294 294
 							array_shift($segment);
295 295
 						}
296 296
 						//method
297
-						if(isset($segment[0])){
297
+						if (isset($segment[0])) {
298 298
 							$this->method = $segment[0];
299 299
 							array_shift($segment);
300 300
 						}
301 301
 						//args
302 302
 						$this->args = $segment;
303 303
 					}
304
-					else{
304
+					else {
305 305
 						$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
306
-						if(in_array($segment[0], $modules)){
306
+						if (in_array($segment[0], $modules)) {
307 307
 							$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
308 308
 							$this->module = $segment[0];
309 309
 							array_shift($segment);
310 310
 							//check if the second arg is the controller from module
311
-							if(isset($segment[0])){
311
+							if (isset($segment[0])) {
312 312
 								$this->controller = $segment[0];
313 313
 								//check if the request use the same module name and controller
314 314
 								$path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
315
-								if(! $path){
315
+								if (!$path) {
316 316
 									$this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller');
317 317
 									$this->controller = $this->getModule();
318 318
 								}
319
-								else{
319
+								else {
320 320
 									$this->controllerPath = $path;
321 321
 									array_shift($segment);
322 322
 								}
323 323
 							}
324 324
 							//check for method
325
-							if(isset($segment[0])){
325
+							if (isset($segment[0])) {
326 326
 								$this->method = $segment[0];
327 327
 								array_shift($segment);
328 328
 							}
329 329
 							//the remaining is for args
330 330
 							$this->args = $segment;
331 331
 						}
332
-						else{
332
+						else {
333 333
 							$this->logger->info('The current request information is not found in the module list');
334 334
 							//controller
335
-							if(isset($segment[0])){
335
+							if (isset($segment[0])) {
336 336
 								$this->controller = $segment[0];
337 337
 								array_shift($segment);
338 338
 							}
339 339
 							//method
340
-							if(isset($segment[0])){
340
+							if (isset($segment[0])) {
341 341
 								$this->method = $segment[0];
342 342
 								array_shift($segment);
343 343
 							}
@@ -347,18 +347,18 @@  discard block
 block discarded – undo
347 347
 					}
348 348
 				}
349 349
 			}
350
-			if(! $this->getController() && $this->getModule()){
350
+			if (!$this->getController() && $this->getModule()) {
351 351
 				$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
352 352
 				$this->controller = $this->getModule();
353 353
 			}
354 354
 			//did we set the controller, so set the controller path
355
-			if($this->getController() && ! $this->getControllerPath()){
355
+			if ($this->getController() && !$this->getControllerPath()) {
356 356
 				$this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']');
357 357
 				//if it is the module controller
358
-				if($this->getModule()){
358
+				if ($this->getModule()) {
359 359
 					$this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
360 360
 				}
361
-				else{
361
+				else {
362 362
 					$this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php';
363 363
 				}
364 364
 			}
@@ -368,20 +368,20 @@  discard block
 block discarded – undo
368 368
 			$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
369 369
 			$benchmark->mark('ROUTING_PROCESS_END');
370 370
 			$e404 = false;
371
-			if(file_exists($classFilePath)){
371
+			if (file_exists($classFilePath)) {
372 372
 				require_once $classFilePath;
373
-				if(! class_exists($controller, false)){
373
+				if (!class_exists($controller, false)) {
374 374
 					$e404 = true;
375
-					$this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
375
+					$this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
376 376
 				}
377
-				else{
377
+				else {
378 378
 					$controllerInstance = new $controller();
379 379
 					$controllerMethod = $this->getMethod();
380
-					if(! method_exists($controllerInstance, $controllerMethod)){
380
+					if (!method_exists($controllerInstance, $controllerMethod)) {
381 381
 						$e404 = true;
382 382
 						$this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
383 383
 					}
384
-					else{
384
+					else {
385 385
 						$this->logger->info('Routing data is set correctly now GO!');
386 386
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs());
387 387
 						$obj = & get_instance();
@@ -391,12 +391,12 @@  discard block
 block discarded – undo
391 391
 					}
392 392
 				}
393 393
 			}
394
-			else{
394
+			else {
395 395
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
396 396
 				$e404 = true;
397 397
 			}
398
-			if($e404){
399
-				$response =& class_loader('Response', 'classes');
398
+			if ($e404) {
399
+				$response = & class_loader('Response', 'classes');
400 400
 				$response->send404();
401 401
 			}
402 402
 		}
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -103,12 +103,10 @@  discard block
 block discarded – undo
103 103
 				if(! empty($route) && is_array($route)){
104 104
 					$this->routes = $route;
105 105
 					unset($route);
106
-				}
107
-				else{
106
+				} else{
108 107
 					show_error('No routing configuration found in [' . $routesPath . ']');
109 108
 				}
110
-			}
111
-			else{
109
+			} else{
112 110
 				show_error('Unable to find the routes configuration file [' . $routesPath . ']');
113 111
 			}
114 112
 			
@@ -118,8 +116,7 @@  discard block
 block discarded – undo
118 116
 			if($modulesRoutes && is_array($modulesRoutes)){
119 117
 				$this->routes = array_merge($this->routes, $modulesRoutes);
120 118
 				$this->logger->info('Routes for all modules loaded successfully');
121
-			}
122
-			else{
119
+			} else{
123 120
 				$this->logger->info('No routes found for all modules skipping.');
124 121
 			}
125 122
 			$this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes));
@@ -135,8 +132,7 @@  discard block
 block discarded – undo
135 132
 			if($suffix = get_config('url_suffix')){
136 133
 				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
137 134
 				$uri = str_ireplace($suffix, '', $uri);
138
-			}
139
-			else{
135
+			} else{
140 136
 				$this->logger->info('URL suffix is not enabled in the configuration');
141 137
 			}
142 138
 			if(strpos($uri, '?') !== false){
@@ -229,8 +225,7 @@  discard block
 block discarded – undo
229 225
 				$this->logger->info('The request URI contains the front controller');
230 226
 				array_shift($segment);
231 227
 				$this->segments = $segment;
232
-			}
233
-			else{
228
+			} else{
234 229
 				$this->logger->info('The request URI does not contain the front controller');
235 230
 			}
236 231
 			$uri = implode('/', $segment);
@@ -252,8 +247,7 @@  discard block
 block discarded – undo
252 247
 						$this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']');
253 248
 						$this->module = $moduleControllerMethod[0];
254 249
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
255
-					}
256
-					else{
250
+					} else{
257 251
 						$this->logger->info('The current request does not use the module');
258 252
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
259 253
 					}
@@ -300,8 +294,7 @@  discard block
 block discarded – undo
300 294
 						}
301 295
 						//args
302 296
 						$this->args = $segment;
303
-					}
304
-					else{
297
+					} else{
305 298
 						$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
306 299
 						if(in_array($segment[0], $modules)){
307 300
 							$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
@@ -315,8 +308,7 @@  discard block
 block discarded – undo
315 308
 								if(! $path){
316 309
 									$this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller');
317 310
 									$this->controller = $this->getModule();
318
-								}
319
-								else{
311
+								} else{
320 312
 									$this->controllerPath = $path;
321 313
 									array_shift($segment);
322 314
 								}
@@ -328,8 +320,7 @@  discard block
 block discarded – undo
328 320
 							}
329 321
 							//the remaining is for args
330 322
 							$this->args = $segment;
331
-						}
332
-						else{
323
+						} else{
333 324
 							$this->logger->info('The current request information is not found in the module list');
334 325
 							//controller
335 326
 							if(isset($segment[0])){
@@ -357,8 +348,7 @@  discard block
 block discarded – undo
357 348
 				//if it is the module controller
358 349
 				if($this->getModule()){
359 350
 					$this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
360
-				}
361
-				else{
351
+				} else{
362 352
 					$this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php';
363 353
 				}
364 354
 			}
@@ -373,15 +363,13 @@  discard block
 block discarded – undo
373 363
 				if(! class_exists($controller, false)){
374 364
 					$e404 = true;
375 365
 					$this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
376
-				}
377
-				else{
366
+				} else{
378 367
 					$controllerInstance = new $controller();
379 368
 					$controllerMethod = $this->getMethod();
380 369
 					if(! method_exists($controllerInstance, $controllerMethod)){
381 370
 						$e404 = true;
382 371
 						$this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
383
-					}
384
-					else{
372
+					} else{
385 373
 						$this->logger->info('Routing data is set correctly now GO!');
386 374
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs());
387 375
 						$obj = & get_instance();
@@ -390,8 +378,7 @@  discard block
 block discarded – undo
390 378
 						$obj->response->renderFinalPage();
391 379
 					}
392 380
 				}
393
-			}
394
-			else{
381
+			} else{
395 382
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
396 383
 				$e404 = true;
397 384
 			}
Please login to merge, or discard this patch.
core/classes/Lang.php 3 patches
Indentation   +3 added lines, -3 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
 	 * For application languages management
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 		 * Construct new Lang instance
69 69
 		 */
70 70
 		public function __construct(){
71
-	        $this->logger =& class_loader('Log', 'classes');
72
-	        $this->logger->setLogger('Library::Lang');
71
+			$this->logger =& class_loader('Log', 'classes');
72
+			$this->logger->setLogger('Library::Lang');
73 73
 
74 74
 			$this->default = get_config('default_language', 'en');
75 75
 			//determine the current language
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * For application languages management
29 29
 	 */
30
-	class Lang{
30
+	class Lang {
31 31
 		
32 32
 		/**
33 33
 		 * The supported available language for this application.
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 		/**
68 68
 		 * Construct new Lang instance
69 69
 		 */
70
-		public function __construct(){
71
-	        $this->logger =& class_loader('Log', 'classes');
70
+		public function __construct() {
71
+	        $this->logger = & class_loader('Log', 'classes');
72 72
 	        $this->logger->setLogger('Library::Lang');
73 73
 
74 74
 			$this->default = get_config('default_language', 'en');
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 			$language = null;
77 77
 			//if the language exists in cookie use it
78 78
 			$cfgKey = get_config('language_cookie_name');
79
-			$this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
79
+			$this->logger->debug('Getting current language from cookie [' . $cfgKey . ']');
80 80
 			$objCookie = & class_loader('Cookie');
81 81
 			$cookieLang = $objCookie->get($cfgKey);
82
-			if($cookieLang && $this->isValid($cookieLang)){
82
+			if ($cookieLang && $this->isValid($cookieLang)) {
83 83
 				$this->current = $cookieLang;
84
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
84
+				$this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']');
85 85
 			}
86
-			else{
87
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
86
+			else {
87
+				$this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']');
88 88
 				$this->current = $this->getDefault();
89 89
 			}
90 90
 		}
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		 *
95 95
 		 * @return array the language message list
96 96
 		 */
97
-		public function getAll(){
97
+		public function getAll() {
98 98
 			return $this->languages;
99 99
 		}
100 100
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		 * @param string $key the language key to identify
105 105
 		 * @param string $value the language message value
106 106
 		 */
107
-		public function set($key, $value){
107
+		public function set($key, $value) {
108 108
 			$this->languages[$key] = $value;
109 109
 		}
110 110
 
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
 		 *
117 117
 		 * @return string the language message value
118 118
 		 */
119
-		public function get($key, $default = 'LANGUAGE_ERROR'){
120
-			if(isset($this->languages[$key])){
119
+		public function get($key, $default = 'LANGUAGE_ERROR') {
120
+			if (isset($this->languages[$key])) {
121 121
 				return $this->languages[$key];
122 122
 			}
123
-			$this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
123
+			$this->logger->warning('Language key  [' . $key . '] does not exist use the default value [' . $default . ']');
124 124
 			return $default;
125 125
 		}
126 126
 
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
 		 *
132 132
 		 * @return boolean true if the language directory exists, false or not
133 133
 		 */
134
-		public function isValid($language){
134
+		public function isValid($language) {
135 135
 			$searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
136
-			foreach($searchDir as $dir){
137
-				if(file_exists($dir . $language) && is_dir($dir . $language)){
136
+			foreach ($searchDir as $dir) {
137
+				if (file_exists($dir . $language) && is_dir($dir . $language)) {
138 138
 					return true;
139 139
 				}
140 140
 			}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return string the default language
148 148
 		 */
149
-		public function getDefault(){
149
+		public function getDefault() {
150 150
 			return $this->default;
151 151
 		}
152 152
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		 *
156 156
 		 * @return string the current language
157 157
 		 */
158
-		public function getCurrent(){
158
+		public function getCurrent() {
159 159
 			return $this->current;
160 160
 		}
161 161
 
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 		 * @param string $name the short language name like "en", "fr".
166 166
 		 * @param string $description the human readable description of this language
167 167
 		 */
168
-		public function addLang($name, $description){
169
-			if(isset($this->availables[$name])){
168
+		public function addLang($name, $description) {
169
+			if (isset($this->availables[$name])) {
170 170
 				return; //already added cost in performance
171 171
 			}
172
-			if($this->isValid($name)){
172
+			if ($this->isValid($name)) {
173 173
 				$this->availables[$name] = $description;
174 174
 			}
175
-			else{
175
+			else {
176 176
 				show_error('The language [' . $name . '] is not valid or does not exists.');
177 177
 			}
178 178
 		}
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		 *
183 183
 		 * @return array the list of the application language
184 184
 		 */
185
-		public function getSupported(){
185
+		public function getSupported() {
186 186
 			return $this->availables;
187 187
 		}
188 188
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 		 *
192 192
 		 * @param array $langs the languages array of the messages to be added
193 193
 		 */
194
-		public function addLangMessages(array $langs){
194
+		public function addLangMessages(array $langs) {
195 195
 			foreach ($langs as $key => $value) {
196 196
 				$this->set($key, $value);
197 197
 			}
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@  discard block
 block discarded – undo
82 82
 			if($cookieLang && $this->isValid($cookieLang)){
83 83
 				$this->current = $cookieLang;
84 84
 				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
85
-			}
86
-			else{
85
+			} else{
87 86
 				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
88 87
 				$this->current = $this->getDefault();
89 88
 			}
@@ -171,8 +170,7 @@  discard block
 block discarded – undo
171 170
 			}
172 171
 			if($this->isValid($name)){
173 172
 				$this->availables[$name] = $description;
174
-			}
175
-			else{
173
+			} else{
176 174
 				show_error('The language [' . $name . '] is not valid or does not exists.');
177 175
 			}
178 176
 		}
Please login to merge, or discard this patch.
core/classes/Security.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 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 Security{
28 28
 		
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 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 Security{
27
+	class Security {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * Get the logger singleton instance
37 37
 		 * @return Log the logger instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(static::$logger == null){
41
-				static::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (static::$logger == null) {
41
+				static::$logger[0] = & class_loader('Log', 'classes');
42 42
 				static::$logger[0]->setLogger('Library::Security');
43 43
 			}
44 44
 			return static::$logger[0];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * This method is used to generate the CSRF token
50 50
 		 * @return string the generated CSRF token
51 51
 		 */
52
-		public static function generateCSRF(){
52
+		public static function generateCSRF() {
53 53
 			$logger = static::getLogger();
54 54
 			$logger->debug('Generation of CSRF ...');
55 55
 			
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 			$expire = get_config('csrf_expire', 60);
58 58
 			$keyExpire = 'csrf_expire';
59 59
 			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
60
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63 63
 			}
64
-			else{
64
+			else {
65 65
 				$newTime = $currentTime + $expire;
66 66
 				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
67
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
68 68
 				Session::set($keyExpire, $newTime);
69 69
 				Session::set($key, $token);
70 70
 				return Session::get($key);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76 76
 		 * @return boolean true if valid, false if not valid
77 77
 		 */
78
-		public static function validateCSRF(){
78
+		public static function validateCSRF() {
79 79
 			$logger = static::getLogger();
80 80
 			$logger->debug('Validation of CSRF ...');
81 81
 				
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
 			$expire = get_config('csrf_expire', 60);
84 84
 			$keyExpire = 'csrf_expire';
85 85
 			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
86
+			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
87
+			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
88 88
 				$logger->warning('The CSRF session data is not valide');
89 89
 				return false;
90 90
 			}
91
-			else{
91
+			else {
92 92
 				//perform form data
93 93
 				//need use request->query() for best retrieve
94 94
 				//super instance
95 95
 				$obj = & get_instance();
96 96
 				$token = $obj->request->query($key);
97
-				if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98
-					$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
97
+				if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
98
+					$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
99 99
 					return false;
100 100
 				}
101
-				else{
102
-					$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
101
+				else {
102
+					$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
103 103
 					//remove the token from session
104 104
 					Session::clear($key);
105 105
 					Session::clear($keyExpire);
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
 		/**
112 112
 		 * This method is used to check the whitelist IP address access
113 113
 		 */
114
-		 public static function checkWhiteListIpAccess(){
114
+		 public static function checkWhiteListIpAccess() {
115 115
 			$logger = static::getLogger();
116 116
 			$logger->debug('Validation of the IP address access ...');
117 117
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
118 118
 			$isEnable = get_config('white_list_ip_enable', false);
119
-			if($isEnable){
119
+			if ($isEnable) {
120 120
 				$logger->info('Whitelist IP access is enabled in the configuration');
121 121
 				$list = get_config('white_list_ip_addresses', array());
122
-				if(! empty($list)){
122
+				if (!empty($list)) {
123 123
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
124 124
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
125 125
 					$ip = get_ip();
126
-					if(count($list) == 1 && $list[0] == '*' || in_array($ip, $list)){
126
+					if (count($list) == 1 && $list[0] == '*' || in_array($ip, $list)) {
127 127
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128 128
 						//wildcard to access all ip address
129 129
 						return;
130 130
 					}
131
-					else{
131
+					else {
132 132
 						// go through all whitelisted ips
133 133
 						foreach ($list as $ipaddr) {
134 134
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 					}
155 155
 				}
156 156
 			}
157
-			else{
157
+			else {
158 158
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159 159
 			}
160 160
 		 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -60,8 +60,7 @@  discard block
 block discarded – undo
60 60
 			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63
-			}
64
-			else{
63
+			} else{
65 64
 				$newTime = $currentTime + $expire;
66 65
 				$token = sha1(uniqid()) . sha1(uniqid());
67 66
 				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
@@ -87,8 +86,7 @@  discard block
 block discarded – undo
87 86
 			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
88 87
 				$logger->warning('The CSRF session data is not valide');
89 88
 				return false;
90
-			}
91
-			else{
89
+			} else{
92 90
 				//perform form data
93 91
 				//need use request->query() for best retrieve
94 92
 				//super instance
@@ -97,8 +95,7 @@  discard block
 block discarded – undo
97 95
 				if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98 96
 					$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
99 97
 					return false;
100
-				}
101
-				else{
98
+				} else{
102 99
 					$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
103 100
 					//remove the token from session
104 101
 					Session::clear($key);
@@ -127,8 +124,7 @@  discard block
 block discarded – undo
127 124
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128 125
 						//wildcard to access all ip address
129 126
 						return;
130
-					}
131
-					else{
127
+					} else{
132 128
 						// go through all whitelisted ips
133 129
 						foreach ($list as $ipaddr) {
134 130
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -153,8 +149,7 @@  discard block
 block discarded – undo
153 149
 						show_error('Access to this application is not allowed');
154 150
 					}
155 151
 				}
156
-			}
157
-			else{
152
+			} else{
158 153
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159 154
 			}
160 155
 		 }
Please login to merge, or discard this patch.