Test Failed
Push — 1.0.0-dev ( c7a39c...6c2ad2 )
by nguereza
03:29
created
core/classes/Module.php 1 patch
Spacing   +83 added lines, -83 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,25 +53,25 @@  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
-			while(($module = readdir($moduleDir)) !== false){
61
-				if($module != '.' && $module != '..'  && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
60
+			while (($module = readdir($moduleDir)) !== false) {
61
+				if ($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) {
62 62
 					self::$list[] = $module;
63 63
 				}
64
-				else{
65
-					$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
64
+				else {
65
+					$logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name');
66 66
 				}
67 67
 			}
68 68
 			closedir($moduleDir);
69 69
 			ksort(self::$list);
70 70
 			
71
-			if(self::hasModule()){
71
+			if (self::hasModule()) {
72 72
 				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
73 73
 			}
74
-			else{
74
+			else {
75 75
 				$logger->info('The application contains no module skipping');
76 76
 			}
77 77
 		}
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 		 * Get the list of the custom autoload configuration from module if exists
81 81
 		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
82 82
 		 */
83
-		public static function getModulesAutoloadConfig(){
83
+		public static function getModulesAutoloadConfig() {
84 84
 			$logger = self::getLogger();
85
-			if(! self::hasModule()){
85
+			if (!self::hasModule()) {
86 86
 				$logger->info('No module was loaded skipping.');
87 87
 				return false;
88 88
 			}
@@ -95,27 +95,27 @@  discard block
 block discarded – undo
95 95
 			
96 96
 			foreach (self::$list as $module) {
97 97
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
98
-				if(file_exists($file)){
98
+				if (file_exists($file)) {
99 99
 					require_once $file;
100
-					if(! empty($autoload) && is_array($autoload)){
100
+					if (!empty($autoload) && is_array($autoload)) {
101 101
 						//libraries autoload
102
-						if(! empty($autoload['libraries']) && is_array($autoload['libraries'])){
102
+						if (!empty($autoload['libraries']) && is_array($autoload['libraries'])) {
103 103
 							$autoloads['libraries'] = array_merge($autoloads['libraries'], $autoload['libraries']);
104 104
 						}
105 105
 						//config autoload
106
-						if(! empty($autoload['config']) && is_array($autoload['config'])){
106
+						if (!empty($autoload['config']) && is_array($autoload['config'])) {
107 107
 							$autoloads['config'] = array_merge($autoloads['config'], $autoload['config']);
108 108
 						}
109 109
 						//models autoload
110
-						if(! empty($autoload['models']) && is_array($autoload['models'])){
110
+						if (!empty($autoload['models']) && is_array($autoload['models'])) {
111 111
 							$autoloads['models'] = array_merge($autoloads['models'], $autoload['models']);
112 112
 						}
113 113
 						//functions autoload
114
-						if(! empty($autoload['functions']) && is_array($autoload['functions'])){
114
+						if (!empty($autoload['functions']) && is_array($autoload['functions'])) {
115 115
 							$autoloads['functions'] = array_merge($autoloads['functions'], $autoload['functions']);
116 116
 						}
117 117
 						//languages autoload
118
-						if(! empty($autoload['languages']) && is_array($autoload['languages'])){
118
+						if (!empty($autoload['languages']) && is_array($autoload['languages'])) {
119 119
 							$autoloads['languages'] = array_merge($autoloads['languages'], $autoload['languages']);
120 120
 						}
121 121
 						unset($autoload);
@@ -129,23 +129,23 @@  discard block
 block discarded – undo
129 129
 		 * Get the list of the custom routes configuration from module if exists
130 130
 		 * @return array|boolean the routes list or false if no module contains the routes configuration
131 131
 		 */
132
-		public static function getModulesRoutes(){
132
+		public static function getModulesRoutes() {
133 133
 			$logger = self::getLogger();
134
-			if(! self::hasModule()){
134
+			if (!self::hasModule()) {
135 135
 				$logger->info('No module was loaded skipping.');
136 136
 				return false;
137 137
 			}
138 138
 			$routes = array();
139 139
 			foreach (self::$list as $module) {
140 140
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
141
-				if(file_exists($file)){
141
+				if (file_exists($file)) {
142 142
 					require_once $file;
143
-					if(! empty($route) && is_array($route)){
143
+					if (!empty($route) && is_array($route)) {
144 144
 						$routes = array_merge($routes, $route);
145 145
 						unset($route);
146 146
 					}
147
-					else{
148
-						show_error('No routing configuration found in [' .$file. '] for module [' . $module . ']');
147
+					else {
148
+						show_error('No routing configuration found in [' . $file . '] for module [' . $module . ']');
149 149
 					}
150 150
 				}
151 151
 			}
@@ -159,23 +159,23 @@  discard block
 block discarded – undo
159 159
 		 * @param  string $module  the module name
160 160
 		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
161 161
 		 */
162
-		public static function findControllerFullPath($class, $module = null){
162
+		public static function findControllerFullPath($class, $module = null) {
163 163
 			$logger = self::getLogger();
164
-			if(! self::hasModule()){
164
+			if (!self::hasModule()) {
165 165
 				$logger->info('No module was loaded skiping.');
166 166
 				return false;
167 167
 			}
168 168
 			$class = str_ireplace('.php', '', $class);
169 169
 			$class = ucfirst($class);
170
-			$classFile = $class.'.php';
171
-			$logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
170
+			$classFile = $class . '.php';
171
+			$logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...');
172 172
 			$filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
173
-			if(file_exists($filePath)){
174
-				$logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
173
+			if (file_exists($filePath)) {
174
+				$logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
175 175
 				return $filePath;
176 176
 			}
177
-			else{
178
-				$logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
177
+			else {
178
+				$logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']');
179 179
 				return false;
180 180
 			}
181 181
 		}
@@ -186,23 +186,23 @@  discard block
 block discarded – undo
186 186
 		 * @param string $module the module name
187 187
 		 * @return boolean|string  false or null if no module have this model, return the full path of this model
188 188
 		 */
189
-		public static function findModelFullPath($class, $module = null){
189
+		public static function findModelFullPath($class, $module = null) {
190 190
 			$logger = self::getLogger();
191
-			if(! self::hasModule()){
191
+			if (!self::hasModule()) {
192 192
 				$logger->info('No module was loaded skiping.');
193 193
 				return false;
194 194
 			}
195 195
 			$class = str_ireplace('.php', '', $class);
196 196
 			$class = ucfirst($class);
197
-			$classFile = $class.'.php';
198
-			$logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
197
+			$classFile = $class . '.php';
198
+			$logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...');
199 199
 			$filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
200
-			if(file_exists($filePath)){
201
-				$logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
200
+			if (file_exists($filePath)) {
201
+				$logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
202 202
 				return $filePath;
203 203
 			}
204
-			else{
205
-				$logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
204
+			else {
205
+				$logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']');
206 206
 				return false;
207 207
 			}
208 208
 		}
@@ -213,22 +213,22 @@  discard block
 block discarded – undo
213 213
 		 * @param string $module the module name
214 214
 		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
215 215
 		 */
216
-		public static function findConfigFullPath($configuration, $module = null){
216
+		public static function findConfigFullPath($configuration, $module = null) {
217 217
 			$logger = self::getLogger();
218
-			if(! self::hasModule()){
218
+			if (!self::hasModule()) {
219 219
 				$logger->info('No module was loaded skiping.');
220 220
 				return false;
221 221
 			}
222 222
 			$configuration = str_ireplace('.php', '', $configuration);
223
-			$file = $configuration.'.php';
224
-			$logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
223
+			$file = $configuration . '.php';
224
+			$logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...');
225 225
 			$filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
226
-			if(file_exists($filePath)){
227
-				$logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
226
+			if (file_exists($filePath)) {
227
+				$logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']');
228 228
 				return $filePath;
229 229
 			}
230
-			else{
231
-				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
230
+			else {
231
+				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']');
232 232
 				return false;
233 233
 			}
234 234
 		}
@@ -239,23 +239,23 @@  discard block
 block discarded – undo
239 239
 		 * @param string $module the module name
240 240
 		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
241 241
 		 */
242
-		public static function findFunctionFullPath($helper, $module = null){
242
+		public static function findFunctionFullPath($helper, $module = null) {
243 243
 			$logger = self::getLogger();
244
-			if(! self::hasModule()){
244
+			if (!self::hasModule()) {
245 245
 				$logger->info('No module was loaded skiping.');
246 246
 				return false;
247 247
 			}
248 248
 			$helper = str_ireplace('.php', '', $helper);
249 249
 			$helper = str_ireplace('function_', '', $helper);
250
-			$file = 'function_'.$helper.'.php';
251
-			$logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
250
+			$file = 'function_' . $helper . '.php';
251
+			$logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...');
252 252
 			$filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
253
-			if(file_exists($filePath)){
254
-				$logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
253
+			if (file_exists($filePath)) {
254
+				$logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']');
255 255
 				return $filePath;
256 256
 			}
257
-			else{
258
-				$logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
257
+			else {
258
+				$logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']');
259 259
 				return false;
260 260
 			}
261 261
 		}
@@ -267,22 +267,22 @@  discard block
 block discarded – undo
267 267
 		 * @param string $module the module name
268 268
 		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
269 269
 		 */
270
-		public static function findLibraryFullPath($class, $module = null){
270
+		public static function findLibraryFullPath($class, $module = null) {
271 271
 			$logger = self::getLogger();
272
-			if(! self::hasModule()){
272
+			if (!self::hasModule()) {
273 273
 				$logger->info('No module was loaded skiping.');
274 274
 				return false;
275 275
 			}
276 276
 			$class = str_ireplace('.php', '', $class);
277
-			$file = $class.'.php';
278
-			$logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
277
+			$file = $class . '.php';
278
+			$logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...');
279 279
 			$filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
280
-			if(file_exists($filePath)){
281
-				$logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
280
+			if (file_exists($filePath)) {
281
+				$logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
282 282
 				return $filePath;
283 283
 			}
284
-			else{
285
-				$logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
284
+			else {
285
+				$logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']');
286 286
 				return false;
287 287
 			}
288 288
 		}
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 		 * @param string $module the module name to check
295 295
 		 * @return boolean|string  false or null if no module have this view, path the full path of the view
296 296
 		 */
297
-		public static function findViewFullPath($view, $module = null){
297
+		public static function findViewFullPath($view, $module = null) {
298 298
 			$logger = self::getLogger();
299
-			if(! self::hasModule()){
299
+			if (!self::hasModule()) {
300 300
 				$logger->info('No module was loaded skiping.');
301 301
 				return false;
302 302
 			}
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
 			$view = trim($view, '/\\');
305 305
 			$view = str_ireplace('/', DS, $view);
306 306
 			$viewFile = $view . '.php';
307
-			$logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
307
+			$logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...');
308 308
 			$filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
309
-			if(file_exists($filePath)){
310
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
309
+			if (file_exists($filePath)) {
310
+				$logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']');
311 311
 				return $filePath;
312 312
 			}
313
-			else{
314
-				$logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
313
+			else {
314
+				$logger->info('View [' . $view . '] does not exist in the module [' . $module . ']');
315 315
 				return false;
316 316
 			}
317 317
 		}
@@ -323,23 +323,23 @@  discard block
 block discarded – undo
323 323
 		 * @param string $appLang the application language like 'en', 'fr'
324 324
 		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
325 325
 		 */
326
-		public static function findLanguageFullPath($language, $module = null, $appLang){
326
+		public static function findLanguageFullPath($language, $module = null, $appLang) {
327 327
 			$logger = self::getLogger();
328
-			if(! self::hasModule()){
328
+			if (!self::hasModule()) {
329 329
 				$logger->info('No module was loaded skiping.');
330 330
 				return false;
331 331
 			}
332 332
 			$language = str_ireplace('.php', '', $language);
333 333
 			$language = str_ireplace('lang_', '', $language);
334
-			$file = 'lang_'.$language.'.php';
335
-			$logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
334
+			$file = 'lang_' . $language . '.php';
335
+			$logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...');
336 336
 			$filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
337
-			if(file_exists($filePath)){
338
-				$logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
337
+			if (file_exists($filePath)) {
338
+				$logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']');
339 339
 				return $filePath;
340 340
 			}
341
-			else{
342
-				$logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
341
+			else {
342
+				$logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']');
343 343
 				return false;
344 344
 			}
345 345
 		}
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 		 * Get the list of module loaded
349 349
 		 * @return array the module list
350 350
 		 */
351
-		public static function getModuleList(){
351
+		public static function getModuleList() {
352 352
 			return self::$list;
353 353
 		}
354 354
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		 * Check if the application has an module
357 357
 		 * @return boolean
358 358
 		 */
359
-		public static function hasModule(){
359
+		public static function hasModule() {
360 360
 			return !empty(self::$list);
361 361
 		}
362 362
 
Please login to merge, or discard this patch.
core/classes/Request.php 1 patch
Spacing   +27 added lines, -27 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 Request{
27
+	class Request {
28 28
 		
29 29
 		/**
30 30
 		 * The value for the super global $_GET
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
 		/**
91 91
 		 * Construct new request instance
92 92
 		 */
93
-		public function __construct(){
93
+		public function __construct() {
94 94
 			$this->get = $_GET;
95 95
 			$this->post = $_POST;
96 96
 			$this->server = $_SERVER;
97 97
 			$this->query = $_REQUEST;
98 98
 			$this->cookie = $_COOKIE;
99 99
 			$this->file = $_FILES;
100
-			$this->session =& class_loader('Session', 'classes');
100
+			$this->session = & class_loader('Session', 'classes');
101 101
 			$this->method = $this->server('REQUEST_METHOD');
102 102
 			$this->requestUri = $this->server('REQUEST_URI');
103 103
 			$this->header = array();
104
-			if(function_exists('apache_request_headers')){
104
+			if (function_exists('apache_request_headers')) {
105 105
 				$this->header = apache_request_headers();
106 106
 			}
107
-			else if(function_exists('getallheaders')){
107
+			else if (function_exists('getallheaders')) {
108 108
 				$this->header = getallheaders();
109 109
 			}
110 110
 		}
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Get the request method
114 114
 		 * @return string
115 115
 		 */
116
-		public function method(){
116
+		public function method() {
117 117
 			return $this->method;
118 118
 		}
119 119
 		
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		 * Get the request URI
122 122
 		 * @return string
123 123
 		 */
124
-		public function requestUri(){
124
+		public function requestUri() {
125 125
 			return $this->requestUri;
126 126
 		}
127 127
 
@@ -131,13 +131,13 @@  discard block
 block discarded – undo
131 131
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
132 132
 		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
133 133
 		 */
134
-		public function query($key = null, $xss = true){
135
-			if(empty($key)){
134
+		public function query($key = null, $xss = true) {
135
+			if (empty($key)) {
136 136
 				//return all
137 137
 				return $xss ? clean_input($this->query) : $this->query;
138 138
 			}
139 139
 			$query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
140
-			if($xss){
140
+			if ($xss) {
141 141
 				$query = clean_input($query);
142 142
 			}
143 143
 			return $query;
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
150 150
 		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
151 151
 		 */
152
-		public function get($key = null, $xss = true){
153
-			if(empty($key)){
152
+		public function get($key = null, $xss = true) {
153
+			if (empty($key)) {
154 154
 				//return all
155 155
 				return $xss ? clean_input($this->get) : $this->get;
156 156
 			}
157 157
 			$get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
158
-			if($xss){
158
+			if ($xss) {
159 159
 				$get = clean_input($get);
160 160
 			}
161 161
 			return $get;
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
168 168
 		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
169 169
 		 */
170
-		public function post($key = null, $xss = true){
171
-			if(empty($key)){
170
+		public function post($key = null, $xss = true) {
171
+			if (empty($key)) {
172 172
 				//return all
173 173
 				return $xss ? clean_input($this->post) : $this->post;
174 174
 			}
175 175
 			$post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
176
-			if($xss){
176
+			if ($xss) {
177 177
 				$post = clean_input($post);
178 178
 			}
179 179
 			return $post;
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
186 186
 		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
187 187
 		 */
188
-		public function server($key = null, $xss = true){
189
-			if(empty($key)){
188
+		public function server($key = null, $xss = true) {
189
+			if (empty($key)) {
190 190
 				//return all
191 191
 				return $xss ? clean_input($this->server) : $this->server;
192 192
 			}
193 193
 			$server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
194
-			if($xss){
194
+			if ($xss) {
195 195
 				$server = clean_input($server);
196 196
 			}
197 197
 			return $server;
@@ -203,13 +203,13 @@  discard block
 block discarded – undo
203 203
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
204 204
 		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
205 205
 		 */
206
-		public function cookie($key = null, $xss = true){
207
-			if(empty($key)){
206
+		public function cookie($key = null, $xss = true) {
207
+			if (empty($key)) {
208 208
 				//return all
209 209
 				return $xss ? clean_input($this->cookie) : $this->cookie;
210 210
 			}
211 211
 			$cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
212
-			if($xss){
212
+			if ($xss) {
213 213
 				$cookie = clean_input($cookie);
214 214
 			}
215 215
 			return $cookie;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		 * @param  string  $key the item key to be fetched
221 221
 		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
222 222
 		 */
223
-		public function file($key){
223
+		public function file($key) {
224 224
 			$file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
225 225
 			return $file;
226 226
 		}
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
232 232
 		 * @return array|mixed       the item value if the key exists or null if the key does not exists
233 233
 		 */
234
-		public function session($key, $xss = true){
234
+		public function session($key, $xss = true) {
235 235
 			$session = $this->session->get($key);
236
-			if($xss){
236
+			if ($xss) {
237 237
 				$session = clean_input($session);
238 238
 			}
239 239
 			return $session;
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 		 * @param  boolean $xss if need apply some XSS attack rule on the value
246 246
 		 * @return mixed       the item value if the key exists or null if the key does not exists
247 247
 		 */
248
-		public function header($key, $xss = true){
248
+		public function header($key, $xss = true) {
249 249
 			$header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
250
-			if($xss){
250
+			if ($xss) {
251 251
 				$header = clean_input($header);
252 252
 			}
253 253
 			return $header;
Please login to merge, or discard this patch.
core/classes/Security.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Security{
27
+	class Security {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * Get the logger singleton instance
37 37
 		 * @return Log the logger instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (self::$logger == null) {
41
+				self::$logger[0] = & class_loader('Log', 'classes');
42 42
 				self::$logger[0]->setLogger('Library::Security');
43 43
 			}
44 44
 			return self::$logger[0];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * This method is used to generate the CSRF token
50 50
 		 * @return string the generated CSRF token
51 51
 		 */
52
-		public static function generateCSRF(){
52
+		public static function generateCSRF() {
53 53
 			$logger = self::getLogger();
54 54
 			$logger->debug('Generation of CSRF ...');
55 55
 			
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 			$expire = get_config('csrf_expire', 60);
58 58
 			$keyExpire = 'csrf_expire';
59 59
 			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
60
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63 63
 			}
64
-			else{
64
+			else {
65 65
 				$newTime = $currentTime + $expire;
66 66
 				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
67
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
68 68
 				Session::set($keyExpire, $newTime);
69 69
 				Session::set($key, $token);
70 70
 				return Session::get($key);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76 76
 		 * @return boolean true if valid, false if not valid
77 77
 		 */
78
-		public static function validateCSRF(){
78
+		public static function validateCSRF() {
79 79
 			$logger = self::getLogger();
80 80
 			$logger->debug('Validation of CSRF ...');
81 81
 				
@@ -83,23 +83,23 @@  discard block
 block discarded – undo
83 83
 			$expire = get_config('csrf_expire', 60);
84 84
 			$keyExpire = 'csrf_expire';
85 85
 			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
86
+			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
87
+			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
88 88
 				$logger->warning('The CSRF session data is not valide');
89 89
 				return false;
90 90
 			}
91
-			else{
91
+			else {
92 92
 				//perform form data
93 93
 				//need use request->query() for best retrieve
94 94
 				//super instance
95 95
 				$obj = & get_instance();
96 96
 				$token = $obj->request->query($key);
97
-				if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
98
-					$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
97
+				if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
98
+					$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
99 99
 					return false;
100 100
 				}
101
-				else{
102
-					$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
101
+				else {
102
+					$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
103 103
 					//remove the token from session
104 104
 					Session::clear($key);
105 105
 					Session::clear($keyExpire);
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
 		/**
112 112
 		 * This method is used to check the whitelist IP address access
113 113
 		 */
114
-		 public static function checkWhiteListIpAccess(){
114
+		 public static function checkWhiteListIpAccess() {
115 115
 			$logger = self::getLogger();
116 116
 			$logger->debug('Validation of the IP address access ...');
117 117
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
118 118
 			$isEnable = get_config('white_list_ip_enable', false);
119
-			if($isEnable){
119
+			if ($isEnable) {
120 120
 				$logger->info('Whitelist IP access is enabled in the configuration');
121 121
 				$list = get_config('white_list_ip_addresses', array());
122
-				if(! empty($list)){
122
+				if (!empty($list)) {
123 123
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
124 124
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
125 125
 					$ip = get_ip();
126
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
126
+					if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) {
127 127
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
128 128
 						//wildcard to access all ip address
129 129
 						return;
130 130
 					}
131
-					else{
131
+					else {
132 132
 						// go through all whitelisted ips
133 133
 						foreach ($list as $ipaddr) {
134 134
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 					}
155 155
 				}
156 156
 			}
157
-			else{
157
+			else {
158 158
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
159 159
 			}
160 160
 		 }
Please login to merge, or discard this patch.
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,37 +139,37 @@  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(){
150
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
151
-				if(ENVIRONMENT == 'production'){
149
+		private static function setBaseUrlUsingServerVar() {
150
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
151
+				if (ENVIRONMENT == 'production') {
152 152
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
153 153
 				}
154 154
 				$baseUrl = null;
155
-				if (isset($_SERVER['SERVER_ADDR'])){
155
+				if (isset($_SERVER['SERVER_ADDR'])) {
156 156
 					//check if the server is running under IPv6
157
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
158
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
157
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
158
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
159 159
 					}
160
-					else{
160
+					else {
161 161
 						$baseUrl = $_SERVER['SERVER_ADDR'];
162 162
 					}
163
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
164
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
163
+					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : '');
164
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
165 165
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
166 166
 				}
167
-				else{
167
+				else {
168 168
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
169 169
 					$baseUrl = 'http://localhost/';
170 170
 				}
171 171
 				self::set('base_url', $baseUrl);
172 172
 			}
173
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
173
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
174 174
 		}
175 175
 	}
Please login to merge, or discard this patch.
core/classes/EventInfo.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * This class represent the event detail to dispatch to correspond listener
29 29
 	 */
30
-	class EventInfo{
30
+	class EventInfo {
31 31
 		
32 32
 		/**
33 33
 		 * The event name
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		 */
55 55
 		public $stop;
56 56
 		
57
-		public function __construct($name, $payload = array(), $returnBack = false, $stop = false){
57
+		public function __construct($name, $payload = array(), $returnBack = false, $stop = false) {
58 58
 			$this->name = $name;
59 59
 			$this->payload = $payload;
60 60
 			$this->returnBack = $returnBack;
Please login to merge, or discard this patch.
core/classes/EventDispatcher.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * also to dispatch the event
30 30
 	 */
31 31
 	
32
-	class EventDispatcher{
32
+	class EventDispatcher {
33 33
 		
34 34
 		/**
35 35
 		 * The list of the registered listeners
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 		 */
45 45
 		private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
47
+		public function __construct() {
48
+			$this->logger = & class_loader('Log', 'classes');
49 49
 			$this->logger->setLogger('Library::EventDispatcher');
50 50
 		}
51 51
 
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 		 * @param string   $eventName the name of the event to register for
55 55
 		 * @param callable $listener  the function or class method to receive the event information after dispatch
56 56
 		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
57
+		public function addListener($eventName, callable $listener) {
58
+			$this->logger->debug('Adding new event listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
59
+			if (!isset($this->listeners[$eventName])) {
60 60
 				$this->logger->info('This event does not have the registered event listener before, adding new one');
61 61
 				$this->listeners[$eventName] = array();
62 62
 			}
63
-			else{
63
+			else {
64 64
 				$this->logger->info('This event already have the registered listener, add this listener to the list');
65 65
 			}
66 66
 			$this->listeners[$eventName][] = $listener;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
 		 * @param  string   $eventName the event name
72 72
 		 * @param  callable $listener  the listener callback
73 73
 		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
74
+		public function removeListener($eventName, callable $listener) {
75
+			$this->logger->debug('Removing of the event listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
76
+			if (isset($this->listeners[$eventName])) {
77 77
 				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
78
+				if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) {
79
+					$this->logger->info('Found the listener at index [' . $index . '] remove it');
80 80
 					unset($this->listeners[$eventName][$index]);
81 81
 				}
82
-				else{
82
+				else {
83 83
 					$this->logger->info('Cannot found this listener in the event listener list');
84 84
 				}
85 85
 			}
86
-			else{
86
+			else {
87 87
 				$this->logger->info('This event does not have this listener ignore remove');
88 88
 			}
89 89
 		}
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 		 * remove all listeners for this event
94 94
 		 * @param  string $eventName the event name
95 95
 		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
-			if($eventName !== null && isset($this->listeners[$eventName])){
96
+		public function removeAllListener($eventName = null) {
97
+			$this->logger->debug('Removing of all event listener, the event name [' . $eventName . ']');
98
+			if ($eventName !== null && isset($this->listeners[$eventName])) {
99 99
 				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100 100
 				unset($this->listeners[$eventName]);
101 101
 			}
102
-			else{
102
+			else {
103 103
 				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104 104
 				$this->listeners = array();
105 105
 			}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		 * @param string $eventName the event name
111 111
 		 * @return array the listeners for this event or empty array if this event does not contain any listener
112 112
 		 */
113
-		public function getListeners($eventName){
113
+		public function getListeners($eventName) {
114 114
 			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115 115
 		}
116 116
 		
@@ -119,21 +119,21 @@  discard block
 block discarded – undo
119 119
 		 * @param  mixed|object $event the event information
120 120
 		 * @return void|object if event need return, will return the final EventInfo object.
121 121
 		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof EventInfo){
122
+		public function dispatch($event) {
123
+			if (!$event || !$event instanceof EventInfo) {
124 124
 				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125 125
 				$event = new EventInfo((string) $event);
126 126
 			}			
127
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
127
+			$this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']');
128
+			if (isset($event->stop) && $event->stop) {
129 129
 				$this->logger->info('This event need stopped, no need call any listener');
130 130
 				return;
131 131
 			}
132
-			if($event->returnBack){
132
+			if ($event->returnBack) {
133 133
 				$this->logger->info('This event need return back, return the result for future use');
134 134
 				return $this->dispatchToListerners($event);
135 135
 			}
136
-			else{
136
+			else {
137 137
 				$this->logger->info('This event no need return back the result, just dispatch it');
138 138
 				$this->dispatchToListerners($event);
139 139
 			}
@@ -144,38 +144,38 @@  discard block
 block discarded – undo
144 144
 		 * @param  object EventInfo $event  the event information
145 145
 		 * @return void|object if event need return, will return the final EventInfo instance.
146 146
 		 */	
147
-		private function dispatchToListerners(EventInfo $event){
147
+		private function dispatchToListerners(EventInfo $event) {
148 148
 			$eBackup = $event;
149 149
 			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
150
+			if (empty($list)) {
151
+				$this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.');
152
+				if ($event->returnBack) {
153 153
 					return $event;
154 154
 				}
155 155
 				return;
156 156
 			}
157
-			else{
158
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
157
+			else {
158
+				$this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list));
159 159
 			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
160
+			foreach ($list as $listener) {
161
+				if ($eBackup->returnBack) {
162 162
 					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof EventInfo){
163
+					if ($returnedEvent instanceof EventInfo) {
164 164
 						$event = $returnedEvent;
165 165
 					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
166
+					else {
167
+						show_error('This event [' . $event->name . '] need you return the event object after processing');
168 168
 					}
169 169
 				}
170
-				else{
170
+				else {
171 171
 					call_user_func_array($listener, array($event));
172 172
 				}
173
-				if($event->stop){
173
+				if ($event->stop) {
174 174
 					break;
175 175
 				}
176 176
 			}
177 177
 			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
178
+			if ($eBackup->returnBack) {
179 179
 				return $event;
180 180
 			}
181 181
 		}
Please login to merge, or discard this patch.
core/classes/Database.php 1 patch
Spacing   +254 added lines, -254 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
 
@@ -195,23 +195,23 @@  discard block
 block discarded – undo
195 195
      * This is used to connect to database
196 196
      * @return bool 
197 197
      */
198
-    public function connect(){
198
+    public function connect() {
199 199
       $config = $this->getDatabaseConfiguration();
200
-      if(! empty($config)){
201
-        try{
200
+      if (!empty($config)) {
201
+        try {
202 202
             $this->pdo = new PDO($this->getDsnFromDriver(), $config['username'], $config['password']);
203 203
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
204 204
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
205 205
             $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
206 206
             return true;
207 207
           }
208
-          catch (PDOException $e){
208
+          catch (PDOException $e) {
209 209
             $this->logger->fatal($e->getMessage());
210 210
             show_error('Cannot connect to Database.');
211 211
             return false;
212 212
           }
213 213
       }
214
-      else{
214
+      else {
215 215
         show_error('Database configuration is not set.');
216 216
         return false;
217 217
       }
@@ -222,15 +222,15 @@  discard block
 block discarded – undo
222 222
      * @param  string|array $table the table name or array of table list
223 223
      * @return object        the current Database instance
224 224
      */
225
-    public function from($table){
226
-      if(is_array($table)){
225
+    public function from($table) {
226
+      if (is_array($table)) {
227 227
         $froms = '';
228
-        foreach($table as $key){
228
+        foreach ($table as $key) {
229 229
           $froms .= $this->prefix . $key . ', ';
230 230
         }
231 231
         $this->from = rtrim($froms, ', ');
232 232
       }
233
-      else{
233
+      else {
234 234
         $this->from = $this->prefix . $table;
235 235
       }
236 236
       return $this;
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @param  string|array $fields the field name or array of field list
242 242
      * @return object        the current Database instance
243 243
      */
244
-    public function select($fields){
244
+    public function select($fields) {
245 245
       $select = (is_array($fields) ? implode(', ', $fields) : $fields);
246 246
       $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select);
247 247
       return $this;
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      * @param  string $field the field name to distinct
253 253
      * @return object        the current Database instance
254 254
      */
255
-    public function distinct($field){
255
+    public function distinct($field) {
256 256
       $distinct = ' DISTINCT ' . $field;
257 257
       $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct);
258 258
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      * @param  string $name  if is not null represent the alias used for this field in the result
266 266
      * @return object        the current Database instance
267 267
      */
268
-    public function max($field, $name = null){
268
+    public function max($field, $name = null) {
269 269
       $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
270 270
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
271 271
       return $this;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      * @param  string $name  if is not null represent the alias used for this field in the result
278 278
      * @return object        the current Database instance
279 279
      */
280
-    public function min($field, $name = null){
280
+    public function min($field, $name = null) {
281 281
       $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
282 282
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
283 283
       return $this;
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      * @param  string $name  if is not null represent the alias used for this field in the result
290 290
      * @return object        the current Database instance
291 291
      */
292
-    public function sum($field, $name = null){
292
+    public function sum($field, $name = null) {
293 293
       $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
294 294
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
295 295
       return $this;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * @param  string $name  if is not null represent the alias used for this field in the result
302 302
      * @return object        the current Database instance
303 303
      */
304
-    public function count($field = '*', $name = null){
304
+    public function count($field = '*', $name = null) {
305 305
       $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
306 306
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
307 307
       return $this;
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      * @param  string $name  if is not null represent the alias used for this field in the result
314 314
      * @return object        the current Database instance
315 315
      */
316
-    public function avg($field, $name = null){
316
+    public function avg($field, $name = null) {
317 317
       $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
318 318
       $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
319 319
       return $this;
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
329 329
      * @return object        the current Database instance
330 330
      */
331
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
331
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
332 332
       $on = $field1;
333 333
       $table = $this->prefix . $table;
334
-      if(! is_null($op)){
335
-        $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
334
+      if (!is_null($op)) {
335
+        $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2);
336 336
       }
337
-      if (empty($this->join)){
337
+      if (empty($this->join)) {
338 338
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
339 339
       }
340
-      else{
340
+      else {
341 341
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
342 342
       }
343 343
       return $this;
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
      * @see  Database::join()
349 349
      * @return object        the current Database instance
350 350
      */
351
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
351
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
352 352
       return $this->join($table, $field1, $op, $field2, 'INNER ');
353 353
     }
354 354
 
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      * @see  Database::join()
358 358
      * @return object        the current Database instance
359 359
      */
360
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
360
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
361 361
       return $this->join($table, $field1, $op, $field2, 'LEFT ');
362 362
 	}
363 363
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
      * @see  Database::join()
367 367
      * @return object        the current Database instance
368 368
      */
369
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
369
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
370 370
       return $this->join($table, $field1, $op, $field2, 'RIGHT ');
371 371
     }
372 372
 
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
      * @see  Database::join()
376 376
      * @return object        the current Database instance
377 377
      */
378
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
378
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
379 379
     	return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
380 380
     }
381 381
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
      * @see  Database::join()
385 385
      * @return object        the current Database instance
386 386
      */
387
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
387
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
388 388
       return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
389 389
     }
390 390
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
      * @see  Database::join()
394 394
      * @return object        the current Database instance
395 395
      */
396
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
396
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
397 397
       return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
398 398
     }
399 399
 
@@ -403,18 +403,18 @@  discard block
 block discarded – undo
403 403
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
404 404
      * @return object        the current Database instance
405 405
      */
406
-    public function whereIsNull($field, $andOr = 'AND'){
407
-      if(is_array($field)){
408
-        foreach($field as $f){
406
+    public function whereIsNull($field, $andOr = 'AND') {
407
+      if (is_array($field)) {
408
+        foreach ($field as $f) {
409 409
         	$this->whereIsNull($f, $andOr);
410 410
         }
411 411
       }
412
-      else{
413
-        if (! $this->where){
414
-          $this->where = $field.' IS NULL ';
412
+      else {
413
+        if (!$this->where) {
414
+          $this->where = $field . ' IS NULL ';
415 415
         }
416
-        else{
417
-            $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL ';
416
+        else {
417
+            $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NULL ';
418 418
           }
419 419
       }
420 420
       return $this;
@@ -426,18 +426,18 @@  discard block
 block discarded – undo
426 426
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
427 427
      * @return object        the current Database instance
428 428
      */
429
-    public function whereIsNotNull($field, $andOr = 'AND'){
430
-      if(is_array($field)){
431
-        foreach($field as $f){
429
+    public function whereIsNotNull($field, $andOr = 'AND') {
430
+      if (is_array($field)) {
431
+        foreach ($field as $f) {
432 432
           $this->whereIsNotNull($f, $andOr);
433 433
         }
434 434
       }
435
-      else{
436
-        if (! $this->where){
437
-          $this->where = $field.' IS NOT NULL ';
435
+      else {
436
+        if (!$this->where) {
437
+          $this->where = $field . ' IS NOT NULL ';
438 438
         }
439
-        else{
440
-            $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL ';
439
+        else {
440
+            $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NOT NULL ';
441 441
           }
442 442
       }
443 443
       return $this;
@@ -449,15 +449,15 @@  discard block
 block discarded – undo
449 449
      *
450 450
      * @return string
451 451
      */
452
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
452
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
453 453
         $_where = array();
454
-        foreach ($where as $column => $data){
455
-          if(is_null($data)){
454
+        foreach ($where as $column => $data) {
455
+          if (is_null($data)) {
456 456
             $data = '';
457 457
           }
458 458
           $_where[] = $type . $column . ' = ' . ($escape ? $this->escape($data) : $data);
459 459
         }
460
-        $where = implode(' '.$andOr.' ', $_where);
460
+        $where = implode(' ' . $andOr . ' ', $_where);
461 461
         return $where;
462 462
     }
463 463
 
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
      *
468 468
      * @return string
469 469
      */
470
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
470
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
471 471
        $x = explode('?', $where);
472 472
        $w = '';
473
-        foreach($x as $k => $v){
474
-          if(! empty($v)){
475
-              if(isset($op[$k]) && is_null($op[$k])){
473
+        foreach ($x as $k => $v) {
474
+          if (!empty($v)) {
475
+              if (isset($op[$k]) && is_null($op[$k])) {
476 476
                 $op[$k] = '';
477 477
               }
478 478
               $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
@@ -487,16 +487,16 @@  discard block
 block discarded – undo
487 487
      *
488 488
      * @return string
489 489
      */
490
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
490
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
491 491
        $w = '';
492
-       if (! in_array((string)$op, $this->operatorList)){
493
-          if(is_null($op)){
492
+       if (!in_array((string) $op, $this->operatorList)) {
493
+          if (is_null($op)) {
494 494
             $op = '';
495 495
           }
496 496
           $w = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op);
497 497
         }
498
-        else{
499
-          if(is_null($val)){
498
+        else {
499
+          if (is_null($val)) {
500 500
             $val = '';
501 501
           }
502 502
           $w = $type . $where . $op . ($escape ? $this->escape($val) : $val);
@@ -509,16 +509,16 @@  discard block
 block discarded – undo
509 509
        * @param string $whereStr the WHERE clause string
510 510
        * @param  string  $andOr the separator type used 'AND', 'OR', etc.
511 511
        */
512
-      protected function setWhereStr($whereStr, $andOr = 'AND'){
513
-        if (empty($this->where)){
512
+      protected function setWhereStr($whereStr, $andOr = 'AND') {
513
+        if (empty($this->where)) {
514 514
           $this->where = $whereStr;
515 515
         }
516
-        else{
517
-          if(substr($this->where, -1) == '('){
516
+        else {
517
+          if (substr($this->where, -1) == '(') {
518 518
             $this->where = $this->where . ' ' . $whereStr;
519 519
           }
520
-          else{
521
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
520
+          else {
521
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
522 522
           }
523 523
         }
524 524
       }
@@ -533,13 +533,13 @@  discard block
 block discarded – undo
533 533
      * @param  boolean $escape whether to escape or not the $val
534 534
      * @return object        the current Database instance
535 535
      */
536
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
536
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
537 537
       $whereStr = '';
538
-      if (is_array($where)){
538
+      if (is_array($where)) {
539 539
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
540 540
       }
541
-      else{
542
-        if(is_array($op)){
541
+      else {
542
+        if (is_array($op)) {
543 543
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
544 544
         } else {
545 545
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape = true);
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
      * @see  Database::where()
555 555
      * @return object        the current Database instance
556 556
      */
557
-    public function orWhere($where, $op = null, $val = null, $escape = true){
557
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
558 558
       return $this->where($where, $op, $val, '', 'OR', $escape);
559 559
     }
560 560
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
      * @see  Database::where()
565 565
      * @return object        the current Database instance
566 566
      */
567
-    public function notWhere($where, $op = null, $val = null, $escape = true){
567
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
568 568
       return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
569 569
     }
570 570
 
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
      * @see  Database::where()
574 574
      * @return object        the current Database instance
575 575
      */
576
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
576
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
577 577
     	return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
578 578
     }
579 579
 
@@ -583,15 +583,15 @@  discard block
 block discarded – undo
583 583
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
584 584
      * @return object        the current Database instance
585 585
      */
586
-    public function groupStart($type = '', $andOr = ' AND'){
587
-      if (empty($this->where)){
586
+    public function groupStart($type = '', $andOr = ' AND') {
587
+      if (empty($this->where)) {
588 588
         $this->where = $type . ' (';
589 589
       }
590
-      else{
591
-          if(substr($this->where, -1) == '('){
590
+      else {
591
+          if (substr($this->where, -1) == '(') {
592 592
             $this->where .= $type . ' (';
593 593
           }
594
-          else{
594
+          else {
595 595
           	$this->where .= $andOr . ' ' . $type . ' (';
596 596
           }
597 597
       }
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      * @see  Database::groupStart()
604 604
      * @return object        the current Database instance
605 605
      */
606
-    public function notGroupStart(){
606
+    public function notGroupStart() {
607 607
       return $this->groupStart('NOT');
608 608
     }
609 609
 
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
      * @see  Database::groupStart()
613 613
      * @return object        the current Database instance
614 614
      */
615
-    public function orGroupStart(){
615
+    public function orGroupStart() {
616 616
       return $this->groupStart('', ' OR');
617 617
     }
618 618
 
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
      * @see  Database::groupStart()
622 622
      * @return object        the current Database instance
623 623
      */
624
-    public function orNotGroupStart(){
624
+    public function orNotGroupStart() {
625 625
       return $this->groupStart('NOT', ' OR');
626 626
     }
627 627
 
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
      * Close the parenthesis for the grouped SQL
630 630
      * @return object        the current Database instance
631 631
      */
632
-    public function groupEnd(){
632
+    public function groupEnd() {
633 633
       $this->where .= ')';
634 634
       return $this;
635 635
     }
@@ -643,10 +643,10 @@  discard block
 block discarded – undo
643 643
      * @param  boolean $escape whether to escape or not the values
644 644
      * @return object        the current Database instance
645 645
      */
646
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
646
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
647 647
       $_keys = array();
648
-      foreach ($keys as $k => $v){
649
-        if(is_null($v)){
648
+      foreach ($keys as $k => $v) {
649
+        if (is_null($v)) {
650 650
           $v = '';
651 651
         }
652 652
         $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v));
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
      * @see  Database::in()
663 663
      * @return object        the current Database instance
664 664
      */
665
-    public function notIn($field, array $keys, $escape = true){
665
+    public function notIn($field, array $keys, $escape = true) {
666 666
       return $this->in($field, $keys, 'NOT ', 'AND', $escape);
667 667
     }
668 668
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      * @see  Database::in()
672 672
      * @return object        the current Database instance
673 673
      */
674
-    public function orIn($field, array $keys, $escape = true){
674
+    public function orIn($field, array $keys, $escape = true) {
675 675
       return $this->in($field, $keys, '', 'OR', $escape);
676 676
     }
677 677
 
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
      * @see  Database::in()
681 681
      * @return object        the current Database instance
682 682
      */
683
-    public function orNotIn($field, array $keys, $escape = true){
683
+    public function orNotIn($field, array $keys, $escape = true) {
684 684
       return $this->in($field, $keys, 'NOT ', 'OR', $escape);
685 685
     }
686 686
 
@@ -694,11 +694,11 @@  discard block
 block discarded – undo
694 694
      * @param  boolean $escape whether to escape or not the values
695 695
      * @return object        the current Database instance
696 696
      */
697
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
698
-      if(is_null($value1)){
697
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
698
+      if (is_null($value1)) {
699 699
         $value1 = '';
700 700
       }
701
-      if(is_null($value2)){
701
+      if (is_null($value2)) {
702 702
         $value2 = '';
703 703
       }
704 704
       $whereStr = $field . ' ' . $type . ' BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2);
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
      * @see  Database::between()
712 712
      * @return object        the current Database instance
713 713
      */
714
-    public function notBetween($field, $value1, $value2, $escape = true){
714
+    public function notBetween($field, $value1, $value2, $escape = true) {
715 715
       return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
716 716
     }
717 717
 
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
      * @see  Database::between()
721 721
      * @return object        the current Database instance
722 722
      */
723
-    public function orBetween($field, $value1, $value2, $escape = true){
723
+    public function orBetween($field, $value1, $value2, $escape = true) {
724 724
       return $this->between($field, $value1, $value2, '', 'OR', $escape);
725 725
     }
726 726
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
      * @see  Database::between()
730 730
      * @return object        the current Database instance
731 731
      */
732
-    public function orNotBetween($field, $value1, $value2, $escape = true){
732
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
733 733
       return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
734 734
     }
735 735
 
@@ -742,20 +742,20 @@  discard block
 block discarded – undo
742 742
      * @param  boolean $escape whether to escape or not the values
743 743
      * @return object        the current Database instance
744 744
      */
745
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
746
-      if(empty($data)){
745
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
746
+      if (empty($data)) {
747 747
         $data = '';
748 748
       }
749 749
       $like = $escape ? $this->escape($data) : $data;
750
-      if (empty($this->where)){
750
+      if (empty($this->where)) {
751 751
         $this->where = $field . ' ' . $type . 'LIKE ' . $like;
752 752
       }
753
-      else{
754
-        if(substr($this->where, -1) == '('){
753
+      else {
754
+        if (substr($this->where, -1) == '(') {
755 755
           $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like;
756 756
         }
757
-        else{
758
-          $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like;
757
+        else {
758
+          $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'LIKE ' . $like;
759 759
         }
760 760
       }
761 761
       return $this;
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
      * @see  Database::like()
767 767
      * @return object        the current Database instance
768 768
      */
769
-    public function orLike($field, $data, $escape = true){
769
+    public function orLike($field, $data, $escape = true) {
770 770
       return $this->like($field, $data, '', 'OR', $escape);
771 771
     }
772 772
 
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      * @see  Database::like()
776 776
      * @return object        the current Database instance
777 777
      */
778
-    public function notLike($field, $data, $escape = true){
778
+    public function notLike($field, $data, $escape = true) {
779 779
       return $this->like($field, $data, 'NOT ', 'AND', $escape);
780 780
     }
781 781
 
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
      * @see  Database::like()
785 785
      * @return object        the current Database instance
786 786
      */
787
-    public function orNotLike($field, $data, $escape = true){
787
+    public function orNotLike($field, $data, $escape = true) {
788 788
       return $this->like($field, $data, 'NOT ', 'OR', $escape);
789 789
     }
790 790
 
@@ -795,14 +795,14 @@  discard block
 block discarded – undo
795 795
      * @param  int $limitEnd the limit count
796 796
      * @return object        the current Database instance
797 797
      */
798
-    public function limit($limit, $limitEnd = null){
799
-      if(empty($limit)){
798
+    public function limit($limit, $limitEnd = null) {
799
+      if (empty($limit)) {
800 800
         return;
801 801
       }
802
-      if (! is_null($limitEnd)){
802
+      if (!is_null($limitEnd)) {
803 803
         $this->limit = $limit . ', ' . $limitEnd;
804 804
       }
805
-      else{
805
+      else {
806 806
         $this->limit = $limit;
807 807
       }
808 808
       return $this;
@@ -814,16 +814,16 @@  discard block
 block discarded – undo
814 814
      * @param  string $orderDir the order direction (ASC or DESC)
815 815
      * @return object        the current Database instance
816 816
      */
817
-    public function orderBy($orderBy, $orderDir = ' ASC'){
818
-      if (! empty($orderDir)){
819
-        $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
817
+    public function orderBy($orderBy, $orderDir = ' ASC') {
818
+      if (!empty($orderDir)) {
819
+        $this->orderBy = !$this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
820 820
       }
821
-      else{
822
-        if(stristr($orderBy, ' ') || $orderBy == 'rand()'){
823
-          $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy;
821
+      else {
822
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
823
+          $this->orderBy = !$this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy;
824 824
         }
825
-        else{
826
-          $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC');
825
+        else {
826
+          $this->orderBy = !$this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC');
827 827
         }
828 828
       }
829 829
       return $this;
@@ -834,11 +834,11 @@  discard block
 block discarded – undo
834 834
      * @param  string|array $field the field name used or array of field list
835 835
      * @return object        the current Database instance
836 836
      */
837
-    public function groupBy($field){
838
-      if(is_array($field)){
837
+    public function groupBy($field) {
838
+      if (is_array($field)) {
839 839
         $this->groupBy = implode(', ', $field);
840 840
       }
841
-      else{
841
+      else {
842 842
         $this->groupBy = $field;
843 843
       }
844 844
       return $this;
@@ -852,13 +852,13 @@  discard block
 block discarded – undo
852 852
      * @param  boolean $escape whether to escape or not the values
853 853
      * @return object        the current Database instance
854 854
      */
855
-    public function having($field, $op = null, $val = null, $escape = true){
856
-      if(is_array($op)){
855
+    public function having($field, $op = null, $val = null, $escape = true) {
856
+      if (is_array($op)) {
857 857
         $x = explode('?', $field);
858 858
         $w = '';
859
-        foreach($x as $k => $v){
860
-  	      if(!empty($v)){
861
-            if(isset($op[$k]) && is_null($op[$k])){
859
+        foreach ($x as $k => $v) {
860
+  	      if (!empty($v)) {
861
+            if (isset($op[$k]) && is_null($op[$k])) {
862 862
               $op[$k] = '';
863 863
             }
864 864
   	      	$w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : '');
@@ -866,14 +866,14 @@  discard block
 block discarded – undo
866 866
       	}
867 867
         $this->having = $w;
868 868
       }
869
-      else if (! in_array($op, $this->operatorList)){
870
-        if(is_null($op)){
869
+      else if (!in_array($op, $this->operatorList)) {
870
+        if (is_null($op)) {
871 871
           $op = '';
872 872
         }
873 873
         $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op);
874 874
       }
875
-      else{
876
-        if(is_null($val)){
875
+      else {
876
+        if (is_null($val)) {
877 877
           $val = '';
878 878
         }
879 879
         $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val);
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
      * Return the number of rows returned by the current query
886 886
      * @return int
887 887
      */
888
-    public function numRows(){
888
+    public function numRows() {
889 889
       return $this->numRows;
890 890
     }
891 891
 
@@ -893,15 +893,15 @@  discard block
 block discarded – undo
893 893
      * Return the last insert id value
894 894
      * @return mixed
895 895
      */
896
-    public function insertId(){
896
+    public function insertId() {
897 897
       return $this->insertId;
898 898
     }
899 899
 
900 900
     /**
901 901
      * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.)
902 902
      */
903
-    public function error(){
904
-  		if($this->error){
903
+    public function error() {
904
+  		if ($this->error) {
905 905
   			show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error');
906 906
   		}
907 907
     }
@@ -912,14 +912,14 @@  discard block
 block discarded – undo
912 912
      * If is string will determine the result type "array" or "object"
913 913
      * @return mixed       the query SQL string or the record result
914 914
      */
915
-    public function get($returnSQLQueryOrResultType = false){
915
+    public function get($returnSQLQueryOrResultType = false) {
916 916
       $this->limit = 1;
917 917
       $query = $this->getAll(true);
918
-      if($returnSQLQueryOrResultType === true){
918
+      if ($returnSQLQueryOrResultType === true) {
919 919
         return $query;
920 920
       }
921
-      else{
922
-        return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) );
921
+      else {
922
+        return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false));
923 923
       }
924 924
     }
925 925
 
@@ -929,37 +929,37 @@  discard block
 block discarded – undo
929 929
      * If is string will determine the result type "array" or "object"
930 930
      * @return mixed       the query SQL string or the record result
931 931
      */
932
-    public function getAll($returnSQLQueryOrResultType = false){
932
+    public function getAll($returnSQLQueryOrResultType = false) {
933 933
       $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
934
-      if (! empty($this->join)){
934
+      if (!empty($this->join)) {
935 935
         $query .= $this->join;
936 936
       }
937 937
 	  
938
-      if (! empty($this->where)){
938
+      if (!empty($this->where)) {
939 939
         $query .= ' WHERE ' . $this->where;
940 940
       }
941 941
 
942
-      if (! empty($this->groupBy)){
942
+      if (!empty($this->groupBy)) {
943 943
         $query .= ' GROUP BY ' . $this->groupBy;
944 944
       }
945 945
 
946
-      if (! empty($this->having)){
946
+      if (!empty($this->having)) {
947 947
         $query .= ' HAVING ' . $this->having;
948 948
       }
949 949
 
950
-      if (! empty($this->orderBy)){
950
+      if (!empty($this->orderBy)) {
951 951
           $query .= ' ORDER BY ' . $this->orderBy;
952 952
       }
953 953
 
954
-      if(! empty($this->limit)){
954
+      if (!empty($this->limit)) {
955 955
       	$query .= ' LIMIT ' . $this->limit;
956 956
       }
957 957
 	  
958
-	   if($returnSQLQueryOrResultType === true){
958
+	   if ($returnSQLQueryOrResultType === true) {
959 959
       	return $query;
960 960
       }
961
-      else{
962
-    	   return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) );
961
+      else {
962
+    	   return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false));
963 963
       }
964 964
     }
965 965
 
@@ -969,15 +969,15 @@  discard block
 block discarded – undo
969 969
      * @param  boolean $escape  whether to escape or not the values
970 970
      * @return mixed          the insert id of the new record or null
971 971
      */
972
-    public function insert($data = array(), $escape = true){
972
+    public function insert($data = array(), $escape = true) {
973 973
       $column = array();
974 974
       $val = array();
975
-      if(empty($data) && $this->getData()){
975
+      if (empty($data) && $this->getData()) {
976 976
         $columns = array_keys($this->getData());
977 977
         $column = implode(',', $columns);
978 978
         $val = implode(', ', $this->getData());
979 979
       }
980
-      else{
980
+      else {
981 981
         $columns = array_keys($data);
982 982
         $column = implode(',', $columns);
983 983
         $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -986,14 +986,14 @@  discard block
 block discarded – undo
986 986
       $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')';
987 987
       $query = $this->query($query);
988 988
 
989
-      if ($query){
990
-        if(! $this->pdo){
989
+      if ($query) {
990
+        if (!$this->pdo) {
991 991
           $this->connect();
992 992
         }
993 993
         $this->insertId = $this->pdo->lastInsertId();
994 994
         return $this->insertId();
995 995
       }
996
-      else{
996
+      else {
997 997
 		  return false;
998 998
       }
999 999
     }
@@ -1004,29 +1004,29 @@  discard block
 block discarded – undo
1004 1004
      * @param  boolean $escape  whether to escape or not the values
1005 1005
      * @return mixed          the update status
1006 1006
      */
1007
-    public function update($data = array(), $escape = true){
1007
+    public function update($data = array(), $escape = true) {
1008 1008
       $query = 'UPDATE ' . $this->from . ' SET ';
1009 1009
       $values = array();
1010
-      if(empty($data) && $this->getData()){
1011
-        foreach ($this->getData() as $column => $val){
1010
+      if (empty($data) && $this->getData()) {
1011
+        foreach ($this->getData() as $column => $val) {
1012 1012
           $values[] = $column . ' = ' . $val;
1013 1013
         }
1014 1014
       }
1015
-      else{
1016
-        foreach ($data as $column => $val){
1015
+      else {
1016
+        foreach ($data as $column => $val) {
1017 1017
           $values[] = $column . '=' . ($escape ? $this->escape($val) : $val);
1018 1018
         }
1019 1019
       }
1020 1020
       $query .= implode(', ', $values);
1021
-      if (! empty($this->where)){
1021
+      if (!empty($this->where)) {
1022 1022
         $query .= ' WHERE ' . $this->where;
1023 1023
       }
1024 1024
 
1025
-      if (! empty($this->orderBy)){
1025
+      if (!empty($this->orderBy)) {
1026 1026
         $query .= ' ORDER BY ' . $this->orderBy;
1027 1027
       }
1028 1028
 
1029
-      if (! empty($this->limit)){
1029
+      if (!empty($this->limit)) {
1030 1030
         $query .= ' LIMIT ' . $this->limit;
1031 1031
       }
1032 1032
       return $this->query($query);
@@ -1036,22 +1036,22 @@  discard block
 block discarded – undo
1036 1036
      * Delete the record in database
1037 1037
      * @return mixed the delete status
1038 1038
      */
1039
-    public function delete(){
1039
+    public function delete() {
1040 1040
     	$query = 'DELETE FROM ' . $this->from;
1041 1041
 
1042
-    	if (! empty($this->where)){
1042
+    	if (!empty($this->where)) {
1043 1043
     		$query .= ' WHERE ' . $this->where;
1044 1044
       	}
1045 1045
 
1046
-    	if (! empty($this->orderBy)){
1046
+    	if (!empty($this->orderBy)) {
1047 1047
     	  $query .= ' ORDER BY ' . $this->orderBy;
1048 1048
       	}
1049 1049
 
1050
-    	if (! empty($this->limit)){
1050
+    	if (!empty($this->limit)) {
1051 1051
     		$query .= ' LIMIT ' . $this->limit;
1052 1052
       	}
1053 1053
 
1054
-    	if($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite'){  
1054
+    	if ($query == 'DELETE FROM ' . $this->from && $this->config['driver'] != 'sqlite') {  
1055 1055
     		$query = 'TRUNCATE TABLE ' . $this->from;
1056 1056
       }
1057 1057
     	return $this->query($query);
@@ -1064,13 +1064,13 @@  discard block
 block discarded – undo
1064 1064
      * @param  boolean $array return the result as array
1065 1065
      * @return mixed         the query result
1066 1066
      */
1067
-    public function query($query, $all = true, $array = false){
1067
+    public function query($query, $all = true, $array = false) {
1068 1068
       $this->reset();
1069
-      if(is_array($all)){
1069
+      if (is_array($all)) {
1070 1070
         $x = explode('?', $query);
1071 1071
         $q = '';
1072
-        foreach($x as $k => $v){
1073
-          if(! empty($v)){
1072
+        foreach ($x as $k => $v) {
1073
+          if (!empty($v)) {
1074 1074
             $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : '');
1075 1075
           }
1076 1076
         }
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
 
1080 1080
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
1081 1081
       $sqlSELECTQuery = stristr($this->query, 'SELECT');
1082
-      $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO'));
1082
+      $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . ($all ? 'YES' : 'NO'));
1083 1083
       //cache expire time
1084 1084
   	  $cacheExpire = $this->temporaryCacheTtl;
1085 1085
   	  
@@ -1101,34 +1101,34 @@  discard block
 block discarded – undo
1101 1101
   	  //if can use cache feature for this query
1102 1102
   	  $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
1103 1103
 	  
1104
-      if ($dbCacheStatus && $sqlSELECTQuery){
1104
+      if ($dbCacheStatus && $sqlSELECTQuery) {
1105 1105
         $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
1106 1106
         $cacheKey = md5($query . $all . $array);
1107
-        if(is_object($this->cacheInstance)){
1107
+        if (is_object($this->cacheInstance)) {
1108 1108
           $cacheInstance = $this->cacheInstance;
1109 1109
         }
1110
-        else{
1110
+        else {
1111 1111
           $obj = & get_instance();
1112 1112
           $cacheInstance = $obj->cache;  
1113 1113
         }
1114 1114
         $cacheContent = $cacheInstance->get($cacheKey);        
1115 1115
       }
1116
-      else{
1116
+      else {
1117 1117
 		  $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database');
1118 1118
       }
1119 1119
 
1120
-      if(! $this->pdo){
1120
+      if (!$this->pdo) {
1121 1121
         $this->connect();
1122 1122
       }
1123 1123
       
1124
-      if (! $cacheContent && $sqlSELECTQuery){
1124
+      if (!$cacheContent && $sqlSELECTQuery) {
1125 1125
 		    //for database query execution time
1126 1126
         $benchmarkMarkerKey = md5($query . $all . $array);
1127 1127
         $bench = null;
1128
-        if(is_object($this->benchmarkInstance)){
1128
+        if (is_object($this->benchmarkInstance)) {
1129 1129
           $bench = $this->benchmarkInstance;
1130 1130
         }
1131
-        else{
1131
+        else {
1132 1132
           $obj = & get_instance();
1133 1133
           $bench = $obj->benchmark;  
1134 1134
         }
@@ -1139,64 +1139,64 @@  discard block
 block discarded – undo
1139 1139
     		//get response time for this query
1140 1140
         $responseTime = $bench->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')');
1141 1141
 	     	//TODO use the configuration value for the high response time currently is 1 second
1142
-        if($responseTime >= 1 ){
1143
-            $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.');
1142
+        if ($responseTime >= 1) {
1143
+            $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.');
1144 1144
         }
1145
-        if ($sqlQuery){
1145
+        if ($sqlQuery) {
1146 1146
             //if need return all result like list of record
1147
-            if ($all){
1147
+            if ($all) {
1148 1148
     				    $this->result = ($array === false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC);
1149 1149
     		    }
1150
-            else{
1150
+            else {
1151 1151
 				        $this->result = ($array === false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC);
1152 1152
             }
1153 1153
             //Sqlite and pgsql always return 0 when using rowCount()
1154
-            if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1154
+            if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1155 1155
               $this->numRows = count($this->result);  
1156 1156
             }
1157
-            else{
1157
+            else {
1158 1158
               $this->numRows = $sqlQuery->rowCount(); 
1159 1159
             }
1160 1160
 
1161
-          if ($dbCacheStatus && $sqlSELECTQuery){
1162
-              $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use');
1161
+          if ($dbCacheStatus && $sqlSELECTQuery) {
1162
+              $this->logger->info('Save the result for query [' . $this->query . '] into cache for future use');
1163 1163
               $cacheInstance->set($cacheKey, $this->result, $cacheExpire);
1164 1164
           }
1165 1165
         }
1166
-        else{
1166
+        else {
1167 1167
           $error = $this->pdo->errorInfo();
1168 1168
           $this->error = isset($error[2]) ? $error[2] : '';
1169 1169
           $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1170 1170
           $this->error();
1171 1171
         }
1172 1172
       }
1173
-      else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){
1173
+      else if ((!$cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)) {
1174 1174
     		$queryStr = $this->pdo->query($this->query);
1175
-    		if($queryStr){
1175
+    		if ($queryStr) {
1176 1176
           //Sqlite and pgsql always return 0 when using rowCount()
1177
-          if(in_array($this->config['driver'], array('sqlite', 'pgsql'))){
1177
+          if (in_array($this->config['driver'], array('sqlite', 'pgsql'))) {
1178 1178
             $this->result = 1; //to test the result for the query like UPDATE, INSERT, DELETE
1179 1179
             $this->numRows = 1;  
1180 1180
           }
1181
-          else{
1181
+          else {
1182 1182
               $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE
1183 1183
               $this->numRows = $queryStr->rowCount(); 
1184 1184
           }
1185 1185
     		}
1186
-        if (! $this->result){
1186
+        if (!$this->result) {
1187 1187
           $error = $this->pdo->errorInfo();
1188 1188
           $this->error = isset($error[2]) ? $error[2] : '';
1189 1189
           $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error));
1190 1190
           $this->error();
1191 1191
         }
1192 1192
       }
1193
-      else{
1194
-        $this->logger->info('The result for query [' .$this->query. '] already cached use it');
1193
+      else {
1194
+        $this->logger->info('The result for query [' . $this->query . '] already cached use it');
1195 1195
         $this->result = $cacheContent;
1196 1196
 	     	$this->numRows = count($this->result);
1197 1197
       }
1198 1198
       $this->queryCount++;
1199
-      if(! $this->result){
1199
+      if (!$this->result) {
1200 1200
         $this->logger->info('No result where found for the query [' . $query . ']');
1201 1201
       }
1202 1202
       return $this->result;
@@ -1207,8 +1207,8 @@  discard block
 block discarded – undo
1207 1207
      * @param integer $ttl the cache time to live in second
1208 1208
      * @return object        the current Database instance
1209 1209
      */
1210
-    public function setCache($ttl = 0){
1211
-      if($ttl > 0){
1210
+    public function setCache($ttl = 0) {
1211
+      if ($ttl > 0) {
1212 1212
         $this->cacheTtl = $ttl;
1213 1213
 		    $this->temporaryCacheTtl = $ttl;
1214 1214
       }
@@ -1220,8 +1220,8 @@  discard block
 block discarded – undo
1220 1220
 	 * @param  integer $ttl the cache time to live in second
1221 1221
 	 * @return object        the current Database instance
1222 1222
 	 */
1223
-	public function cached($ttl = 0){
1224
-      if($ttl > 0){
1223
+	public function cached($ttl = 0) {
1224
+      if ($ttl > 0) {
1225 1225
         $this->temporaryCacheTtl = $ttl;
1226 1226
       }
1227 1227
 	  return $this;
@@ -1232,11 +1232,11 @@  discard block
 block discarded – undo
1232 1232
      * @param  mixed $data the data to be escaped
1233 1233
      * @return mixed       the data after escaped
1234 1234
      */
1235
-    public function escape($data){
1236
-      if(is_null($data)){
1235
+    public function escape($data) {
1236
+      if (is_null($data)) {
1237 1237
         return null;
1238 1238
       }
1239
-      if(! $this->pdo){
1239
+      if (!$this->pdo) {
1240 1240
         $this->connect();
1241 1241
       }
1242 1242
       return $this->pdo->quote(trim($data));
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
      * Return the number query executed count for the current request
1247 1247
      * @return int
1248 1248
      */
1249
-    public function queryCount(){
1249
+    public function queryCount() {
1250 1250
       return $this->queryCount;
1251 1251
     }
1252 1252
 
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
      * Return the current query SQL string
1255 1255
      * @return string
1256 1256
      */
1257
-    public function getQuery(){
1257
+    public function getQuery() {
1258 1258
       return $this->query;
1259 1259
     }
1260 1260
 
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
      * Return the application database name
1263 1263
      * @return string
1264 1264
      */
1265
-    public function getDatabaseName(){
1265
+    public function getDatabaseName() {
1266 1266
       return $this->databaseName;
1267 1267
     }
1268 1268
 
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
      * Return the database configuration
1271 1271
      * @return array
1272 1272
      */
1273
-    public  function getDatabaseConfiguration(){
1273
+    public  function getDatabaseConfiguration() {
1274 1274
       return $this->config;
1275 1275
     }
1276 1276
 
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
      * set the database configuration
1279 1279
      * @param array $config the configuration
1280 1280
      */
1281
-    public function setDatabaseConfiguration(array $config){
1281
+    public function setDatabaseConfiguration(array $config) {
1282 1282
       $this->config = array_merge($this->config, $config);
1283 1283
       $this->prefix = $this->config['prefix'];
1284 1284
       $this->databaseName = $this->config['database'];
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
      * Return the PDO instance
1291 1291
      * @return PDO
1292 1292
      */
1293
-    public function getPdo(){
1293
+    public function getPdo() {
1294 1294
       return $this->pdo;
1295 1295
     }
1296 1296
 
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
      * Set the PDO instance
1299 1299
      * @param PDO $pdo the pdo object
1300 1300
      */
1301
-    public function setPdo(PDO $pdo){
1301
+    public function setPdo(PDO $pdo) {
1302 1302
       $this->pdo = $pdo;
1303 1303
       return $this;
1304 1304
     }
@@ -1308,7 +1308,7 @@  discard block
 block discarded – undo
1308 1308
      * Return the Log instance
1309 1309
      * @return Log
1310 1310
      */
1311
-    public function getLogger(){
1311
+    public function getLogger() {
1312 1312
       return $this->logger;
1313 1313
     }
1314 1314
 
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
      * Set the log instance
1317 1317
      * @param Log $logger the log object
1318 1318
      */
1319
-    public function setLogger($logger){
1319
+    public function setLogger($logger) {
1320 1320
       $this->logger = $logger;
1321 1321
       return $this;
1322 1322
     }
@@ -1325,7 +1325,7 @@  discard block
 block discarded – undo
1325 1325
      * Return the cache instance
1326 1326
      * @return CacheInterface
1327 1327
      */
1328
-    public function getCacheInstance(){
1328
+    public function getCacheInstance() {
1329 1329
       return $this->cacheInstance;
1330 1330
     }
1331 1331
 
@@ -1333,7 +1333,7 @@  discard block
 block discarded – undo
1333 1333
      * Set the cache instance
1334 1334
      * @param CacheInterface $cache the cache object
1335 1335
      */
1336
-    public function setCacheInstance($cache){
1336
+    public function setCacheInstance($cache) {
1337 1337
       $this->cacheInstance = $cache;
1338 1338
       return $this;
1339 1339
     }
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
      * Return the benchmark instance
1343 1343
      * @return Benchmark
1344 1344
      */
1345
-    public function getBenchmark(){
1345
+    public function getBenchmark() {
1346 1346
       return $this->benchmarkInstance;
1347 1347
     }
1348 1348
 
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
      * Set the benchmark instance
1351 1351
      * @param Benchmark $cache the cache object
1352 1352
      */
1353
-    public function setBenchmark($benchmark){
1353
+    public function setBenchmark($benchmark) {
1354 1354
       $this->benchmarkInstance = $benchmark;
1355 1355
       return $this;
1356 1356
     }
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
      * Return the data to be used for insert, update, etc.
1360 1360
      * @return array
1361 1361
      */
1362
-    public function getData(){
1362
+    public function getData() {
1363 1363
       return $this->data;
1364 1364
     }
1365 1365
 
@@ -1370,7 +1370,7 @@  discard block
 block discarded – undo
1370 1370
      * @param boolean $escape whether to escape or not the $value
1371 1371
      * @return object        the current Database instance
1372 1372
      */
1373
-    public function setData($key, $value, $escape = true){
1373
+    public function setData($key, $value, $escape = true) {
1374 1374
       $this->data[$key] = $escape ? $this->escape($value) : $value;
1375 1375
       return $this;
1376 1376
     }
@@ -1379,12 +1379,12 @@  discard block
 block discarded – undo
1379 1379
      * Set the Log instance using argument or create new instance
1380 1380
      * @param object $logger the Log instance if not null
1381 1381
      */
1382
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
1383
-      if($logger !== null){
1382
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
1383
+      if ($logger !== null) {
1384 1384
         $this->logger = $logger;
1385 1385
       }
1386
-      else{
1387
-          $this->logger =& class_loader('Log', 'classes');
1386
+      else {
1387
+          $this->logger = & class_loader('Log', 'classes');
1388 1388
           $this->logger->setLogger('Library::Database');
1389 1389
       }
1390 1390
     }
@@ -1393,14 +1393,14 @@  discard block
 block discarded – undo
1393 1393
     * Setting the database configuration using the configuration file
1394 1394
     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
1395 1395
     */
1396
-    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()){
1396
+    protected function setDatabaseConfigurationFromConfigFile(array $overwriteConfig = array()) {
1397 1397
         $db = array();
1398
-        if(file_exists(CONFIG_PATH . 'database.php')){
1398
+        if (file_exists(CONFIG_PATH . 'database.php')) {
1399 1399
             //here don't use require_once because somewhere user can create database instance directly
1400 1400
             require CONFIG_PATH . 'database.php';
1401 1401
         }
1402 1402
           
1403
-        if(! empty($overwriteConfig)){
1403
+        if (!empty($overwriteConfig)) {
1404 1404
           $db = array_merge($db, $overwriteConfig);
1405 1405
         }
1406 1406
         $config = array();
@@ -1413,12 +1413,12 @@  discard block
 block discarded – undo
1413 1413
         $config['collation'] = isset($db['collation']) ? $db['collation'] : 'utf8_general_ci';
1414 1414
         $config['prefix']    = isset($db['prefix']) ? $db['prefix'] : '';
1415 1415
         $port = '';
1416
-        if(strstr($config['hostname'], ':')){
1416
+        if (strstr($config['hostname'], ':')) {
1417 1417
           $p = explode(':', $config['hostname']);
1418 1418
           $port = isset($p[1]) ? $p[1] : '';
1419 1419
           $config['hostname'] = isset($p[0]) ? $p[0] : '';
1420 1420
         }
1421
-        $config['port']      = $port;
1421
+        $config['port'] = $port;
1422 1422
         $this->setDatabaseConfiguration($config);  
1423 1423
     }
1424 1424
 
@@ -1426,9 +1426,9 @@  discard block
 block discarded – undo
1426 1426
      * This method is used to get the PDO DSN string using th configured driver
1427 1427
      * @return string the DSN string
1428 1428
      */
1429
-    protected function getDsnFromDriver(){
1429
+    protected function getDsnFromDriver() {
1430 1430
       $config = $this->getDatabaseConfiguration();
1431
-      if(! empty($config)){
1431
+      if (!empty($config)) {
1432 1432
             $driverDsnMap = array(
1433 1433
                                     'mysql' => 'mysql:host=' . $config['hostname'] . ';' 
1434 1434
                                                 . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') 
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
   /**
1452 1452
    * Reset the database class attributs to the initail values before each query.
1453 1453
    */
1454
-  private function reset(){
1454
+  private function reset() {
1455 1455
     $this->select   = '*';
1456 1456
     $this->from     = null;
1457 1457
     $this->where    = null;
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
   /**
1472 1472
    * The class destructor
1473 1473
    */
1474
-  public function __destruct(){
1474
+  public function __destruct() {
1475 1475
     $this->pdo = null;
1476 1476
   }
1477 1477
 
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Spacing   +74 added lines, -74 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 Response{
27
+	class Response {
28 28
 
29 29
 		/**
30 30
 		 * The list of request header to send with response
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Construct new response instance
67 67
 		 */
68
-		public function __construct(){
69
-			$this->_currentUrl =  (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' )
70
-					. (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' );
68
+		public function __construct() {
69
+			$this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')
70
+					. (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '');
71 71
 					
72 72
 			$this->_currentUrlCacheKey = md5($this->_currentUrl);
73 73
 			
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 		 * Get the logger singleton instance
83 83
 		 * @return Log the logger instance
84 84
 		 */
85
-		private static function getLogger(){
86
-			if(self::$logger == null){
87
-				self::$logger[0] =& class_loader('Log', 'classes');
85
+		private static function getLogger() {
86
+			if (self::$logger == null) {
87
+				self::$logger[0] = & class_loader('Log', 'classes');
88 88
 				self::$logger[0]->setLogger('Library::Response');
89 89
 			}
90 90
 			return self::$logger[0];
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 		 * @param  integer $httpCode the HTTP status code
96 96
 		 * @param  array   $headers   the additional headers to add to the existing headers list
97 97
 		 */
98
-		public static function sendHeaders($httpCode = 200, array $headers = array()){
98
+		public static function sendHeaders($httpCode = 200, array $headers = array()) {
99 99
 			set_http_status_header($httpCode);
100 100
 			self::setHeaders($headers);
101
-			if(! headers_sent()){
102
-				foreach(self::getHeaders() as $key => $value){
103
-					header($key .': '.$value);
101
+			if (!headers_sent()) {
102
+				foreach (self::getHeaders() as $key => $value) {
103
+					header($key . ': ' . $value);
104 104
 				}
105 105
 			}
106 106
 		}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		 * Get the list of the headers
110 110
 		 * @return array the headers list
111 111
 		 */
112
-		public static function getHeaders(){
112
+		public static function getHeaders() {
113 113
 			return self::$headers;
114 114
 		}
115 115
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		 * @param  string $name the header name
119 119
 		 * @return string       the header value
120 120
 		 */
121
-		public static function getHeader($name){
121
+		public static function getHeader($name) {
122 122
 			return array_key_exists($name, self::$headers) ? self::$headers[$name] : null;
123 123
 		}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		 * @param string $name  the header name
129 129
 		 * @param string $value the header value to be set
130 130
 		 */
131
-		public static function setHeader($name, $value){
131
+		public static function setHeader($name, $value) {
132 132
 			self::$headers[$name] = $value;
133 133
 		}
134 134
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * @param array $headers the list of the headers to set. 
138 138
 		 * Note: this will merge with the existing headers
139 139
 		 */
140
-		public static function setHeaders(array $headers){
140
+		public static function setHeaders(array $headers) {
141 141
 			self::$headers = array_merge(self::getHeaders(), $headers);
142 142
 		}
143 143
 		
@@ -145,17 +145,17 @@  discard block
 block discarded – undo
145 145
 		 * Redirect user in the specified page
146 146
 		 * @param  string $path the URL or URI to be redirect to
147 147
 		 */
148
-		public static function redirect($path = ''){
148
+		public static function redirect($path = '') {
149 149
 			$logger = self::getLogger();
150 150
 			$url = Url::site_url($path);
151
-			$logger->info('Redirect to URL [' .$url. ']');
152
-			if(! headers_sent()){
153
-				header('Location: '.$url);
151
+			$logger->info('Redirect to URL [' . $url . ']');
152
+			if (!headers_sent()) {
153
+				header('Location: ' . $url);
154 154
 				exit;
155 155
 			}
156
-			else{
156
+			else {
157 157
 				echo '<script>
158
-						location.href = "'.$url.'";
158
+						location.href = "'.$url . '";
159 159
 					</script>';
160 160
 			}
161 161
 		}
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
 		 * @return void|string          if $return is true will return the view content otherwise
169 169
 		 * will display the view content.
170 170
 		 */
171
-		public function render($view, $data = null, $return = false){
171
+		public function render($view, $data = null, $return = false) {
172 172
 			$logger = self::getLogger();
173 173
 			//convert data to an array
174
-			$data = ! is_array($data) ? (array) $data : $data;
174
+			$data = !is_array($data) ? (array) $data : $data;
175 175
 			$view = str_ireplace('.php', '', $view);
176 176
 			$view = trim($view, '/\\');
177 177
 			$viewFile = $view . '.php';
@@ -180,42 +180,42 @@  discard block
 block discarded – undo
180 180
 			//super instance
181 181
 			$obj = & get_instance();
182 182
 			
183
-			if(Module::hasModule()){
183
+			if (Module::hasModule()) {
184 184
 				//check in module first
185 185
 				$logger->debug('Checking the view [' . $view . '] from module list ...');
186 186
 				$mod = null;
187 187
 				//check if the request class contains module name
188
-				if(strpos($view, '/') !== false){
188
+				if (strpos($view, '/') !== false) {
189 189
 					$viewPath = explode('/', $view);
190
-					if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
190
+					if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
191 191
 						$mod = $viewPath[0];
192 192
 						array_shift($viewPath);
193 193
 						$view = implode('/', $viewPath);
194 194
 						$viewFile = $view . '.php';
195 195
 					}
196 196
 				}
197
-				if(! $mod && !empty($obj->moduleName)){
197
+				if (!$mod && !empty($obj->moduleName)) {
198 198
 					$mod = $obj->moduleName;
199 199
 				}
200
-				if($mod){
200
+				if ($mod) {
201 201
 					$moduleViewPath = Module::findViewFullPath($view, $mod);
202
-					if($moduleViewPath){
202
+					if ($moduleViewPath) {
203 203
 						$path = $moduleViewPath;
204
-						$logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it');
204
+						$logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it');
205 205
 					}
206
-					else{
207
-						$logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location');
206
+					else {
207
+						$logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location');
208 208
 					}
209 209
 				}
210
-				else{
210
+				else {
211 211
 					$logger->info('The current request does not use module using the default location.');
212 212
 				}
213 213
 			}
214 214
 			$logger->info('The view file path to be loaded is [' . $path . ']');
215 215
 			$found = false;
216
-			if(file_exists($path)){
217
-				foreach(get_object_vars($obj) as $key => $value){
218
-					if(! isset($this->{$key})){
216
+			if (file_exists($path)) {
217
+				foreach (get_object_vars($obj) as $key => $value) {
218
+					if (!isset($this->{$key})) {
219 219
 						$this->{$key} = & $obj->{$key};
220 220
 					}
221 221
 				}
@@ -224,39 +224,39 @@  discard block
 block discarded – undo
224 224
 				//need use require() instead of require_once because can load this view many time
225 225
 				require $path;
226 226
 				$content = ob_get_clean();
227
-				if($return){
227
+				if ($return) {
228 228
 					return $content;
229 229
 				}
230 230
 				$this->_pageRender .= $content;
231 231
 				$found = true;
232 232
 			}
233
-			if(! $found){
234
-				show_error('Unable to find view [' .$view . ']');
233
+			if (!$found) {
234
+				show_error('Unable to find view [' . $view . ']');
235 235
 			}
236 236
 		}
237 237
 		
238 238
 		/**
239 239
 		* Send the final page output to user
240 240
 		*/
241
-		public function renderFinalPage(){
241
+		public function renderFinalPage() {
242 242
 			$logger = self::getLogger();
243 243
 			$obj = & get_instance();
244 244
 			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
245 245
 			$dispatcher = $obj->eventdispatcher;
246 246
 			$content = $this->_pageRender;
247
-			if(! $content){
247
+			if (!$content) {
248 248
 				$logger->warning('The final view content is empty.');
249 249
 				return;
250 250
 			}
251 251
 			//dispatch
252 252
 			$event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
253
-			$content = ! empty($event->payload) ? $event->payload : null;
254
-			if(empty($content)){
253
+			$content = !empty($event->payload) ? $event->payload : null;
254
+			if (empty($content)) {
255 255
 				$logger->warning('The view content is empty after dispatch to event listeners.');
256 256
 			}
257 257
 			
258 258
 			//check whether need save the page into cache.
259
-			if($cachePageStatus){
259
+			if ($cachePageStatus) {
260 260
 				//current page URL
261 261
 				$url = $this->_currentUrl;
262 262
 				//Cache view Time to live in second
@@ -271,14 +271,14 @@  discard block
 block discarded – undo
271 271
 				
272 272
 				//get the cache information to prepare header to send to browser
273 273
 				$cacheInfo = $cacheInstance->getInfo($cacheKey);
274
-				if($cacheInfo){
274
+				if ($cacheInfo) {
275 275
 					$lastModified = $cacheInfo['mtime'];
276 276
 					$expire = $cacheInfo['expire'];
277 277
 					$maxAge = $expire - time();
278 278
 					self::setHeader('Pragma', 'public');
279 279
 					self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
280
-					self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
281
-					self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
280
+					self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
281
+					self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
282 282
 				}
283 283
 			}
284 284
 			
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
 			$content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);
290 290
 			
291 291
 			//compress the output if is available
292
-			if (self::$_canCompressOutput){
292
+			if (self::$_canCompressOutput) {
293 293
 				ob_start('ob_gzhandler');
294 294
 			}
295
-			else{
295
+			else {
296 296
 				ob_start();
297 297
 			}
298 298
 			self::sendHeaders(200);
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		/**
304 304
 		* Send the final page output to user if is cached
305 305
 		*/
306
-		public function renderFinalPageFromCache(&$cache){
306
+		public function renderFinalPageFromCache(&$cache) {
307 307
 			$logger = self::getLogger();
308 308
 			$url = $this->_currentUrl;					
309 309
 			//the current page cache key for identification
@@ -312,25 +312,25 @@  discard block
 block discarded – undo
312 312
 			$logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...');
313 313
 			//get the cache information to prepare header to send to browser
314 314
 			$cacheInfo = $cache->getInfo($pageCacheKey);
315
-			if($cacheInfo){
315
+			if ($cacheInfo) {
316 316
 				$lastModified = $cacheInfo['mtime'];
317 317
 				$expire = $cacheInfo['expire'];
318 318
 				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
319 319
 				self::setHeader('Pragma', 'public');
320 320
 				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
321
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
322
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
323
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
321
+				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
322
+				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
323
+				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
324 324
 					$logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser');
325 325
 					self::sendHeaders(304);
326 326
 					return;
327 327
 				}
328
-				else{
328
+				else {
329 329
 					$logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser');
330 330
 					self::sendHeaders(200);
331 331
 					//get the cache content
332 332
 					$content = $cache->get($pageCacheKey);
333
-					if($content){
333
+					if ($content) {
334 334
 						$logger->info('The page content for the URL [' . $url . '] already cached just display it');
335 335
 						//load benchmark class
336 336
 						$benchmark = & class_loader('Benchmark');
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 						
344 344
 						///display the final output
345 345
 						//compress the output if is available
346
-						if (self::$_canCompressOutput){
346
+						if (self::$_canCompressOutput) {
347 347
 							ob_start('ob_gzhandler');
348 348
 						}
349
-						else{
349
+						else {
350 350
 							ob_start();
351 351
 						}
352 352
 						echo $content;
353 353
 						ob_end_flush();
354 354
 						return;
355 355
 					}
356
-					else{
356
+					else {
357 357
 						$logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired');
358 358
 						$cache->delete($pageCacheKey);
359 359
 					}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		* Get the final page to be rendered
366 366
 		* @return string
367 367
 		*/
368
-		public function getFinalPageRendered(){
368
+		public function getFinalPageRendered() {
369 369
 			return $this->_pageRender;
370 370
 		}
371 371
 
@@ -373,14 +373,14 @@  discard block
 block discarded – undo
373 373
 		 * Send the HTTP 404 error if can not found the 
374 374
 		 * routing information for the current request
375 375
 		 */
376
-		public static function send404(){
376
+		public static function send404() {
377 377
 			/********* for logs **************/
378 378
 			//can't use $obj = & get_instance()  here because the global super object will be available until
379 379
 			//the main controller is loaded even for Loader::library('xxxx');
380 380
 			$logger = self::getLogger();
381
-			$request =& class_loader('Request', 'classes');
382
-			$userAgent =& class_loader('Browser');
383
-			$browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
381
+			$request = & class_loader('Request', 'classes');
382
+			$userAgent = & class_loader('Browser');
383
+			$browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
384 384
 			
385 385
 			//here can't use Loader::functions just include the helper manually
386 386
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
@@ -390,12 +390,12 @@  discard block
 block discarded – undo
390 390
 			$logger->error($str);
391 391
 			/***********************************/
392 392
 			$path = CORE_VIEWS_PATH . '404.php';
393
-			if(file_exists($path)){
393
+			if (file_exists($path)) {
394 394
 				//compress the output if is available
395
-				if (self::$_canCompressOutput){
395
+				if (self::$_canCompressOutput) {
396 396
 					ob_start('ob_gzhandler');
397 397
 				}
398
-				else{
398
+				else {
399 399
 					ob_start();
400 400
 				}
401 401
 				require_once $path;
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 				self::sendHeaders(404);
404 404
 				echo $output;
405 405
 			}
406
-			else{
407
-				show_error('The 404 view [' .$path. '] does not exist');
406
+			else {
407
+				show_error('The 404 view [' . $path . '] does not exist');
408 408
 			}
409 409
 		}
410 410
 
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
 		 * Display the error to user
413 413
 		 * @param  array  $data the error information
414 414
 		 */
415
-		public static function sendError(array $data = array()){
415
+		public static function sendError(array $data = array()) {
416 416
 			$path = CORE_VIEWS_PATH . 'errors.php';
417
-			if(file_exists($path)){
417
+			if (file_exists($path)) {
418 418
 				//compress the output if exists
419
-				if (self::$_canCompressOutput){
419
+				if (self::$_canCompressOutput) {
420 420
 					ob_start('ob_gzhandler');
421 421
 				}
422
-				else{
422
+				else {
423 423
 					ob_start();
424 424
 				}
425 425
 				extract($data);
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 				self::sendHeaders(503);
429 429
 				echo $output;
430 430
 			}
431
-			else{
431
+			else {
432 432
 				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
433 433
 				set_http_status_header(503);
434 434
 				echo 'The error view [' . $path . '] does not exist';
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(null);
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.