Passed
Push — 1.0.0-dev ( d4f0e6...ead601 )
by nguereza
03:42
created
core/classes/Config.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param Log $logger the log object
58 58
 		 * @return Log the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,38 +139,38 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
156
+				if (isset($_SERVER['SERVER_ADDR'])) {
157 157
 					//check if the server is running under IPv6
158
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
158
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
159
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
160 160
 					}
161
-					else{
161
+					else {
162 162
 						$baseUrl = $_SERVER['SERVER_ADDR'];
163 163
 					}
164
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
164
+					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
166 166
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167 167
 				}
168
-				else{
168
+				else {
169 169
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170 170
 					$baseUrl = 'http://localhost/';
171 171
 				}
172 172
 				self::set('base_url', $baseUrl);
173 173
 			}
174
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
174
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
175 175
 		}
176 176
 	}
Please login to merge, or discard this patch.
core/classes/Loader.php 1 patch
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		 * Get the logger singleton instance
52 52
 		 * @return Log the logger instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Loader');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 		 *
68 68
 		 * @return void
69 69
 		 */
70
-		public static function model($class, $instance = null){
70
+		public static function model($class, $instance = null) {
71 71
 			$logger = static::getLogger();
72 72
 			$class = str_ireplace('.php', '', $class);
73 73
 			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
74
+			$file = ucfirst($class) . '.php';
75 75
 			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
76
+			if (!$instance) {
77 77
 				//for module
78
-				if(strpos($class, '/') !== false){
78
+				if (strpos($class, '/') !== false) {
79 79
 					$path = explode('/', $class);
80
-					if(isset($path[1])){
80
+					if (isset($path[1])) {
81 81
 						$instance = strtolower($path[1]);
82 82
 					}
83 83
 				}
84
-				else{
84
+				else {
85 85
 					$instance = strtolower($class);
86 86
 				}
87 87
 			}
88
-			if(isset(static::$loaded[$instance])){
88
+			if (isset(static::$loaded[$instance])) {
89 89
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90 90
 				return;
91 91
 			}
@@ -95,43 +95,43 @@  discard block
 block discarded – undo
95 95
 			$searchModuleName = null;
96 96
 			$obj = & get_instance();
97 97
 			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
98
+			if (strpos($class, '/') !== false) {
99 99
 				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
100
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
101 101
 					$searchModuleName = $path[0];
102 102
 					$class = ucfirst($path[1]);
103 103
 				}
104 104
 			}
105
-			else{
105
+			else {
106 106
 				$class = ucfirst($class);
107 107
 			}
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
109
+			if (!$searchModuleName && !empty($obj->moduleName)) {
110 110
 				$searchModuleName = $obj->moduleName;
111 111
 			}
112 112
 			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
113
+			if ($moduleModelFilePath) {
114
+				$logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it');
115 115
 				$classFilePath = $moduleModelFilePath;
116 116
 			}
117
-			else{
117
+			else {
118 118
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119 119
 			}
120 120
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
121
+			if (file_exists($classFilePath)) {
122 122
 				require_once $classFilePath;
123
-				if(class_exists($class)){
123
+				if (class_exists($class)) {
124 124
 					$c = new $class();
125 125
 					$obj = & get_instance();
126 126
 					$obj->{$instance} = $c;
127 127
 					static::$loaded[$instance] = $class;
128 128
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129 129
 				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
130
+				else {
131
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
132 132
 				}
133 133
 			}
134
-			else{
134
+			else {
135 135
 				show_error('Unable to find the model [' . $class . ']');
136 136
 			}
137 137
 		}
@@ -146,31 +146,31 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return void
148 148
 		 */
149
-		public static function library($class, $instance = null, array $params = array()){
149
+		public static function library($class, $instance = null, array $params = array()) {
150 150
 			$logger = static::getLogger();
151 151
 			$class = str_ireplace('.php', '', $class);
152 152
 			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
153
+			$file = ucfirst($class) . '.php';
154 154
 			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
155
+			if (!$instance) {
156 156
 				//for module
157
-				if(strpos($class, '/') !== false){
157
+				if (strpos($class, '/') !== false) {
158 158
 					$path = explode('/', $class);
159
-					if(isset($path[1])){
159
+					if (isset($path[1])) {
160 160
 						$instance = strtolower($path[1]);
161 161
 					}
162 162
 				}
163
-				else{
163
+				else {
164 164
 					$instance = strtolower($class);
165 165
 				}
166 166
 			}
167
-			if(isset(static::$loaded[$instance])){
167
+			if (isset(static::$loaded[$instance])) {
168 168
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169 169
 				return;
170 170
 			}
171 171
 			$obj = & get_instance();
172 172
 			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
173
+			if (strtolower($class) == 'database') {
174 174
 				$logger->info('This is the Database library ...');
175 175
 				$dbInstance = & class_loader('Database', 'classes', $params);
176 176
 				$obj->{$instance} = $dbInstance;
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 			$libraryFilePath = null;
182 182
 			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
183
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
184 184
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185 185
 				$class = ucfirst($class);
186 186
 				$logger->info('This library is a system library');
187 187
 			}
188
-			else{
188
+			else {
189 189
 				$logger->info('This library is not a system library');	
190 190
 				//first check if this library is in the module
191 191
 				$logger->debug('Checking library [' . $class . '] from module list ...');
192 192
 				$searchModuleName = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
194
+				if (strpos($class, '/') !== false) {
195 195
 					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
196
+					if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
197 197
 						$searchModuleName = $path[0];
198 198
 						$class = ucfirst($path[1]);
199 199
 					}
200 200
 				}
201
-				else{
201
+				else {
202 202
 					$class = ucfirst($class);
203 203
 				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
204
+				if (!$searchModuleName && !empty($obj->moduleName)) {
205 205
 					$searchModuleName = $obj->moduleName;
206 206
 				}
207 207
 				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
208
+				if ($moduleLibraryPath) {
209
+					$logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it');
210 210
 					$libraryFilePath = $moduleLibraryPath;
211 211
 				}
212
-				else{
212
+				else {
213 213
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214 214
 				}
215 215
 			}
216
-			if(! $libraryFilePath){
216
+			if (!$libraryFilePath) {
217 217
 				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
218
+				foreach ($searchDir as $dir) {
219 219
 					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
220
+					if (file_exists($filePath)) {
221 221
 						$libraryFilePath = $filePath;
222 222
 						//is already found not to continue
223 223
 						break;
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
 				}
226 226
 			}
227 227
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
228
+			if ($libraryFilePath) {
229 229
 				require_once $libraryFilePath;
230
-				if(class_exists($class)){
230
+				if (class_exists($class)) {
231 231
 					$c = $params ? new $class($params) : new $class();
232 232
 					$obj = & get_instance();
233 233
 					$obj->{$instance} = $c;
234 234
 					static::$loaded[$instance] = $class;
235 235
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236 236
 				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
237
+				else {
238
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
239 239
 				}
240 240
 			}
241
-			else{
241
+			else {
242 242
 				show_error('Unable to find library class [' . $class . ']');
243 243
 			}
244 244
 		}
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		 *
251 251
 		 * @return void
252 252
 		 */
253
-		public static function functions($function){
253
+		public static function functions($function) {
254 254
 			$logger = static::getLogger();
255 255
 			$function = str_ireplace('.php', '', $function);
256 256
 			$function = trim($function, '/\\');
257 257
 			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
258
+			$file = 'function_' . $function . '.php';
259 259
 			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
260
+			if (isset(static::$loaded['function_' . $function])) {
261 261
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262 262
 				return;
263 263
 			}
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 			$searchModuleName = null;
268 268
 			$obj = & get_instance();
269 269
 			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
270
+			if (strpos($function, '/') !== false) {
271 271
 				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
272
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
273 273
 					$searchModuleName = $path[0];
274 274
 					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
275
+					$file = $path[0] . DS . 'function_' . $function . '.php';
276 276
 				}
277 277
 			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
278
+			if (!$searchModuleName && !empty($obj->moduleName)) {
279 279
 				$searchModuleName = $obj->moduleName;
280 280
 			}
281 281
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
282
+			if ($moduleFunctionPath) {
283
+				$logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it');
284 284
 				$functionFilePath = $moduleFunctionPath;
285 285
 			}
286
-			else{
286
+			else {
287 287
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288 288
 			}
289
-			if(! $functionFilePath){
289
+			if (!$functionFilePath) {
290 290
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
291
+				foreach ($searchDir as $dir) {
292 292
 					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
293
+					if (file_exists($filePath)) {
294 294
 						$functionFilePath = $filePath;
295 295
 						//is already found not to continue
296 296
 						break;
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 				}
299 299
 			}
300 300
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
301
+			if ($functionFilePath) {
302 302
 				require_once $functionFilePath;
303 303
 				static::$loaded['function_' . $function] = $functionFilePath;
304 304
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305 305
 			}
306
-			else{
306
+			else {
307 307
 				show_error('Unable to find helper file [' . $file . ']');
308 308
 			}
309 309
 		}
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 		 *
316 316
 		 * @return void
317 317
 		 */
318
-		public static function config($filename){
318
+		public static function config($filename) {
319 319
 			$logger = static::getLogger();
320 320
 			$filename = str_ireplace('.php', '', $filename);
321 321
 			$filename = trim($filename, '/\\');
322 322
 			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
323
+			$file = 'config_' . $filename . '.php';
324 324
 			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
325
+			if (isset(static::$loaded['config_' . $filename])) {
326 326
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327 327
 				return;
328 328
 			}
@@ -332,33 +332,33 @@  discard block
 block discarded – undo
332 332
 			$searchModuleName = null;
333 333
 			$obj = & get_instance();
334 334
 			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
335
+			if (strpos($filename, '/') !== false) {
336 336
 				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
337
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
338 338
 					$searchModuleName = $path[0];
339 339
 					$filename = $path[1] . '.php';
340 340
 				}
341 341
 			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
342
+			if (!$searchModuleName && !empty($obj->moduleName)) {
343 343
 				$searchModuleName = $obj->moduleName;
344 344
 			}
345 345
 			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
346
+			if ($moduleConfigPath) {
347
+				$logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it');
348 348
 				$configFilePath = $moduleConfigPath;
349 349
 			}
350
-			else{
350
+			else {
351 351
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352 352
 			}
353 353
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
-			if(file_exists($configFilePath)){
354
+			if (file_exists($configFilePath)) {
355 355
 				require_once $configFilePath;
356
-				if(! empty($config) && is_array($config)){
356
+				if (!empty($config) && is_array($config)) {
357 357
 					Config::setAll($config);
358 358
 				}
359 359
 			}
360
-			else{
361
-				show_error('Unable to find config file ['. $configFilePath . ']');
360
+			else {
361
+				show_error('Unable to find config file [' . $configFilePath . ']');
362 362
 			}
363 363
 			static::$loaded['config_' . $filename] = $configFilePath;
364 364
 			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 		 *
375 375
 		 * @return void
376 376
 		 */
377
-		public static function lang($language){
377
+		public static function lang($language) {
378 378
 			$logger = static::getLogger();
379 379
 			$language = str_ireplace('.php', '', $language);
380 380
 			$language = trim($language, '/\\');
381 381
 			$language = str_ireplace('lang_', '', $language);
382
-			$file = 'lang_'.$language.'.php';
382
+			$file = 'lang_' . $language . '.php';
383 383
 			$logger->debug('Loading language [' . $language . '] ...');
384
-			if(isset(static::$loaded['lang_' . $language])){
384
+			if (isset(static::$loaded['lang_' . $language])) {
385 385
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
386 386
 				return;
387 387
 			}
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			$cfgKey = get_config('language_cookie_name');
392 392
 			$objCookie = & class_loader('Cookie');
393 393
 			$cookieLang = $objCookie->get($cfgKey);
394
-			if($cookieLang){
394
+			if ($cookieLang) {
395 395
 				$appLang = $cookieLang;
396 396
 			}
397 397
 			$languageFilePath = null;
@@ -400,30 +400,30 @@  discard block
 block discarded – undo
400 400
 			$searchModuleName = null;
401 401
 			$obj = & get_instance();
402 402
 			//check if the request class contains module name
403
-			if(strpos($language, '/') !== false){
403
+			if (strpos($language, '/') !== false) {
404 404
 				$path = explode('/', $language);
405
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
405
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
406 406
 					$searchModuleName = $path[0];
407 407
 					$language = 'lang_' . $path[1] . '.php';
408
-					$file = $path[0] . DS .$language;
408
+					$file = $path[0] . DS . $language;
409 409
 				}
410 410
 			}
411
-			if(! $searchModuleName && !empty($obj->moduleName)){
411
+			if (!$searchModuleName && !empty($obj->moduleName)) {
412 412
 				$searchModuleName = $obj->moduleName;
413 413
 			}
414 414
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
415
-			if($moduleLanguagePath){
416
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
415
+			if ($moduleLanguagePath) {
416
+				$logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it');
417 417
 				$languageFilePath = $moduleLanguagePath;
418 418
 			}
419
-			else{
419
+			else {
420 420
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
421 421
 			}
422
-			if(! $languageFilePath){
422
+			if (!$languageFilePath) {
423 423
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
424
-				foreach($searchDir as $dir){
424
+				foreach ($searchDir as $dir) {
425 425
 					$filePath = $dir . $appLang . DS . $file;
426
-					if(file_exists($filePath)){
426
+					if (file_exists($filePath)) {
427 427
 						$languageFilePath = $filePath;
428 428
 						//is already found not to continue
429 429
 						break;
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
 				}
432 432
 			}
433 433
 			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
434
-			if($languageFilePath){
434
+			if ($languageFilePath) {
435 435
 				require_once $languageFilePath;
436
-				if(! empty($lang) && is_array($lang)){
437
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
436
+				if (!empty($lang) && is_array($lang)) {
437
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
438 438
 					//Note: may be here the class 'Lang' not yet loaded
439
-					$langObj =& class_loader('Lang', 'classes');
439
+					$langObj = & class_loader('Lang', 'classes');
440 440
 					$langObj->addLangMessages($lang);
441 441
 					//free the memory
442 442
 					unset($lang);
@@ -444,13 +444,13 @@  discard block
 block discarded – undo
444 444
 				static::$loaded['lang_' . $language] = $languageFilePath;
445 445
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
446 446
 			}
447
-			else{
447
+			else {
448 448
 				show_error('Unable to find language file [' . $file . ']');
449 449
 			}
450 450
 		}
451 451
 
452 452
 
453
-		private function getResourcesFromAutoloadConfig(){
453
+		private function getResourcesFromAutoloadConfig() {
454 454
 			$autoloads = array();
455 455
 			$autoloads['config']    = array();
456 456
 			$autoloads['languages'] = array();
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
 			$autoloads['models']    = array();
459 459
 			$autoloads['functions'] = array();
460 460
 			//loading of the resources in autoload.php configuration file
461
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
461
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
462 462
 				require_once CONFIG_PATH . 'autoload.php';
463
-				if(! empty($autoload) && is_array($autoload)){
463
+				if (!empty($autoload) && is_array($autoload)) {
464 464
 					$autoloads = array_merge($autoloads, $autoload);
465 465
 					unset($autoload);
466 466
 				}
467 467
 			}
468 468
 			//loading autoload configuration for modules
469 469
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
470
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
470
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
471 471
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
472 472
 			}
473 473
 			return $autoloads;
474 474
 		}
475 475
 
476
-		private function loadResourcesFromAutoloadConfig(){
476
+		private function loadResourcesFromAutoloadConfig() {
477 477
 			$autoloads = array();
478 478
 			$autoloads['config']    = array();
479 479
 			$autoloads['languages'] = array();
@@ -485,29 +485,29 @@  discard block
 block discarded – undo
485 485
 
486 486
 			$autoloads = array_merge($autoloads, $list);
487 487
 			//config autoload
488
-			foreach($autoloads['config'] as $c){
488
+			foreach ($autoloads['config'] as $c) {
489 489
 				$this->config($c);
490 490
 			}
491 491
 			
492 492
 			//languages autoload
493
-			foreach($autoloads['languages'] as $language){
493
+			foreach ($autoloads['languages'] as $language) {
494 494
 				$this->lang($language);
495 495
 			}
496 496
 			
497 497
 			//libraries autoload
498
-			foreach($autoloads['libraries'] as $library){
498
+			foreach ($autoloads['libraries'] as $library) {
499 499
 				$this->library($library);
500 500
 			}
501 501
 
502 502
 			//models autoload
503
-			if(! empty($autoloads['models']) && is_array($autoloads['models'])){
503
+			if (!empty($autoloads['models']) && is_array($autoloads['models'])) {
504 504
 				require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
505
-				foreach($autoloads['models'] as $model){
505
+				foreach ($autoloads['models'] as $model) {
506 506
 					$this->model($model);
507 507
 				}
508 508
 			}
509 509
 			
510
-			foreach($autoloads['functions'] as $function){
510
+			foreach ($autoloads['functions'] as $function) {
511 511
 				$this->functions($function);
512 512
 			}
513 513
 		}
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+     class FormValidation {
29 29
 		 
30 30
         /**
31 31
          * The form validation status
32 32
          * @var boolean
33 33
          */
34
-        protected $_success  = false;
34
+        protected $_success = false;
35 35
 
36 36
         /**
37 37
          * The list of errors messages
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
         protected $_errorsMessages = array();
41 41
         
42 42
         // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
43
+        protected $_rules = array();
44 44
         
45 45
         // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
46
+        protected $_errors = array();
47 47
         
48 48
         // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
49
+        protected $_labels = array();
50 50
         
51 51
         /**
52 52
          * The errors delimiters
53 53
          * @var array
54 54
          */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
55
+        protected $_allErrorsDelimiter = array('<div class="error">', '</div>');
56 56
 
57 57
         /**
58 58
          * The each error delimiter
59 59
          * @var array
60 60
          */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
61
+        protected $_eachErrorDelimiter = array('<p class="error">', '</p>');
62 62
         
63 63
 		/**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
67
-        protected $_forceFail            = false;
67
+        protected $_forceFail = false;
68 68
 
69 69
         /**
70 70
          * The list of the error messages overrides by the original
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
          * @return void
99 99
          */
100 100
         public function __construct() {
101
-            $this->logger =& class_loader('Log', 'classes');
101
+            $this->logger = & class_loader('Log', 'classes');
102 102
             $this->logger->setLogger('Library::FormValidation');
103 103
            
104 104
 		   //Load form validation language message
105 105
             Loader::lang('form_validation');
106 106
             $obj = & get_instance();
107
-            $this->_errorsMessages  = array(
107
+            $this->_errorsMessages = array(
108 108
                         'required'         => $obj->lang->get('fv_required'),
109 109
                         'min_length'       => $obj->lang->get('fv_min_length'),
110 110
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
             $this->_success              = false;
142 142
             $this->_forceFail            = false;
143 143
             $this->data                  = array();
144
-			$this->enableCsrfCheck       = false;
144
+			$this->enableCsrfCheck = false;
145 145
         }
146 146
 
147 147
         /**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		 *
151 151
          * @return FormValidation Current instance of object.
152 152
          */
153
-        public function setData(array $data){
153
+        public function setData(array $data) {
154 154
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155 155
             $this->data = $data;
156 156
 			return $this;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
          * Get the form validation data
161 161
          * @return array the form validation data to be validated
162 162
          */
163
-        public function getData(){
163
+        public function getData() {
164 164
             return $this->data;
165 165
         }
166 166
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		*
170 170
 		* @return string the function name
171 171
 		*/
172
-        protected function _toCallCase($funcName, $prefix='_validate') {
172
+        protected function _toCallCase($funcName, $prefix = '_validate') {
173 173
             $funcName = strtolower($funcName);
174 174
             $finalFuncName = $prefix;
175 175
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
194 194
          */
195 195
         public function canDoValidation() {
196
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
196
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
197 197
         }
198 198
 
199 199
         /**
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
          * afterwards.
216 216
          */
217 217
         protected function _run() {
218
-            if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){
218
+            if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) {
219 219
                 $this->logger->debug('Check if CSRF is enabled in configuration');
220 220
                 //first check for CSRF
221
-                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
221
+                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && !Security::validateCSRF()) {
222 222
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
223 223
                 }
224
-                else{
224
+                else {
225 225
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
226 226
                 }
227 227
             }
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
             $this->_forceFail = false;
230 230
 
231 231
             foreach ($this->getData() as $inputName => $inputVal) {
232
-    			if(is_array($this->data[$inputName])){
232
+    			if (is_array($this->data[$inputName])) {
233 233
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
234 234
     			}
235
-    			else{
235
+    			else {
236 236
     				$this->data[$inputName] = trim($this->data[$inputName]);
237 237
     			}
238 238
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         public function setRule($inputField, $inputLabel, $ruleSets) {
260 260
             $this->_rules[$inputField] = $ruleSets;
261 261
             $this->_labels[$inputField] = $inputLabel;
262
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
262
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
263 263
             return $this;
264 264
         }
265 265
 
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             }
424 424
             $errorOutput .= $errorsEnd;
425 425
             echo ($echo) ? $errorOutput : '';
426
-            return (! $echo) ? $errorOutput : null;
426
+            return (!$echo) ? $errorOutput : null;
427 427
         }
428 428
 
429 429
         /**
@@ -448,25 +448,25 @@  discard block
 block discarded – undo
448 448
             /*
449 449
             //////////////// hack for regex rule that can contain "|"
450 450
             */
451
-            if(strpos($ruleString, 'regex') !== false){
451
+            if (strpos($ruleString, 'regex') !== false) {
452 452
                 $regexRule = array();
453 453
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
454 454
                 preg_match($rule, $ruleString, $regexRule);
455 455
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
456
-                 if(!empty($regexRule[0])){
456
+                 if (!empty($regexRule[0])) {
457 457
                      $ruleSets[] = $regexRule[0];
458 458
                  }
459 459
                  $ruleStringRegex = explode('|', $ruleStringTemp);
460 460
                 foreach ($ruleStringRegex as $rule) {
461 461
                     $rule = trim($rule);
462
-                    if($rule){
462
+                    if ($rule) {
463 463
                         $ruleSets[] = $rule;
464 464
                     }
465 465
                 }
466 466
                  
467 467
             }
468 468
             /***********************************/
469
-            else{
469
+            else {
470 470
                 if (strpos($ruleString, '|') !== FALSE) {
471 471
                     $ruleSets = explode('|', $ruleString);
472 472
                 } else {
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
          * @return void
499 499
          */
500 500
         protected function _validateRule($inputName, $inputVal, $ruleName) {
501
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
501
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
502 502
             // Array to store args
503 503
             $ruleArgs = array();
504 504
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
                 $key = $i - 1;
544 544
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
545 545
             }
546
-            if (! array_key_exists($inputName, $this->_errors)) {
546
+            if (!array_key_exists($inputName, $this->_errors)) {
547 547
                 $this->_errors[$inputName] = $rulePhrase;
548 548
             }
549 549
         }
@@ -595,13 +595,13 @@  discard block
 block discarded – undo
595 595
          */
596 596
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
597 597
             $inputVal = $this->post($inputName);
598
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
598
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
599 599
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
600 600
                 if ($inputVal == '' && $callbackReturn == true) {
601 601
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
602 602
                 }
603 603
             } 
604
-			else if($inputVal == '') {
604
+			else if ($inputVal == '') {
605 605
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
606 606
             }
607 607
         }
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
628 628
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
629 629
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
630
-				if(! $result){
630
+				if (!$result) {
631 631
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
632 632
 				}
633 633
             }
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
                         continue;
662 662
                     }
663 663
                 } 
664
-				else{
664
+				else {
665 665
                     if ($inputVal == $doNotEqual) {
666 666
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
667 667
                         continue;
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
          */
692 692
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
693 693
             $inputVal = $this->post($inputName);
694
-            if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
695
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
694
+            if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
695
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
696 696
                     return;
697 697
                 }
698 698
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
709 709
             $inputVal = $this->post($inputName);
710 710
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
711
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
711
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
712 712
                     return;
713 713
                 }
714 714
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
725 725
             $inputVal = $this->post($inputName);
726 726
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
727
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
727
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
728 728
                     return;
729 729
                 }
730 730
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
741 741
             $inputVal = $this->post($inputName);
742 742
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
743
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
743
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
744 744
                     return;
745 745
                 }
746 746
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
757 757
             $inputVal = $this->post($inputName);
758 758
             if ($inputVal >= $ruleArgs[1]) { 
759
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
759
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
760 760
                     return;
761 761
                 }
762 762
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
773 773
             $inputVal = $this->post($inputName);
774 774
             if ($inputVal <= $ruleArgs[1]) {
775
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
775
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
776 776
                     return;
777 777
                 }
778 778
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
          */
788 788
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
789 789
             $inputVal = $this->post($inputName);
790
-            if (! is_numeric($inputVal)) {
791
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
790
+            if (!is_numeric($inputVal)) {
791
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
792 792
                     return;
793 793
                 }
794 794
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
805 805
             $inputVal = $this->post($inputName);
806 806
     		$obj = & get_instance();
807
-    		if(! isset($obj->database)){
807
+    		if (!isset($obj->database)) {
808 808
     			return;
809 809
     		}
810 810
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     			          ->get();
814 814
     		$nb = $obj->database->numRows();
815 815
             if ($nb == 0) {
816
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
816
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
817 817
                     return;
818 818
                 }
819 819
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
830 830
             $inputVal = $this->post($inputName);
831 831
     		$obj = & get_instance();
832
-    		if(! isset($obj->database)){
832
+    		if (!isset($obj->database)) {
833 833
     			return;
834 834
     		}
835 835
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
     			          ->get();
839 839
     		$nb = $obj->database->numRows();
840 840
             if ($nb != 0) {
841
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
841
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
842 842
                     return;
843 843
                 }
844 844
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
855 855
             $inputVal = $this->post($inputName);
856 856
     		$obj = & get_instance();
857
-    		if(! isset($obj->database)){
857
+    		if (!isset($obj->database)) {
858 858
     			return;
859 859
     		}
860 860
     		$data = explode(',', $ruleArgs[1]);
861
-    		if(count($data) < 2){
861
+    		if (count($data) < 2) {
862 862
     			return;
863 863
     		}
864 864
     		list($table, $column) = explode('.', $data[0]);
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
                 		  ->get();
870 870
     		$nb = $obj->database->numRows();
871 871
             if ($nb != 0) {
872
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
872
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
873 873
                     return;
874 874
                 }
875 875
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -886,8 +886,8 @@  discard block
 block discarded – undo
886 886
             $inputVal = $this->post($inputName);
887 887
     		$list = explode(',', $ruleArgs[1]);
888 888
             $list = array_map('trim', $list);
889
-            if (! in_array($inputVal, $list)) {
890
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
889
+            if (!in_array($inputVal, $list)) {
890
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
891 891
                     return;
892 892
                 }
893 893
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -903,8 +903,8 @@  discard block
 block discarded – undo
903 903
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
904 904
             $inputVal = $this->post($inputName);
905 905
     		$regex = $ruleArgs[1];
906
-            if (! preg_match($regex, $inputVal)) {
907
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
906
+            if (!preg_match($regex, $inputVal)) {
907
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
908 908
                     return;
909 909
                 }
910 910
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
core/classes/Controller.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Controller{
27
+	class Controller {
28 28
 		
29 29
 		/**
30 30
 		 * The name of the module if this controller belong to an module
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		 * Class constructor
49 49
 		 * @param object $logger the Log instance to use if is null will create one
50 50
 		 */
51
-		public function __construct(Log $logger = null){
51
+		public function __construct(Log $logger = null) {
52 52
 			//setting the Log instance
53 53
 			$this->setLoggerFromParamOrCreateNewInstance($logger);
54 54
 			
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 		/**
85 85
 		 * This method is used to set the module name
86 86
 		 */
87
-		protected function setModuleNameFromRouter(){
87
+		protected function setModuleNameFromRouter() {
88 88
 			//determine the current module
89
-			if(isset($this->router) && $this->router->getModule()){
89
+			if (isset($this->router) && $this->router->getModule()) {
90 90
 				$this->moduleName = $this->router->getModule();
91 91
 			}
92 92
 		}
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 		 * Set the cache using the argument otherwise will use the configuration
96 96
 		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
97 97
 		 */
98
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
98
+		protected function setCacheFromParamOrConfig(CacheInterface $cache = null) {
99 99
 			$this->logger->debug('Setting the cache handler instance');
100 100
 			//set cache handler instance
101
-			if(get_config('cache_enable', false)){
102
-				if ($cache !== null){
101
+			if (get_config('cache_enable', false)) {
102
+				if ($cache !== null) {
103 103
 					$this->cache = $cache;
104
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
104
+				} else if (isset($this->{strtolower(get_config('cache_handler'))})) {
105 105
 					$this->cache = $this->{strtolower(get_config('cache_handler'))};
106 106
 					unset($this->{strtolower(get_config('cache_handler'))});
107 107
 				} 
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 		 * Set the Log instance using argument or create new instance
113 113
 		 * @param object $logger the Log instance if not null
114 114
 		 */
115
-		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116
-			if($logger !== null){
115
+		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
116
+			if ($logger !== null) {
117 117
 	          $this->logger = $logger;
118 118
 	        }
119
-	        else{
120
-	            $this->logger =& class_loader('Log', 'classes');
119
+	        else {
120
+	            $this->logger = & class_loader('Log', 'classes');
121 121
 				$this->logger->setLogger('MainController');
122 122
 	        }
123 123
 		}
@@ -126,20 +126,20 @@  discard block
 block discarded – undo
126 126
 		 * This method is used to load the required resources for framework to work
127 127
 		 * @return void 
128 128
 		 */
129
-		private function loadRequiredResources(){
129
+		private function loadRequiredResources() {
130 130
 			$this->logger->debug('Adding the loaded classes to the super instance');
131
-			foreach (class_loaded() as $var => $class){
132
-				$this->$var =& class_loader($class);
131
+			foreach (class_loaded() as $var => $class) {
132
+				$this->$var = & class_loader($class);
133 133
 			}
134 134
 
135 135
 			$this->logger->debug('Loading the required classes into super instance');
136
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
137
-			$this->loader =& class_loader('Loader', 'classes');
138
-			$this->lang =& class_loader('Lang', 'classes');
139
-			$this->request =& class_loader('Request', 'classes');
136
+			$this->eventdispatcher = & class_loader('EventDispatcher', 'classes');
137
+			$this->loader = & class_loader('Loader', 'classes');
138
+			$this->lang = & class_loader('Lang', 'classes');
139
+			$this->request = & class_loader('Request', 'classes');
140 140
 			//dispatch the request instance created event
141 141
 			$this->eventdispatcher->dispatch('REQUEST_CREATED');
142
-			$this->response =& class_loader('Response', 'classes', 'classes');
142
+			$this->response = & class_loader('Response', 'classes', 'classes');
143 143
 		}
144 144
 
145 145
 	}
Please login to merge, or discard this patch.
core/classes/Database.php 1 patch
Spacing   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -23,165 +23,165 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class Database{
26
+  class Database {
27 27
 	
28 28
 	/**
29 29
 	 * The PDO instance
30 30
 	 * @var object
31 31
 	*/
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
 	/**
35 35
 	 * The database name used for the application
36 36
 	 * @var string
37 37
 	*/
38
-	private $databaseName        = null;
38
+	private $databaseName = null;
39 39
     
40 40
 	/**
41 41
 	 * The SQL SELECT statment
42 42
 	 * @var string
43 43
 	*/
44
-	private $select              = '*';
44
+	private $select = '*';
45 45
 	
46 46
 	/**
47 47
 	 * The SQL FROM statment
48 48
 	 * @var string
49 49
 	*/
50
-    private $from                = null;
50
+    private $from = null;
51 51
 	
52 52
 	/**
53 53
 	 * The SQL WHERE statment
54 54
 	 * @var string
55 55
 	*/
56
-    private $where               = null;
56
+    private $where = null;
57 57
 	
58 58
 	/**
59 59
 	 * The SQL LIMIT statment
60 60
 	 * @var string
61 61
 	*/
62
-    private $limit               = null;
62
+    private $limit = null;
63 63
 	
64 64
 	/**
65 65
 	 * The SQL JOIN statment
66 66
 	 * @var string
67 67
 	*/
68
-    private $join                = null;
68
+    private $join = null;
69 69
 	
70 70
 	/**
71 71
 	 * The SQL ORDER BY statment
72 72
 	 * @var string
73 73
 	*/
74
-    private $orderBy             = null;
74
+    private $orderBy = null;
75 75
 	
76 76
 	/**
77 77
 	 * The SQL GROUP BY statment
78 78
 	 * @var string
79 79
 	*/
80
-    private $groupBy             = null;
80
+    private $groupBy = null;
81 81
 	
82 82
 	/**
83 83
 	 * The SQL HAVING statment
84 84
 	 * @var string
85 85
 	*/
86
-    private $having              = null;
86
+    private $having = null;
87 87
 	
88 88
 	/**
89 89
 	 * The number of rows returned by the last query
90 90
 	 * @var int
91 91
 	*/
92
-    private $numRows             = 0;
92
+    private $numRows = 0;
93 93
 	
94 94
 	/**
95 95
 	 * The last insert id for the primary key column that have auto increment or sequence
96 96
 	 * @var mixed
97 97
 	*/
98
-    private $insertId            = null;
98
+    private $insertId = null;
99 99
 	
100 100
 	/**
101 101
 	 * The full SQL query statment after build for each command
102 102
 	 * @var string
103 103
 	*/
104
-    private $query               = null;
104
+    private $query = null;
105 105
 	
106 106
 	/**
107 107
 	 * The error returned for the last query
108 108
 	 * @var string
109 109
 	*/
110
-    private $error               = null;
110
+    private $error = null;
111 111
 	
112 112
 	/**
113 113
 	 * The result returned for the last query
114 114
 	 * @var mixed
115 115
 	*/
116
-    private $result              = array();
116
+    private $result = array();
117 117
 	
118 118
 	/**
119 119
 	 * The prefix used in each database table
120 120
 	 * @var string
121 121
 	*/
122
-    private $prefix              = null;
122
+    private $prefix = null;
123 123
 	
124 124
 	/**
125 125
 	 * The list of SQL valid operators
126 126
 	 * @var array
127 127
 	*/
128
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
128
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
129 129
     
130 130
 	/**
131 131
 	 * The cache default time to live in second. 0 means no need to use the cache feature
132 132
 	 * @var int
133 133
 	*/
134
-	private $cacheTtl              = 0;
134
+	private $cacheTtl = 0;
135 135
 	
136 136
 	/**
137 137
 	 * The cache current time to live. 0 means no need to use the cache feature
138 138
 	 * @var int
139 139
 	*/
140
-    private $temporaryCacheTtl   = 0;
140
+    private $temporaryCacheTtl = 0;
141 141
 	
142 142
 	/**
143 143
 	 * The number of executed query for the current request
144 144
 	 * @var int
145 145
 	*/
146
-    private $queryCount          = 0;
146
+    private $queryCount = 0;
147 147
 	
148 148
 	/**
149 149
 	 * The default data to be used in the statments query INSERT, UPDATE
150 150
 	 * @var array
151 151
 	*/
152
-    private $data                = array();
152
+    private $data = array();
153 153
 	
154 154
 	/**
155 155
 	 * The database configuration
156 156
 	 * @var array
157 157
 	*/
158
-    private $config              = array();
158
+    private $config = array();
159 159
 	
160 160
 	/**
161 161
 	 * The logger instance
162 162
 	 * @var Log
163 163
 	 */
164
-    private $logger              = null;
164
+    private $logger = null;
165 165
 
166 166
 
167 167
     /**
168 168
     * The cache instance
169 169
     * @var CacheInterface
170 170
     */
171
-    private $cacheInstance       = null;
171
+    private $cacheInstance = null;
172 172
 
173 173
      /**
174 174
     * The benchmark instance
175 175
     * @var Benchmark
176 176
     */
177
-    private $benchmarkInstance   = null;
177
+    private $benchmarkInstance = null;
178 178
 
179 179
 
180 180
     /**
181 181
      * Construct new database
182 182
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
183 183
      */
184
-    public function __construct($overwriteConfig = array()){
184
+    public function __construct($overwriteConfig = array()) {
185 185
         //Set Log instance to use
186 186
         $this->setLoggerFromParamOrCreateNewInstance(null);
187 187
 
@@ -197,23 +197,23 @@  discard block
 block discarded – undo
197 197
      * This is used to connect to database
198 198
      * @return bool 
199 199
      */
200
-    public function connect(){
200
+    public function connect() {
201 201
       $config = $this->getDatabaseConfiguration();
202
-      if (! empty($config)){
203
-        try{
202
+      if (!empty($config)) {
203
+        try {
204 204
             $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
205 205
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
206 206
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
207 207
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
208 208
             return true;
209 209
           }
210
-          catch (PDOException $e){
210
+          catch (PDOException $e) {
211 211
             $this->logger->fatal($e->getMessage());
212 212
             show_error('Cannot connect to Database.');
213 213
             return false;
214 214
           }
215 215
       }
216
-      else{
216
+      else {
217 217
         show_error('Database configuration is not set.');
218 218
         return false;
219 219
       }
@@ -224,15 +224,15 @@  discard block
 block discarded – undo
224 224
      * @param  string|array $table the table name or array of table list
225 225
      * @return object        the current Database instance
226 226
      */
227
-    public function from($table){
228
-      if (is_array($table)){
227
+    public function from($table) {
228
+      if (is_array($table)) {
229 229
         $froms = '';
230
-        foreach($table as $key){
230
+        foreach ($table as $key) {
231 231
           $froms .= $this->prefix . $key . ', ';
232 232
         }
233 233
         $this->from = rtrim($froms, ', ');
234 234
       }
235
-      else{
235
+      else {
236 236
         $this->from = $this->prefix . $table;
237 237
       }
238 238
       return $this;
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      * @param  string|array $fields the field name or array of field list
244 244
      * @return object        the current Database instance
245 245
      */
246
-    public function select($fields){
246
+    public function select($fields) {
247 247
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
248 248
       $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select);
249 249
       return $this;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      * @param  string $field the field name to distinct
255 255
      * @return object        the current Database instance
256 256
      */
257
-    public function distinct($field){
257
+    public function distinct($field) {
258 258
       $distinct = ' DISTINCT ' . $field;
259 259
       $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct);
260 260
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
      * @param  string $name  if is not null represent the alias used for this field in the result
268 268
      * @return object        the current Database instance
269 269
      */
270
-    public function max($field, $name = null){
270
+    public function max($field, $name = null) {
271 271
       $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
272 272
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
273 273
       return $this;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      * @param  string $name  if is not null represent the alias used for this field in the result
280 280
      * @return object        the current Database instance
281 281
      */
282
-    public function min($field, $name = null){
282
+    public function min($field, $name = null) {
283 283
       $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
284 284
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
285 285
       return $this;
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @param  string $name  if is not null represent the alias used for this field in the result
292 292
      * @return object        the current Database instance
293 293
      */
294
-    public function sum($field, $name = null){
294
+    public function sum($field, $name = null) {
295 295
       $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
296 296
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
297 297
       return $this;
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      * @param  string $name  if is not null represent the alias used for this field in the result
304 304
      * @return object        the current Database instance
305 305
      */
306
-    public function count($field = '*', $name = null){
306
+    public function count($field = '*', $name = null) {
307 307
       $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
308 308
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
309 309
       return $this;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      * @param  string $name  if is not null represent the alias used for this field in the result
316 316
      * @return object        the current Database instance
317 317
      */
318
-    public function avg($field, $name = null){
318
+    public function avg($field, $name = null) {
319 319
       $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
320 320
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
321 321
       return $this;
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
331 331
      * @return object        the current Database instance
332 332
      */
333
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
333
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
334 334
       $on = $field1;
335 335
       $table = $this->prefix . $table;
336
-      if (! is_null($op)){
337
-        $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
336
+      if (!is_null($op)) {
337
+        $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
338 338
       }
339
-      if (empty($this->join)){
339
+      if (empty($this->join)) {
340 340
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
341 341
       }
342
-      else{
342
+      else {
343 343
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
344 344
       }
345 345
       return $this;
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      * @see  Database::join()
351 351
      * @return object        the current Database instance
352 352
      */
353
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
353
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
354 354
       return $this->join($table, $field1, $op, $field2, 'INNER ');
355 355
     }
356 356
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
      * @see  Database::join()
360 360
      * @return object        the current Database instance
361 361
      */
362
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
362
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
363 363
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
364 364
 	}
365 365
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      * @see  Database::join()
369 369
      * @return object        the current Database instance
370 370
      */
371
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
371
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
372 372
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
373 373
     }
374 374
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      * @see  Database::join()
378 378
      * @return object        the current Database instance
379 379
      */
380
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
380
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
381 381
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
382 382
     }
383 383
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
      * @see  Database::join()
387 387
      * @return object        the current Database instance
388 388
      */
389
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
389
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
390 390
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
391 391
     }
392 392
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
      * @see  Database::join()
396 396
      * @return object        the current Database instance
397 397
      */
398
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
398
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
399 399
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
400 400
     }
401 401
 
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
406 406
      * @return object        the current Database instance
407 407
      */
408
-    public function whereIsNull($field, $andOr = 'AND'){
409
-      if (is_array($field)){
410
-        foreach($field as $f){
408
+    public function whereIsNull($field, $andOr = 'AND') {
409
+      if (is_array($field)) {
410
+        foreach ($field as $f) {
411 411
         	$this->whereIsNull($f, $andOr);
412 412
         }
413 413
       }
414
-      else{
415
-           $this->setWhereStr($field.' IS NULL ', $andOr);
414
+      else {
415
+           $this->setWhereStr($field . ' IS NULL ', $andOr);
416 416
       }
417 417
       return $this;
418 418
     }
@@ -423,14 +423,14 @@  discard block
 block discarded – undo
423 423
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
424 424
      * @return object        the current Database instance
425 425
      */
426
-    public function whereIsNotNull($field, $andOr = 'AND'){
427
-      if (is_array($field)){
428
-        foreach($field as $f){
426
+    public function whereIsNotNull($field, $andOr = 'AND') {
427
+      if (is_array($field)) {
428
+        foreach ($field as $f) {
429 429
           $this->whereIsNotNull($f, $andOr);
430 430
         }
431 431
       }
432
-      else{
433
-          $this->setWhereStr($field.' IS NOT NULL ', $andOr);
432
+      else {
433
+          $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
434 434
       }
435 435
       return $this;
436 436
     }
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
      * @param  boolean $escape whether to escape or not the $val
446 446
      * @return object        the current Database instance
447 447
      */
448
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
448
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
449 449
       $whereStr = '';
450
-      if (is_array($where)){
450
+      if (is_array($where)) {
451 451
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
452 452
       }
453
-      else{
454
-        if (is_array($op)){
453
+      else {
454
+        if (is_array($op)) {
455 455
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
456 456
         } else {
457 457
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @see  Database::where()
467 467
      * @return object        the current Database instance
468 468
      */
469
-    public function orWhere($where, $op = null, $val = null, $escape = true){
469
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
470 470
       return $this->where($where, $op, $val, '', 'OR', $escape);
471 471
     }
472 472
 
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
      * @see  Database::where()
477 477
      * @return object        the current Database instance
478 478
      */
479
-    public function notWhere($where, $op = null, $val = null, $escape = true){
479
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
480 480
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
481 481
     }
482 482
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
      * @see  Database::where()
486 486
      * @return object        the current Database instance
487 487
      */
488
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
488
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
489 489
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
490 490
     }
491 491
 
@@ -495,15 +495,15 @@  discard block
 block discarded – undo
495 495
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
496 496
      * @return object        the current Database instance
497 497
      */
498
-    public function groupStart($type = '', $andOr = ' AND'){
499
-      if (empty($this->where)){
498
+    public function groupStart($type = '', $andOr = ' AND') {
499
+      if (empty($this->where)) {
500 500
         $this->where = $type . ' (';
501 501
       }
502
-      else{
503
-          if (substr($this->where, -1) == '('){
502
+      else {
503
+          if (substr($this->where, -1) == '(') {
504 504
             $this->where .= $type . ' (';
505 505
           }
506
-          else{
506
+          else {
507 507
           	$this->where .= $andOr . ' ' . $type . ' (';
508 508
           }
509 509
       }
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
      * @see  Database::groupStart()
516 516
      * @return object        the current Database instance
517 517
      */
518
-    public function notGroupStart(){
518
+    public function notGroupStart() {
519 519
       return $this->groupStart('NOT');
520 520
     }
521 521
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
      * @see  Database::groupStart()
525 525
      * @return object        the current Database instance
526 526
      */
527
-    public function orGroupStart(){
527
+    public function orGroupStart() {
528 528
       return $this->groupStart('', ' OR');
529 529
     }
530 530
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
      * @see  Database::groupStart()
534 534
      * @return object        the current Database instance
535 535
      */
536
-    public function orNotGroupStart(){
536
+    public function orNotGroupStart() {
537 537
       return $this->groupStart('NOT', ' OR');
538 538
     }
539 539
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
      * Close the parenthesis for the grouped SQL
542 542
      * @return object        the current Database instance
543 543
      */
544
-    public function groupEnd(){
544
+    public function groupEnd() {
545 545
       $this->where .= ')';
546 546
       return $this;
547 547
     }
@@ -555,10 +555,10 @@  discard block
 block discarded – undo
555 555
      * @param  boolean $escape whether to escape or not the values
556 556
      * @return object        the current Database instance
557 557
      */
558
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
558
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
559 559
       $_keys = array();
560
-      foreach ($keys as $k => $v){
561
-        if (is_null($v)){
560
+      foreach ($keys as $k => $v) {
561
+        if (is_null($v)) {
562 562
           $v = '';
563 563
         }
564 564
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      * @see  Database::in()
575 575
      * @return object        the current Database instance
576 576
      */
577
-    public function notIn($field, array $keys, $escape = true){
577
+    public function notIn($field, array $keys, $escape = true) {
578 578
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
579 579
     }
580 580
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      * @see  Database::in()
584 584
      * @return object        the current Database instance
585 585
      */
586
-    public function orIn($field, array $keys, $escape = true){
586
+    public function orIn($field, array $keys, $escape = true) {
587 587
       return $this->in($field, $keys, '', 'OR', $escape);
588 588
     }
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      * @see  Database::in()
593 593
      * @return object        the current Database instance
594 594
      */
595
-    public function orNotIn($field, array $keys, $escape = true){
595
+    public function orNotIn($field, array $keys, $escape = true) {
596 596
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
597 597
     }
598 598
 
@@ -606,11 +606,11 @@  discard block
 block discarded – undo
606 606
      * @param  boolean $escape whether to escape or not the values
607 607
      * @return object        the current Database instance
608 608
      */
609
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
610
-      if (is_null($value1)){
609
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
610
+      if (is_null($value1)) {
611 611
         $value1 = '';
612 612
       }
613
-      if (is_null($value2)){
613
+      if (is_null($value2)) {
614 614
         $value2 = '';
615 615
       }
616 616
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
      * @see  Database::between()
624 624
      * @return object        the current Database instance
625 625
      */
626
-    public function notBetween($field, $value1, $value2, $escape = true){
626
+    public function notBetween($field, $value1, $value2, $escape = true) {
627 627
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
628 628
     }
629 629
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
      * @see  Database::between()
633 633
      * @return object        the current Database instance
634 634
      */
635
-    public function orBetween($field, $value1, $value2, $escape = true){
635
+    public function orBetween($field, $value1, $value2, $escape = true) {
636 636
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
637 637
     }
638 638
 
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
      * @see  Database::between()
642 642
      * @return object        the current Database instance
643 643
      */
644
-    public function orNotBetween($field, $value1, $value2, $escape = true){
644
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
645 645
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
646 646
     }
647 647
 
@@ -654,8 +654,8 @@  discard block
 block discarded – undo
654 654
      * @param  boolean $escape whether to escape or not the values
655 655
      * @return object        the current Database instance
656 656
      */
657
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
658
-      if (empty($data)){
657
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
658
+      if (empty($data)) {
659 659
         $data = '';
660 660
       }
661 661
       $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
      * @see  Database::like()
668 668
      * @return object        the current Database instance
669 669
      */
670
-    public function orLike($field, $data, $escape = true){
670
+    public function orLike($field, $data, $escape = true) {
671 671
       return $this->like($field, $data, '', 'OR', $escape);
672 672
     }
673 673
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
      * @see  Database::like()
677 677
      * @return object        the current Database instance
678 678
      */
679
-    public function notLike($field, $data, $escape = true){
679
+    public function notLike($field, $data, $escape = true) {
680 680
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
681 681
     }
682 682
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
      * @see  Database::like()
686 686
      * @return object        the current Database instance
687 687
      */
688
-    public function orNotLike($field, $data, $escape = true){
688
+    public function orNotLike($field, $data, $escape = true) {
689 689
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
690 690
     }
691 691
 
@@ -696,14 +696,14 @@  discard block
 block discarded – undo
696 696
      * @param  int $limitEnd the limit count
697 697
      * @return object        the current Database instance
698 698
      */
699
-    public function limit($limit, $limitEnd = null){
700
-      if (empty($limit)){
699
+    public function limit($limit, $limitEnd = null) {
700
+      if (empty($limit)) {
701 701
         return;
702 702
       }
703
-      if (! is_null($limitEnd)){
703
+      if (!is_null($limitEnd)) {
704 704
         $this->limit = $limit . ', ' . $limitEnd;
705 705
       }
706
-      else{
706
+      else {
707 707
         $this->limit = $limit;
708 708
       }
709 709
       return $this;
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
      * @param  string $orderDir the order direction (ASC or DESC)
716 716
      * @return object        the current Database instance
717 717
      */
718
-    public function orderBy($orderBy, $orderDir = ' ASC'){
719
-        if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
718
+    public function orderBy($orderBy, $orderDir = ' ASC') {
719
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
720 720
           $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
721 721
         }
722
-        else{
722
+        else {
723 723
           $this->orderBy = empty($this->orderBy) ? ($orderBy . ' ' 
724 724
                             . strtoupper($orderDir)) : $this->orderBy 
725 725
                             . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -732,11 +732,11 @@  discard block
 block discarded – undo
732 732
      * @param  string|array $field the field name used or array of field list
733 733
      * @return object        the current Database instance
734 734
      */
735
-    public function groupBy($field){
736
-      if (is_array($field)){
735
+    public function groupBy($field) {
736
+      if (is_array($field)) {
737 737
         $this->groupBy = implode(', ', $field);
738 738
       }
739
-      else{
739
+      else {
740 740
         $this->groupBy = $field;
741 741
       }
742 742
       return $this;
@@ -750,13 +750,13 @@  discard block
 block discarded – undo
750 750
      * @param  boolean $escape whether to escape or not the values
751 751
      * @return object        the current Database instance
752 752
      */
753
-    public function having($field, $op = null, $val = null, $escape = true){
754
-      if (is_array($op)){
753
+    public function having($field, $op = null, $val = null, $escape = true) {
754
+      if (is_array($op)) {
755 755
         $x = explode('?', $field);
756 756
         $w = '';
757
-        foreach($x as $k => $v){
758
-  	      if (!empty($v)){
759
-            if (! isset($op[$k])){
757
+        foreach ($x as $k => $v) {
758
+  	      if (!empty($v)) {
759
+            if (!isset($op[$k])) {
760 760
               $op[$k] = '';
761 761
             }
762 762
   	      	$w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -764,14 +764,14 @@  discard block
 block discarded – undo
764 764
       	}
765 765
         $this->having = $w;
766 766
       }
767
-      else if (! in_array($op, $this->operatorList)){
768
-        if (is_null($op)){
767
+      else if (!in_array($op, $this->operatorList)) {
768
+        if (is_null($op)) {
769 769
           $op = '';
770 770
         }
771 771
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
772 772
       }
773
-      else{
774
-        if (is_null($val)){
773
+      else {
774
+        if (is_null($val)) {
775 775
           $val = '';
776 776
         }
777 777
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
      * Return the number of rows returned by the current query
784 784
      * @return int
785 785
      */
786
-    public function numRows(){
786
+    public function numRows() {
787 787
       return $this->numRows;
788 788
     }
789 789
 
@@ -791,15 +791,15 @@  discard block
 block discarded – undo
791 791
      * Return the last insert id value
792 792
      * @return mixed
793 793
      */
794
-    public function insertId(){
794
+    public function insertId() {
795 795
       return $this->insertId;
796 796
     }
797 797
 
798 798
     /**
799 799
      * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
800 800
      */
801
-    public function error(){
802
-  		if ($this->error){
801
+    public function error() {
802
+  		if ($this->error) {
803 803
   			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
804 804
   		}
805 805
     }
@@ -810,14 +810,14 @@  discard block
 block discarded – undo
810 810
      * If is string will determine the result type "array" or "object"
811 811
      * @return mixed       the query SQL string or the record result
812 812
      */
813
-    public function get($returnSQLQueryOrResultType = false){
813
+    public function get($returnSQLQueryOrResultType = false) {
814 814
       $this->limit = 1;
815 815
       $query = $this->getAll(true);
816
-      if ($returnSQLQueryOrResultType === true){
816
+      if ($returnSQLQueryOrResultType === true) {
817 817
         return $query;
818 818
       }
819
-      else{
820
-        return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) );
819
+      else {
820
+        return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false));
821 821
       }
822 822
     }
823 823
 
@@ -827,33 +827,33 @@  discard block
 block discarded – undo
827 827
      * If is string will determine the result type "array" or "object"
828 828
      * @return mixed       the query SQL string or the record result
829 829
      */
830
-    public function getAll($returnSQLQueryOrResultType = false){
830
+    public function getAll($returnSQLQueryOrResultType = false) {
831 831
       $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
832
-      if (! empty($this->join)){
832
+      if (!empty($this->join)) {
833 833
         $query .= $this->join;
834 834
       }
835 835
 	  
836
-      if (! empty($this->where)){
836
+      if (!empty($this->where)) {
837 837
         $query .= ' WHERE ' . $this->where;
838 838
       }
839 839
 
840
-      if (! empty($this->groupBy)){
840
+      if (!empty($this->groupBy)) {
841 841
         $query .= ' GROUP BY ' . $this->groupBy;
842 842
       }
843 843
 
844
-      if (! empty($this->having)){
844
+      if (!empty($this->having)) {
845 845
         $query .= ' HAVING ' . $this->having;
846 846
       }
847 847
 
848
-      if (! empty($this->orderBy)){
848
+      if (!empty($this->orderBy)) {
849 849
           $query .= ' ORDER BY ' . $this->orderBy;
850 850
       }
851 851
 
852
-      if (! empty($this->limit)){
852
+      if (!empty($this->limit)) {
853 853
       	$query .= ' LIMIT ' . $this->limit;
854 854
       }
855 855
 	  
856
-	   if ($returnSQLQueryOrResultType === true){
856
+	   if ($returnSQLQueryOrResultType === true) {
857 857
       	return $query;
858 858
       }
859 859
     	return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -865,8 +865,8 @@  discard block
 block discarded – undo
865 865
      * @param  boolean $escape  whether to escape or not the values
866 866
      * @return mixed          the insert id of the new record or null
867 867
      */
868
-    public function insert($data = array(), $escape = true){
869
-      if (empty($data) && $this->getData()){
868
+    public function insert($data = array(), $escape = true) {
869
+      if (empty($data) && $this->getData()) {
870 870
         //as when using $this->setData() the data already escaped
871 871
         $escape = false;
872 872
         $data = $this->getData();
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
       $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
880 880
       $query = $this->query($query);
881 881
 
882
-      if ($query){
882
+      if ($query) {
883 883
         $this->insertId = $this->pdo->lastInsertId();
884 884
         return $this->insertId();
885 885
       }
@@ -892,27 +892,27 @@  discard block
 block discarded – undo
892 892
      * @param  boolean $escape  whether to escape or not the values
893 893
      * @return mixed          the update status
894 894
      */
895
-    public function update($data = array(), $escape = true){
895
+    public function update($data = array(), $escape = true) {
896 896
       $query = 'UPDATE ' . $this->from . ' SET ';
897 897
       $values = array();
898
-      if (empty($data) && $this->getData()){
898
+      if (empty($data) && $this->getData()) {
899 899
         //as when using $this->setData() the data already escaped
900 900
         $escape = false;
901 901
         $data = $this->getData();
902 902
       }
903
-      foreach ($data as $column => $val){
903
+      foreach ($data as $column => $val) {
904 904
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
905 905
       }
906 906
       $query .= implode(', ', $values);
907
-      if (! empty($this->where)){
907
+      if (!empty($this->where)) {
908 908
         $query .= ' WHERE ' . $this->where;
909 909
       }
910 910
 
911
-      if (! empty($this->orderBy)){
911
+      if (!empty($this->orderBy)) {
912 912
         $query .= ' ORDER BY ' . $this->orderBy;
913 913
       }
914 914
 
915
-      if (! empty($this->limit)){
915
+      if (!empty($this->limit)) {
916 916
         $query .= ' LIMIT ' . $this->limit;
917 917
       }
918 918
       return $this->query($query);
@@ -922,22 +922,22 @@  discard block
 block discarded – undo
922 922
      * Delete the record in database
923 923
      * @return mixed the delete status
924 924
      */
925
-    public function delete(){
925
+    public function delete() {
926 926
     	$query = 'DELETE FROM ' . $this->from;
927 927
 
928
-    	if (! empty($this->where)){
928
+    	if (!empty($this->where)) {
929 929
     		$query .= ' WHERE ' . $this->where;
930 930
       	}
931 931
 
932
-    	if (! empty($this->orderBy)){
932
+    	if (!empty($this->orderBy)) {
933 933
     	  $query .= ' ORDER BY ' . $this->orderBy;
934 934
       	}
935 935
 
936
-    	if (! empty($this->limit)){
936
+    	if (!empty($this->limit)) {
937 937
     		$query .= ' LIMIT ' . $this->limit;
938 938
       	}
939 939
 
940
-    	if ($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite'){  
940
+    	if ($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite') {  
941 941
     		$query = 'TRUNCATE TABLE ' . $this->from;
942 942
       }
943 943
     	return $this->query($query);
@@ -948,8 +948,8 @@  discard block
 block discarded – undo
948 948
      * @param integer $ttl the cache time to live in second
949 949
      * @return object        the current Database instance
950 950
      */
951
-    public function setCache($ttl = 0){
952
-      if ($ttl > 0){
951
+    public function setCache($ttl = 0) {
952
+      if ($ttl > 0) {
953 953
         $this->cacheTtl = $ttl;
954 954
 		    $this->temporaryCacheTtl = $ttl;
955 955
       }
@@ -961,8 +961,8 @@  discard block
 block discarded – undo
961 961
 	 * @param  integer $ttl the cache time to live in second
962 962
 	 * @return object        the current Database instance
963 963
 	 */
964
-	public function cached($ttl = 0){
965
-      if ($ttl > 0){
964
+	public function cached($ttl = 0) {
965
+      if ($ttl > 0) {
966 966
         $this->temporaryCacheTtl = $ttl;
967 967
       }
968 968
 	  return $this;
@@ -974,9 +974,9 @@  discard block
 block discarded – undo
974 974
      * @param boolean $escaped whether we can do escape of not 
975 975
      * @return mixed       the data after escaped or the same data if not
976 976
      */
977
-    public function escape($data, $escaped = true){
978
-      if ($escaped){
979
-        if (! $this->pdo){
977
+    public function escape($data, $escaped = true) {
978
+      if ($escaped) {
979
+        if (!$this->pdo) {
980 980
           $this->connect();
981 981
         }
982 982
         return $this->pdo->quote(trim($data)); 
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
      * Return the number query executed count for the current request
989 989
      * @return int
990 990
      */
991
-    public function queryCount(){
991
+    public function queryCount() {
992 992
       return $this->queryCount;
993 993
     }
994 994
 
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
      * Return the current query SQL string
997 997
      * @return string
998 998
      */
999
-    public function getQuery(){
999
+    public function getQuery() {
1000 1000
       return $this->query;
1001 1001
     }
1002 1002
 
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
      * Return the application database name
1005 1005
      * @return string
1006 1006
      */
1007
-    public function getDatabaseName(){
1007
+    public function getDatabaseName() {
1008 1008
       return $this->databaseName;
1009 1009
     }
1010 1010
 
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
      * Return the database configuration
1013 1013
      * @return array
1014 1014
      */
1015
-    public  function getDatabaseConfiguration(){
1015
+    public  function getDatabaseConfiguration() {
1016 1016
       return $this->config;
1017 1017
     }
1018 1018
 
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
      * set the database configuration
1021 1021
      * @param array $config the configuration
1022 1022
      */
1023
-    public function setDatabaseConfiguration(array $config){
1023
+    public function setDatabaseConfiguration(array $config) {
1024 1024
       $this->config = array_merge($this->config, $config);
1025 1025
       $this->prefix = $this->config['prefix'];
1026 1026
       $this->databaseName = $this->config['database'];
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
      * Return the PDO instance
1033 1033
      * @return PDO
1034 1034
      */
1035
-    public function getPdo(){
1035
+    public function getPdo() {
1036 1036
       return $this->pdo;
1037 1037
     }
1038 1038
 
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
      * Set the PDO instance
1041 1041
      * @param PDO $pdo the pdo object
1042 1042
      */
1043
-    public function setPdo(PDO $pdo){
1043
+    public function setPdo(PDO $pdo) {
1044 1044
       $this->pdo = $pdo;
1045 1045
       return $this;
1046 1046
     }
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
      * Return the Log instance
1051 1051
      * @return Log
1052 1052
      */
1053
-    public function getLogger(){
1053
+    public function getLogger() {
1054 1054
       return $this->logger;
1055 1055
     }
1056 1056
 
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
      * Set the log instance
1059 1059
      * @param Log $logger the log object
1060 1060
      */
1061
-    public function setLogger($logger){
1061
+    public function setLogger($logger) {
1062 1062
       $this->logger = $logger;
1063 1063
       return $this;
1064 1064
     }
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
      * Return the cache instance
1068 1068
      * @return CacheInterface
1069 1069
      */
1070
-    public function getCacheInstance(){
1070
+    public function getCacheInstance() {
1071 1071
       return $this->cacheInstance;
1072 1072
     }
1073 1073
 
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
      * Set the cache instance
1076 1076
      * @param CacheInterface $cache the cache object
1077 1077
      */
1078
-    public function setCacheInstance($cache){
1078
+    public function setCacheInstance($cache) {
1079 1079
       $this->cacheInstance = $cache;
1080 1080
       return $this;
1081 1081
     }
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
      * Return the benchmark instance
1085 1085
      * @return Benchmark
1086 1086
      */
1087
-    public function getBenchmark(){
1087
+    public function getBenchmark() {
1088 1088
       return $this->benchmarkInstance;
1089 1089
     }
1090 1090
 
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
      * Set the benchmark instance
1093 1093
      * @param Benchmark $cache the cache object
1094 1094
      */
1095
-    public function setBenchmark($benchmark){
1095
+    public function setBenchmark($benchmark) {
1096 1096
       $this->benchmarkInstance = $benchmark;
1097 1097
       return $this;
1098 1098
     }
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
      * Return the data to be used for insert, update, etc.
1102 1102
      * @return array
1103 1103
      */
1104
-    public function getData(){
1104
+    public function getData() {
1105 1105
       return $this->data;
1106 1106
     }
1107 1107
 
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
      * @param boolean $escape whether to escape or not the $value
1113 1113
      * @return object        the current Database instance
1114 1114
      */
1115
-    public function setData($key, $value, $escape = true){
1115
+    public function setData($key, $value, $escape = true) {
1116 1116
       $this->data[$key] = $this->escape($value, $escape);
1117 1117
       return $this;
1118 1118
     }
@@ -1125,14 +1125,14 @@  discard block
 block discarded – undo
1125 1125
      * @param  boolean $array return the result as array
1126 1126
      * @return mixed         the query result
1127 1127
      */
1128
-    public function query($query, $all = true, $array = false){
1128
+    public function query($query, $all = true, $array = false) {
1129 1129
       $this->reset();
1130 1130
       $query = $this->transformPreparedQuery($query, $all);
1131 1131
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
1132 1132
       
1133 1133
       $isSqlSELECTQuery = stristr($this->query, 'SELECT');
1134 1134
 
1135
-      $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . (is_bool($all) && $all ? 'YES':'NO'));
1135
+      $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . (is_bool($all) && $all ? 'YES' : 'NO'));
1136 1136
       //cache expire time
1137 1137
       $cacheExpire = $this->temporaryCacheTtl;
1138 1138
       
@@ -1148,15 +1148,15 @@  discard block
 block discarded – undo
1148 1148
       //if can use cache feature for this query
1149 1149
       $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
1150 1150
     
1151
-      if ($dbCacheStatus && $isSqlSELECTQuery){
1151
+      if ($dbCacheStatus && $isSqlSELECTQuery) {
1152 1152
           $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
1153 1153
           $cacheContent = $this->getCacheContentForQuery($query, $all, $array);  
1154 1154
       }
1155 1155
       
1156
-      if ( !$cacheContent){
1156
+      if (!$cacheContent) {
1157 1157
         $sqlQuery = $this->runSqlQuery($query, $all, $array);
1158
-        if (is_object($sqlQuery)){
1159
-          if ($isSqlSELECTQuery){
1158
+        if (is_object($sqlQuery)) {
1159
+          if ($isSqlSELECTQuery) {
1160 1160
             $this->setQueryResultForSelect($sqlQuery, $all, $array);
1161 1161
             $this->setCacheContentForQuery(
1162 1162
                                             $this->query, 
@@ -1166,20 +1166,20 @@  discard block
 block discarded – undo
1166 1166
                                             $this->temporaryCacheTtl
1167 1167
                                           );
1168 1168
           }
1169
-          else{
1169
+          else {
1170 1170
               $this->setQueryResultForNonSelect($sqlQuery);
1171
-              if (! $this->result){
1171
+              if (!$this->result) {
1172 1172
                 $this->setQueryError();
1173 1173
               }
1174 1174
           }
1175 1175
         }
1176
-      } else if ($isSqlSELECTQuery){
1177
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
1176
+      } else if ($isSqlSELECTQuery) {
1177
+          $this->logger->info('The result for query [' . $this->query . '] already cached use it');
1178 1178
           $this->result = $cacheContent;
1179 1179
           $this->numRows = count($this->result);
1180 1180
       }
1181 1181
       $this->queryCount++;
1182
-      if (! $this->result){
1182
+      if (!$this->result) {
1183 1183
         $this->logger->info('No result where found for the query [' . $query . ']');
1184 1184
       }
1185 1185
       return $this->result;
@@ -1190,12 +1190,12 @@  discard block
 block discarded – undo
1190 1190
      * Set the Log instance using argument or create new instance
1191 1191
      * @param object $logger the Log instance if not null
1192 1192
      */
1193
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
1194
-      if ($logger !== null){
1193
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
1194
+      if ($logger !== null) {
1195 1195
         $this->logger = $logger;
1196 1196
       }
1197
-      else{
1198
-          $this->logger =& class_loader('Log', 'classes');
1197
+      else {
1198
+          $this->logger = & class_loader('Log', 'classes');
1199 1199
           $this->logger->setLogger('Library::Database');
1200 1200
       }
1201 1201
     }
@@ -1204,14 +1204,14 @@  discard block
 block discarded – undo
1204 1204
     * Setting the database configuration using the configuration file
1205 1205
     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
1206 1206
     */
1207
-    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()){
1207
+    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()) {
1208 1208
         $db = array();
1209
-        if (file_exists(CONFIG_PATH . 'database.php')){
1209
+        if (file_exists(CONFIG_PATH . 'database.php')) {
1210 1210
             //here don't use require_once because somewhere user can create database instance directly
1211 1211
             require CONFIG_PATH . 'database.php';
1212 1212
         }
1213 1213
           
1214
-        if (! empty($overwriteConfig)){
1214
+        if (!empty($overwriteConfig)) {
1215 1215
           $db = array_merge($db, $overwriteConfig);
1216 1216
         }
1217 1217
         $config = array(
@@ -1233,9 +1233,9 @@  discard block
 block discarded – undo
1233 1233
      * This method is used to get the PDO DSN string using th configured driver
1234 1234
      * @return string the DSN string
1235 1235
      */
1236
-    protected function getDsnFromDriver(){
1236
+    protected function getDsnFromDriver() {
1237 1237
       $config = $this->getDatabaseConfiguration();
1238
-      if (! empty($config)){
1238
+      if (!empty($config)) {
1239 1239
             $driverDsnMap = array(
1240 1240
                                     'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
1241 1241
                                                 . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') 
@@ -1257,10 +1257,10 @@  discard block
 block discarded – undo
1257 1257
      * Set the database server port configuration using the current hostname like localhost:3309 
1258 1258
      * @return void
1259 1259
      */
1260
-    protected function setPortConfigurationFromHostname(){
1261
-      if (strstr($this->config['hostname'], ':')){
1260
+    protected function setPortConfigurationFromHostname() {
1261
+      if (strstr($this->config['hostname'], ':')) {
1262 1262
         $p = explode(':', $this->config['hostname']);
1263
-        if (count($p) >= 2){
1263
+        if (count($p) >= 2) {
1264 1264
           $this->setDatabaseConfiguration(array(
1265 1265
             'hostname' => $p[0],
1266 1266
             'port' => $p[1]
@@ -1275,15 +1275,15 @@  discard block
 block discarded – undo
1275 1275
      *
1276 1276
      * @return string
1277 1277
      */
1278
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
1278
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
1279 1279
         $_where = array();
1280
-        foreach ($where as $column => $data){
1281
-          if (is_null($data)){
1280
+        foreach ($where as $column => $data) {
1281
+          if (is_null($data)) {
1282 1282
             $data = '';
1283 1283
           }
1284 1284
           $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
1285 1285
         }
1286
-        $where = implode(' '.$andOr.' ', $_where);
1286
+        $where = implode(' ' . $andOr . ' ', $_where);
1287 1287
         return $where;
1288 1288
     }
1289 1289
 
@@ -1293,12 +1293,12 @@  discard block
 block discarded – undo
1293 1293
      *
1294 1294
      * @return string
1295 1295
      */
1296
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
1296
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
1297 1297
        $x = explode('?', $where);
1298 1298
        $w = '';
1299
-        foreach($x as $k => $v){
1300
-          if (! empty($v)){
1301
-              if (isset($op[$k]) && is_null($op[$k])){
1299
+        foreach ($x as $k => $v) {
1300
+          if (!empty($v)) {
1301
+              if (isset($op[$k]) && is_null($op[$k])) {
1302 1302
                 $op[$k] = '';
1303 1303
               }
1304 1304
               $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -1313,16 +1313,16 @@  discard block
 block discarded – undo
1313 1313
      *
1314 1314
      * @return string
1315 1315
      */
1316
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
1316
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
1317 1317
        $w = '';
1318
-       if (! in_array((string)$op, $this->operatorList)){
1319
-          if (is_null($op)){
1318
+       if (!in_array((string) $op, $this->operatorList)) {
1319
+          if (is_null($op)) {
1320 1320
             $op = '';
1321 1321
           }
1322 1322
           $w = $type . $where . ' = ' . ($this->escape($op, $escape));
1323 1323
         }
1324
-        else{
1325
-          if (is_null($val)){
1324
+        else {
1325
+          if (is_null($val)) {
1326 1326
             $val = '';
1327 1327
           }
1328 1328
           $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -1335,16 +1335,16 @@  discard block
 block discarded – undo
1335 1335
        * @param string $whereStr the WHERE clause string
1336 1336
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
1337 1337
        */
1338
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
1339
-        if (empty($this->where)){
1338
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
1339
+        if (empty($this->where)) {
1340 1340
           $this->where = $whereStr;
1341 1341
         }
1342
-        else{
1343
-          if (substr($this->where, -1) == '('){
1342
+        else {
1343
+          if (substr($this->where, -1) == '(') {
1344 1344
             $this->where = $this->where . ' ' . $whereStr;
1345 1345
           }
1346
-          else{
1347
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
1346
+          else {
1347
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
1348 1348
           }
1349 1349
         }
1350 1350
       }
@@ -1355,12 +1355,12 @@  discard block
 block discarded – undo
1355 1355
      *
1356 1356
      * @return string
1357 1357
      */
1358
-    protected function transformPreparedQuery($query, $data){
1359
-      if (is_array($data)){
1358
+    protected function transformPreparedQuery($query, $data) {
1359
+      if (is_array($data)) {
1360 1360
         $x = explode('?', $query);
1361 1361
         $q = '';
1362
-        foreach($x as $k => $v){
1363
-          if (! empty($v)){
1362
+        foreach ($x as $k => $v) {
1363
+          if (!empty($v)) {
1364 1364
             $q .= $v . (isset($data[$k]) ? $this->escape($data[$k]) : '');
1365 1365
           }
1366 1366
         }
@@ -1375,8 +1375,8 @@  discard block
 block discarded – undo
1375 1375
      * 
1376 1376
      *  @return string
1377 1377
      */
1378
-    protected function getCacheBenchmarkKeyForQuery($query, $all, $array){
1379
-      if (is_array($all)){
1378
+    protected function getCacheBenchmarkKeyForQuery($query, $all, $array) {
1379
+      if (is_array($all)) {
1380 1380
         $all = 'array';
1381 1381
       }
1382 1382
       return md5($query . $all . $array);
@@ -1388,9 +1388,9 @@  discard block
 block discarded – undo
1388 1388
      *      
1389 1389
      * @return mixed
1390 1390
      */
1391
-    protected function getCacheContentForQuery($query, $all, $array){
1391
+    protected function getCacheContentForQuery($query, $all, $array) {
1392 1392
         $cacheKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
1393
-        if (is_object($this->cacheInstance)){
1393
+        if (is_object($this->cacheInstance)) {
1394 1394
           return $this->cacheInstance->get($cacheKey);
1395 1395
         }
1396 1396
         $instance = & get_instance()->cache;
@@ -1406,9 +1406,9 @@  discard block
 block discarded – undo
1406 1406
      * @param boolean $status whether can save the query result into cache
1407 1407
      * @param int $expire the cache TTL
1408 1408
      */
1409
-     protected function setCacheContentForQuery($query, $key, $result, $status, $expire){
1410
-        if ($status){
1411
-            $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
1409
+     protected function setCacheContentForQuery($query, $key, $result, $status, $expire) {
1410
+        if ($status) {
1411
+            $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
1412 1412
             $this->getCacheInstance()->set($key, $result, $expire);
1413 1413
         }
1414 1414
      }
@@ -1417,19 +1417,19 @@  discard block
 block discarded – undo
1417 1417
      * Set the result for SELECT query using PDOStatment
1418 1418
      * @see Database::query
1419 1419
      */
1420
-    protected function setQueryResultForSelect($pdoStatment, $all, $array){
1420
+    protected function setQueryResultForSelect($pdoStatment, $all, $array) {
1421 1421
       //if need return all result like list of record
1422
-      if (is_bool($all) && $all){
1422
+      if (is_bool($all) && $all) {
1423 1423
           $this->result = ($array === false) ? $pdoStatment->fetchAll(PDO::FETCH_OBJ) : $pdoStatment->fetchAll(PDO::FETCH_ASSOC);
1424 1424
       }
1425
-      else{
1425
+      else {
1426 1426
           $this->result = ($array === false) ? $pdoStatment->fetch(PDO::FETCH_OBJ) : $pdoStatment->fetch(PDO::FETCH_ASSOC);
1427 1427
       }
1428 1428
       //Sqlite and pgsql always return 0 when using rowCount()
1429
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1429
+      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1430 1430
         $this->numRows = count($this->result);  
1431 1431
       }
1432
-      else{
1432
+      else {
1433 1433
         $this->numRows = $pdoStatment->rowCount(); 
1434 1434
       }
1435 1435
     }
@@ -1438,13 +1438,13 @@  discard block
 block discarded – undo
1438 1438
      * Set the result for other command than SELECT query using PDOStatment
1439 1439
      * @see Database::query
1440 1440
      */
1441
-    protected function setQueryResultForNonSelect($pdoStatment){
1441
+    protected function setQueryResultForNonSelect($pdoStatment) {
1442 1442
       //Sqlite and pgsql always return 0 when using rowCount()
1443
-      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1443
+      if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1444 1444
         $this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE
1445 1445
         $this->numRows = 1;  
1446 1446
       }
1447
-      else{
1447
+      else {
1448 1448
           $this->result = $pdoStatment->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
1449 1449
           $this->numRows = $pdoStatment->rowCount(); 
1450 1450
       }
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
     /**
1454 1454
      * Set error for database query execution
1455 1455
      */
1456
-    protected function setQueryError(){
1456
+    protected function setQueryError() {
1457 1457
       $error = $this->pdo->errorInfo();
1458 1458
       $this->error = isset($error[2]) ? $error[2] : '';
1459 1459
       $this->logger->error('The database query execution got error: ' . stringfy_vars($error));
@@ -1466,16 +1466,16 @@  discard block
 block discarded – undo
1466 1466
      * 
1467 1467
      * @return object|void
1468 1468
      */
1469
-    protected function runSqlQuery($query, $all, $array){
1469
+    protected function runSqlQuery($query, $all, $array) {
1470 1470
        //for database query execution time
1471 1471
         $benchmarkMarkerKey = $this->getCacheBenchmarkKeyForQuery($query, $all, $array);
1472 1472
         $benchmarkInstance = $this->getBenchmark();
1473
-        if (! is_object($benchmarkInstance)){
1473
+        if (!is_object($benchmarkInstance)) {
1474 1474
           $obj = & get_instance();
1475 1475
           $benchmarkInstance = $obj->benchmark; 
1476 1476
           $this->setBenchmark($benchmarkInstance);
1477 1477
         }
1478
-        if (! $this->pdo){
1478
+        if (!$this->pdo) {
1479 1479
             $this->connect();
1480 1480
         }
1481 1481
         
@@ -1486,10 +1486,10 @@  discard block
 block discarded – undo
1486 1486
         //get response time for this query
1487 1487
         $responseTime = $benchmarkInstance->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
1488 1488
         //TODO use the configuration value for the high response time currently is 1 second
1489
-        if ($responseTime >= 1 ){
1490
-            $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
1489
+        if ($responseTime >= 1) {
1490
+            $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.');
1491 1491
         }
1492
-        if ($sqlQuery){
1492
+        if ($sqlQuery) {
1493 1493
           return $sqlQuery;
1494 1494
         }
1495 1495
         $this->setQueryError();
@@ -1498,7 +1498,7 @@  discard block
 block discarded – undo
1498 1498
     /**
1499 1499
      * Reset the database class attributs to the initail values before each query.
1500 1500
      */
1501
-    private function reset(){
1501
+    private function reset() {
1502 1502
       $this->select   = '*';
1503 1503
       $this->from     = null;
1504 1504
       $this->where    = null;
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
     /**
1519 1519
      * The class destructor
1520 1520
      */
1521
-    public function __destruct(){
1521
+    public function __destruct() {
1522 1522
       $this->pdo = null;
1523 1523
   }
1524 1524
 
Please login to merge, or discard this patch.
core/classes/Module.php 1 patch
Spacing   +84 added lines, -84 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 Module{
27
+	class Module {
28 28
 		
29 29
 		/**
30 30
 		 * list of loaded module
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
47
-				self::$logger[0] =& class_loader('Log', 'classes');
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47
+				self::$logger[0] = & class_loader('Log', 'classes');
48 48
 				self::$logger[0]->setLogger('Library::Module');
49 49
 			}
50 50
 			return self::$logger[0];
@@ -53,27 +53,27 @@  discard block
 block discarded – undo
53 53
 		/**
54 54
 		 * Initialise the module list by scanning the directory MODULE_PATH
55 55
 		 */
56
-		public function init(){
56
+		public function init() {
57 57
 			$logger = self::getLogger();
58 58
 			$logger->debug('Check if the application contains the modules ...');
59 59
 			$moduleDir = opendir(MODULE_PATH);
60
-			if(is_resource($moduleDir)){
61
-				while(($module = readdir($moduleDir)) !== false){
62
-					if($module != '.' && $module != '..'  && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
60
+			if (is_resource($moduleDir)) {
61
+				while (($module = readdir($moduleDir)) !== false) {
62
+					if ($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) {
63 63
 						self::$list[] = $module;
64 64
 					}
65
-					else{
66
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
65
+					else {
66
+						$logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name');
67 67
 					}
68 68
 				}
69 69
 				closedir($moduleDir);
70 70
 			}
71 71
 			ksort(self::$list);
72 72
 			
73
-			if(self::hasModule()){
73
+			if (self::hasModule()) {
74 74
 				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
75 75
 			}
76
-			else{
76
+			else {
77 77
 				$logger->info('The application contains no module skipping');
78 78
 			}
79 79
 		}
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 		 * Get the list of the custom autoload configuration from module if exists
83 83
 		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
84 84
 		 */
85
-		public static function getModulesAutoloadConfig(){
85
+		public static function getModulesAutoloadConfig() {
86 86
 			$logger = self::getLogger();
87
-			if(! self::hasModule()){
87
+			if (!self::hasModule()) {
88 88
 				$logger->info('No module was loaded skipping.');
89 89
 				return false;
90 90
 			}
@@ -97,27 +97,27 @@  discard block
 block discarded – undo
97 97
 			
98 98
 			foreach (self::$list as $module) {
99 99
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
100
-				if(file_exists($file)){
100
+				if (file_exists($file)) {
101 101
 					require_once $file;
102
-					if(! empty($autoload) && is_array($autoload)){
102
+					if (!empty($autoload) && is_array($autoload)) {
103 103
 						//libraries autoload
104
-						if(! empty($autoload['libraries']) && is_array($autoload['libraries'])){
104
+						if (!empty($autoload['libraries']) && is_array($autoload['libraries'])) {
105 105
 							$autoloads['libraries'] = array_merge($autoloads['libraries'], $autoload['libraries']);
106 106
 						}
107 107
 						//config autoload
108
-						if(! empty($autoload['config']) && is_array($autoload['config'])){
108
+						if (!empty($autoload['config']) && is_array($autoload['config'])) {
109 109
 							$autoloads['config'] = array_merge($autoloads['config'], $autoload['config']);
110 110
 						}
111 111
 						//models autoload
112
-						if(! empty($autoload['models']) && is_array($autoload['models'])){
112
+						if (!empty($autoload['models']) && is_array($autoload['models'])) {
113 113
 							$autoloads['models'] = array_merge($autoloads['models'], $autoload['models']);
114 114
 						}
115 115
 						//functions autoload
116
-						if(! empty($autoload['functions']) && is_array($autoload['functions'])){
116
+						if (!empty($autoload['functions']) && is_array($autoload['functions'])) {
117 117
 							$autoloads['functions'] = array_merge($autoloads['functions'], $autoload['functions']);
118 118
 						}
119 119
 						//languages autoload
120
-						if(! empty($autoload['languages']) && is_array($autoload['languages'])){
120
+						if (!empty($autoload['languages']) && is_array($autoload['languages'])) {
121 121
 							$autoloads['languages'] = array_merge($autoloads['languages'], $autoload['languages']);
122 122
 						}
123 123
 						unset($autoload);
@@ -131,23 +131,23 @@  discard block
 block discarded – undo
131 131
 		 * Get the list of the custom routes configuration from module if exists
132 132
 		 * @return array|boolean the routes list or false if no module contains the routes configuration
133 133
 		 */
134
-		public static function getModulesRoutes(){
134
+		public static function getModulesRoutes() {
135 135
 			$logger = self::getLogger();
136
-			if(! self::hasModule()){
136
+			if (!self::hasModule()) {
137 137
 				$logger->info('No module was loaded skipping.');
138 138
 				return false;
139 139
 			}
140 140
 			$routes = array();
141 141
 			foreach (self::$list as $module) {
142 142
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
143
-				if(file_exists($file)){
143
+				if (file_exists($file)) {
144 144
 					require_once $file;
145
-					if(! empty($route) && is_array($route)){
145
+					if (!empty($route) && is_array($route)) {
146 146
 						$routes = array_merge($routes, $route);
147 147
 						unset($route);
148 148
 					}
149
-					else{
150
-						show_error('No routing configuration found in [' .$file. '] for module [' . $module . ']');
149
+					else {
150
+						show_error('No routing configuration found in [' . $file . '] for module [' . $module . ']');
151 151
 					}
152 152
 				}
153 153
 			}
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
 		 * @param  string $module  the module name
162 162
 		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
163 163
 		 */
164
-		public static function findControllerFullPath($class, $module = null){
164
+		public static function findControllerFullPath($class, $module = null) {
165 165
 			$logger = self::getLogger();
166
-			if(! self::hasModule()){
166
+			if (!self::hasModule()) {
167 167
 				$logger->info('No module was loaded skiping.');
168 168
 				return false;
169 169
 			}
170 170
 			$class = str_ireplace('.php', '', $class);
171 171
 			$class = ucfirst($class);
172
-			$classFile = $class.'.php';
173
-			$logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
172
+			$classFile = $class . '.php';
173
+			$logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...');
174 174
 			$filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
175
-			if(file_exists($filePath)){
176
-				$logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
175
+			if (file_exists($filePath)) {
176
+				$logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
177 177
 				return $filePath;
178 178
 			}
179
-			else{
180
-				$logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
179
+			else {
180
+				$logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']');
181 181
 				return false;
182 182
 			}
183 183
 		}
@@ -188,23 +188,23 @@  discard block
 block discarded – undo
188 188
 		 * @param string $module the module name
189 189
 		 * @return boolean|string  false or null if no module have this model, return the full path of this model
190 190
 		 */
191
-		public static function findModelFullPath($class, $module = null){
191
+		public static function findModelFullPath($class, $module = null) {
192 192
 			$logger = self::getLogger();
193
-			if(! self::hasModule()){
193
+			if (!self::hasModule()) {
194 194
 				$logger->info('No module was loaded skiping.');
195 195
 				return false;
196 196
 			}
197 197
 			$class = str_ireplace('.php', '', $class);
198 198
 			$class = ucfirst($class);
199
-			$classFile = $class.'.php';
200
-			$logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
199
+			$classFile = $class . '.php';
200
+			$logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...');
201 201
 			$filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
202
-			if(file_exists($filePath)){
203
-				$logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
202
+			if (file_exists($filePath)) {
203
+				$logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
204 204
 				return $filePath;
205 205
 			}
206
-			else{
207
-				$logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
206
+			else {
207
+				$logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']');
208 208
 				return false;
209 209
 			}
210 210
 		}
@@ -215,22 +215,22 @@  discard block
 block discarded – undo
215 215
 		 * @param string $module the module name
216 216
 		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
217 217
 		 */
218
-		public static function findConfigFullPath($configuration, $module = null){
218
+		public static function findConfigFullPath($configuration, $module = null) {
219 219
 			$logger = self::getLogger();
220
-			if(! self::hasModule()){
220
+			if (!self::hasModule()) {
221 221
 				$logger->info('No module was loaded skiping.');
222 222
 				return false;
223 223
 			}
224 224
 			$configuration = str_ireplace('.php', '', $configuration);
225
-			$file = $configuration.'.php';
226
-			$logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
225
+			$file = $configuration . '.php';
226
+			$logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...');
227 227
 			$filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
228
-			if(file_exists($filePath)){
229
-				$logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
228
+			if (file_exists($filePath)) {
229
+				$logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']');
230 230
 				return $filePath;
231 231
 			}
232
-			else{
233
-				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
232
+			else {
233
+				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']');
234 234
 				return false;
235 235
 			}
236 236
 		}
@@ -241,23 +241,23 @@  discard block
 block discarded – undo
241 241
 		 * @param string $module the module name
242 242
 		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
243 243
 		 */
244
-		public static function findFunctionFullPath($helper, $module = null){
244
+		public static function findFunctionFullPath($helper, $module = null) {
245 245
 			$logger = self::getLogger();
246
-			if(! self::hasModule()){
246
+			if (!self::hasModule()) {
247 247
 				$logger->info('No module was loaded skiping.');
248 248
 				return false;
249 249
 			}
250 250
 			$helper = str_ireplace('.php', '', $helper);
251 251
 			$helper = str_ireplace('function_', '', $helper);
252
-			$file = 'function_'.$helper.'.php';
253
-			$logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
252
+			$file = 'function_' . $helper . '.php';
253
+			$logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...');
254 254
 			$filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
255
-			if(file_exists($filePath)){
256
-				$logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
255
+			if (file_exists($filePath)) {
256
+				$logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']');
257 257
 				return $filePath;
258 258
 			}
259
-			else{
260
-				$logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
259
+			else {
260
+				$logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']');
261 261
 				return false;
262 262
 			}
263 263
 		}
@@ -269,22 +269,22 @@  discard block
 block discarded – undo
269 269
 		 * @param string $module the module name
270 270
 		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
271 271
 		 */
272
-		public static function findLibraryFullPath($class, $module = null){
272
+		public static function findLibraryFullPath($class, $module = null) {
273 273
 			$logger = self::getLogger();
274
-			if(! self::hasModule()){
274
+			if (!self::hasModule()) {
275 275
 				$logger->info('No module was loaded skiping.');
276 276
 				return false;
277 277
 			}
278 278
 			$class = str_ireplace('.php', '', $class);
279
-			$file = $class.'.php';
280
-			$logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
279
+			$file = $class . '.php';
280
+			$logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...');
281 281
 			$filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
282
-			if(file_exists($filePath)){
283
-				$logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
282
+			if (file_exists($filePath)) {
283
+				$logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
284 284
 				return $filePath;
285 285
 			}
286
-			else{
287
-				$logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
286
+			else {
287
+				$logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']');
288 288
 				return false;
289 289
 			}
290 290
 		}
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 		 * @param string $module the module name to check
297 297
 		 * @return boolean|string  false or null if no module have this view, path the full path of the view
298 298
 		 */
299
-		public static function findViewFullPath($view, $module = null){
299
+		public static function findViewFullPath($view, $module = null) {
300 300
 			$logger = self::getLogger();
301
-			if(! self::hasModule()){
301
+			if (!self::hasModule()) {
302 302
 				$logger->info('No module was loaded skiping.');
303 303
 				return false;
304 304
 			}
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 			$view = trim($view, '/\\');
307 307
 			$view = str_ireplace('/', DS, $view);
308 308
 			$viewFile = $view . '.php';
309
-			$logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
309
+			$logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...');
310 310
 			$filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
311
-			if(file_exists($filePath)){
312
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
311
+			if (file_exists($filePath)) {
312
+				$logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']');
313 313
 				return $filePath;
314 314
 			}
315
-			else{
316
-				$logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
315
+			else {
316
+				$logger->info('View [' . $view . '] does not exist in the module [' . $module . ']');
317 317
 				return false;
318 318
 			}
319 319
 		}
@@ -325,23 +325,23 @@  discard block
 block discarded – undo
325 325
 		 * @param string $appLang the application language like 'en', 'fr'
326 326
 		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
327 327
 		 */
328
-		public static function findLanguageFullPath($language, $module = null, $appLang){
328
+		public static function findLanguageFullPath($language, $module = null, $appLang) {
329 329
 			$logger = self::getLogger();
330
-			if(! self::hasModule()){
330
+			if (!self::hasModule()) {
331 331
 				$logger->info('No module was loaded skiping.');
332 332
 				return false;
333 333
 			}
334 334
 			$language = str_ireplace('.php', '', $language);
335 335
 			$language = str_ireplace('lang_', '', $language);
336
-			$file = 'lang_'.$language.'.php';
337
-			$logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
336
+			$file = 'lang_' . $language . '.php';
337
+			$logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...');
338 338
 			$filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
339
-			if(file_exists($filePath)){
340
-				$logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
339
+			if (file_exists($filePath)) {
340
+				$logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']');
341 341
 				return $filePath;
342 342
 			}
343
-			else{
344
-				$logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
343
+			else {
344
+				$logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']');
345 345
 				return false;
346 346
 			}
347 347
 		}
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 		 * Get the list of module loaded
351 351
 		 * @return array the module list
352 352
 		 */
353
-		public static function getModuleList(){
353
+		public static function getModuleList() {
354 354
 			return self::$list;
355 355
 		}
356 356
 
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 		 * Check if the application has an module
359 359
 		 * @return boolean
360 360
 		 */
361
-		public static function hasModule(){
361
+		public static function hasModule() {
362 362
 			return !empty(self::$list);
363 363
 		}
364 364
 
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload{
40
+    class Upload {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
         *    @return    object
218 218
         *    @method    object    __construct
219 219
         */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
220
+        public function __construct() {
221
+            $this->logger = & class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
223 223
 
224 224
             Loader::lang('file_upload');
225
-            $obj =& get_instance();
225
+            $obj = & get_instance();
226 226
 
227 227
             $this->error_messages = array(
228 228
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
             );
240 240
 
241 241
             $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
242
+                'status'                =>    false, // True: success upload
243
+                'mime'                  =>    '', // Empty string
244
+                'filename'              =>    '', // Empty string
245
+                'original'              =>    '', // Empty string
246
+                'size'                  =>    0, // 0 Bytes
247
+                'sizeFormated'          =>    '0B', // 0 Bytes
248
+                'destination'           =>    './', // Default: ./
249
+                'allowed_mime_types'    =>    array(), // Allowed mime types
250
+                'error'                 =>    null, // File error
251 251
             );
252 252
 
253 253
             // Change dir to current dir
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             } elseif (isset($HTTP_POST_FILES) && is_array($HTTP_POST_FILES)) {
260 260
                 $this->file_array = $HTTP_POST_FILES;
261 261
             }
262
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
262
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
263 263
         }
264 264
         /**
265 265
         *    Set input.
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         */
276 276
         public function setInput($input)
277 277
         {
278
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
278
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
279 279
                 $this->input = $input;
280 280
             }
281 281
             return $this;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         */
312 312
         public function setAutoFilename()
313 313
         {
314
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
314
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
315 315
             $this->filename .= time();
316 316
             return $this;
317 317
         }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
                 $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
333 333
                 // Calculate difference
334 334
                 if ($php_size < $file_size) {
335
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
335
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
336 336
                 }
337 337
                 $this->max_file_size = $file_size;
338 338
             }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         public function setAllowedMimeTypes(array $mimes)
351 351
         {
352 352
             if (count($mimes) > 0) {
353
-                array_map(array($this , 'setAllowMimeType'), $mimes);
353
+                array_map(array($this, 'setAllowMimeType'), $mimes);
354 354
             }
355 355
             return $this;
356 356
         }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
         {
416 416
             if (!empty($name) && is_string($name)) {
417 417
                 if (array_key_exists($name, $this->mime_helping)) {
418
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
418
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
419 419
                 }
420 420
             }
421 421
             return $this;
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
         */
435 435
         public function setUploadFunction($function)
436 436
         {
437
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
438
-                if (is_callable( $function)) {
437
+            if (!empty($function) && (is_array($function) || is_string($function))) {
438
+                if (is_callable($function)) {
439 439
                     $this->upload_function = $function;
440 440
                 }
441 441
             }
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
                         $this->destination_directory = $destination_directory;
481 481
                         chdir($destination_directory);
482 482
                     }
483
-                    else{
484
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
483
+                    else {
484
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
485 485
                     }
486 486
                 }
487 487
             }
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         public function isFilename($filename)
532 532
         {
533 533
             $filename = basename($filename);
534
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
534
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
535 535
         }
536 536
         /**
537 537
         *    Validate mime type with allowed mime types,
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
         */
574 574
         public function isDirpath($path)
575 575
         {
576
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
576
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
577 577
                 if (DIRECTORY_SEPARATOR == '/') {
578
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
578
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
579 579
                 } else {
580
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
580
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
581 581
                 }
582 582
             }
583 583
             return false;
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
         */
606 606
         public function getInfo()
607 607
         {
608
-            return (object)$this->file;
608
+            return (object) $this->file;
609 609
         }
610 610
 
611 611
 
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
          * Check if the file is uploaded
614 614
          * @return boolean
615 615
          */
616
-        public function isUploaded(){
616
+        public function isUploaded() {
617 617
             return isset($this->file_array[$this->input])
618 618
             && is_uploaded_file($this->file_array[$this->input]['tmp_name']);
619 619
         }
@@ -622,15 +622,15 @@  discard block
 block discarded – undo
622 622
          * Check if file upload has error
623 623
          * @return boolean
624 624
          */
625
-        protected function uploadHasError(){
625
+        protected function uploadHasError() {
626 626
             //check if file upload is  allowed in the configuration
627
-            if(! ini_get('file_uploads')){
627
+            if (!ini_get('file_uploads')) {
628 628
                 $this->setError($this->error_messages['file_uploads']);
629 629
                 return true;
630 630
             }
631 631
 
632 632
              //check for php upload error
633
-            if(is_numeric($this->file['error']) && $this->file['error'] > 0){
633
+            if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
634 634
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
635 635
                 return true;
636 636
             }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
         *    @return    boolean
666 666
         *    @method    boolean    save
667 667
         */
668
-        public function save(){
668
+        public function save() {
669 669
             if (count($this->file_array) > 0) {
670 670
                 if (array_key_exists($this->input, $this->file_array)) {
671 671
                     // set original filename if not have a new name
672 672
                     if (empty($this->filename)) {
673 673
                         $this->filename = $this->file_array[$this->input]['name'];
674 674
                     }
675
-                    else{
675
+                    else {
676 676
                         // Replace %s for extension in filename
677 677
                         // Before: /[\w\d]*(.[\d\w]+)$/i
678 678
                         // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -696,15 +696,15 @@  discard block
 block discarded – undo
696 696
                     $this->file['filename']     = $this->filename;
697 697
                     $this->file['error']        = $this->file_array[$this->input]['error'];
698 698
 
699
-                    $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
699
+                    $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
700 700
 
701 701
                     $error = $this->uploadHasError();
702
-                    if($error){
702
+                    if ($error) {
703 703
                         return false;
704 704
                     }
705 705
                     // Execute input callback
706
-                    if (!empty( $this->callbacks['input'])) {
707
-                        call_user_func($this->callbacks['input'], (object)$this->file);
706
+                    if (!empty($this->callbacks['input'])) {
707
+                        call_user_func($this->callbacks['input'], (object) $this->file);
708 708
                     }
709 709
                    
710 710
 
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
                     );
717 717
 
718 718
                     // Execute output callback
719
-                    if (!empty( $this->callbacks['output'])) {
720
-                        call_user_func($this->callbacks['output'], (object)$this->file);
719
+                    if (!empty($this->callbacks['output'])) {
720
+                        call_user_func($this->callbacks['output'], (object) $this->file);
721 721
                     }
722 722
                     return $this->file['status'];
723 723
                 }
@@ -736,10 +736,10 @@  discard block
 block discarded – undo
736 736
         */
737 737
         public function sizeFormat($size, $precision = 2)
738 738
         {
739
-            if($size > 0){
739
+            if ($size > 0) {
740 740
                 $base       = log($size) / log(1024);
741 741
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
742
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
742
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
743 743
             }
744 744
             return null;
745 745
         }
@@ -763,14 +763,14 @@  discard block
 block discarded – undo
763 763
             if (array_key_exists('unit', $matches)) {
764 764
                 $unit = strtoupper($matches['unit']);
765 765
             }
766
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
766
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
767 767
         }
768 768
 
769 769
         /**
770 770
          * Get the upload error message
771 771
          * @return string
772 772
          */
773
-        public function getError(){
773
+        public function getError() {
774 774
             return $this->error;
775 775
         }
776 776
 
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
          * Set the upload error message
779 779
          * @param string $message the upload error message to set
780 780
          */
781
-        public function setError($message){
781
+        public function setError($message) {
782 782
             $this->logger->info('The file upload got error : ' . $message);
783 783
             $this->error = $message;
784 784
         }
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
          * @param  int $code the error code
789 789
          * @return string the error message
790 790
          */
791
-        private function getPhpUploadErrorMessageByCode($code){
791
+        private function getPhpUploadErrorMessageByCode($code) {
792 792
             $codeMessageMaps = array(
793 793
                 1 => $this->error_messages['upload_err_ini_size'],
794 794
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
 	 */
30
-	if( !interface_exists('SessionHandlerInterface')){
30
+	if (!interface_exists('SessionHandlerInterface')) {
31 31
 		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
 	}
33 33
 
34
-	class DBSessionHandler implements SessionHandlerInterface{
34
+	class DBSessionHandler implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -81,25 +81,25 @@  discard block
 block discarded – undo
81 81
          */
82 82
         protected $loader = null;
83 83
 
84
-		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){
84
+		public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) {
85 85
 			/**
86 86
 	         * instance of the Log class
87 87
 	         */
88
-	        if(is_object($logger)){
88
+	        if (is_object($logger)) {
89 89
 	          $this->setLogger($logger);
90 90
 	        }
91
-	        else{
92
-	            $this->logger =& class_loader('Log', 'classes');
91
+	        else {
92
+	            $this->logger = & class_loader('Log', 'classes');
93 93
 	            $this->logger->setLogger('Library::DBSessionHandler');
94 94
 	        }
95 95
 
96
-	        if(is_object($loader)){
96
+	        if (is_object($loader)) {
97 97
 	          $this->setLoader($loader);
98 98
 	        }
99 99
 		    $this->OBJ = & get_instance();
100 100
 
101 101
 		    
102
-			if(is_object($modelInstance)){
102
+			if (is_object($modelInstance)) {
103 103
 				$this->setModelInstance($modelInstance);
104 104
 			}
105 105
 		}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		 * Set the session secret used to encrypt the data in database 
109 109
 		 * @param string $secret the base64 string secret
110 110
 		 */
111
-		public function setSessionSecret($secret){
111
+		public function setSessionSecret($secret) {
112 112
 			$this->sessionSecret = $secret;
113 113
 			return $this;
114 114
 		}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Return the session secret
118 118
 		 * @return string 
119 119
 		 */
120
-		public function getSessionSecret(){
120
+		public function getSessionSecret() {
121 121
 			return $this->sessionSecret;
122 122
 		}
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * Set the initializer vector for openssl 
127 127
 		 * @param string $key the session secret used
128 128
 		 */
129
-		public function setInitializerVector($key){
129
+		public function setInitializerVector($key) {
130 130
 			$iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
131 131
 			$key = base64_decode($key);
132 132
 			$this->iv = substr(hash('sha256', $key), 0, $iv_length);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * Return the initializer vector
138 138
 		 * @return string 
139 139
 		 */
140
-		public function getInitializerVector(){
140
+		public function getInitializerVector() {
141 141
 			return $this->iv;
142 142
 		}
143 143
 
@@ -147,17 +147,17 @@  discard block
 block discarded – undo
147 147
 		 * @param  string $sessionName the session name
148 148
 		 * @return boolean 
149 149
 		 */
150
-		public function open($savePath, $sessionName){
150
+		public function open($savePath, $sessionName) {
151 151
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
152 152
 			//try to check if session secret is set before
153 153
 			$secret = $this->getSessionSecret();
154
-			if(empty($secret)){
154
+			if (empty($secret)) {
155 155
 				$secret = get_config('session_secret', null);
156 156
 				$this->setSessionSecret($secret);
157 157
 			}
158 158
 			$this->logger->info('Session secret: ' . $secret);
159 159
 
160
-			if(! $this->getModelInstance()){
160
+			if (!$this->getModelInstance()) {
161 161
 				$this->setModelInstanceFromConfig();
162 162
 			}
163 163
 			$this->setInitializerVector($secret);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 			//set session tables columns
166 166
 			$this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns();
167 167
 
168
-			if(empty($this->sessionTableColumns)){
168
+			if (empty($this->sessionTableColumns)) {
169 169
 				show_error('The session handler is "database" but the table columns not set');
170 170
 			}
171 171
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		 * Close the session
182 182
 		 * @return boolean
183 183
 		 */
184
-		public function close(){
184
+		public function close() {
185 185
 			$this->logger->debug('Closing database session handler');
186 186
 			return true;
187 187
 		}
@@ -191,28 +191,28 @@  discard block
 block discarded – undo
191 191
 		 * @param  string $sid the session id to use
192 192
 		 * @return string      the session data in serialiaze format
193 193
 		 */
194
-		public function read($sid){
194
+		public function read($sid) {
195 195
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
196 196
 			$instance = $this->getModelInstance();
197 197
 			$columns = $this->sessionTableColumns;
198
-			if($this->getLoader()){
198
+			if ($this->getLoader()) {
199 199
 				$this->getLoader()->functions('user_agent'); 
200 200
 				$this->getLoader()->library('Browser'); 
201 201
 			}
202
-			else{
202
+			else {
203 203
             	Loader::functions('user_agent');
204 204
             	Loader::library('Browser');
205 205
             }
206 206
 			
207 207
 			$ip = get_ip();
208 208
 			$host = @gethostbyaddr($ip) or null;
209
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
209
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
210 210
 			
211 211
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
212
-			if($data && isset($data->{$columns['sdata']})){
212
+			if ($data && isset($data->{$columns['sdata']})) {
213 213
 				//checking inactivity 
214 214
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
215
-				if($data->{$columns['stime']} < $timeInactivity){
215
+				if ($data->{$columns['stime']} < $timeInactivity) {
216 216
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
217 217
 					$this->destroy($sid);
218 218
 					return null;
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
 		 * @param  mixed $data the session data to save in serialize format
230 230
 		 * @return boolean 
231 231
 		 */
232
-		public function write($sid, $data){
232
+		public function write($sid, $data) {
233 233
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
234 234
 			$instance = $this->getModelInstance();
235 235
 			$columns = $this->sessionTableColumns;
236 236
 
237
-			if($this->getLoader()){
237
+			if ($this->getLoader()) {
238 238
 				$this->getLoader()->functions('user_agent'); 
239 239
 				$this->getLoader()->library('Browser'); 
240 240
 			}
241
-			else{
241
+			else {
242 242
             	Loader::functions('user_agent');
243 243
             	Loader::library('Browser');
244 244
             }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			$ip = get_ip();
247 247
 			$keyValue = $instance->getKeyValue();
248 248
 			$host = @gethostbyaddr($ip) or null;
249
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
249
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
250 250
 			$data = $this->encode($data);
251 251
 			$params = array(
252 252
 							$columns['sid'] => $sid,
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
 						);
260 260
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
261 261
 			$exists = $instance->get($sid);
262
-			if($exists){
262
+			if ($exists) {
263 263
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
264 264
 				//update
265 265
 				unset($params[$columns['sid']]);
266 266
 				$instance->update($sid, $params);
267 267
 			}
268
-			else{
268
+			else {
269 269
 				$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
270 270
 				$instance->insert($params);
271 271
 			}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		 * @param  string $sid the session id value
279 279
 		 * @return boolean
280 280
 		 */
281
-		public function destroy($sid){
281
+		public function destroy($sid) {
282 282
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
283 283
 			$instance = $this->modelInstanceName;
284 284
 			$instance->delete($sid);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		 * @param  integer $maxLifetime the max lifetime
291 291
 		 * @return boolean
292 292
 		 */
293
-		public function gc($maxLifetime){
293
+		public function gc($maxLifetime) {
294 294
 			$instance = $this->modelInstanceName;
295 295
 			$time = time() - $maxLifetime;
296 296
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
 		 * @param  mixed $data the session data to encode
304 304
 		 * @return mixed the encoded session data
305 305
 		 */
306
-		public function encode($data){
306
+		public function encode($data) {
307 307
 			$key = base64_decode($this->sessionSecret);
308
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
308
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
309 309
 			$output = base64_encode($dataEncrypted);
310 310
 			return $output;
311 311
 		}
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		 * @param  mixed $data the data to decode
317 317
 		 * @return mixed       the decoded data
318 318
 		 */
319
-		public function decode($data){
319
+		public function decode($data) {
320 320
 			$key = base64_decode($this->sessionSecret);
321 321
 			$data = base64_decode($data);
322 322
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
          * Return the loader instance
329 329
          * @return object Loader the loader instance
330 330
          */
331
-        public function getLoader(){
331
+        public function getLoader() {
332 332
             return $this->loader;
333 333
         }
334 334
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
          * set the loader instance for future use
337 337
          * @param object Loader $loader the loader object
338 338
          */
339
-         public function setLoader($loader){
339
+         public function setLoader($loader) {
340 340
             $this->loader = $loader;
341 341
             return $this;
342 342
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
          * Return the model instance
346 346
          * @return object DBSessionHandlerModel the model instance
347 347
          */
348
-        public function getModelInstance(){
348
+        public function getModelInstance() {
349 349
             return $this->modelInstanceName;
350 350
         }
351 351
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
          * set the model instance for future use
354 354
          * @param DBSessionHandlerModel $modelInstance the model object
355 355
          */
356
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
356
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
357 357
             $this->modelInstanceName = $modelInstance;
358 358
             return $this;
359 359
         }
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	     * Return the Log instance
363 363
 	     * @return Log
364 364
 	     */
365
-	    public function getLogger(){
365
+	    public function getLogger() {
366 366
 	      return $this->logger;
367 367
 	    }
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	     * Set the log instance
371 371
 	     * @param Log $logger the log object
372 372
 	     */
373
-	    public function setLogger(Log $logger){
373
+	    public function setLogger(Log $logger) {
374 374
 	      $this->logger = $logger;
375 375
 	      return $this;
376 376
 	    }
@@ -378,18 +378,18 @@  discard block
 block discarded – undo
378 378
 	    /**
379 379
 	     * Set the model instance using the configuration for session
380 380
 	     */
381
-	    private function setModelInstanceFromConfig(){
381
+	    private function setModelInstanceFromConfig() {
382 382
 	    	$modelName = get_config('session_save_path');
383 383
 			$this->logger->info('The database session model: ' . $modelName);
384
-			if($this->getLoader()){
384
+			if ($this->getLoader()) {
385 385
 				$this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); 
386 386
 			}
387 387
 			//@codeCoverageIgnoreStart
388
-			else{
388
+			else {
389 389
             	Loader::model($modelName, 'dbsessionhandlerinstance'); 
390 390
             }
391
-            if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){
392
-				show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"');
391
+            if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) {
392
+				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
393 393
 			}  
394 394
 			//@codeCoverageIgnoreEnd
395 395
 			
Please login to merge, or discard this patch.
core/common.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 		//put the first letter of class to upper case 
54 54
 		$class = ucfirst($class);
55 55
 		static $classes = array();
56
-		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
56
+		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') {
57 57
 			return $classes[$class];
58 58
 		}
59 59
 		$found = false;
60 60
 		foreach (array(ROOT_PATH, CORE_PATH) as $path) {
61 61
 			$file = $path . $dir . '/' . $class . '.php';
62
-			if (file_exists($file)){
63
-				if (class_exists($class, false) === false){
62
+			if (file_exists($file)) {
63
+				if (class_exists($class, false) === false) {
64 64
 					require_once $file;
65 65
 				}
66 66
 				//already found
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 				break;
69 69
 			}
70 70
 		}
71
-		if (! $found){
71
+		if (!$found) {
72 72
 			//can't use show_error() at this time because some dependencies not yet loaded
73 73
 			set_http_status_header(503);
74 74
 			echo 'Cannot find the class [' . $class . ']';
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		/*
79 79
 		   TODO use the best method to get the Log instance
80 80
 		 */
81
-		if ($class == 'Log'){
81
+		if ($class == 'Log') {
82 82
 			//can't use the instruction like "return new Log()" 
83 83
 			//because we need return the reference instance of the loaded class.
84 84
 			$log = new Log();
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	function & class_loaded($class = null){
104 104
 		static $list = array();
105
-		if ($class !== null){
105
+		if ($class !== null) {
106 106
 			$list[strtolower($class)] = $class;
107 107
 		}
108 108
 		return $list;
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	function & load_configurations(array $overwrite_values = array()){
119 119
 		static $config;
120
-		if (empty($config)){
120
+		if (empty($config)) {
121 121
 			$file = CONFIG_PATH . 'config.php';
122 122
 			$found = false;
123
-			if (file_exists($file)){
123
+			if (file_exists($file)) {
124 124
 				require_once $file;
125 125
 				$found = true;
126 126
 			}
127
-			if (! $found){
127
+			if (!$found) {
128 128
 				set_http_status_header(503);
129 129
 				echo 'Unable to find the configuration file [' . $file . ']';
130 130
 				die();
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 	 * 
145 145
 	 * @return mixed          the config value
146 146
 	 */
147
-	function get_config($key, $default = null){
147
+	function get_config($key, $default = null) {
148 148
 		static $cfg;
149
-		if (empty($cfg)){
149
+		if (empty($cfg)) {
150 150
 			$cfg[0] = & load_configurations();
151 151
 		}
152 152
 		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	 * 
161 161
 	 * @codeCoverageIgnore
162 162
 	 */
163
-	function save_to_log($level, $message, $logger = null){
164
-		$log =& class_loader('Log', 'classes');
165
-		if ($logger){
163
+	function save_to_log($level, $message, $logger = null) {
164
+		$log = & class_loader('Log', 'classes');
165
+		if ($logger) {
166 166
 			$log->setLogger($logger);
167 167
 		}
168 168
 		$log->writeLog($message, $level);
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * 
176 176
 	 * @codeCoverageIgnore
177 177
 	 */
178
-	function set_http_status_header($code = 200, $text = null){
179
-		if (empty($text)){
178
+	function set_http_status_header($code = 200, $text = null) {
179
+		if (empty($text)) {
180 180
 			$http_status = array(
181 181
 								100 => 'Continue',
182 182
 								101 => 'Switching Protocols',
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
 								504 => 'Gateway Timeout',
225 225
 								505 => 'HTTP Version Not Supported',
226 226
 							);
227
-			if (isset($http_status[$code])){
227
+			if (isset($http_status[$code])) {
228 228
 				$text = $http_status[$code];
229 229
 			}
230
-			else{
230
+			else {
231 231
 				show_error('No HTTP status text found for your code please check it.');
232 232
 			}
233 233
 		}
234 234
 		
235
-		if (strpos(php_sapi_name(), 'cgi') === 0){
235
+		if (strpos(php_sapi_name(), 'cgi') === 0) {
236 236
 			header('Status: ' . $code . ' ' . $text, TRUE);
237 237
 		}
238
-		else{
238
+		else {
239 239
 			$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
240 240
 			header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
241 241
 		}
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	 *  
251 251
 	 *  @codeCoverageIgnore
252 252
 	 */
253
-	function show_error($msg, $title = 'error', $logging = true){
253
+	function show_error($msg, $title = 'error', $logging = true) {
254 254
 		$title = strtoupper($title);
255 255
 		$data = array();
256 256
 		$data['error'] = $msg;
257 257
 		$data['title'] = $title;
258
-		if ($logging){
259
-			save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR');
258
+		if ($logging) {
259
+			save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR');
260 260
 		}
261 261
 		$response = & class_loader('Response', 'classes');
262 262
 		$response->sendError($data);
@@ -270,18 +270,18 @@  discard block
 block discarded – undo
270 270
 	 *  
271 271
 	 *  @return boolean true if the web server uses the https protocol, false if not.
272 272
 	 */
273
-	function is_https(){
273
+	function is_https() {
274 274
 		/*
275 275
 		* some servers pass the "HTTPS" parameter in the server variable,
276 276
 		* if is the case, check if the value is "on", "true", "1".
277 277
 		*/
278
-		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
278
+		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
279 279
 			return true;
280 280
 		}
281
-		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
281
+		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
282 282
 			return true;
283 283
 		}
284
-		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
284
+		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
285 285
 			return true;
286 286
 		}
287 287
 		return false;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 *  
297 297
 	 *  @return boolean true if is a valid URL address or false.
298 298
 	 */
299
-	function is_url($url){
299
+	function is_url($url) {
300 300
 		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1;
301 301
 	}
302 302
 	
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
 	 *  @param string $controllerClass the controller class name to be loaded
307 307
 	 *  @codeCoverageIgnore
308 308
 	 */
309
-	function autoload_controller($controllerClass){
310
-		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){
309
+	function autoload_controller($controllerClass) {
310
+		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) {
311 311
 			require_once $path;
312 312
 		}
313 313
 	}
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
 	 *  
322 322
 	 *  @return boolean
323 323
 	 */
324
-	function php_exception_handler($ex){
325
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
326
-			show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
324
+	function php_exception_handler($ex) {
325
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
326
+			show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
327 327
 		}
328
-		else{
328
+		else {
329 329
 			save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
330 330
 		}
331 331
 		return true;
@@ -342,16 +342,16 @@  discard block
 block discarded – undo
342 342
 	 *  
343 343
 	 *  @return boolean	
344 344
 	 */
345
-	function php_error_handler($errno , $errstr, $errfile , $errline){
345
+	function php_error_handler($errno, $errstr, $errfile, $errline) {
346 346
 		$isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno);
347
-		if ($isError){
347
+		if ($isError) {
348 348
 			set_http_status_header(500);
349 349
 		}
350
-		if (! (error_reporting() & $errno)) {
350
+		if (!(error_reporting() & $errno)) {
351 351
 			save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR');
352 352
 			return;
353 353
 		}
354
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
354
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
355 355
 			$errorType = 'error';
356 356
 			switch ($errno) {
357 357
 				case E_USER_ERROR:
@@ -367,9 +367,9 @@  discard block
 block discarded – undo
367 367
 					$errorType = 'error';
368 368
 					break;
369 369
 			}
370
-			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType);
370
+			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType);
371 371
 		}
372
-		if ($isError){
372
+		if ($isError) {
373 373
 			die();
374 374
 		}
375 375
 		return true;
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
 	 * This function is used to run in shutdown situation of the script
380 380
 	 * @codeCoverageIgnore
381 381
 	 */
382
-	function php_shudown_handler(){
382
+	function php_shudown_handler() {
383 383
 		$lastError = error_get_last();
384 384
 		if (isset($lastError) &&
385
-			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){
385
+			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) {
386 386
 			php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
387 387
 		}
388 388
 	}
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 *   
401 401
 	 *  @return string string of the HTML attribute.
402 402
 	 */
403
-	function attributes_to_string(array $attributes){
403
+	function attributes_to_string(array $attributes) {
404 404
 		$str = ' ';
405 405
 		//we check that the array passed as an argument is not empty.
406
-		if (! empty($attributes)){
407
-			foreach($attributes as $key => $value){
406
+		if (!empty($attributes)) {
407
+			foreach ($attributes as $key => $value) {
408 408
 				$key = trim(htmlspecialchars($key));
409 409
 				$value = trim(htmlspecialchars($value));
410 410
 				/*
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
 				* 	$attr = array('placeholder' => 'I am a "puple"')
415 415
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
416 416
 				 */
417
-				if ($value && strpos('"', $value) !== false){
417
+				if ($value && strpos('"', $value) !== false) {
418 418
 					$value = addslashes($value);
419 419
 				}
420
-				$str .= $key.' = "'.$value.'" ';
420
+				$str .= $key . ' = "' . $value . '" ';
421 421
 			}
422 422
 		}
423 423
 		//remove the space after using rtrim()
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	*
434 434
 	* @return string the stringfy value
435 435
 	*/
436
-	function stringfy_vars($var){
436
+	function stringfy_vars($var) {
437 437
 		return print_r($var, true);
438 438
 	}
439 439
 
@@ -444,18 +444,18 @@  discard block
 block discarded – undo
444 444
 	 * 
445 445
 	 * @return mixed   the sanitize value
446 446
 	 */
447
-	function clean_input($str){
448
-		if (is_array($str)){
447
+	function clean_input($str) {
448
+		if (is_array($str)) {
449 449
 			$str = array_map('clean_input', $str);
450 450
 		}
451
-		else if (is_object($str)){
451
+		else if (is_object($str)) {
452 452
 			$obj = $str;
453 453
 			foreach ($str as $var => $value) {
454 454
 				$obj->$var = clean_input($value);
455 455
 			}
456 456
 			$str = $obj;
457 457
 		}
458
-		else{
458
+		else {
459 459
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
460 460
 		}
461 461
 		return $str;
@@ -473,11 +473,11 @@  discard block
 block discarded – undo
473 473
 	 * 
474 474
 	 * @return string the string with the hidden part.
475 475
 	 */
476
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
476
+	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') {
477 477
 		//get the string length
478 478
 		$len = strlen($str);
479 479
 		//if str is empty
480
-		if ($len <= 0){
480
+		if ($len <= 0) {
481 481
 			return str_repeat($hiddenChar, 6);
482 482
 		}
483 483
 		//if the length is less than startCount and endCount
@@ -485,14 +485,14 @@  discard block
 block discarded – undo
485 485
 		//or startCount is negative or endCount is negative
486 486
 		//return the full string hidden
487 487
 		
488
-		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
488
+		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) {
489 489
 			return str_repeat($hiddenChar, $len);
490 490
 		}
491 491
 		//the start non hidden string
492 492
 		$startNonHiddenStr = substr($str, 0, $startCount);
493 493
 		//the end non hidden string
494 494
 		$endNonHiddenStr = null;
495
-		if ($endCount > 0){
495
+		if ($endCount > 0) {
496 496
 			$endNonHiddenStr = substr($str, - $endCount);
497 497
 		}
498 498
 		//the hidden string
@@ -505,31 +505,31 @@  discard block
 block discarded – undo
505 505
 	 * This function is used to set the initial session config regarding the configuration
506 506
 	 * @codeCoverageIgnore
507 507
 	 */
508
-	function set_session_config(){
508
+	function set_session_config() {
509 509
 		//$_SESSION is not available on cli mode 
510
-		if (! IS_CLI){
511
-			$logger =& class_loader('Log', 'classes');
510
+		if (!IS_CLI) {
511
+			$logger = & class_loader('Log', 'classes');
512 512
 			$logger->setLogger('PHPSession');
513 513
 			//set session params
514 514
 			$sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files
515 515
 			$sessionName = get_config('session_name');
516
-			if ($sessionName){
516
+			if ($sessionName) {
517 517
 				session_name($sessionName);
518 518
 			}
519 519
 			$logger->info('Session handler: ' . $sessionHandler);
520 520
 			$logger->info('Session name: ' . $sessionName);
521 521
 
522
-			if ($sessionHandler == 'files'){
522
+			if ($sessionHandler == 'files') {
523 523
 				$sessionSavePath = get_config('session_save_path');
524
-				if ($sessionSavePath){
525
-					if (! is_dir($sessionSavePath)){
524
+				if ($sessionSavePath) {
525
+					if (!is_dir($sessionSavePath)) {
526 526
 						mkdir($sessionSavePath, 1773);
527 527
 					}
528 528
 					session_save_path($sessionSavePath);
529 529
 					$logger->info('Session save path: ' . $sessionSavePath);
530 530
 				}
531 531
 			}
532
-			else if ($sessionHandler == 'database'){
532
+			else if ($sessionHandler == 'database') {
533 533
 				//load database session handle library
534 534
 				//Model
535 535
 				require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
@@ -537,11 +537,11 @@  discard block
 block discarded – undo
537 537
 				//Database Session handler Model
538 538
 				require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
539 539
 
540
-				$DBS =& class_loader('DBSessionHandler', 'classes');
540
+				$DBS = & class_loader('DBSessionHandler', 'classes');
541 541
 				session_set_save_handler($DBS, true);
542 542
 				$logger->info('session save path: ' . get_config('session_save_path'));
543 543
 			}
544
-			else{
544
+			else {
545 545
 				show_error('Invalid session handler configuration');
546 546
 			}
547 547
 			$lifetime = get_config('session_cookie_lifetime', 0);
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
 			$logger->info('Session lifetime: ' . $lifetime);
565 565
 			$logger->info('Session cookie path: ' . $path);
566 566
 			$logger->info('Session domain: ' . $domain);
567
-			$logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE'));
567
+			$logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE'));
568 568
 			
569
-			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){
569
+			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) {
570 570
 				$logger->info('Session not yet start, start it now');
571 571
 				session_start();
572 572
 			}
Please login to merge, or discard this patch.