Passed
Pull Request — 1.0.0-dev (#1)
by
unknown
02:46
created
core/classes/DBSessionHandler.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
     /**
28 28
      * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
      */
30
-    if ( !interface_exists('SessionHandlerInterface')){
30
+    if (!interface_exists('SessionHandlerInterface')) {
31 31
         show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
     }
33 33
 
34
-    class DBSessionHandler extends BaseClass implements SessionHandlerInterface{
34
+    class DBSessionHandler extends BaseClass implements SessionHandlerInterface {
35 35
 		
36 36
         /**
37 37
          * The encryption method to use to encrypt session data in database
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
          * Create new instance of Database session handler
80 80
          * @param object $modelInstance the model instance
81 81
          */
82
-        public function __construct(DBSessionHandlerModel $modelInstance = null){
82
+        public function __construct(DBSessionHandlerModel $modelInstance = null) {
83 83
             parent::__construct();
84 84
 			
85 85
             //Set Loader instance to use
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	       
88 88
             $this->OBJ = & get_instance();
89 89
 		    
90
-            if (is_object($modelInstance)){
90
+            if (is_object($modelInstance)) {
91 91
                 $this->setModelInstance($modelInstance);
92 92
             }
93 93
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
          * Set the session secret used to encrypt the data in database 
97 97
          * @param string $secret the base64 string secret
98 98
          */
99
-        public function setSessionSecret($secret){
99
+        public function setSessionSecret($secret) {
100 100
             $this->sessionSecret = $secret;
101 101
             return $this;
102 102
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
          * Return the session secret
106 106
          * @return string 
107 107
          */
108
-        public function getSessionSecret(){
108
+        public function getSessionSecret() {
109 109
             return $this->sessionSecret;
110 110
         }
111 111
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
          * Set the initializer vector for openssl 
115 115
          * @param string $key the session secret used in base64 format
116 116
          */
117
-        public function setInitializerVector($key){
117
+        public function setInitializerVector($key) {
118 118
             $ivLength = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
119 119
             $key = base64_decode($key);
120 120
             $this->iv = substr(hash('sha256', $key), 0, $ivLength);
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
          * Return the initializer vector
126 126
          * @return string 
127 127
          */
128
-        public function getInitializerVector(){
128
+        public function getInitializerVector() {
129 129
             return $this->iv;
130 130
         }
131 131
 
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
          * @param  string $sessionName the session name
136 136
          * @return boolean 
137 137
          */
138
-        public function open($savePath, $sessionName){
138
+        public function open($savePath, $sessionName) {
139 139
             $this->logger->debug('Opening database session handler for [' . $sessionName . ']');
140 140
             //try to check if session secret is set before
141 141
             $secret = $this->getSessionSecret();
142
-            if (empty($secret)){
142
+            if (empty($secret)) {
143 143
                 $secret = get_config('session_secret', null);
144 144
                 $this->setSessionSecret($secret);
145 145
             }
146 146
             $this->logger->info('Session secret: ' . $secret);
147 147
 
148
-            if (! is_object($this->modelInstance)){
148
+            if (!is_object($this->modelInstance)) {
149 149
                 $this->setModelInstanceFromSessionConfig();
150 150
             }
151 151
             $this->setInitializerVector($secret);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
             //set session tables columns
154 154
             $this->sessionTableColumns = $this->modelInstance->getSessionTableColumns();
155 155
 
156
-            if (empty($this->sessionTableColumns)){
156
+            if (empty($this->sessionTableColumns)) {
157 157
                 show_error('The session handler is "database" but the table columns not set');
158 158
             }
159 159
             $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
          * Close the session
170 170
          * @return boolean
171 171
          */
172
-        public function close(){
172
+        public function close() {
173 173
             $this->logger->debug('Closing database session handler');
174 174
             return true;
175 175
         }
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
          * @param  string $sid the session id to use
180 180
          * @return string      the session data in serialiaze format
181 181
          */
182
-        public function read($sid){
182
+        public function read($sid) {
183 183
             $this->logger->debug('Reading database session data for SID: ' . $sid);
184 184
             $instance = $this->getModelInstance();
185 185
             $columns = $this->sessionTableColumns;
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 			
189 189
             $ip = get_ip();
190 190
             $host = @gethostbyaddr($ip) or null;
191
-            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
191
+            $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
192 192
 			
193 193
             $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
194
-            if ($data && isset($data->{$columns['sdata']})){
194
+            if ($data && isset($data->{$columns['sdata']})) {
195 195
                 //checking inactivity 
196 196
                 $timeInactivity = time() - get_config('session_inactivity_time', 100);
197
-                if ($data->{$columns['stime']} < $timeInactivity){
197
+                if ($data->{$columns['stime']} < $timeInactivity) {
198 198
                     $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
199 199
                     $this->destroy($sid);
200 200
                     return null;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
          * @param  mixed $data the session data to save in serialize format
212 212
          * @return boolean 
213 213
          */
214
-        public function write($sid, $data){
214
+        public function write($sid, $data) {
215 215
             $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
216 216
             $instance = $this->getModelInstance();
217 217
             $columns = $this->sessionTableColumns;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
             $ip = get_ip();
223 223
             $keyValue = $instance->getKeyValue();
224 224
             $host = @gethostbyaddr($ip) or null;
225
-            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
225
+            $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
226 226
             $data = $this->encode($data);
227 227
             $params = array(
228 228
                             $columns['sid'] => $sid,
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
                         );
236 236
             $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
237 237
             $exists = $instance->get($sid);
238
-            if ($exists){
238
+            if ($exists) {
239 239
                 $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
240 240
                 //update
241 241
                 unset($params[$columns['sid']]);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
          * @param  string $sid the session id value
252 252
          * @return boolean
253 253
          */
254
-        public function destroy($sid){
254
+        public function destroy($sid) {
255 255
             $this->logger->debug('Destroy of session data for SID: ' . $sid);
256 256
             $instance = $this->modelInstance;
257 257
             $instance->delete($sid);
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
          * @param  integer $maxLifetime the max lifetime
264 264
          * @return boolean
265 265
          */
266
-        public function gc($maxLifetime){
266
+        public function gc($maxLifetime) {
267 267
             $instance = $this->modelInstance;
268 268
             $time = time() - $maxLifetime;
269 269
             $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
          * @param  mixed $data the session data to encode
277 277
          * @return mixed the encoded session data
278 278
          */
279
-        public function encode($data){
279
+        public function encode($data) {
280 280
             $key = base64_decode($this->sessionSecret);
281
-            $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
281
+            $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
282 282
             $output = base64_encode($dataEncrypted);
283 283
             return $output;
284 284
         }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
          * @param  mixed $data the data to decode
290 290
          * @return mixed       the decoded data
291 291
          */
292
-        public function decode($data){
292
+        public function decode($data) {
293 293
             $key = base64_decode($this->sessionSecret);
294 294
             $data = base64_decode($data);
295 295
             $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
          * set the loader instance for future use
310 310
          * @param object Loader $loader the loader object
311 311
          */
312
-            public function setLoader($loader){
312
+            public function setLoader($loader) {
313 313
             $this->loader = $loader;
314 314
             return $this;
315 315
         }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
          * set the model instance for future use
327 327
          * @param DBSessionHandlerModel $modelInstance the model object
328 328
          */
329
-            public function setModelInstance(DBSessionHandlerModel $modelInstance){
329
+            public function setModelInstance(DBSessionHandlerModel $modelInstance) {
330 330
             $this->modelInstance = $modelInstance;
331 331
             return $this;
332 332
         }
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
         /**
335 335
          * Set the model instance using the configuration for session
336 336
          */
337
-        protected function setModelInstanceFromSessionConfig(){
337
+        protected function setModelInstanceFromSessionConfig() {
338 338
             $modelName = get_config('session_save_path');
339 339
             $this->logger->info('The database session model: ' . $modelName);
340 340
             $this->loader->model($modelName, 'dbsessionhandlerinstance'); 
341 341
             //@codeCoverageIgnoreStart
342 342
             if (isset($this->OBJ->dbsessionhandlerinstance) 
343
-                && ! ($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
343
+                && !($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
344 344
             ) {
345 345
                 show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
346 346
             }  
Please login to merge, or discard this patch.
core/classes/Response.php 2 patches
Indentation   +460 added lines, -460 removed lines patch added patch discarded remove patch
@@ -1,508 +1,508 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Response extends BaseStaticClass {
27
+    class Response extends BaseStaticClass {
28 28
 
29
-		/**
30
-		 * The list of request header to send with response
31
-		 * @var array
32
-		 */
33
-		private static $headers = array();
29
+        /**
30
+         * The list of request header to send with response
31
+         * @var array
32
+         */
33
+        private static $headers = array();
34 34
 		
35
-		/**
36
-		 * The final page content to display to user
37
-		 * @var string
38
-		 */
39
-		private $_pageRender = null;
35
+        /**
36
+         * The final page content to display to user
37
+         * @var string
38
+         */
39
+        private $_pageRender = null;
40 40
 		
41
-		/**
42
-		 * The current request URL
43
-		 * @var string
44
-		 */
45
-		private $_currentUrl = null;
41
+        /**
42
+         * The current request URL
43
+         * @var string
44
+         */
45
+        private $_currentUrl = null;
46 46
 		
47
-		/**
48
-		 * The current request URL cache key
49
-		 * @var string
50
-		 */
51
-		private $_currentUrlCacheKey = null;
47
+        /**
48
+         * The current request URL cache key
49
+         * @var string
50
+         */
51
+        private $_currentUrlCacheKey = null;
52 52
 		
53
-		/**
54
-		* Whether we can compress the output using Gzip
55
-		* @var boolean
56
-		*/
57
-		private static $_canCompressOutput = false;
53
+        /**
54
+         * Whether we can compress the output using Gzip
55
+         * @var boolean
56
+         */
57
+        private static $_canCompressOutput = false;
58 58
 		
59
-		/**
60
-		 * Construct new response instance
61
-		 */
62
-		public function __construct() {
63
-			$currentUrl = '';
64
-			if (!empty($_SERVER['REQUEST_URI'])) {
65
-				$currentUrl = $_SERVER['REQUEST_URI'];
66
-			}
67
-			if (!empty($_SERVER['QUERY_STRING'])) {
68
-				$currentUrl .= '?' . $_SERVER['QUERY_STRING'];
69
-			}
70
-			$this->_currentUrl = $currentUrl;
59
+        /**
60
+         * Construct new response instance
61
+         */
62
+        public function __construct() {
63
+            $currentUrl = '';
64
+            if (!empty($_SERVER['REQUEST_URI'])) {
65
+                $currentUrl = $_SERVER['REQUEST_URI'];
66
+            }
67
+            if (!empty($_SERVER['QUERY_STRING'])) {
68
+                $currentUrl .= '?' . $_SERVER['QUERY_STRING'];
69
+            }
70
+            $this->_currentUrl = $currentUrl;
71 71
 					
72
-			$this->_currentUrlCacheKey = md5($this->_currentUrl);
72
+            $this->_currentUrlCacheKey = md5($this->_currentUrl);
73 73
 			
74
-			self::$_canCompressOutput = get_config('compress_output')
75
-										  && isset($_SERVER['HTTP_ACCEPT_ENCODING']) 
76
-										  && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false 
77
-										  && extension_loaded('zlib')
78
-										  && (bool) ini_get('zlib.output_compression') === false;
79
-		}
74
+            self::$_canCompressOutput = get_config('compress_output')
75
+                                          && isset($_SERVER['HTTP_ACCEPT_ENCODING']) 
76
+                                          && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false 
77
+                                          && extension_loaded('zlib')
78
+                                          && (bool) ini_get('zlib.output_compression') === false;
79
+        }
80 80
 
81 81
 		
82
-		/**
83
-		 * Send the HTTP Response headers
84
-		 * @param  integer $httpCode the HTTP status code
85
-		 * @param  array   $headers   the additional headers to add to the existing headers list
86
-		 */
87
-		public static function sendHeaders($httpCode = 200, array $headers = array()) {
88
-			set_http_status_header($httpCode);
89
-			self::setHeaders($headers);
90
-			if (!headers_sent()) {
91
-				foreach (self::getHeaders() as $key => $value) {
92
-					header($key . ': ' . $value);
93
-				}
94
-			}
95
-		}
82
+        /**
83
+         * Send the HTTP Response headers
84
+         * @param  integer $httpCode the HTTP status code
85
+         * @param  array   $headers   the additional headers to add to the existing headers list
86
+         */
87
+        public static function sendHeaders($httpCode = 200, array $headers = array()) {
88
+            set_http_status_header($httpCode);
89
+            self::setHeaders($headers);
90
+            if (!headers_sent()) {
91
+                foreach (self::getHeaders() as $key => $value) {
92
+                    header($key . ': ' . $value);
93
+                }
94
+            }
95
+        }
96 96
 
97
-		/**
98
-		 * Get the list of the headers
99
-		 * @return array the headers list
100
-		 */
101
-		public static function getHeaders() {
102
-			return self::$headers;
103
-		}
97
+        /**
98
+         * Get the list of the headers
99
+         * @return array the headers list
100
+         */
101
+        public static function getHeaders() {
102
+            return self::$headers;
103
+        }
104 104
 
105
-		/**
106
-		 * Get the header value for the given name
107
-		 * @param  string $name the header name
108
-		 * @return string|null       the header value
109
-		 */
110
-		public static function getHeader($name) {
111
-			if (array_key_exists($name, self::$headers)) {
112
-				return self::$headers[$name];
113
-			}
114
-			return null;
115
-		}
105
+        /**
106
+         * Get the header value for the given name
107
+         * @param  string $name the header name
108
+         * @return string|null       the header value
109
+         */
110
+        public static function getHeader($name) {
111
+            if (array_key_exists($name, self::$headers)) {
112
+                return self::$headers[$name];
113
+            }
114
+            return null;
115
+        }
116 116
 
117 117
 
118
-		/**
119
-		 * Set the header value for the specified name
120
-		 * @param string $name  the header name
121
-		 * @param string $value the header value to be set
122
-		 */
123
-		public static function setHeader($name, $value) {
124
-			self::$headers[$name] = $value;
125
-		}
118
+        /**
119
+         * Set the header value for the specified name
120
+         * @param string $name  the header name
121
+         * @param string $value the header value to be set
122
+         */
123
+        public static function setHeader($name, $value) {
124
+            self::$headers[$name] = $value;
125
+        }
126 126
 
127
-		/**
128
-		 * Set the headers using array
129
-		 * @param array $headers the list of the headers to set. 
130
-		 * Note: this will merge with the existing headers
131
-		 */
132
-		public static function setHeaders(array $headers) {
133
-			self::$headers = array_merge(self::getHeaders(), $headers);
134
-		}
127
+        /**
128
+         * Set the headers using array
129
+         * @param array $headers the list of the headers to set. 
130
+         * Note: this will merge with the existing headers
131
+         */
132
+        public static function setHeaders(array $headers) {
133
+            self::$headers = array_merge(self::getHeaders(), $headers);
134
+        }
135 135
 		
136
-		/**
137
-		 * Redirect user to the specified page
138
-		 * @param  string $path the URL or URI to be redirect to
139
-		 */
140
-		public static function redirect($path = '') {
141
-			$logger = self::getLogger();
142
-			$url = Url::site_url($path);
143
-			$logger->info('Redirect to URL [' . $url . ']');
144
-			if (!headers_sent()) {
145
-				header('Location: ' . $url);
146
-				exit;
147
-			}
148
-			echo '<script>
136
+        /**
137
+         * Redirect user to the specified page
138
+         * @param  string $path the URL or URI to be redirect to
139
+         */
140
+        public static function redirect($path = '') {
141
+            $logger = self::getLogger();
142
+            $url = Url::site_url($path);
143
+            $logger->info('Redirect to URL [' . $url . ']');
144
+            if (!headers_sent()) {
145
+                header('Location: ' . $url);
146
+                exit;
147
+            }
148
+            echo '<script>
149 149
 					location.href = "'.$url . '";
150 150
 				</script>';
151
-		}
151
+        }
152 152
 
153
-		/**
154
-		 * Render the view to display later or return the content
155
-		 * @param  string  $view   the view name or path
156
-		 * @param  array|object   $data   the variable data to use in the view
157
-		 * @param  boolean $return whether to return the view generated content or display it directly
158
-		 * @return void|string          if $return is true will return the view content otherwise
159
-		 * will display the view content.
160
-		 */
161
-		public function render($view, $data = null, $return = false) {
162
-			$logger = self::getLogger();
163
-			//convert data to an array
164
-			$data = (array) $data;
165
-			$view = str_ireplace('.php', '', $view);
166
-			$view = trim($view, '/\\');
167
-			$viewFile = $view . '.php';
168
-			$path = APPS_VIEWS_PATH . $viewFile;
153
+        /**
154
+         * Render the view to display later or return the content
155
+         * @param  string  $view   the view name or path
156
+         * @param  array|object   $data   the variable data to use in the view
157
+         * @param  boolean $return whether to return the view generated content or display it directly
158
+         * @return void|string          if $return is true will return the view content otherwise
159
+         * will display the view content.
160
+         */
161
+        public function render($view, $data = null, $return = false) {
162
+            $logger = self::getLogger();
163
+            //convert data to an array
164
+            $data = (array) $data;
165
+            $view = str_ireplace('.php', '', $view);
166
+            $view = trim($view, '/\\');
167
+            $viewFile = $view . '.php';
168
+            $path = APPS_VIEWS_PATH . $viewFile;
169 169
 			
170
-			//check in module first
171
-			$logger->debug('Checking the view [' . $view . '] from module list ...');
172
-			$moduleInfo = $this->getModuleInfoForView($view);
173
-			$module    = $moduleInfo['module'];
174
-			$view  = $moduleInfo['view'];
170
+            //check in module first
171
+            $logger->debug('Checking the view [' . $view . '] from module list ...');
172
+            $moduleInfo = $this->getModuleInfoForView($view);
173
+            $module    = $moduleInfo['module'];
174
+            $view  = $moduleInfo['view'];
175 175
 			
176
-			$moduleViewPath = Module::findViewFullPath($view, $module);
177
-			if($moduleViewPath){
178
-				$path = $moduleViewPath;
179
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it');
180
-			} else{
181
-				$logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location');
182
-			}
176
+            $moduleViewPath = Module::findViewFullPath($view, $module);
177
+            if($moduleViewPath){
178
+                $path = $moduleViewPath;
179
+                $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it');
180
+            } else{
181
+                $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location');
182
+            }
183 183
 			
184
-			$logger->info('The view file path to be loaded is [' . $path . ']');
184
+            $logger->info('The view file path to be loaded is [' . $path . ']');
185 185
 			
186
-			/////////
187
-			if($return){
188
-				return $this->loadView($path, $data, true);
189
-			}
190
-			$this->loadView($path, $data, false);
191
-		}
186
+            /////////
187
+            if($return){
188
+                return $this->loadView($path, $data, true);
189
+            }
190
+            $this->loadView($path, $data, false);
191
+        }
192 192
 
193 193
 		
194
-		/**
195
-		* Send the final page output to user
196
-		*/
197
-		public function renderFinalPage() {
198
-			$logger = self::getLogger();
199
-			$obj = & get_instance();
200
-			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
201
-			$dispatcher = $obj->eventdispatcher;
202
-			$content = $this->_pageRender;
203
-			if (!$content) {
204
-				$logger->warning('The final view content is empty.');
205
-				return;
206
-			}
207
-			//dispatch
208
-			$event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
209
-			$content = null;
210
-			if (!empty($event->payload)) {
211
-				$content = $event->payload;
212
-			}
213
-			if (empty($content)) {
214
-				$logger->warning('The view content is empty after dispatch to event listeners.');
215
-			}
216
-			//remove unsed space in the content
217
-			$content = preg_replace('~>\s*\n\s*<~', '><', $content);
218
-			//check whether need save the page into cache.
219
-			if ($cachePageStatus) {
220
-				$this->savePageContentIntoCache($content);
221
-			}
222
-			$content = $this->replaceElapseTimeAndMemoryUsage($content);
194
+        /**
195
+         * Send the final page output to user
196
+         */
197
+        public function renderFinalPage() {
198
+            $logger = self::getLogger();
199
+            $obj = & get_instance();
200
+            $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
201
+            $dispatcher = $obj->eventdispatcher;
202
+            $content = $this->_pageRender;
203
+            if (!$content) {
204
+                $logger->warning('The final view content is empty.');
205
+                return;
206
+            }
207
+            //dispatch
208
+            $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
209
+            $content = null;
210
+            if (!empty($event->payload)) {
211
+                $content = $event->payload;
212
+            }
213
+            if (empty($content)) {
214
+                $logger->warning('The view content is empty after dispatch to event listeners.');
215
+            }
216
+            //remove unsed space in the content
217
+            $content = preg_replace('~>\s*\n\s*<~', '><', $content);
218
+            //check whether need save the page into cache.
219
+            if ($cachePageStatus) {
220
+                $this->savePageContentIntoCache($content);
221
+            }
222
+            $content = $this->replaceElapseTimeAndMemoryUsage($content);
223 223
 
224
-			//compress the output if is available
225
-			$type = null;
226
-			if (self::$_canCompressOutput) {
227
-				$type = 'ob_gzhandler';
228
-			}
229
-			ob_start($type);
230
-			self::sendHeaders(200);
231
-			echo $content;
232
-			ob_end_flush();
233
-		}
224
+            //compress the output if is available
225
+            $type = null;
226
+            if (self::$_canCompressOutput) {
227
+                $type = 'ob_gzhandler';
228
+            }
229
+            ob_start($type);
230
+            self::sendHeaders(200);
231
+            echo $content;
232
+            ob_end_flush();
233
+        }
234 234
 
235 235
 		
236
-		/**
237
-		* Send the final page output to user if is cached
238
-		* @param object $cache the cache instance
239
-		*
240
-		* @return boolean whether the page content if available or not
241
-		*/
242
-		public function renderFinalPageFromCache(&$cache) {
243
-			$logger = self::getLogger();
244
-			//the current page cache key for identification
245
-			$pageCacheKey = $this->_currentUrlCacheKey;
236
+        /**
237
+         * Send the final page output to user if is cached
238
+         * @param object $cache the cache instance
239
+         *
240
+         * @return boolean whether the page content if available or not
241
+         */
242
+        public function renderFinalPageFromCache(&$cache) {
243
+            $logger = self::getLogger();
244
+            //the current page cache key for identification
245
+            $pageCacheKey = $this->_currentUrlCacheKey;
246 246
 			
247
-			$logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...');
248
-			//get the cache information to prepare header to send to browser
249
-			$cacheInfo = $cache->getInfo($pageCacheKey);
250
-			if ($cacheInfo) {
251
-				$status = $this->sendCacheNotYetExpireInfoToBrowser($cacheInfo);
252
-				if ($status === false) {
253
-					return $this->sendCachePageContentToBrowser($cache);
254
-				}
255
-				return true;
256
-			}
257
-			return false;
258
-		}
247
+            $logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...');
248
+            //get the cache information to prepare header to send to browser
249
+            $cacheInfo = $cache->getInfo($pageCacheKey);
250
+            if ($cacheInfo) {
251
+                $status = $this->sendCacheNotYetExpireInfoToBrowser($cacheInfo);
252
+                if ($status === false) {
253
+                    return $this->sendCachePageContentToBrowser($cache);
254
+                }
255
+                return true;
256
+            }
257
+            return false;
258
+        }
259 259
 	
260 260
 		
261
-		/**
262
-		* Get the final page to be rendered
263
-		* @return string
264
-		*/
265
-		public function getFinalPageRendered() {
266
-			return $this->_pageRender;
267
-		}
261
+        /**
262
+         * Get the final page to be rendered
263
+         * @return string
264
+         */
265
+        public function getFinalPageRendered() {
266
+            return $this->_pageRender;
267
+        }
268 268
 
269
-		/**
270
-		 * Send the HTTP 404 error if can not found the 
271
-		 * routing information for the current request
272
-		 */
273
-		public static function send404() {
274
-			/********* for logs **************/
275
-			//can't use $obj = & get_instance()  here because the global super object will be available until
276
-			//the main controller is loaded even for Loader::library('xxxx');
277
-			$logger = self::getLogger();
278
-			$request = & class_loader('Request', 'classes');
279
-			$userAgent = & class_loader('Browser');
280
-			$browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
269
+        /**
270
+         * Send the HTTP 404 error if can not found the 
271
+         * routing information for the current request
272
+         */
273
+        public static function send404() {
274
+            /********* for logs **************/
275
+            //can't use $obj = & get_instance()  here because the global super object will be available until
276
+            //the main controller is loaded even for Loader::library('xxxx');
277
+            $logger = self::getLogger();
278
+            $request = & class_loader('Request', 'classes');
279
+            $userAgent = & class_loader('Browser');
280
+            $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
281 281
 			
282
-			//here can't use Loader::functions just include the helper manually
283
-			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
282
+            //here can't use Loader::functions just include the helper manually
283
+            require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
284 284
 
285
-			$str = '[404 page not found] : ';
286
-			$str .= ' Unable to find the request page [' . $request->requestUri() . ']. The visitor IP address [' . get_ip() . '], browser [' . $browser . ']';
287
-			$logger->error($str);
288
-			/***********************************/
289
-			$path = CORE_VIEWS_PATH . '404.php';
290
-			if (file_exists($path)) {
291
-				//compress the output if is available
292
-				$type = null;
293
-				if (self::$_canCompressOutput) {
294
-					$type = 'ob_gzhandler';
295
-				}
296
-				ob_start($type);
297
-				require_once $path;
298
-				$output = ob_get_clean();
299
-				self::sendHeaders(404);
300
-				echo $output;
301
-			} else{
302
-				show_error('The 404 view [' .$path. '] does not exist');
303
-			}
304
-		}
285
+            $str = '[404 page not found] : ';
286
+            $str .= ' Unable to find the request page [' . $request->requestUri() . ']. The visitor IP address [' . get_ip() . '], browser [' . $browser . ']';
287
+            $logger->error($str);
288
+            /***********************************/
289
+            $path = CORE_VIEWS_PATH . '404.php';
290
+            if (file_exists($path)) {
291
+                //compress the output if is available
292
+                $type = null;
293
+                if (self::$_canCompressOutput) {
294
+                    $type = 'ob_gzhandler';
295
+                }
296
+                ob_start($type);
297
+                require_once $path;
298
+                $output = ob_get_clean();
299
+                self::sendHeaders(404);
300
+                echo $output;
301
+            } else{
302
+                show_error('The 404 view [' .$path. '] does not exist');
303
+            }
304
+        }
305 305
 
306
-		/**
307
-		 * Display the error to user
308
-		 * @param  array  $data the error information
309
-		 */
310
-		public static function sendError(array $data = array()) {
311
-			$path = CORE_VIEWS_PATH . 'errors.php';
312
-			if (file_exists($path)) {
313
-				//compress the output if is available
314
-				$type = null;
315
-				if (self::$_canCompressOutput) {
316
-					$type = 'ob_gzhandler';
317
-				}
318
-				ob_start($type);
319
-				extract($data);
320
-				require_once $path;
321
-				$output = ob_get_clean();
322
-				self::sendHeaders(503);
323
-				echo $output;
324
-			} else{
325
-				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
326
-				set_http_status_header(503);
327
-				echo 'The error view [' . $path . '] does not exist';
328
-			}
329
-		}
306
+        /**
307
+         * Display the error to user
308
+         * @param  array  $data the error information
309
+         */
310
+        public static function sendError(array $data = array()) {
311
+            $path = CORE_VIEWS_PATH . 'errors.php';
312
+            if (file_exists($path)) {
313
+                //compress the output if is available
314
+                $type = null;
315
+                if (self::$_canCompressOutput) {
316
+                    $type = 'ob_gzhandler';
317
+                }
318
+                ob_start($type);
319
+                extract($data);
320
+                require_once $path;
321
+                $output = ob_get_clean();
322
+                self::sendHeaders(503);
323
+                echo $output;
324
+            } else{
325
+                //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
326
+                set_http_status_header(503);
327
+                echo 'The error view [' . $path . '] does not exist';
328
+            }
329
+        }
330 330
 
331
-		/**
332
-		 * Send the cache not yet expire to browser
333
-		 * @param  array $cacheInfo the cache information
334
-		 * @return boolean            true if the information is sent otherwise false
335
-		 */
336
-		protected function sendCacheNotYetExpireInfoToBrowser($cacheInfo) {
337
-			if (!empty($cacheInfo)) {
338
-				$logger = self::getLogger();
339
-				$lastModified = $cacheInfo['mtime'];
340
-				$expire = $cacheInfo['expire'];
341
-				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
342
-				self::setHeader('Pragma', 'public');
343
-				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
344
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
345
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
346
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
347
-					$logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser');
348
-					self::sendHeaders(304);
349
-					return true;
350
-				}
351
-			}
352
-			return false;
353
-		}
331
+        /**
332
+         * Send the cache not yet expire to browser
333
+         * @param  array $cacheInfo the cache information
334
+         * @return boolean            true if the information is sent otherwise false
335
+         */
336
+        protected function sendCacheNotYetExpireInfoToBrowser($cacheInfo) {
337
+            if (!empty($cacheInfo)) {
338
+                $logger = self::getLogger();
339
+                $lastModified = $cacheInfo['mtime'];
340
+                $expire = $cacheInfo['expire'];
341
+                $maxAge = $expire - $_SERVER['REQUEST_TIME'];
342
+                self::setHeader('Pragma', 'public');
343
+                self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
344
+                self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
345
+                self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
346
+                if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
347
+                    $logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser');
348
+                    self::sendHeaders(304);
349
+                    return true;
350
+                }
351
+            }
352
+            return false;
353
+        }
354 354
 
355
-		/**
356
-		 * Set the value of '{elapsed_time}' and '{memory_usage}'
357
-		 * @param  string $content the page content
358
-		 * @return string          the page content after replace 
359
-		 * '{elapsed_time}', '{memory_usage}'
360
-		 */
361
-		protected function replaceElapseTimeAndMemoryUsage($content) {
362
-			//load benchmark class
363
-			$benchmark = & class_loader('Benchmark');
355
+        /**
356
+         * Set the value of '{elapsed_time}' and '{memory_usage}'
357
+         * @param  string $content the page content
358
+         * @return string          the page content after replace 
359
+         * '{elapsed_time}', '{memory_usage}'
360
+         */
361
+        protected function replaceElapseTimeAndMemoryUsage($content) {
362
+            //load benchmark class
363
+            $benchmark = & class_loader('Benchmark');
364 364
 			
365
-			// Parse out the elapsed time and memory usage,
366
-			// then swap the pseudo-variables with the data
367
-			$elapsedTime = $benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END');
368
-			$memoryUsage	= round($benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB';
369
-			return str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);	
370
-		}
365
+            // Parse out the elapsed time and memory usage,
366
+            // then swap the pseudo-variables with the data
367
+            $elapsedTime = $benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END');
368
+            $memoryUsage	= round($benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB';
369
+            return str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);	
370
+        }
371 371
 
372
-		/**
373
-		 * Send the page content from cache to browser
374
-		 * @param object $cache the cache instance
375
-		 * @return boolean     the status of the operation
376
-		 */
377
-		protected function sendCachePageContentToBrowser(&$cache) {
378
-			$logger = self::getLogger();
379
-			$logger->info('The cache page content is expired or the browser does not send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser');
380
-			self::sendHeaders(200);
381
-			//current page cache key
382
-			$pageCacheKey = $this->_currentUrlCacheKey;
383
-			//get the cache content
384
-			$content = $cache->get($pageCacheKey);
385
-			if ($content) {
386
-				$logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it');
387
-				$content = $this->replaceElapseTimeAndMemoryUsage($content);
388
-				///display the final output
389
-				//compress the output if is available
390
-				$type = null;
391
-				if (self::$_canCompressOutput) {
392
-					$type = 'ob_gzhandler';
393
-				}
394
-				ob_start($type);
395
-				echo $content;
396
-				ob_end_flush();
397
-				return true;
398
-			}
399
-			$logger->info('The page cache content for the URL [' . $this->_currentUrl . '] is not valid may be already expired');
400
-			$cache->delete($pageCacheKey);
401
-			return false;
402
-		}
372
+        /**
373
+         * Send the page content from cache to browser
374
+         * @param object $cache the cache instance
375
+         * @return boolean     the status of the operation
376
+         */
377
+        protected function sendCachePageContentToBrowser(&$cache) {
378
+            $logger = self::getLogger();
379
+            $logger->info('The cache page content is expired or the browser does not send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser');
380
+            self::sendHeaders(200);
381
+            //current page cache key
382
+            $pageCacheKey = $this->_currentUrlCacheKey;
383
+            //get the cache content
384
+            $content = $cache->get($pageCacheKey);
385
+            if ($content) {
386
+                $logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it');
387
+                $content = $this->replaceElapseTimeAndMemoryUsage($content);
388
+                ///display the final output
389
+                //compress the output if is available
390
+                $type = null;
391
+                if (self::$_canCompressOutput) {
392
+                    $type = 'ob_gzhandler';
393
+                }
394
+                ob_start($type);
395
+                echo $content;
396
+                ob_end_flush();
397
+                return true;
398
+            }
399
+            $logger->info('The page cache content for the URL [' . $this->_currentUrl . '] is not valid may be already expired');
400
+            $cache->delete($pageCacheKey);
401
+            return false;
402
+        }
403 403
 
404
-		/**
405
-		 * Save the content of page into cache
406
-		 * @param  string $content the page content to be saved
407
-		 * @return void
408
-		 */
409
-		protected function savePageContentIntoCache($content) {
410
-			$obj = & get_instance();
411
-			$logger = self::getLogger();
404
+        /**
405
+         * Save the content of page into cache
406
+         * @param  string $content the page content to be saved
407
+         * @return void
408
+         */
409
+        protected function savePageContentIntoCache($content) {
410
+            $obj = & get_instance();
411
+            $logger = self::getLogger();
412 412
 
413
-			//current page URL
414
-			$url = $this->_currentUrl;
415
-			//Cache view Time to live in second
416
-			$viewCacheTtl = get_config('cache_ttl');
417
-			if (!empty($obj->view_cache_ttl)) {
418
-				$viewCacheTtl = $obj->view_cache_ttl;
419
-			}
420
-			//the cache handler instance
421
-			$cacheInstance = $obj->cache;
422
-			//the current page cache key for identification
423
-			$cacheKey = $this->_currentUrlCacheKey;
424
-			$logger->debug('Save the page content for URL [' . $url . '] into the cache ...');
425
-			$cacheInstance->set($cacheKey, $content, $viewCacheTtl);
413
+            //current page URL
414
+            $url = $this->_currentUrl;
415
+            //Cache view Time to live in second
416
+            $viewCacheTtl = get_config('cache_ttl');
417
+            if (!empty($obj->view_cache_ttl)) {
418
+                $viewCacheTtl = $obj->view_cache_ttl;
419
+            }
420
+            //the cache handler instance
421
+            $cacheInstance = $obj->cache;
422
+            //the current page cache key for identification
423
+            $cacheKey = $this->_currentUrlCacheKey;
424
+            $logger->debug('Save the page content for URL [' . $url . '] into the cache ...');
425
+            $cacheInstance->set($cacheKey, $content, $viewCacheTtl);
426 426
 			
427
-			//get the cache information to prepare header to send to browser
428
-			$cacheInfo = $cacheInstance->getInfo($cacheKey);
429
-			if ($cacheInfo) {
430
-				$lastModified = $cacheInfo['mtime'];
431
-				$expire = $cacheInfo['expire'];
432
-				$maxAge = $expire - time();
433
-				self::setHeader('Pragma', 'public');
434
-				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
435
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
436
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
437
-			}
438
-		}
427
+            //get the cache information to prepare header to send to browser
428
+            $cacheInfo = $cacheInstance->getInfo($cacheKey);
429
+            if ($cacheInfo) {
430
+                $lastModified = $cacheInfo['mtime'];
431
+                $expire = $cacheInfo['expire'];
432
+                $maxAge = $expire - time();
433
+                self::setHeader('Pragma', 'public');
434
+                self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
435
+                self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
436
+                self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
437
+            }
438
+        }
439 439
 		
440 440
 
441
-		/**
442
-		 * Get the module information for the view to load
443
-		 * @param  string $view the view name like moduleName/viewName, viewName
444
-		 * 
445
-		 * @return array        the module information
446
-		 * array(
447
-		 * 	'module'=> 'module_name'
448
-		 * 	'view' => 'view_name'
449
-		 * 	'viewFile' => 'view_file'
450
-		 * )
451
-		 */
452
-		protected  function getModuleInfoForView($view) {
453
-			$module = null;
454
-			$viewFile = null;
455
-			$obj = & get_instance();
456
-			//check if the request class contains module name
457
-			if (strpos($view, '/') !== false) {
458
-				$viewPath = explode('/', $view);
459
-				if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
460
-					$module = $viewPath[0];
461
-					array_shift($viewPath);
462
-					$view = implode('/', $viewPath);
463
-					$viewFile = $view . '.php';
464
-				}
465
-			}
466
-			if (!$module && !empty($obj->moduleName)) {
467
-				$module = $obj->moduleName;
468
-			}
469
-			return array(
470
-						'view' => $view,
471
-						'module' => $module,
472
-						'viewFile' => $viewFile
473
-					);
474
-		}
441
+        /**
442
+         * Get the module information for the view to load
443
+         * @param  string $view the view name like moduleName/viewName, viewName
444
+         * 
445
+         * @return array        the module information
446
+         * array(
447
+         * 	'module'=> 'module_name'
448
+         * 	'view' => 'view_name'
449
+         * 	'viewFile' => 'view_file'
450
+         * )
451
+         */
452
+        protected  function getModuleInfoForView($view) {
453
+            $module = null;
454
+            $viewFile = null;
455
+            $obj = & get_instance();
456
+            //check if the request class contains module name
457
+            if (strpos($view, '/') !== false) {
458
+                $viewPath = explode('/', $view);
459
+                if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
460
+                    $module = $viewPath[0];
461
+                    array_shift($viewPath);
462
+                    $view = implode('/', $viewPath);
463
+                    $viewFile = $view . '.php';
464
+                }
465
+            }
466
+            if (!$module && !empty($obj->moduleName)) {
467
+                $module = $obj->moduleName;
468
+            }
469
+            return array(
470
+                        'view' => $view,
471
+                        'module' => $module,
472
+                        'viewFile' => $viewFile
473
+                    );
474
+        }
475 475
 
476
-		/**
477
-		 * Render the view page
478
-		 * @see  Response::render
479
-		 * @return void|string
480
-		 */
481
-		protected  function loadView($path, array $data = array(), $return = false) {
482
-			$found = false;
483
-			if (file_exists($path)) {
484
-				//super instance
485
-				$obj = & get_instance();
486
-				foreach (get_object_vars($obj) as $key => $value) {
487
-					if (!isset($this->{$key})) {
488
-						$this->{$key} = & $obj->{$key};
489
-					}
490
-				}
491
-				ob_start();
492
-				extract($data);
493
-				//need use require() instead of require_once because can load this view many time
494
-				require $path;
495
-				$content = ob_get_clean();
496
-				if ($return) {
497
-					//remove unused html space 
498
-					return preg_replace('~>\s*\n\s*<~', '><', $content);
499
-				}
500
-				$this->_pageRender .= $content;
501
-				$found = true;
502
-			}
503
-			if (!$found) {
504
-				show_error('Unable to find view [' . $path . ']');
505
-			}
506
-		}
476
+        /**
477
+         * Render the view page
478
+         * @see  Response::render
479
+         * @return void|string
480
+         */
481
+        protected  function loadView($path, array $data = array(), $return = false) {
482
+            $found = false;
483
+            if (file_exists($path)) {
484
+                //super instance
485
+                $obj = & get_instance();
486
+                foreach (get_object_vars($obj) as $key => $value) {
487
+                    if (!isset($this->{$key})) {
488
+                        $this->{$key} = & $obj->{$key};
489
+                    }
490
+                }
491
+                ob_start();
492
+                extract($data);
493
+                //need use require() instead of require_once because can load this view many time
494
+                require $path;
495
+                $content = ob_get_clean();
496
+                if ($return) {
497
+                    //remove unused html space 
498
+                    return preg_replace('~>\s*\n\s*<~', '><', $content);
499
+                }
500
+                $this->_pageRender .= $content;
501
+                $found = true;
502
+            }
503
+            if (!$found) {
504
+                show_error('Unable to find view [' . $path . ']');
505
+            }
506
+        }
507 507
 
508
-	}
508
+    }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -170,21 +170,21 @@  discard block
 block discarded – undo
170 170
 			//check in module first
171 171
 			$logger->debug('Checking the view [' . $view . '] from module list ...');
172 172
 			$moduleInfo = $this->getModuleInfoForView($view);
173
-			$module    = $moduleInfo['module'];
174
-			$view  = $moduleInfo['view'];
173
+			$module = $moduleInfo['module'];
174
+			$view = $moduleInfo['view'];
175 175
 			
176 176
 			$moduleViewPath = Module::findViewFullPath($view, $module);
177
-			if($moduleViewPath){
177
+			if ($moduleViewPath) {
178 178
 				$path = $moduleViewPath;
179
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it');
180
-			} else{
181
-				$logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location');
179
+				$logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $moduleViewPath . '] we will used it');
180
+			} else {
181
+				$logger->info('Cannot find view [' . $view . '] in module [' . $module . '] using the default location');
182 182
 			}
183 183
 			
184 184
 			$logger->info('The view file path to be loaded is [' . $path . ']');
185 185
 			
186 186
 			/////////
187
-			if($return){
187
+			if ($return) {
188 188
 				return $this->loadView($path, $data, true);
189 189
 			}
190 190
 			$this->loadView($path, $data, false);
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 				$output = ob_get_clean();
299 299
 				self::sendHeaders(404);
300 300
 				echo $output;
301
-			} else{
302
-				show_error('The 404 view [' .$path. '] does not exist');
301
+			} else {
302
+				show_error('The 404 view [' . $path . '] does not exist');
303 303
 			}
304 304
 		}
305 305
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 				$output = ob_get_clean();
322 322
 				self::sendHeaders(503);
323 323
 				echo $output;
324
-			} else{
324
+			} else {
325 325
 				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
326 326
 				set_http_status_header(503);
327 327
 				echo 'The error view [' . $path . '] does not exist';
Please login to merge, or discard this patch.
core/classes/Request.php 2 patches
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -1,255 +1,255 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Request {
27
+    class Request {
28 28
 		
29
-		/**
30
-		 * The value for the super global $_GET
31
-		 * @var array
32
-		 */
33
-		public $get = null;
29
+        /**
30
+         * The value for the super global $_GET
31
+         * @var array
32
+         */
33
+        public $get = null;
34 34
 
35
-		/**
36
-		 * The value for the super global $_POST
37
-		 * @var array
38
-		 */
39
-		public $post = null;
35
+        /**
36
+         * The value for the super global $_POST
37
+         * @var array
38
+         */
39
+        public $post = null;
40 40
 
41
-		/**
42
-		 * The value for the super global $_SERVER
43
-		 * @var array
44
-		 */
45
-		public $server = null;
41
+        /**
42
+         * The value for the super global $_SERVER
43
+         * @var array
44
+         */
45
+        public $server = null;
46 46
 
47
-		/**
48
-		 * The value for the super global $_COOKIE
49
-		 * @var array
50
-		 */
51
-		public $cookie = null;
47
+        /**
48
+         * The value for the super global $_COOKIE
49
+         * @var array
50
+         */
51
+        public $cookie = null;
52 52
 
53
-		/**
54
-		 * The value for the super global $_FILES
55
-		 * @var array
56
-		 */
57
-		public $file = null;
53
+        /**
54
+         * The value for the super global $_FILES
55
+         * @var array
56
+         */
57
+        public $file = null;
58 58
 
59
-		/**
60
-		 * The value for the super global $_REQUEST
61
-		 * @var array
62
-		 */
63
-		public $query = null;
59
+        /**
60
+         * The value for the super global $_REQUEST
61
+         * @var array
62
+         */
63
+        public $query = null;
64 64
 		
65
-		/**
66
-		 * The session instance
67
-		 * @var Session
68
-		 */
69
-		public $session = null;
65
+        /**
66
+         * The session instance
67
+         * @var Session
68
+         */
69
+        public $session = null;
70 70
 		
71
-		/**
72
-		 * The request headers
73
-		 * @var array
74
-		 */
75
-		public $header = null;
71
+        /**
72
+         * The request headers
73
+         * @var array
74
+         */
75
+        public $header = null;
76 76
 
77
-		/**
78
-		 * The current request method 'GET', 'POST', 'PUT', etc.
79
-		 * @var null
80
-		 */
81
-		private $method = null;
77
+        /**
78
+         * The current request method 'GET', 'POST', 'PUT', etc.
79
+         * @var null
80
+         */
81
+        private $method = null;
82 82
 
83
-		/**
84
-		 * The current request URI
85
-		 * @var string
86
-		 */
87
-		private $requestUri = null;
83
+        /**
84
+         * The current request URI
85
+         * @var string
86
+         */
87
+        private $requestUri = null;
88 88
 		
89 89
 		
90
-		/**
91
-		 * Construct new request instance
92
-		 */
93
-		public function __construct(){
94
-			$this->get = $_GET;
95
-			$this->post = $_POST;
96
-			$this->server = $_SERVER;
97
-			$this->query = $_REQUEST;
98
-			$this->cookie = $_COOKIE;
99
-			$this->file = $_FILES;
100
-			$this->session =& class_loader('Session', 'classes');
101
-			$this->method = $this->server('REQUEST_METHOD');
102
-			$this->requestUri = $this->server('REQUEST_URI');
103
-			$this->header = array();
104
-			if(function_exists('apache_request_headers')){
105
-				$this->header = apache_request_headers();
106
-			} else if(function_exists('getallheaders')){
107
-				$this->header = getallheaders();
108
-			}
109
-		}
90
+        /**
91
+         * Construct new request instance
92
+         */
93
+        public function __construct(){
94
+            $this->get = $_GET;
95
+            $this->post = $_POST;
96
+            $this->server = $_SERVER;
97
+            $this->query = $_REQUEST;
98
+            $this->cookie = $_COOKIE;
99
+            $this->file = $_FILES;
100
+            $this->session =& class_loader('Session', 'classes');
101
+            $this->method = $this->server('REQUEST_METHOD');
102
+            $this->requestUri = $this->server('REQUEST_URI');
103
+            $this->header = array();
104
+            if(function_exists('apache_request_headers')){
105
+                $this->header = apache_request_headers();
106
+            } else if(function_exists('getallheaders')){
107
+                $this->header = getallheaders();
108
+            }
109
+        }
110 110
 
111
-		/**
112
-		 * Get the request method
113
-		 * @return string
114
-		 */
115
-		public function method() {
116
-			return $this->method;
117
-		}
111
+        /**
112
+         * Get the request method
113
+         * @return string
114
+         */
115
+        public function method() {
116
+            return $this->method;
117
+        }
118 118
 		
119
-		/**
120
-		 * Get the request URI
121
-		 * @return string
122
-		 */
123
-		public function requestUri() {
124
-			return $this->requestUri;
125
-		}
119
+        /**
120
+         * Get the request URI
121
+         * @return string
122
+         */
123
+        public function requestUri() {
124
+            return $this->requestUri;
125
+        }
126 126
 
127
-		/**
128
-		 * Get the value from $_REQUEST for given key. if the key is empty will return the all values
129
-		 * @param  string  $key the item key to be fetched
130
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
131
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
132
-		 */
133
-		public function query($key = null, $xss = true) {
134
-			if (empty($key)) {
135
-				//return all
136
-				return $xss ? clean_input($this->query) : $this->query;
137
-			}
138
-			$query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
139
-			if ($xss) {
140
-				$query = clean_input($query);
141
-			}
142
-			return $query;
143
-		}
127
+        /**
128
+         * Get the value from $_REQUEST for given key. if the key is empty will return the all values
129
+         * @param  string  $key the item key to be fetched
130
+         * @param  boolean $xss if need apply some XSS attack rule on the value
131
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
132
+         */
133
+        public function query($key = null, $xss = true) {
134
+            if (empty($key)) {
135
+                //return all
136
+                return $xss ? clean_input($this->query) : $this->query;
137
+            }
138
+            $query = array_key_exists($key, $this->query) ? $this->query[$key] : null;
139
+            if ($xss) {
140
+                $query = clean_input($query);
141
+            }
142
+            return $query;
143
+        }
144 144
 		
145
-		/**
146
-		 * Get the value from $_GET for given key. if the key is empty will return the all values
147
-		 * @param  string  $key the item key to be fetched
148
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
149
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
150
-		 */
151
-		public function get($key = null, $xss = true) {
152
-			if (empty($key)) {
153
-				//return all
154
-				return $xss ? clean_input($this->get) : $this->get;
155
-			}
156
-			$get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
157
-			if ($xss) {
158
-				$get = clean_input($get);
159
-			}
160
-			return $get;
161
-		}
145
+        /**
146
+         * Get the value from $_GET for given key. if the key is empty will return the all values
147
+         * @param  string  $key the item key to be fetched
148
+         * @param  boolean $xss if need apply some XSS attack rule on the value
149
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
150
+         */
151
+        public function get($key = null, $xss = true) {
152
+            if (empty($key)) {
153
+                //return all
154
+                return $xss ? clean_input($this->get) : $this->get;
155
+            }
156
+            $get = array_key_exists($key, $this->get) ? $this->get[$key] : null;
157
+            if ($xss) {
158
+                $get = clean_input($get);
159
+            }
160
+            return $get;
161
+        }
162 162
 		
163
-		/**
164
-		 * Get the value from $_POST for given key. if the key is empty will return the all values
165
-		 * @param  string  $key the item key to be fetched
166
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
167
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
168
-		 */
169
-		public function post($key = null, $xss = true) {
170
-			if (empty($key)) {
171
-				//return all
172
-				return $xss ? clean_input($this->post) : $this->post;
173
-			}
174
-			$post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
175
-			if ($xss) {
176
-				$post = clean_input($post);
177
-			}
178
-			return $post;
179
-		}
163
+        /**
164
+         * Get the value from $_POST for given key. if the key is empty will return the all values
165
+         * @param  string  $key the item key to be fetched
166
+         * @param  boolean $xss if need apply some XSS attack rule on the value
167
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
168
+         */
169
+        public function post($key = null, $xss = true) {
170
+            if (empty($key)) {
171
+                //return all
172
+                return $xss ? clean_input($this->post) : $this->post;
173
+            }
174
+            $post = array_key_exists($key, $this->post) ? $this->post[$key] : null;
175
+            if ($xss) {
176
+                $post = clean_input($post);
177
+            }
178
+            return $post;
179
+        }
180 180
 		
181
-		/**
182
-		 * Get the value from $_SERVER for given key. if the key is empty will return the all values
183
-		 * @param  string  $key the item key to be fetched
184
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
185
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
186
-		 */
187
-		public function server($key = null, $xss = true) {
188
-			if (empty($key)) {
189
-				//return all
190
-				return $xss ? clean_input($this->server) : $this->server;
191
-			}
192
-			$server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
193
-			if ($xss) {
194
-				$server = clean_input($server);
195
-			}
196
-			return $server;
197
-		}
181
+        /**
182
+         * Get the value from $_SERVER for given key. if the key is empty will return the all values
183
+         * @param  string  $key the item key to be fetched
184
+         * @param  boolean $xss if need apply some XSS attack rule on the value
185
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
186
+         */
187
+        public function server($key = null, $xss = true) {
188
+            if (empty($key)) {
189
+                //return all
190
+                return $xss ? clean_input($this->server) : $this->server;
191
+            }
192
+            $server = array_key_exists($key, $this->server) ? $this->server[$key] : null;
193
+            if ($xss) {
194
+                $server = clean_input($server);
195
+            }
196
+            return $server;
197
+        }
198 198
 		
199
-		/**
200
-		 * Get the value from $_COOKIE for given key. if the key is empty will return the all values
201
-		 * @param  string  $key the item key to be fetched
202
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
203
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
204
-		 */
205
-		public function cookie($key = null, $xss = true) {
206
-			if (empty($key)) {
207
-				//return all
208
-				return $xss ? clean_input($this->cookie) : $this->cookie;
209
-			}
210
-			$cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
211
-			if ($xss) {
212
-				$cookie = clean_input($cookie);
213
-			}
214
-			return $cookie;
215
-		}
199
+        /**
200
+         * Get the value from $_COOKIE for given key. if the key is empty will return the all values
201
+         * @param  string  $key the item key to be fetched
202
+         * @param  boolean $xss if need apply some XSS attack rule on the value
203
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
204
+         */
205
+        public function cookie($key = null, $xss = true) {
206
+            if (empty($key)) {
207
+                //return all
208
+                return $xss ? clean_input($this->cookie) : $this->cookie;
209
+            }
210
+            $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null;
211
+            if ($xss) {
212
+                $cookie = clean_input($cookie);
213
+            }
214
+            return $cookie;
215
+        }
216 216
 		
217
-		/**
218
-		 * Get the value from $_FILES for given key. if the key is empty will return the all values
219
-		 * @param  string  $key the item key to be fetched
220
-		 * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
221
-		 */
222
-		public function file($key) {
223
-			$file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
224
-			return $file;
225
-		}
217
+        /**
218
+         * Get the value from $_FILES for given key. if the key is empty will return the all values
219
+         * @param  string  $key the item key to be fetched
220
+         * @return array|mixed       the item value if the key exists or all array if the key does not exists or is empty
221
+         */
222
+        public function file($key) {
223
+            $file = array_key_exists($key, $this->file) ? $this->file[$key] : null;
224
+            return $file;
225
+        }
226 226
 		
227
-		/**
228
-		 * Get the value from $_SESSION for given key. if the key is empty will return the all values
229
-		 * @param  string  $key the item key to be fetched
230
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
231
-		 * @return array|mixed       the item value if the key exists or null if the key does not exists
232
-		 */
233
-		public function session($key, $xss = true) {
234
-			$session = $this->session->get($key);
235
-			if ($xss) {
236
-				$session = clean_input($session);
237
-			}
238
-			return $session;
239
-		}
227
+        /**
228
+         * Get the value from $_SESSION for given key. if the key is empty will return the all values
229
+         * @param  string  $key the item key to be fetched
230
+         * @param  boolean $xss if need apply some XSS attack rule on the value
231
+         * @return array|mixed       the item value if the key exists or null if the key does not exists
232
+         */
233
+        public function session($key, $xss = true) {
234
+            $session = $this->session->get($key);
235
+            if ($xss) {
236
+                $session = clean_input($session);
237
+            }
238
+            return $session;
239
+        }
240 240
 
241
-		/**
242
-		 * Get the value from header array for given key.
243
-		 * @param  string  $key the item key to be fetched
244
-		 * @param  boolean $xss if need apply some XSS attack rule on the value
245
-		 * @return mixed       the item value if the key exists or null if the key does not exists
246
-		 */
247
-		public function header($key, $xss = true) {
248
-			$header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
249
-			if ($xss) {
250
-				$header = clean_input($header);
251
-			}
252
-			return $header;
253
-		}
241
+        /**
242
+         * Get the value from header array for given key.
243
+         * @param  string  $key the item key to be fetched
244
+         * @param  boolean $xss if need apply some XSS attack rule on the value
245
+         * @return mixed       the item value if the key exists or null if the key does not exists
246
+         */
247
+        public function header($key, $xss = true) {
248
+            $header = array_key_exists($key, $this->header) ? $this->header[$key] : null;
249
+            if ($xss) {
250
+                $header = clean_input($header);
251
+            }
252
+            return $header;
253
+        }
254 254
 		
255
-	}
255
+    }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -90,20 +90,20 @@
 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
-			} else if(function_exists('getallheaders')){
106
+			} else if (function_exists('getallheaders')) {
107 107
 				$this->header = getallheaders();
108 108
 			}
109 109
 		}
Please login to merge, or discard this patch.
core/classes/BaseClass.php 1 patch
Spacing   +9 added lines, -9 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 BaseClass{
27
+    class BaseClass {
28 28
         /**
29 29
          * The logger instance
30 30
          * @var object
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         /**
35 35
          * Class constructor
36 36
          */
37
-        public function __construct(){
37
+        public function __construct() {
38 38
             //Set Log instance to use
39 39
                 $this->setLoggerFromParamOrCreate(null);
40 40
         }
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
          *
50 50
          * @return object this current instance
51 51
          */
52
-        protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
53
-            if ($instance !== null){
52
+        protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes') {
53
+            if ($instance !== null) {
54 54
             $this->{$name} = $instance;
55 55
             return $this;
56 56
             }
57
-            $this->{$name} =& class_loader($loadClassName, $loadClassePath);
57
+            $this->{$name} = & class_loader($loadClassName, $loadClassePath);
58 58
             return $this;
59 59
         }
60 60
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
          * Return the Log instance
63 63
          * @return object
64 64
          */
65
-        public function getLogger(){
65
+        public function getLogger() {
66 66
             return $this->logger;
67 67
         }
68 68
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
          * @param object $logger the log object
72 72
          * @return object Database
73 73
          */
74
-        public function setLogger($logger){
74
+        public function setLogger($logger) {
75 75
             $this->logger = $logger;
76 76
             return $this;
77 77
         }
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
          *
83 83
          * @return object this current instance
84 84
          */
85
-        protected function setLoggerFromParamOrCreate(Log $logger = null){
85
+        protected function setLoggerFromParamOrCreate(Log $logger = null) {
86 86
             $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
87
-            if ($logger === null){
87
+            if ($logger === null) {
88 88
             $this->logger->setLogger('Class::' . get_class($this));
89 89
             }
90 90
             return $this;
Please login to merge, or discard this patch.
core/classes/cache/ApcCache.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
      */
26 26
 	
27
-    class ApcCache extends BaseClass implements CacheInterface{
27
+    class ApcCache extends BaseClass implements CacheInterface {
28 28
 
29 29
 		
30 30
 		
31
-        public function __construct(){
31
+        public function __construct() {
32 32
             parent::__construct();
33
-            if(! $this->isSupported()){
33
+            if (!$this->isSupported()) {
34 34
                 show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
35 35
             }
36 36
         }
@@ -40,21 +40,21 @@  discard block
 block discarded – undo
40 40
          * @param  string $key the key to identify the cache data
41 41
          * @return mixed      the cache data if exists else return false
42 42
          */
43
-        public function get($key){
44
-            $this->logger->debug('Getting cache data for key ['. $key .']');
43
+        public function get($key) {
44
+            $this->logger->debug('Getting cache data for key [' . $key . ']');
45 45
             $success = false;
46 46
             $data = apc_fetch($key, $success);
47
-            if($success === false){
48
-                $this->logger->info('No cache found for the key ['. $key .'], return false');
47
+            if ($success === false) {
48
+                $this->logger->info('No cache found for the key [' . $key . '], return false');
49 49
                 return false;
50 50
             }
51
-            else{
51
+            else {
52 52
                 $cacheInfo = $this->_getCacheInfo($key);
53 53
                 $expire = time();
54
-                if($cacheInfo){
54
+                if ($cacheInfo) {
55 55
                     $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
56 56
                 }
57
-                $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
57
+                $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
58 58
                 return $data;
59 59
             }
60 60
         }
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
          * @param integer $ttl  the cache life time
68 68
          * @return boolean true if success otherwise will return false
69 69
          */
70
-        public function set($key, $data, $ttl = 0){
70
+        public function set($key, $data, $ttl = 0) {
71 71
             $expire = time() + $ttl;
72
-            $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
72
+            $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73 73
             $result = apc_store($key, $data, $ttl);
74
-            if($result === false){
75
-                $this->logger->error('Can not write cache data for the key ['. $key .'], return false');
74
+            if ($result === false) {
75
+                $this->logger->error('Can not write cache data for the key [' . $key . '], return false');
76 76
                 return false;
77 77
             }
78
-            else{
79
-                $this->logger->info('Cache data saved for the key ['. $key .']');
78
+            else {
79
+                $this->logger->info('Cache data saved for the key [' . $key . ']');
80 80
                 return true;
81 81
             }
82 82
         }
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
          * @return boolean      true if the cache is deleted, false if can't delete 
89 89
          * the cache or the cache with the given key not exist
90 90
          */
91
-        public function delete($key){
92
-            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
91
+        public function delete($key) {
92
+            $this->logger->debug('Deleting of cache data for key [' . $key . ']');
93 93
             $cacheInfo = $this->_getCacheInfo($key);
94
-            if($cacheInfo === false){
94
+            if ($cacheInfo === false) {
95 95
                 $this->logger->info('This cache data does not exists skipping');
96 96
                 return false;
97 97
             }
98
-            else{
99
-                $this->logger->info('Found cache data for the key [' .$key. '] remove it');
98
+            else {
99
+                $this->logger->info('Found cache data for the key [' . $key . '] remove it');
100 100
                     return apc_delete($key) === true;
101 101
             }
102 102
         }
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
          * 'expire' => expiration time of the cache (Unix timestamp),
110 110
          * 'ttl' => the time to live of the cache in second
111 111
          */
112
-        public function getInfo($key){
113
-            $this->logger->debug('Getting of cache info for key [' .$key. ']');
112
+        public function getInfo($key) {
113
+            $this->logger->debug('Getting of cache info for key [' . $key . ']');
114 114
             $cacheInfos = $this->_getCacheInfo($key);
115
-            if($cacheInfos){
115
+            if ($cacheInfos) {
116 116
                 $data = array(
117 117
                             'mtime' => $cacheInfos['creation_time'],
118 118
                             'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                             );
121 121
                 return $data;
122 122
             }
123
-            else{
123
+            else {
124 124
                 $this->logger->info('This cache does not exists skipping');
125 125
                 return false;
126 126
             }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         /**
131 131
          * Used to delete expired cache data
132 132
          */
133
-        public function deleteExpiredCache(){
133
+        public function deleteExpiredCache() {
134 134
             //for APC[u] is done automatically
135 135
             return true;
136 136
         }
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
         /**
139 139
          * Remove all cache data
140 140
          */
141
-        public function clean(){
141
+        public function clean() {
142 142
             $this->logger->debug('Deleting of all cache data');
143 143
             $cacheInfos = apc_cache_info('user');
144
-            if(empty($cacheInfos['cache_list'])){
144
+            if (empty($cacheInfos['cache_list'])) {
145 145
                 $this->logger->info('No cache data were found skipping');
146 146
                 return false;
147 147
             }
148
-            else{
148
+            else {
149 149
                 $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
150 150
                 return apc_clear_cache('user');
151 151
             }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
          *
158 158
          * @return bool
159 159
          */
160
-        public function isSupported(){
160
+        public function isSupported() {
161 161
             return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
162 162
         }
163 163
 		
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
          * @param string $key the cache key to get the cache information 
168 168
          * @return boolean|array
169 169
          */
170
-        private function _getCacheInfo($key){
170
+        private function _getCacheInfo($key) {
171 171
             $caches = apc_cache_info('user');
172
-            if(! empty($caches['cache_list'])){
172
+            if (!empty($caches['cache_list'])) {
173 173
                 $cacheLists = $caches['cache_list'];
174
-                foreach ($cacheLists as $c){
175
-                    if(isset($c['info']) && $c['info'] === $key){
174
+                foreach ($cacheLists as $c) {
175
+                    if (isset($c['info']) && $c['info'] === $key) {
176 176
                         return $c;
177 177
                     }
178 178
                 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@  discard block
 block discarded – undo
47 47
             if($success === false){
48 48
                 $this->logger->info('No cache found for the key ['. $key .'], return false');
49 49
                 return false;
50
-            }
51
-            else{
50
+            } else{
52 51
                 $cacheInfo = $this->_getCacheInfo($key);
53 52
                 $expire = time();
54 53
                 if($cacheInfo){
@@ -74,8 +73,7 @@  discard block
 block discarded – undo
74 73
             if($result === false){
75 74
                 $this->logger->error('Can not write cache data for the key ['. $key .'], return false');
76 75
                 return false;
77
-            }
78
-            else{
76
+            } else{
79 77
                 $this->logger->info('Cache data saved for the key ['. $key .']');
80 78
                 return true;
81 79
             }
@@ -94,8 +92,7 @@  discard block
 block discarded – undo
94 92
             if($cacheInfo === false){
95 93
                 $this->logger->info('This cache data does not exists skipping');
96 94
                 return false;
97
-            }
98
-            else{
95
+            } else{
99 96
                 $this->logger->info('Found cache data for the key [' .$key. '] remove it');
100 97
                     return apc_delete($key) === true;
101 98
             }
@@ -119,8 +116,7 @@  discard block
 block discarded – undo
119 116
                             'ttl' => $cacheInfos['ttl']
120 117
                             );
121 118
                 return $data;
122
-            }
123
-            else{
119
+            } else{
124 120
                 $this->logger->info('This cache does not exists skipping');
125 121
                 return false;
126 122
             }
@@ -144,8 +140,7 @@  discard block
 block discarded – undo
144 140
             if(empty($cacheInfos['cache_list'])){
145 141
                 $this->logger->info('No cache data were found skipping');
146 142
                 return false;
147
-            }
148
-            else{
143
+            } else{
149 144
                 $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
150 145
                 return apc_clear_cache('user');
151 146
             }
Please login to merge, or discard this patch.
core/classes/cache/CacheInterface.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,84 +1,84 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	interface CacheInterface {
27
+    interface CacheInterface {
28 28
 
29
-		/**
30
-		 * This is used to get the cache data using the key
31
-		 * @param  string $key the key to identify the cache data
32
-		 * @return mixed      the cache data if exists else return false
33
-		 */
34
-		public function get($key);
29
+        /**
30
+         * This is used to get the cache data using the key
31
+         * @param  string $key the key to identify the cache data
32
+         * @return mixed      the cache data if exists else return false
33
+         */
34
+        public function get($key);
35 35
 
36 36
 
37
-		/**
38
-		 * Save data to the cache
39
-		 * @param string  $key  the key to identify this cache data
40
-		 * @param mixed  $data the cache data to be saved
41
-		 * @param integer $ttl  the cache life time
42
-		 * @return boolean true if success otherwise will return false
43
-		 */
44
-		public function set($key, $data, $ttl = 0);
37
+        /**
38
+         * Save data to the cache
39
+         * @param string  $key  the key to identify this cache data
40
+         * @param mixed  $data the cache data to be saved
41
+         * @param integer $ttl  the cache life time
42
+         * @return boolean true if success otherwise will return false
43
+         */
44
+        public function set($key, $data, $ttl = 0);
45 45
 
46 46
 
47
-		/**
48
-		 * Delete the cache data for given key
49
-		 * @param  string $key the key for cache to be deleted
50
-		 * @return boolean      true if the cache is deleted, false if can't delete 
51
-		 * the cache or the cache with the given key not exist
52
-		 */
53
-		public function delete($key);
47
+        /**
48
+         * Delete the cache data for given key
49
+         * @param  string $key the key for cache to be deleted
50
+         * @return boolean      true if the cache is deleted, false if can't delete 
51
+         * the cache or the cache with the given key not exist
52
+         */
53
+        public function delete($key);
54 54
 		
55 55
 		
56
-		/**
57
-		 * Get the cache information for given key
58
-		 * @param  string $key the key for cache to get the information for
59
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
60
-		 * 'mtime' => creation time of the cache (Unix timestamp),
61
-		 * 'expire' => expiration time of the cache (Unix timestamp),
62
-		 * 'ttl' => the time to live of the cache in second
63
-		 */
64
-		public function getInfo($key);
56
+        /**
57
+         * Get the cache information for given key
58
+         * @param  string $key the key for cache to get the information for
59
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
60
+         * 'mtime' => creation time of the cache (Unix timestamp),
61
+         * 'expire' => expiration time of the cache (Unix timestamp),
62
+         * 'ttl' => the time to live of the cache in second
63
+         */
64
+        public function getInfo($key);
65 65
 
66 66
 
67
-		/**
68
-		 * Used to delete expired cache data
69
-		 */
70
-		public function deleteExpiredCache();
67
+        /**
68
+         * Used to delete expired cache data
69
+         */
70
+        public function deleteExpiredCache();
71 71
 
72
-		/**
73
-		 * Remove all cache data
74
-		 */
75
-		public function clean();
72
+        /**
73
+         * Remove all cache data
74
+         */
75
+        public function clean();
76 76
 		
77 77
 		
78
-		/**
79
-		 * Check whether the cache feature for the handle is supported
80
-		 *
81
-		 * @return bool
82
-		 */
83
-		public function isSupported();
84
-	}
78
+        /**
79
+         * Check whether the cache feature for the handle is supported
80
+         *
81
+         * @return bool
82
+         */
83
+        public function isSupported();
84
+    }
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 2 patches
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
      */
26 26
 
27
-    class FileCache extends BaseClass implements CacheInterface{
27
+    class FileCache extends BaseClass implements CacheInterface {
28 28
 		
29 29
         /**
30 30
          * Whether to enable compression of the cache data file.
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
         /**
36 36
          * Class constructor
37 37
          */
38
-        public function __construct(){
38
+        public function __construct() {
39 39
             parent::__construct();
40
-            if(! $this->isSupported()){
40
+            if (!$this->isSupported()) {
41 41
                 show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
42 42
             }
43 43
 			
44 44
             //if Zlib extension is not loaded set compressCacheData to false
45
-            if(! extension_loaded('zlib')){
45
+            if (!extension_loaded('zlib')) {
46 46
                 $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
47 47
                 $this->compressCacheData = false;
48 48
             }
@@ -53,17 +53,17 @@  discard block
 block discarded – undo
53 53
          * @param  string $key the key to identify the cache data
54 54
          * @return mixed      the cache data if exists else return false
55 55
          */
56
-        public function get($key){
57
-            $this->logger->debug('Getting cache data for key ['. $key .']');
56
+        public function get($key) {
57
+            $this->logger->debug('Getting cache data for key [' . $key . ']');
58 58
             $filePath = $this->getFilePath($key);
59
-            if(! file_exists($filePath)){
60
-                $this->logger->info('No cache file found for the key ['. $key .'], return false');
59
+            if (!file_exists($filePath)) {
60
+                $this->logger->info('No cache file found for the key [' . $key . '], return false');
61 61
                 return false;
62 62
             }
63
-            $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
64
-            $handle = fopen($filePath,'r');
65
-            if(! is_resource($handle)){
66
-                $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
63
+            $this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid');
64
+            $handle = fopen($filePath, 'r');
65
+            if (!is_resource($handle)) {
66
+                $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
67 67
                 return false;
68 68
             }
69 69
             // Getting a shared lock 
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
             $data = file_get_contents($filePath);
72 72
                 fclose($handle);
73 73
                 $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
74
-                if (! $data) {
75
-                    $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
74
+                if (!$data) {
75
+                    $this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false');
76 76
                     // If unserializing somehow didn't work out, we'll delete the file
77 77
                     unlink($filePath);
78 78
                     return false;
79 79
                 }
80 80
                 if (time() > $data['expire']) {
81
-                    $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
81
+                    $this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']');
82 82
                 // Unlinking when the file was expired
83 83
                 unlink($filePath);
84 84
                 return false;
85 85
                 }
86
-                else{
87
-                    $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
86
+                else {
87
+                    $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
88 88
                     return $data['data'];
89 89
                 }
90 90
         }
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
          * @param integer $ttl  the cache life time
98 98
          * @return boolean true if success otherwise will return false
99 99
          */
100
-        public function set($key, $data, $ttl = 0){
100
+        public function set($key, $data, $ttl = 0) {
101 101
             $expire = time() + $ttl;
102
-            $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
102
+            $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
103 103
             $filePath = $this->getFilePath($key);
104
-            $handle = fopen($filePath,'w');
105
-            if(! is_resource($handle)){
106
-                $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
104
+            $handle = fopen($filePath, 'w');
105
+            if (!is_resource($handle)) {
106
+                $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
107 107
                 return false;
108 108
             }
109 109
             flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
                                     )
117 117
                                 );		   
118 118
             $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
119
-            if(! $result){
120
-                $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
119
+            if (!$result) {
120
+                $this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false');
121 121
                 fclose($handle);
122 122
                 return false;
123 123
             }
124
-            else{
125
-                $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
124
+            else {
125
+                $this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']');
126 126
                 fclose($handle);
127 127
                 chmod($filePath, 0640);
128 128
                 return true;
@@ -136,16 +136,16 @@  discard block
 block discarded – undo
136 136
          * @return boolean      true if the cache is delete, false if can't delete 
137 137
          * the cache or the cache with the given key not exist
138 138
          */
139
-        public function delete($key){
140
-            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
139
+        public function delete($key) {
140
+            $this->logger->debug('Deleting of cache data for key [' . $key . ']');
141 141
             $filePath = $this->getFilePath($key);
142
-            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
143
-            if(! file_exists($filePath)){
142
+            $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
143
+            if (!file_exists($filePath)) {
144 144
                 $this->logger->info('This cache file does not exists skipping');
145 145
                 return false;
146 146
             }
147
-            else{
148
-                $this->logger->info('Found cache file [' .$filePath. '] remove it');
147
+            else {
148
+                $this->logger->info('Found cache file [' . $filePath . '] remove it');
149 149
                     unlink($filePath);
150 150
                 return true;
151 151
             }
@@ -159,23 +159,23 @@  discard block
 block discarded – undo
159 159
          * 'expire' => expiration time of the cache (Unix timestamp),
160 160
          * 'ttl' => the time to live of the cache in second
161 161
          */
162
-        public function getInfo($key){
163
-            $this->logger->debug('Getting of cache info for key [' .$key. ']');
162
+        public function getInfo($key) {
163
+            $this->logger->debug('Getting of cache info for key [' . $key . ']');
164 164
             $filePath = $this->getFilePath($key);
165
-            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
166
-            if(! file_exists($filePath)){
165
+            $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
166
+            if (!file_exists($filePath)) {
167 167
                 $this->logger->info('This cache file does not exists skipping');
168 168
                 return false;
169 169
             }
170
-            $this->logger->info('Found cache file [' .$filePath. '] check the validity');
170
+            $this->logger->info('Found cache file [' . $filePath . '] check the validity');
171 171
                 $data = file_get_contents($filePath);
172 172
             $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
173
-            if(! $data){
173
+            if (!$data) {
174 174
                 $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
175 175
                 return false;
176 176
             }
177 177
             $this->logger->info('This cache data is OK check for expire');
178
-            if(isset($data['expire']) && $data['expire'] > time()){
178
+            if (isset($data['expire']) && $data['expire'] > time()) {
179 179
                 $this->logger->info('This cache not yet expired return cache informations');
180 180
                 $info = array(
181 181
                     'mtime' => $data['mtime'],
@@ -192,26 +192,26 @@  discard block
 block discarded – undo
192 192
         /**
193 193
          * Used to delete expired cache data
194 194
          */
195
-        public function deleteExpiredCache(){
195
+        public function deleteExpiredCache() {
196 196
             $this->logger->debug('Deleting of expired cache files');
197 197
             $list = glob(CACHE_PATH . '*.cache');
198
-            if(! $list){
198
+            if (!$list) {
199 199
                 $this->logger->info('No cache files were found skipping');
200 200
             }
201
-            else{
201
+            else {
202 202
                 $this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
203 203
                 foreach ($list as $file) {
204 204
                     $this->logger->debug('Processing the cache file [' . $file . ']');
205 205
                     $data = file_get_contents($file);
206 206
                         $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
207
-                        if(! $data){
207
+                        if (!$data) {
208 208
                             $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
209 209
                         }
210
-                        else if(time() > $data['expire']){
210
+                        else if (time() > $data['expire']) {
211 211
                             $this->logger->info('The cache data for file [' . $file . '] already expired remove it');
212 212
                             unlink($file);
213 213
                         }
214
-                        else{
214
+                        else {
215 215
                             $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
216 216
                         }
217 217
                 }
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
         /**
222 222
          * Remove all file from cache folder
223 223
          */
224
-        public function clean(){
224
+        public function clean() {
225 225
             $this->logger->debug('Deleting of all cache files');
226 226
             $list = glob(CACHE_PATH . '*.cache');
227
-            if(! $list){
227
+            if (!$list) {
228 228
                 $this->logger->info('No cache files were found skipping');
229 229
             }
230
-            else{
230
+            else {
231 231
                 $this->logger->info('Found [' . count($list) . '] cache files to remove');
232 232
                 foreach ($list as $file) {
233 233
                     $this->logger->debug('Processing the cache file [' . $file . ']');
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
         /**
240 240
          * @return boolean
241 241
          */
242
-        public function isCompressCacheData(){
242
+        public function isCompressCacheData() {
243 243
             return $this->compressCacheData;
244 244
         }
245 245
 
@@ -248,14 +248,14 @@  discard block
 block discarded – undo
248 248
          *
249 249
          * @return object
250 250
          */
251
-        public function setCompressCacheData($status = true){
251
+        public function setCompressCacheData($status = true) {
252 252
             //if Zlib extension is not loaded set compressCacheData to false
253
-            if($status === true && ! extension_loaded('zlib')){
253
+            if ($status === true && !extension_loaded('zlib')) {
254 254
 				
255 255
                 $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
256 256
                 $this->compressCacheData = false;
257 257
             }
258
-            else{
258
+            else {
259 259
                 $this->compressCacheData = $status;
260 260
             }
261 261
             return $this;
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
          *
267 267
          * @return bool
268 268
          */
269
-        public function isSupported(){
269
+        public function isSupported() {
270 270
             return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
271 271
         }
272 272
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
          * @param string $key the cache item key
278 278
          * @return string the full cache file path for this key
279 279
          */
280
-        private function getFilePath($key){
280
+        private function getFilePath($key) {
281 281
             return CACHE_PATH . md5($key) . '.cache';
282 282
         }
283 283
     }
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@  discard block
 block discarded – undo
82 82
                 // Unlinking when the file was expired
83 83
                 unlink($filePath);
84 84
                 return false;
85
-                }
86
-                else{
85
+                } else{
87 86
                     $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
88 87
                     return $data['data'];
89 88
                 }
@@ -120,8 +119,7 @@  discard block
 block discarded – undo
120 119
                 $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
121 120
                 fclose($handle);
122 121
                 return false;
123
-            }
124
-            else{
122
+            } else{
125 123
                 $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
126 124
                 fclose($handle);
127 125
                 chmod($filePath, 0640);
@@ -143,8 +141,7 @@  discard block
 block discarded – undo
143 141
             if(! file_exists($filePath)){
144 142
                 $this->logger->info('This cache file does not exists skipping');
145 143
                 return false;
146
-            }
147
-            else{
144
+            } else{
148 145
                 $this->logger->info('Found cache file [' .$filePath. '] remove it');
149 146
                     unlink($filePath);
150 147
                 return true;
@@ -197,8 +194,7 @@  discard block
 block discarded – undo
197 194
             $list = glob(CACHE_PATH . '*.cache');
198 195
             if(! $list){
199 196
                 $this->logger->info('No cache files were found skipping');
200
-            }
201
-            else{
197
+            } else{
202 198
                 $this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
203 199
                 foreach ($list as $file) {
204 200
                     $this->logger->debug('Processing the cache file [' . $file . ']');
@@ -206,12 +202,10 @@  discard block
 block discarded – undo
206 202
                         $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
207 203
                         if(! $data){
208 204
                             $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
209
-                        }
210
-                        else if(time() > $data['expire']){
205
+                        } else if(time() > $data['expire']){
211 206
                             $this->logger->info('The cache data for file [' . $file . '] already expired remove it');
212 207
                             unlink($file);
213
-                        }
214
-                        else{
208
+                        } else{
215 209
                             $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
216 210
                         }
217 211
                 }
@@ -226,8 +220,7 @@  discard block
 block discarded – undo
226 220
             $list = glob(CACHE_PATH . '*.cache');
227 221
             if(! $list){
228 222
                 $this->logger->info('No cache files were found skipping');
229
-            }
230
-            else{
223
+            } else{
231 224
                 $this->logger->info('Found [' . count($list) . '] cache files to remove');
232 225
                 foreach ($list as $file) {
233 226
                     $this->logger->debug('Processing the cache file [' . $file . ']');
@@ -254,8 +247,7 @@  discard block
 block discarded – undo
254 247
 				
255 248
                 $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
256 249
                 $this->compressCacheData = false;
257
-            }
258
-            else{
250
+            } else{
259 251
                 $this->compressCacheData = $status;
260 252
             }
261 253
             return $this;
Please login to merge, or discard this patch.
core/classes/Router.php 2 patches
Spacing   +71 added lines, -71 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 Router extends BaseClass{
27
+    class Router extends BaseClass {
28 28
         /**
29 29
          * @var array $pattern: The list of URIs to validate against
30 30
          */
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
         /**
91 91
          * Construct the new Router instance
92 92
          */
93
-        public function __construct(){
93
+        public function __construct() {
94 94
             parent::__construct();
95 95
 			
96 96
             //loading routes for module
97 97
             $moduleRouteList = array();
98 98
             $modulesRoutes = Module::getModulesRoutesConfig();
99
-            if($modulesRoutes && is_array($modulesRoutes)){
99
+            if ($modulesRoutes && is_array($modulesRoutes)) {
100 100
                 $moduleRouteList = $modulesRoutes;
101 101
                 unset($modulesRoutes);
102 102
             }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
          * Get the route patterns
112 112
          * @return array
113 113
          */
114
-        public function getPattern(){
114
+        public function getPattern() {
115 115
             return $this->pattern;
116 116
         }
117 117
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
          * Get the route callbacks
120 120
          * @return array
121 121
          */
122
-        public function getCallback(){
122
+        public function getCallback() {
123 123
             return $this->callback;
124 124
         }
125 125
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
          * Get the module name
128 128
          * @return string
129 129
          */
130
-        public function getModule(){
130
+        public function getModule() {
131 131
             return $this->module;
132 132
         }
133 133
 		
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
          * Get the controller name
136 136
          * @return string
137 137
          */
138
-        public function getController(){
138
+        public function getController() {
139 139
             return $this->controller;
140 140
         }
141 141
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
          * Get the controller file path
144 144
          * @return string
145 145
          */
146
-        public function getControllerPath(){
146
+        public function getControllerPath() {
147 147
             return $this->controllerPath;
148 148
         }
149 149
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
          * Get the controller method
152 152
          * @return string
153 153
          */
154
-        public function getMethod(){
154
+        public function getMethod() {
155 155
             return $this->method;
156 156
         }
157 157
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
          * Get the request arguments
160 160
          * @return array
161 161
          */
162
-        public function getArgs(){
162
+        public function getArgs() {
163 163
             return $this->args;
164 164
         }
165 165
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
          * Get the URL segments array
168 168
          * @return array
169 169
          */
170
-        public function getSegments(){
170
+        public function getSegments() {
171 171
             return $this->segments;
172 172
         }
173 173
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
          * Get the route URI
176 176
          * @return string
177 177
          */
178
-        public function getRouteUri(){
178
+        public function getRouteUri() {
179 179
             return $this->uri;
180 180
         }
181 181
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
          */
190 190
         public function add($uri, $callback) {
191 191
             $uri = trim($uri, $this->uriTrim);
192
-            if(in_array($uri, $this->pattern)){
192
+            if (in_array($uri, $this->pattern)) {
193 193
                 $this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
194 194
             }
195 195
             $this->pattern[] = $uri;
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
          * @return object the current instance
206 206
          */
207 207
         public function removeRoute($uri) {
208
-            $index  = array_search($uri, $this->pattern, true);
209
-            if($index !== false){
208
+            $index = array_search($uri, $this->pattern, true);
209
+            if ($index !== false) {
210 210
                 $this->logger->info('Remove route for uri [' . $uri . '] from the configuration');
211 211
                 unset($this->pattern[$index]);
212 212
                 unset($this->callback[$index]);
@@ -234,26 +234,26 @@  discard block
 block discarded – undo
234 234
          * @param string $uri the route URI, if is empty will determine automatically
235 235
          * @return object
236 236
          */
237
-        public function setRouteUri($uri = ''){
237
+        public function setRouteUri($uri = '') {
238 238
             $routeUri = '';
239
-            if(! empty($uri)){
239
+            if (!empty($uri)) {
240 240
                 $routeUri = $uri;
241 241
             }
242 242
             //if the application is running in CLI mode use the first argument
243
-            else if(IS_CLI && isset($_SERVER['argv'][1])){
243
+            else if (IS_CLI && isset($_SERVER['argv'][1])) {
244 244
                 $routeUri = $_SERVER['argv'][1];
245 245
             }
246
-            else if(isset($_SERVER['REQUEST_URI'])){
246
+            else if (isset($_SERVER['REQUEST_URI'])) {
247 247
                 $routeUri = $_SERVER['REQUEST_URI'];
248 248
             }
249 249
             $this->logger->debug('Check if URL suffix is enabled in the configuration');
250 250
             //remove url suffix from the request URI
251 251
             $suffix = get_config('url_suffix');
252 252
             if ($suffix) {
253
-                $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
253
+                $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
254 254
                 $routeUri = str_ireplace($suffix, '', $routeUri);
255 255
             } 
256
-            if (strpos($routeUri, '?') !== false){
256
+            if (strpos($routeUri, '?') !== false) {
257 257
                 $routeUri = substr($routeUri, 0, strpos($routeUri, '?'));
258 258
             }
259 259
             $this->uri = trim($routeUri, $this->uriTrim);
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
              * 
267 267
              * @return object
268 268
              */
269
-        public function setRouteSegments(array $segments = array()){
270
-            if(! empty($segments)){
269
+        public function setRouteSegments(array $segments = array()) {
270
+            if (!empty($segments)) {
271 271
                 $this->segments = $segments;
272 272
             } else if (!empty($this->uri)) {
273 273
                 $this->segments = explode('/', $this->uri);
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
             $segment = $this->segments;
276 276
             $baseUrl = get_config('base_url');
277 277
             //check if the app is not in DOCUMENT_ROOT
278
-            if(isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false){
278
+            if (isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false) {
279 279
                 array_shift($segment);
280 280
                 $this->segments = $segment;
281 281
             }
282 282
             $this->logger->debug('Check if the request URI contains the front controller');
283
-            if(isset($segment[0]) && $segment[0] == SELF){
283
+            if (isset($segment[0]) && $segment[0] == SELF) {
284 284
                 $this->logger->info('The request URI contains the front controller');
285 285
                 array_shift($segment);
286 286
                 $this->segments = $segment;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 			
301 301
             //if can not determine the module/controller/method via the defined routes configuration we will use
302 302
             //the URL like http://domain.com/module/controller/method/arg1/arg2
303
-            if(! $this->controller){
303
+            if (!$this->controller) {
304 304
                 $this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
305 305
                 //determine route parameters using the REQUEST_URI param
306 306
                 $this->determineRouteParamsFromRequestUri();
@@ -316,14 +316,14 @@  discard block
 block discarded – undo
316 316
              * Routing the request to the correspondant module/controller/method if exists
317 317
              * otherwise send 404 error.
318 318
              */
319
-        public function processRequest(){
319
+        public function processRequest() {
320 320
             //Setting the route URI
321 321
             $this->setRouteUri();
322 322
 
323 323
             //setting route segments
324 324
             $this->setRouteSegments();
325 325
 
326
-            $this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']' );
326
+            $this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']');
327 327
 
328 328
             //determine the route parameters information
329 329
             $this->determineRouteParamsInformation();
@@ -334,20 +334,20 @@  discard block
 block discarded – undo
334 334
             $this->logger->info('The routing information are: module [' . $this->module . '], controller [' . $controller . '], method [' . $this->method . '], args [' . stringfy_vars($this->args) . ']');
335 335
             $this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
336 336
 	    	
337
-            if(file_exists($classFilePath)){
337
+            if (file_exists($classFilePath)) {
338 338
                 require_once $classFilePath;
339
-                if(! class_exists($controller, false)){
339
+                if (!class_exists($controller, false)) {
340 340
                     $e404 = true;
341
-                    $this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
341
+                    $this->logger->warning('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
342 342
                 }
343
-                else{
343
+                else {
344 344
                     $controllerInstance = new $controller();
345 345
                     $controllerMethod = $this->getMethod();
346
-                    if(! method_exists($controllerInstance, $controllerMethod)){
346
+                    if (!method_exists($controllerInstance, $controllerMethod)) {
347 347
                         $e404 = true;
348 348
                         $this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
349 349
                     }
350
-                    else{
350
+                    else {
351 351
                         $this->logger->info('Routing data is set correctly now GO!');
352 352
                         call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
353 353
                         //render the final page to user
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
                     }
357 357
                 }
358 358
             }
359
-            else{
359
+            else {
360 360
                 $this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
361 361
                 $e404 = true;
362 362
             }
363
-            if($e404){
364
-                if(IS_CLI){
363
+            if ($e404) {
364
+                if (IS_CLI) {
365 365
                     set_http_status_header(404);
366 366
                     echo 'Error 404: page not found.';
367 367
                 } else {
368
-                    $response =& class_loader('Response', 'classes');
368
+                    $response = & class_loader('Response', 'classes');
369 369
                     $response->send404();
370 370
                 }
371 371
             }
@@ -378,15 +378,15 @@  discard block
 block discarded – undo
378 378
          * @param boolean $useConfigFile whether to use route configuration file
379 379
          * @return object
380 380
          */
381
-        public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
381
+        public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
382 382
             $route = array();
383
-            if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
383
+            if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')) {
384 384
                 require_once CONFIG_PATH . 'routes.php';
385 385
             }
386 386
             $route = array_merge($route, $overwriteConfig);
387 387
             $this->routes = $route;
388 388
             //if route is empty remove all configuration
389
-            if(empty($route)){
389
+            if (empty($route)) {
390 390
                 $this->removeAllRoute();
391 391
             }
392 392
             return $this;
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
              * Get the route configuration
397 397
              * @return array
398 398
              */
399
-        public function getRouteConfiguration(){
399
+        public function getRouteConfiguration() {
400 400
             return $this->routes;
401 401
         }
402 402
 
@@ -408,19 +408,19 @@  discard block
 block discarded – undo
408 408
          *
409 409
          * @return object the current instance
410 410
          */
411
-        public function setControllerFilePath($path = null){
412
-            if($path !== null){
411
+        public function setControllerFilePath($path = null) {
412
+            if ($path !== null) {
413 413
                 $this->controllerPath = $path;
414 414
                 return $this;
415 415
             }
416 416
             //did we set the controller, so set the controller path
417
-            if($this->controller && ! $this->controllerPath){
417
+            if ($this->controller && !$this->controllerPath) {
418 418
                 $this->logger->debug('Setting the file path for the controller [' . $this->controller . ']');
419 419
                 $controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->controller) . '.php';
420 420
                 //if the controller is in module
421
-                if($this->module){
421
+                if ($this->module) {
422 422
                     $path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
423
-                    if($path !== false){
423
+                    if ($path !== false) {
424 424
                         $controllerPath = $path;
425 425
                     }
426 426
                 }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
          * Determine the route parameters from route configuration
434 434
          * @return void
435 435
          */
436
-        protected function determineRouteParamsFromConfig(){
436
+        protected function determineRouteParamsFromConfig() {
437 437
             $uri = implode('/', $this->segments);
438 438
             /*
439 439
 	   		* Generics routes patterns
@@ -458,20 +458,20 @@  discard block
 block discarded – undo
458 458
                     array_shift($args);
459 459
                     //check if this contains an module
460 460
                     $moduleControllerMethod = explode('#', $this->callback[$index]);
461
-                    if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
461
+                    if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
462 462
                         $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
463 463
                         $this->module = $moduleControllerMethod[0];
464 464
                         $moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
465 465
                     }
466
-                    else{
466
+                    else {
467 467
                         $this->logger->info('The current request does not use the module');
468 468
                         $moduleControllerMethod = explode('@', $this->callback[$index]);
469 469
                     }
470
-                    if(is_array($moduleControllerMethod)){
471
-                        if(isset($moduleControllerMethod[0])){
470
+                    if (is_array($moduleControllerMethod)) {
471
+                        if (isset($moduleControllerMethod[0])) {
472 472
                             $this->controller = $moduleControllerMethod[0];	
473 473
                         }
474
-                        if(isset($moduleControllerMethod[1])){
474
+                        if (isset($moduleControllerMethod[1])) {
475 475
                             $this->method = $moduleControllerMethod[1];
476 476
                         }
477 477
                         $this->args = $args;
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
             }
483 483
 
484 484
             //first if the controller is not set and the module is set use the module name as the controller
485
-            if(! $this->controller && $this->module){
485
+            if (!$this->controller && $this->module) {
486 486
                 $this->logger->info(
487 487
                                     'After loop in predefined routes configuration, 
488 488
 									the module name is set but the controller is not set, 
@@ -496,67 +496,67 @@  discard block
 block discarded – undo
496 496
          * Determine the route parameters using the server variable "REQUEST_URI"
497 497
          * @return void
498 498
          */
499
-        protected function determineRouteParamsFromRequestUri(){
499
+        protected function determineRouteParamsFromRequestUri() {
500 500
             $segment = $this->segments;
501 501
             $nbSegment = count($segment);
502 502
             //if segment is null so means no need to perform
503
-            if($nbSegment > 0){
503
+            if ($nbSegment > 0) {
504 504
                 //get the module list
505 505
                 $modules = Module::getModuleList();
506 506
                 //first check if no module
507
-                if(empty($modules)){
507
+                if (empty($modules)) {
508 508
                     $this->logger->info('No module was loaded will skip the module checking');
509 509
                     //the application don't use module
510 510
                     //controller
511
-                    if(isset($segment[0])){
511
+                    if (isset($segment[0])) {
512 512
                         $this->controller = $segment[0];
513 513
                         array_shift($segment);
514 514
                     }
515 515
                     //method
516
-                    if(isset($segment[0])){
516
+                    if (isset($segment[0])) {
517 517
                         $this->method = $segment[0];
518 518
                         array_shift($segment);
519 519
                     }
520 520
                     //args
521 521
                     $this->args = $segment;
522 522
                 }
523
-                else{
523
+                else {
524 524
                     $this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
525
-                    if(in_array($segment[0], $modules)){
525
+                    if (in_array($segment[0], $modules)) {
526 526
                         $this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
527 527
                         $this->module = $segment[0];
528 528
                         array_shift($segment);
529 529
                         //check if the second arg is the controller from module
530
-                        if(isset($segment[0])){
530
+                        if (isset($segment[0])) {
531 531
                             $this->controller = $segment[0];
532 532
                             //check if the request use the same module name and controller
533 533
                             $path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
534
-                            if(! $path){
534
+                            if (!$path) {
535 535
                                 $this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
536 536
                                 $this->controller = $this->module;
537 537
                             }
538
-                            else{
538
+                            else {
539 539
                                 $this->controllerPath = $path;
540 540
                                 array_shift($segment);
541 541
                             }
542 542
                         }
543 543
                         //check for method
544
-                        if(isset($segment[0])){
544
+                        if (isset($segment[0])) {
545 545
                             $this->method = $segment[0];
546 546
                             array_shift($segment);
547 547
                         }
548 548
                         //the remaining is for args
549 549
                         $this->args = $segment;
550 550
                     }
551
-                    else{
551
+                    else {
552 552
                         $this->logger->info('The current request information is not found in the module list');
553 553
                         //controller
554
-                        if(isset($segment[0])){
554
+                        if (isset($segment[0])) {
555 555
                             $this->controller = $segment[0];
556 556
                             array_shift($segment);
557 557
                         }
558 558
                         //method
559
-                        if(isset($segment[0])){
559
+                        if (isset($segment[0])) {
560 560
                             $this->method = $segment[0];
561 561
                             array_shift($segment);
562 562
                         }
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                         $this->args = $segment;
565 565
                     }
566 566
                 }
567
-                if(! $this->controller && $this->module){
567
+                if (!$this->controller && $this->module) {
568 568
                     $this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
569 569
                     $this->controller = $this->module;
570 570
                 }
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
          *
577 577
          * @return object the current instance
578 578
          */
579
-        protected function setRouteConfigurationInfos(){
579
+        protected function setRouteConfigurationInfos() {
580 580
             //adding route
581
-            foreach($this->routes as $pattern => $callback){
581
+            foreach ($this->routes as $pattern => $callback) {
582 582
                 $this->add($pattern, $callback);
583 583
             }
584 584
             return $this;
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -242,8 +242,7 @@  discard block
 block discarded – undo
242 242
             //if the application is running in CLI mode use the first argument
243 243
             else if(IS_CLI && isset($_SERVER['argv'][1])){
244 244
                 $routeUri = $_SERVER['argv'][1];
245
-            }
246
-            else if(isset($_SERVER['REQUEST_URI'])){
245
+            } else if(isset($_SERVER['REQUEST_URI'])){
247 246
                 $routeUri = $_SERVER['REQUEST_URI'];
248 247
             }
249 248
             $this->logger->debug('Check if URL suffix is enabled in the configuration');
@@ -339,15 +338,13 @@  discard block
 block discarded – undo
339 338
                 if(! class_exists($controller, false)){
340 339
                     $e404 = true;
341 340
                     $this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
342
-                }
343
-                else{
341
+                } else{
344 342
                     $controllerInstance = new $controller();
345 343
                     $controllerMethod = $this->getMethod();
346 344
                     if(! method_exists($controllerInstance, $controllerMethod)){
347 345
                         $e404 = true;
348 346
                         $this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
349
-                    }
350
-                    else{
347
+                    } else{
351 348
                         $this->logger->info('Routing data is set correctly now GO!');
352 349
                         call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
353 350
                         //render the final page to user
@@ -355,8 +352,7 @@  discard block
 block discarded – undo
355 352
                         get_instance()->response->renderFinalPage();
356 353
                     }
357 354
                 }
358
-            }
359
-            else{
355
+            } else{
360 356
                 $this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
361 357
                 $e404 = true;
362 358
             }
@@ -462,8 +458,7 @@  discard block
 block discarded – undo
462 458
                         $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
463 459
                         $this->module = $moduleControllerMethod[0];
464 460
                         $moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
465
-                    }
466
-                    else{
461
+                    } else{
467 462
                         $this->logger->info('The current request does not use the module');
468 463
                         $moduleControllerMethod = explode('@', $this->callback[$index]);
469 464
                     }
@@ -519,8 +514,7 @@  discard block
 block discarded – undo
519 514
                     }
520 515
                     //args
521 516
                     $this->args = $segment;
522
-                }
523
-                else{
517
+                } else{
524 518
                     $this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
525 519
                     if(in_array($segment[0], $modules)){
526 520
                         $this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
@@ -534,8 +528,7 @@  discard block
 block discarded – undo
534 528
                             if(! $path){
535 529
                                 $this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
536 530
                                 $this->controller = $this->module;
537
-                            }
538
-                            else{
531
+                            } else{
539 532
                                 $this->controllerPath = $path;
540 533
                                 array_shift($segment);
541 534
                             }
@@ -547,8 +540,7 @@  discard block
 block discarded – undo
547 540
                         }
548 541
                         //the remaining is for args
549 542
                         $this->args = $segment;
550
-                    }
551
-                    else{
543
+                    } else{
552 544
                         $this->logger->info('The current request information is not found in the module list');
553 545
                         //controller
554 546
                         if(isset($segment[0])){
Please login to merge, or discard this patch.
core/classes/EventDispatcher.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -1,167 +1,167 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 * This class represent the event dispatcher management, permit to record the listener and 
29
-	 * also to dispatch the event
30
-	 */
27
+    /**
28
+     * This class represent the event dispatcher management, permit to record the listener and 
29
+     * also to dispatch the event
30
+     */
31 31
 	
32
-	class EventDispatcher extends BaseClass {
32
+    class EventDispatcher extends BaseClass {
33 33
 		
34
-		/**
35
-		 * The list of the registered listeners
36
-		 * @var array
37
-		 */
38
-		private $listeners = array();
34
+        /**
35
+         * The list of the registered listeners
36
+         * @var array
37
+         */
38
+        private $listeners = array();
39 39
 		
40 40
 
41
-		public function __construct() {
42
-			parent::__construct();
43
-		}
41
+        public function __construct() {
42
+            parent::__construct();
43
+        }
44 44
 
45
-		/**
46
-		 * Register new listener
47
-		 * @param string   $eventName the name of the event to register for
48
-		 * @param callable $listener  the function or class method to receive the event information after dispatch
49
-		 */
50
-		public function addListener($eventName, callable $listener){
51
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
52
-			if(! isset($this->listeners[$eventName])){
53
-				$this->logger->info('This event does not have the registered event listener before, adding new one');
54
-				$this->listeners[$eventName] = array();
55
-			} else{
56
-				$this->logger->info('This event already have the registered listener, add this listener to the list');
57
-			}
58
-			$this->listeners[$eventName][] = $listener;
59
-		}
45
+        /**
46
+         * Register new listener
47
+         * @param string   $eventName the name of the event to register for
48
+         * @param callable $listener  the function or class method to receive the event information after dispatch
49
+         */
50
+        public function addListener($eventName, callable $listener){
51
+            $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
52
+            if(! isset($this->listeners[$eventName])){
53
+                $this->logger->info('This event does not have the registered event listener before, adding new one');
54
+                $this->listeners[$eventName] = array();
55
+            } else{
56
+                $this->logger->info('This event already have the registered listener, add this listener to the list');
57
+            }
58
+            $this->listeners[$eventName][] = $listener;
59
+        }
60 60
 		
61
-		/**
62
-		 * Remove the event listener from list
63
-		 * @param  string   $eventName the event name
64
-		 * @param  callable $listener  the listener callback
65
-		 */
66
-		public function removeListener($eventName, callable $listener){
67
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
68
-			if(isset($this->listeners[$eventName])){
69
-				$this->logger->info('This event have the listeners, check if this listener exists');
70
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
71
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
72
-					unset($this->listeners[$eventName][$index]);
73
-				} else{
74
-					$this->logger->info('Cannot found this listener in the event listener list');
75
-				}
76
-			} else{
77
-				$this->logger->info('This event does not have this listener ignore remove');
78
-			}
79
-		}
61
+        /**
62
+         * Remove the event listener from list
63
+         * @param  string   $eventName the event name
64
+         * @param  callable $listener  the listener callback
65
+         */
66
+        public function removeListener($eventName, callable $listener){
67
+            $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
68
+            if(isset($this->listeners[$eventName])){
69
+                $this->logger->info('This event have the listeners, check if this listener exists');
70
+                if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
71
+                    $this->logger->info('Found the listener at index [' .$index. '] remove it');
72
+                    unset($this->listeners[$eventName][$index]);
73
+                } else{
74
+                    $this->logger->info('Cannot found this listener in the event listener list');
75
+                }
76
+            } else{
77
+                $this->logger->info('This event does not have this listener ignore remove');
78
+            }
79
+        }
80 80
 		
81
-		/**
82
-		 * Remove all the event listener. If event name is null will remove all listeners, else will just 
83
-		 * remove all listeners for this event
84
-		 * @param  string $eventName the event name
85
-		 */
86
-		public function removeAllListener($eventName = null){
87
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
88
-			if($eventName !== null && isset($this->listeners[$eventName])){
89
-				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
90
-				unset($this->listeners[$eventName]);
91
-			} else{
92
-				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
93
-				$this->listeners = array();
94
-			}
95
-		}
81
+        /**
82
+         * Remove all the event listener. If event name is null will remove all listeners, else will just 
83
+         * remove all listeners for this event
84
+         * @param  string $eventName the event name
85
+         */
86
+        public function removeAllListener($eventName = null){
87
+            $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
88
+            if($eventName !== null && isset($this->listeners[$eventName])){
89
+                $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
90
+                unset($this->listeners[$eventName]);
91
+            } else{
92
+                $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
93
+                $this->listeners = array();
94
+            }
95
+        }
96 96
 		
97
-		/**
98
-		 * Get the list of listener for this event
99
-		 * @param string $eventName the event name
100
-		 * @return array the listeners for this event or empty array if this event does not contain any listener
101
-		 */
102
-		public function getListeners($eventName) {
103
-			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
104
-		}
97
+        /**
98
+         * Get the list of listener for this event
99
+         * @param string $eventName the event name
100
+         * @return array the listeners for this event or empty array if this event does not contain any listener
101
+         */
102
+        public function getListeners($eventName) {
103
+            return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
104
+        }
105 105
 		
106
-		/**
107
-		 * Dispatch the event to the registered listeners.
108
-		 * @param  mixed|object $event the event information
109
-		 * @return void|object if event need return, will return the final EventInfo object.
110
-		 */	
111
-		public function dispatch($event){
112
-			if(! $event || !$event instanceof EventInfo){
113
-				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
114
-				$event = new EventInfo((string) $event);
115
-			}			
116
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
117
-			if(isset($event->stop) && $event->stop){
118
-				$this->logger->info('This event need stopped, no need call any listener');
119
-				return;
120
-			}
121
-			if($event->returnBack){
122
-				$this->logger->info('This event need return back, return the result for future use');
123
-				return $this->dispatchToListerners($event);
124
-			} else{
125
-				$this->logger->info('This event no need return back the result, just dispatch it');
126
-				$this->dispatchToListerners($event);
127
-			}
128
-		}
106
+        /**
107
+         * Dispatch the event to the registered listeners.
108
+         * @param  mixed|object $event the event information
109
+         * @return void|object if event need return, will return the final EventInfo object.
110
+         */	
111
+        public function dispatch($event){
112
+            if(! $event || !$event instanceof EventInfo){
113
+                $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
114
+                $event = new EventInfo((string) $event);
115
+            }			
116
+            $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
117
+            if(isset($event->stop) && $event->stop){
118
+                $this->logger->info('This event need stopped, no need call any listener');
119
+                return;
120
+            }
121
+            if($event->returnBack){
122
+                $this->logger->info('This event need return back, return the result for future use');
123
+                return $this->dispatchToListerners($event);
124
+            } else{
125
+                $this->logger->info('This event no need return back the result, just dispatch it');
126
+                $this->dispatchToListerners($event);
127
+            }
128
+        }
129 129
 		
130
-		/**
131
-		 * Dispatch the event to the registered listeners.
132
-		 * @param  object EventInfo $event  the event information
133
-		 * @return void|object if event need return, will return the final EventInfo instance.
134
-		 */	
135
-		private function dispatchToListerners(EventInfo $event){
136
-			$eBackup = $event;
137
-			$list = $this->getListeners($event->name);
138
-			if(empty($list)){
139
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
140
-				if($event->returnBack){
141
-					return $event;
142
-				}
143
-				return;
144
-			} else{
145
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
146
-			}
147
-			foreach($list as $listener){
148
-				if($eBackup->returnBack){
149
-					$returnedEvent = call_user_func_array($listener, array($event));
150
-					if($returnedEvent instanceof EventInfo){
151
-						$event = $returnedEvent;
152
-					} else{
153
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
154
-					}
155
-				} else{
156
-					call_user_func_array($listener, array($event));
157
-				}
158
-				if($event->stop){
159
-					break;
160
-				}
161
-			}
162
-			//only test for original event may be during the flow some listeners change this parameter
163
-			if($eBackup->returnBack){
164
-				return $event;
165
-			}
166
-		}
167
-	}
130
+        /**
131
+         * Dispatch the event to the registered listeners.
132
+         * @param  object EventInfo $event  the event information
133
+         * @return void|object if event need return, will return the final EventInfo instance.
134
+         */	
135
+        private function dispatchToListerners(EventInfo $event){
136
+            $eBackup = $event;
137
+            $list = $this->getListeners($event->name);
138
+            if(empty($list)){
139
+                $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
140
+                if($event->returnBack){
141
+                    return $event;
142
+                }
143
+                return;
144
+            } else{
145
+                $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
146
+            }
147
+            foreach($list as $listener){
148
+                if($eBackup->returnBack){
149
+                    $returnedEvent = call_user_func_array($listener, array($event));
150
+                    if($returnedEvent instanceof EventInfo){
151
+                        $event = $returnedEvent;
152
+                    } else{
153
+                        show_error('This event [' .$event->name. '] need you return the event object after processing');
154
+                    }
155
+                } else{
156
+                    call_user_func_array($listener, array($event));
157
+                }
158
+                if($event->stop){
159
+                    break;
160
+                }
161
+            }
162
+            //only test for original event may be during the flow some listeners change this parameter
163
+            if($eBackup->returnBack){
164
+                return $event;
165
+            }
166
+        }
167
+    }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
 		 * @param string   $eventName the name of the event to register for
48 48
 		 * @param callable $listener  the function or class method to receive the event information after dispatch
49 49
 		 */
50
-		public function addListener($eventName, callable $listener){
51
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
52
-			if(! isset($this->listeners[$eventName])){
50
+		public function addListener($eventName, callable $listener) {
51
+			$this->logger->debug('Adding new event listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
52
+			if (!isset($this->listeners[$eventName])) {
53 53
 				$this->logger->info('This event does not have the registered event listener before, adding new one');
54 54
 				$this->listeners[$eventName] = array();
55
-			} else{
55
+			} else {
56 56
 				$this->logger->info('This event already have the registered listener, add this listener to the list');
57 57
 			}
58 58
 			$this->listeners[$eventName][] = $listener;
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
 		 * @param  string   $eventName the event name
64 64
 		 * @param  callable $listener  the listener callback
65 65
 		 */
66
-		public function removeListener($eventName, callable $listener){
67
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
68
-			if(isset($this->listeners[$eventName])){
66
+		public function removeListener($eventName, callable $listener) {
67
+			$this->logger->debug('Removing of the event listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
68
+			if (isset($this->listeners[$eventName])) {
69 69
 				$this->logger->info('This event have the listeners, check if this listener exists');
70
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
71
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
70
+				if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) {
71
+					$this->logger->info('Found the listener at index [' . $index . '] remove it');
72 72
 					unset($this->listeners[$eventName][$index]);
73
-				} else{
73
+				} else {
74 74
 					$this->logger->info('Cannot found this listener in the event listener list');
75 75
 				}
76
-			} else{
76
+			} else {
77 77
 				$this->logger->info('This event does not have this listener ignore remove');
78 78
 			}
79 79
 		}
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * remove all listeners for this event
84 84
 		 * @param  string $eventName the event name
85 85
 		 */
86
-		public function removeAllListener($eventName = null){
87
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
88
-			if($eventName !== null && isset($this->listeners[$eventName])){
86
+		public function removeAllListener($eventName = null) {
87
+			$this->logger->debug('Removing of all event listener, the event name [' . $eventName . ']');
88
+			if ($eventName !== null && isset($this->listeners[$eventName])) {
89 89
 				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
90 90
 				unset($this->listeners[$eventName]);
91
-			} else{
91
+			} else {
92 92
 				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
93 93
 				$this->listeners = array();
94 94
 			}
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 		 * @param  mixed|object $event the event information
109 109
 		 * @return void|object if event need return, will return the final EventInfo object.
110 110
 		 */	
111
-		public function dispatch($event){
112
-			if(! $event || !$event instanceof EventInfo){
111
+		public function dispatch($event) {
112
+			if (!$event || !$event instanceof EventInfo) {
113 113
 				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
114 114
 				$event = new EventInfo((string) $event);
115 115
 			}			
116
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
117
-			if(isset($event->stop) && $event->stop){
116
+			$this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']');
117
+			if (isset($event->stop) && $event->stop) {
118 118
 				$this->logger->info('This event need stopped, no need call any listener');
119 119
 				return;
120 120
 			}
121
-			if($event->returnBack){
121
+			if ($event->returnBack) {
122 122
 				$this->logger->info('This event need return back, return the result for future use');
123 123
 				return $this->dispatchToListerners($event);
124
-			} else{
124
+			} else {
125 125
 				$this->logger->info('This event no need return back the result, just dispatch it');
126 126
 				$this->dispatchToListerners($event);
127 127
 			}
@@ -132,35 +132,35 @@  discard block
 block discarded – undo
132 132
 		 * @param  object EventInfo $event  the event information
133 133
 		 * @return void|object if event need return, will return the final EventInfo instance.
134 134
 		 */	
135
-		private function dispatchToListerners(EventInfo $event){
135
+		private function dispatchToListerners(EventInfo $event) {
136 136
 			$eBackup = $event;
137 137
 			$list = $this->getListeners($event->name);
138
-			if(empty($list)){
139
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
140
-				if($event->returnBack){
138
+			if (empty($list)) {
139
+				$this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.');
140
+				if ($event->returnBack) {
141 141
 					return $event;
142 142
 				}
143 143
 				return;
144
-			} else{
145
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
144
+			} else {
145
+				$this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list));
146 146
 			}
147
-			foreach($list as $listener){
148
-				if($eBackup->returnBack){
147
+			foreach ($list as $listener) {
148
+				if ($eBackup->returnBack) {
149 149
 					$returnedEvent = call_user_func_array($listener, array($event));
150
-					if($returnedEvent instanceof EventInfo){
150
+					if ($returnedEvent instanceof EventInfo) {
151 151
 						$event = $returnedEvent;
152
-					} else{
153
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
152
+					} else {
153
+						show_error('This event [' . $event->name . '] need you return the event object after processing');
154 154
 					}
155
-				} else{
155
+				} else {
156 156
 					call_user_func_array($listener, array($event));
157 157
 				}
158
-				if($event->stop){
158
+				if ($event->stop) {
159 159
 					break;
160 160
 				}
161 161
 			}
162 162
 			//only test for original event may be during the flow some listeners change this parameter
163
-			if($eBackup->returnBack){
163
+			if ($eBackup->returnBack) {
164 164
 				return $event;
165 165
 			}
166 166
 		}
Please login to merge, or discard this patch.