Passed
Push — 1.0.0-dev ( 93958a...e1c8ef )
by nguereza
02:26
created
core/classes/cache/FileCache.php 3 patches
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -1,283 +1,283 @@
 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 FileCache extends BaseClass implements CacheInterface{
27
+    class FileCache extends BaseClass implements CacheInterface{
28 28
 		
29
-		/**
30
-		 * Whether to enable compression of the cache data file.
31
-		 * @var boolean
32
-		 */
33
-		private $compressCacheData = true;
29
+        /**
30
+         * Whether to enable compression of the cache data file.
31
+         * @var boolean
32
+         */
33
+        private $compressCacheData = true;
34 34
 
35
-		/**
36
-		 * Class constructor
37
-		 */
38
-		public function __construct(){
39
-			parent::__construct();
40
-			if(! $this->isSupported()){
41
-				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
42
-			}
35
+        /**
36
+         * Class constructor
37
+         */
38
+        public function __construct(){
39
+            parent::__construct();
40
+            if(! $this->isSupported()){
41
+                show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
42
+            }
43 43
 			
44
-			//if Zlib extension is not loaded set compressCacheData to false
45
-			if(! extension_loaded('zlib')){
46
-				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
47
-				$this->compressCacheData = false;
48
-			}
49
-		}
44
+            //if Zlib extension is not loaded set compressCacheData to false
45
+            if(! extension_loaded('zlib')){
46
+                $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
47
+                $this->compressCacheData = false;
48
+            }
49
+        }
50 50
 
51
-		/**
52
-		 * This is used to get the cache data using the key
53
-		 * @param  string $key the key to identify the cache data
54
-		 * @return mixed      the cache data if exists else return false
55
-		 */
56
-		public function get($key){
57
-			$this->logger->debug('Getting cache data for key ['. $key .']');
58
-			$filePath = $this->getFilePath($key);
59
-			if(! file_exists($filePath)){
60
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
61
-				return false;
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');
67
-				return false;
68
-			}
69
-			// Getting a shared lock 
70
-		    flock($handle, LOCK_SH);
71
-		    $data = file_get_contents($filePath);
72
-      		fclose($handle);
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');
76
-		         // If unserializing somehow didn't work out, we'll delete the file
77
-		         unlink($filePath);
78
-		         return false;
79
-	      	}
80
-	      	if (time() > $data['expire']) {
81
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
82
-		        // Unlinking when the file was expired
83
-		        unlink($filePath);
84
-		        return false;
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']) . ']');
88
-		     	return $data['data'];
89
-		     }
90
-		}
51
+        /**
52
+         * This is used to get the cache data using the key
53
+         * @param  string $key the key to identify the cache data
54
+         * @return mixed      the cache data if exists else return false
55
+         */
56
+        public function get($key){
57
+            $this->logger->debug('Getting cache data for key ['. $key .']');
58
+            $filePath = $this->getFilePath($key);
59
+            if(! file_exists($filePath)){
60
+                $this->logger->info('No cache file found for the key ['. $key .'], return false');
61
+                return false;
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');
67
+                return false;
68
+            }
69
+            // Getting a shared lock 
70
+            flock($handle, LOCK_SH);
71
+            $data = file_get_contents($filePath);
72
+                fclose($handle);
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');
76
+                    // If unserializing somehow didn't work out, we'll delete the file
77
+                    unlink($filePath);
78
+                    return false;
79
+                }
80
+                if (time() > $data['expire']) {
81
+                    $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
82
+                // Unlinking when the file was expired
83
+                unlink($filePath);
84
+                return false;
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']) . ']');
88
+                    return $data['data'];
89
+                }
90
+        }
91 91
 
92 92
 
93
-		/**
94
-		 * Save data to the cache
95
-		 * @param string  $key  the key to identify this cache data
96
-		 * @param mixed  $data the cache data
97
-		 * @param integer $ttl  the cache life time
98
-		 * @return boolean true if success otherwise will return false
99
-		 */
100
-		public function set($key, $data, $ttl = 0){
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) . ']');
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');
107
-				return false;
108
-			}
109
-			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
110
-			//Serializing along with the TTL
111
-		    $cacheData = serialize(array(
112
-									'mtime' => time(),
113
-									'expire' => $expire,
114
-									'data' => $data,
115
-									'ttl' => $ttl
116
-									)
117
-								);		   
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');
121
-		    	fclose($handle);
122
-		    	return false;
123
-		    }
124
-		    else{
125
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
126
-		    	fclose($handle);
127
-				chmod($filePath, 0640);
128
-				return true;
129
-		    }
130
-		}	
93
+        /**
94
+         * Save data to the cache
95
+         * @param string  $key  the key to identify this cache data
96
+         * @param mixed  $data the cache data
97
+         * @param integer $ttl  the cache life time
98
+         * @return boolean true if success otherwise will return false
99
+         */
100
+        public function set($key, $data, $ttl = 0){
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) . ']');
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');
107
+                return false;
108
+            }
109
+            flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
110
+            //Serializing along with the TTL
111
+            $cacheData = serialize(array(
112
+                                    'mtime' => time(),
113
+                                    'expire' => $expire,
114
+                                    'data' => $data,
115
+                                    'ttl' => $ttl
116
+                                    )
117
+                                );		   
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');
121
+                fclose($handle);
122
+                return false;
123
+            }
124
+            else{
125
+                $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
126
+                fclose($handle);
127
+                chmod($filePath, 0640);
128
+                return true;
129
+            }
130
+        }	
131 131
 
132 132
 
133
-		/**
134
-		 * Delete the cache data for given key
135
-		 * @param  string $key the key for cache to be deleted
136
-		 * @return boolean      true if the cache is delete, false if can't delete 
137
-		 * the cache or the cache with the given key not exist
138
-		 */
139
-		public function delete($key){
140
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
141
-			$filePath = $this->getFilePath($key);
142
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
143
-			if(! file_exists($filePath)){
144
-				$this->logger->info('This cache file does not exists skipping');
145
-				return false;
146
-			}
147
-			else{
148
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
149
-	      		unlink($filePath);
150
-				return true;
151
-			}
152
-		}
133
+        /**
134
+         * Delete the cache data for given key
135
+         * @param  string $key the key for cache to be deleted
136
+         * @return boolean      true if the cache is delete, false if can't delete 
137
+         * the cache or the cache with the given key not exist
138
+         */
139
+        public function delete($key){
140
+            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
141
+            $filePath = $this->getFilePath($key);
142
+            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
143
+            if(! file_exists($filePath)){
144
+                $this->logger->info('This cache file does not exists skipping');
145
+                return false;
146
+            }
147
+            else{
148
+                $this->logger->info('Found cache file [' .$filePath. '] remove it');
149
+                    unlink($filePath);
150
+                return true;
151
+            }
152
+        }
153 153
 		
154
-		/**
155
-		 * Get the cache information for given key
156
-		 * @param  string $key the key for cache to get the information for
157
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
158
-		 * 'mtime' => creation time of the cache (Unix timestamp),
159
-		 * 'expire' => expiration time of the cache (Unix timestamp),
160
-		 * 'ttl' => the time to live of the cache in second
161
-		 */
162
-		public function getInfo($key){
163
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
164
-			$filePath = $this->getFilePath($key);
165
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
166
-			if(! file_exists($filePath)){
167
-				$this->logger->info('This cache file does not exists skipping');
168
-				return false;
169
-			}
170
-			$this->logger->info('Found cache file [' .$filePath. '] check the validity');
171
-      		$data = file_get_contents($filePath);
172
-			$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
173
-			if(! $data){
174
-				$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
175
-				return false;
176
-			}
177
-			$this->logger->info('This cache data is OK check for expire');
178
-			if(isset($data['expire']) && $data['expire'] > time()){
179
-				$this->logger->info('This cache not yet expired return cache informations');
180
-				$info = array(
181
-					'mtime' => $data['mtime'],
182
-					'expire' => $data['expire'],
183
-					'ttl' => $data['ttl']
184
-					);
185
-				return $info;
186
-			}
187
-			$this->logger->info('This cache already expired return false');
188
-			return false;
189
-		}
154
+        /**
155
+         * Get the cache information for given key
156
+         * @param  string $key the key for cache to get the information for
157
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
158
+         * 'mtime' => creation time of the cache (Unix timestamp),
159
+         * 'expire' => expiration time of the cache (Unix timestamp),
160
+         * 'ttl' => the time to live of the cache in second
161
+         */
162
+        public function getInfo($key){
163
+            $this->logger->debug('Getting of cache info for key [' .$key. ']');
164
+            $filePath = $this->getFilePath($key);
165
+            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
166
+            if(! file_exists($filePath)){
167
+                $this->logger->info('This cache file does not exists skipping');
168
+                return false;
169
+            }
170
+            $this->logger->info('Found cache file [' .$filePath. '] check the validity');
171
+                $data = file_get_contents($filePath);
172
+            $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
173
+            if(! $data){
174
+                $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
175
+                return false;
176
+            }
177
+            $this->logger->info('This cache data is OK check for expire');
178
+            if(isset($data['expire']) && $data['expire'] > time()){
179
+                $this->logger->info('This cache not yet expired return cache informations');
180
+                $info = array(
181
+                    'mtime' => $data['mtime'],
182
+                    'expire' => $data['expire'],
183
+                    'ttl' => $data['ttl']
184
+                    );
185
+                return $info;
186
+            }
187
+            $this->logger->info('This cache already expired return false');
188
+            return false;
189
+        }
190 190
 
191 191
 
192
-		/**
193
-		 * Used to delete expired cache data
194
-		 */
195
-		public function deleteExpiredCache(){
196
-			$this->logger->debug('Deleting of expired cache files');
197
-			$list = glob(CACHE_PATH . '*.cache');
198
-			if(! $list){
199
-				$this->logger->info('No cache files were found skipping');
200
-			}
201
-			else{
202
-				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
203
-				foreach ($list as $file) {
204
-					$this->logger->debug('Processing the cache file [' . $file . ']');
205
-					$data = file_get_contents($file);
206
-		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
207
-		      		if(! $data){
208
-		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
209
-		      		}
210
-		      		else if(time() > $data['expire']){
211
-		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
212
-		      			unlink($file);
213
-		      		}
214
-		      		else{
215
-		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
216
-		      		}
217
-				}
218
-			}
219
-		}	
192
+        /**
193
+         * Used to delete expired cache data
194
+         */
195
+        public function deleteExpiredCache(){
196
+            $this->logger->debug('Deleting of expired cache files');
197
+            $list = glob(CACHE_PATH . '*.cache');
198
+            if(! $list){
199
+                $this->logger->info('No cache files were found skipping');
200
+            }
201
+            else{
202
+                $this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
203
+                foreach ($list as $file) {
204
+                    $this->logger->debug('Processing the cache file [' . $file . ']');
205
+                    $data = file_get_contents($file);
206
+                        $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
207
+                        if(! $data){
208
+                            $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
209
+                        }
210
+                        else if(time() > $data['expire']){
211
+                            $this->logger->info('The cache data for file [' . $file . '] already expired remove it');
212
+                            unlink($file);
213
+                        }
214
+                        else{
215
+                            $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
216
+                        }
217
+                }
218
+            }
219
+        }	
220 220
 
221
-		/**
222
-		 * Remove all file from cache folder
223
-		 */
224
-		public function clean(){
225
-			$this->logger->debug('Deleting of all cache files');
226
-			$list = glob(CACHE_PATH . '*.cache');
227
-			if(! $list){
228
-				$this->logger->info('No cache files were found skipping');
229
-			}
230
-			else{
231
-				$this->logger->info('Found [' . count($list) . '] cache files to remove');
232
-				foreach ($list as $file) {
233
-					$this->logger->debug('Processing the cache file [' . $file . ']');
234
-					unlink($file);
235
-				}
236
-			}
237
-		}
221
+        /**
222
+         * Remove all file from cache folder
223
+         */
224
+        public function clean(){
225
+            $this->logger->debug('Deleting of all cache files');
226
+            $list = glob(CACHE_PATH . '*.cache');
227
+            if(! $list){
228
+                $this->logger->info('No cache files were found skipping');
229
+            }
230
+            else{
231
+                $this->logger->info('Found [' . count($list) . '] cache files to remove');
232
+                foreach ($list as $file) {
233
+                    $this->logger->debug('Processing the cache file [' . $file . ']');
234
+                    unlink($file);
235
+                }
236
+            }
237
+        }
238 238
 	
239
-	    /**
240
-	     * @return boolean
241
-	     */
242
-	    public function isCompressCacheData(){
243
-	        return $this->compressCacheData;
244
-	    }
239
+        /**
240
+         * @return boolean
241
+         */
242
+        public function isCompressCacheData(){
243
+            return $this->compressCacheData;
244
+        }
245 245
 
246
-	    /**
247
-	     * @param boolean $compressCacheData
248
-	     *
249
-	     * @return object
250
-	     */
251
-	    public function setCompressCacheData($status = true){
252
-			//if Zlib extension is not loaded set compressCacheData to false
253
-			if($status === true && ! extension_loaded('zlib')){
246
+        /**
247
+         * @param boolean $compressCacheData
248
+         *
249
+         * @return object
250
+         */
251
+        public function setCompressCacheData($status = true){
252
+            //if Zlib extension is not loaded set compressCacheData to false
253
+            if($status === true && ! extension_loaded('zlib')){
254 254
 				
255
-				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
256
-				$this->compressCacheData = false;
257
-			}
258
-			else{
259
-				$this->compressCacheData = $status;
260
-			}
261
-			return $this;
262
-	    }
255
+                $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
256
+                $this->compressCacheData = false;
257
+            }
258
+            else{
259
+                $this->compressCacheData = $status;
260
+            }
261
+            return $this;
262
+        }
263 263
 		
264
-		/**
265
-		 * Check whether the cache feature for the handle is supported
266
-		 *
267
-		 * @return bool
268
-		 */
269
-		public function isSupported(){
270
-			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
271
-		}
264
+        /**
265
+         * Check whether the cache feature for the handle is supported
266
+         *
267
+         * @return bool
268
+         */
269
+        public function isSupported(){
270
+            return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
271
+        }
272 272
 
273 273
 	
274
-		/**
275
-		* Get the cache file full path for the given key
276
-		*
277
-		* @param string $key the cache item key
278
-		* @return string the full cache file path for this key
279
-		*/
280
-		private function getFilePath($key){
281
-			return CACHE_PATH . md5($key) . '.cache';
282
-		}
283
-	}
274
+        /**
275
+         * Get the cache file full path for the given key
276
+         *
277
+         * @param string $key the cache item key
278
+         * @return string the full cache file path for this key
279
+         */
280
+        private function getFilePath($key){
281
+            return CACHE_PATH . md5($key) . '.cache';
282
+        }
283
+    }
Please login to merge, or discard this patch.
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/Controller.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -1,126 +1,126 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Controller extends BaseClass{
27
+    class Controller extends BaseClass{
28 28
 		
29
-		/**
30
-		 * The name of the module if this controller belong to an module
31
-		 * @var string
32
-		 */
33
-		public $moduleName = null;
29
+        /**
30
+         * The name of the module if this controller belong to an module
31
+         * @var string
32
+         */
33
+        public $moduleName = null;
34 34
 
35
-		/**
36
-		 * The singleton of the super object
37
-		 * @var Controller
38
-		 */
39
-		private static $instance;
35
+        /**
36
+         * The singleton of the super object
37
+         * @var Controller
38
+         */
39
+        private static $instance;
40 40
 
41 41
 
42
-		/**
43
-		 * Class constructor
44
-		 */
45
-		public function __construct(){
46
-			parent::__construct();
42
+        /**
43
+         * Class constructor
44
+         */
45
+        public function __construct(){
46
+            parent::__construct();
47 47
 			
48
-			//instance of the super object
49
-			self::$instance = & $this;
48
+            //instance of the super object
49
+            self::$instance = & $this;
50 50
 
51
-			//Load the resources loaded during the application bootstrap
52
-			$this->logger->debug('Adding the loaded classes to the super instance');
53
-			foreach (class_loaded() as $var => $class){
54
-				$this->$var =& class_loader($class);
55
-			}
51
+            //Load the resources loaded during the application bootstrap
52
+            $this->logger->debug('Adding the loaded classes to the super instance');
53
+            foreach (class_loaded() as $var => $class){
54
+                $this->$var =& class_loader($class);
55
+            }
56 56
 			
57
-			//set module using the router
58
-			$this->setModuleNameFromRouter();
57
+            //set module using the router
58
+            $this->setModuleNameFromRouter();
59 59
 
60
-			//load the required resources
61
-			$this->loadRequiredResources();
60
+            //load the required resources
61
+            $this->loadRequiredResources();
62 62
 			
63
-			//set the cache using the configuration
64
-			$this->setCacheFromParamOrConfig(null);
63
+            //set the cache using the configuration
64
+            $this->setCacheFromParamOrConfig(null);
65 65
 			
66
-			//set application session configuration
67
-			$this->logger->debug('Setting PHP application session handler');
68
-			set_session_config();
66
+            //set application session configuration
67
+            $this->logger->debug('Setting PHP application session handler');
68
+            set_session_config();
69 69
 
70
-			//dispatch the loaded instance of super controller event
71
-			$this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
72
-		}
70
+            //dispatch the loaded instance of super controller event
71
+            $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
72
+        }
73 73
 
74 74
 
75
-		/**
76
-		 * This is a very useful method it's used to get the super object instance
77
-		 * @return Controller the super object instance
78
-		 */
79
-		public static function &get_instance(){
80
-			return self::$instance;
81
-		}
75
+        /**
76
+         * This is a very useful method it's used to get the super object instance
77
+         * @return Controller the super object instance
78
+         */
79
+        public static function &get_instance(){
80
+            return self::$instance;
81
+        }
82 82
 
83
-		/**
84
-		 * This method is used to set the module name
85
-		 */
86
-		protected function setModuleNameFromRouter(){
87
-			//set the module using the router instance
88
-			if(isset($this->router) && $this->router->getModule()){
89
-				$this->moduleName = $this->router->getModule();
90
-			}
91
-		}
83
+        /**
84
+         * This method is used to set the module name
85
+         */
86
+        protected function setModuleNameFromRouter(){
87
+            //set the module using the router instance
88
+            if(isset($this->router) && $this->router->getModule()){
89
+                $this->moduleName = $this->router->getModule();
90
+            }
91
+        }
92 92
 
93
-		/**
94
-		 * Set the cache using the argument otherwise will use the configuration
95
-		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
96
-		 */
97
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
98
-			$this->logger->debug('Setting the cache handler instance');
99
-			//set cache handler instance
100
-			if(get_config('cache_enable', false)){
101
-				if ($cache !== null){
102
-					$this->cache = $cache;
103
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
104
-					$this->cache = $this->{strtolower(get_config('cache_handler'))};
105
-					unset($this->{strtolower(get_config('cache_handler'))});
106
-				} 
107
-			}
108
-		}
93
+        /**
94
+         * Set the cache using the argument otherwise will use the configuration
95
+         * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
96
+         */
97
+        protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
98
+            $this->logger->debug('Setting the cache handler instance');
99
+            //set cache handler instance
100
+            if(get_config('cache_enable', false)){
101
+                if ($cache !== null){
102
+                    $this->cache = $cache;
103
+                } else if (isset($this->{strtolower(get_config('cache_handler'))})){
104
+                    $this->cache = $this->{strtolower(get_config('cache_handler'))};
105
+                    unset($this->{strtolower(get_config('cache_handler'))});
106
+                } 
107
+            }
108
+        }
109 109
 
110 110
 
111
-		/**
112
-		 * This method is used to load the required resources for framework to work
113
-		 * @return void 
114
-		 */
115
-		private function loadRequiredResources(){
116
-			$this->logger->debug('Loading the required classes into super instance');
117
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
118
-			$this->loader =& class_loader('Loader', 'classes');
119
-			$this->lang =& class_loader('Lang', 'classes');
120
-			$this->request =& class_loader('Request', 'classes');
121
-			//dispatch the request instance created event
122
-			$this->eventdispatcher->dispatch('REQUEST_CREATED');
123
-			$this->response =& class_loader('Response', 'classes', 'classes');
124
-		}
111
+        /**
112
+         * This method is used to load the required resources for framework to work
113
+         * @return void 
114
+         */
115
+        private function loadRequiredResources(){
116
+            $this->logger->debug('Loading the required classes into super instance');
117
+            $this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
118
+            $this->loader =& class_loader('Loader', 'classes');
119
+            $this->lang =& class_loader('Lang', 'classes');
120
+            $this->request =& class_loader('Request', 'classes');
121
+            //dispatch the request instance created event
122
+            $this->eventdispatcher->dispatch('REQUEST_CREATED');
123
+            $this->response =& class_loader('Response', 'classes', 'classes');
124
+        }
125 125
 
126
-	}
126
+    }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Controller extends BaseClass{
27
+	class Controller extends BaseClass {
28 28
 		
29 29
 		/**
30 30
 		 * The name of the module if this controller belong to an module
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 		/**
43 43
 		 * Class constructor
44 44
 		 */
45
-		public function __construct(){
45
+		public function __construct() {
46 46
 			parent::__construct();
47 47
 			
48 48
 			//instance of the super object
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 
51 51
 			//Load the resources loaded during the application bootstrap
52 52
 			$this->logger->debug('Adding the loaded classes to the super instance');
53
-			foreach (class_loaded() as $var => $class){
54
-				$this->$var =& class_loader($class);
53
+			foreach (class_loaded() as $var => $class) {
54
+				$this->$var = & class_loader($class);
55 55
 			}
56 56
 			
57 57
 			//set module using the router
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 		/**
84 84
 		 * This method is used to set the module name
85 85
 		 */
86
-		protected function setModuleNameFromRouter(){
86
+		protected function setModuleNameFromRouter() {
87 87
 			//set the module using the router instance
88
-			if(isset($this->router) && $this->router->getModule()){
88
+			if (isset($this->router) && $this->router->getModule()) {
89 89
 				$this->moduleName = $this->router->getModule();
90 90
 			}
91 91
 		}
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
 		 * Set the cache using the argument otherwise will use the configuration
95 95
 		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
96 96
 		 */
97
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
97
+		protected function setCacheFromParamOrConfig(CacheInterface $cache = null) {
98 98
 			$this->logger->debug('Setting the cache handler instance');
99 99
 			//set cache handler instance
100
-			if(get_config('cache_enable', false)){
101
-				if ($cache !== null){
100
+			if (get_config('cache_enable', false)) {
101
+				if ($cache !== null) {
102 102
 					$this->cache = $cache;
103
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
103
+				} else if (isset($this->{strtolower(get_config('cache_handler'))})) {
104 104
 					$this->cache = $this->{strtolower(get_config('cache_handler'))};
105 105
 					unset($this->{strtolower(get_config('cache_handler'))});
106 106
 				} 
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
 		 * This method is used to load the required resources for framework to work
113 113
 		 * @return void 
114 114
 		 */
115
-		private function loadRequiredResources(){
115
+		private function loadRequiredResources() {
116 116
 			$this->logger->debug('Loading the required classes into super instance');
117
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
118
-			$this->loader =& class_loader('Loader', 'classes');
119
-			$this->lang =& class_loader('Lang', 'classes');
120
-			$this->request =& class_loader('Request', 'classes');
117
+			$this->eventdispatcher = & class_loader('EventDispatcher', 'classes');
118
+			$this->loader = & class_loader('Loader', 'classes');
119
+			$this->lang = & class_loader('Lang', 'classes');
120
+			$this->request = & class_loader('Request', 'classes');
121 121
 			//dispatch the request instance created event
122 122
 			$this->eventdispatcher->dispatch('REQUEST_CREATED');
123
-			$this->response =& class_loader('Response', 'classes', 'classes');
123
+			$this->response = & class_loader('Response', 'classes', 'classes');
124 124
 		}
125 125
 
126 126
 	}
Please login to merge, or discard this patch.
core/classes/BaseClass.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,93 +1,93 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class BaseClass{
28
-		/**
29
-		 * The logger instance
30
-		 * @var object
31
-		 */
32
-		protected $logger;
27
+    class BaseClass{
28
+        /**
29
+         * The logger instance
30
+         * @var object
31
+         */
32
+        protected $logger;
33 33
 
34
-		/**
35
-		 * Class constructor
36
-		 */
37
-		public function __construct(){
38
-			//Set Log instance to use
39
-       		$this->setLoggerFromParamOrCreate(null);
40
-		}
34
+        /**
35
+         * Class constructor
36
+         */
37
+        public function __construct(){
38
+            //Set Log instance to use
39
+                $this->setLoggerFromParamOrCreate(null);
40
+        }
41 41
 
42
-		/**
43
-	     * Set the dependencies instance using argument or create new instance if is null
44
-	     * @param string $name this class property name.
45
-	     * @param object $instance the instance. If is not null will use it
46
-	     * otherwise will create new instance.
47
-	     * @param string $loadClassName the name of class to load using class_loader function.
48
-	     * @param string $loadClassPath the path of class to load using class_loader function.
49
-	     *
50
-	     * @return object this current instance
51
-	     */
52
-	    protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
53
-	      if ($instance !== null){
54
-	        $this->{$name} = $instance;
55
-	        return $this;
56
-	      }
57
-	      $this->{$name} =& class_loader($loadClassName, $loadClassePath);
58
-	      return $this;
59
-	    }
42
+        /**
43
+         * Set the dependencies instance using argument or create new instance if is null
44
+         * @param string $name this class property name.
45
+         * @param object $instance the instance. If is not null will use it
46
+         * otherwise will create new instance.
47
+         * @param string $loadClassName the name of class to load using class_loader function.
48
+         * @param string $loadClassPath the path of class to load using class_loader function.
49
+         *
50
+         * @return object this current instance
51
+         */
52
+        protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
53
+            if ($instance !== null){
54
+            $this->{$name} = $instance;
55
+            return $this;
56
+            }
57
+            $this->{$name} =& class_loader($loadClassName, $loadClassePath);
58
+            return $this;
59
+        }
60 60
 
61
-	    /**
62
-	     * Return the Log instance
63
-	     * @return object
64
-	     */
65
-	    public function getLogger(){
66
-	      return $this->logger;
67
-	    }
61
+        /**
62
+         * Return the Log instance
63
+         * @return object
64
+         */
65
+        public function getLogger(){
66
+            return $this->logger;
67
+        }
68 68
 
69
-	    /**
70
-	     * Set the log instance
71
-	     * @param object $logger the log object
72
-		 * @return object Database
73
-	     */
74
-	    public function setLogger($logger){
75
-	      $this->logger = $logger;
76
-	      return $this;
77
-	    }
69
+        /**
70
+         * Set the log instance
71
+         * @param object $logger the log object
72
+         * @return object Database
73
+         */
74
+        public function setLogger($logger){
75
+            $this->logger = $logger;
76
+            return $this;
77
+        }
78 78
 
79
-	    /**
80
-	     * Set the Log instance using argument or create new instance
81
-	     * @param object $logger the Log instance if not null
82
-	     *
83
-	     * @return object this current instance
84
-	     */
85
-	    protected function setLoggerFromParamOrCreate(Log $logger = null){
86
-	      $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
87
-	      if ($logger === null){
88
-	        $this->logger->setLogger('Class::' . get_class($this));
89
-	      }
90
-	      return $this;
91
-	    }
79
+        /**
80
+         * Set the Log instance using argument or create new instance
81
+         * @param object $logger the Log instance if not null
82
+         *
83
+         * @return object this current instance
84
+         */
85
+        protected function setLoggerFromParamOrCreate(Log $logger = null){
86
+            $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
87
+            if ($logger === null){
88
+            $this->logger->setLogger('Class::' . get_class($this));
89
+            }
90
+            return $this;
91
+        }
92 92
 
93
-	}
93
+    }
Please login to merge, or discard this 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/BaseStaticClass.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,58 +1,58 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class BaseStaticClass{
28
-		/**
29
-		 * The logger instance
30
-		 * @var object
31
-		 */
32
-		protected static $logger;
27
+    class BaseStaticClass{
28
+        /**
29
+         * The logger instance
30
+         * @var object
31
+         */
32
+        protected static $logger;
33 33
 
34
-		/**
35
-		 * The signleton of the logger
36
-		 * @return Object the Log instance
37
-		 */
38
-		public static function getLogger(){
39
-			if(self::$logger == null){
40
-				$logger = array();
41
-				$logger[0] =& class_loader('Log', 'classes');
42
-				$logger[0]->setLogger('Class::' . get_called_class());
43
-				self::$logger = $logger[0];
44
-			}
45
-			return self::$logger;			
46
-		}
34
+        /**
35
+         * The signleton of the logger
36
+         * @return Object the Log instance
37
+         */
38
+        public static function getLogger(){
39
+            if(self::$logger == null){
40
+                $logger = array();
41
+                $logger[0] =& class_loader('Log', 'classes');
42
+                $logger[0]->setLogger('Class::' . get_called_class());
43
+                self::$logger = $logger[0];
44
+            }
45
+            return self::$logger;			
46
+        }
47 47
 
48
-		/**
49
-		 * Set the log instance for future use
50
-		 * @param object $logger the log object
51
-		 * @return object the log instance
52
-		 */
53
-		public static function setLogger($logger){
54
-			self::$logger = $logger;
55
-			return self::$logger;
56
-		}
48
+        /**
49
+         * Set the log instance for future use
50
+         * @param object $logger the log object
51
+         * @return object the log instance
52
+         */
53
+        public static function setLogger($logger){
54
+            self::$logger = $logger;
55
+            return self::$logger;
56
+        }
57 57
 
58
-	}
58
+    }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 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 BaseStaticClass{
27
+	class BaseStaticClass {
28 28
 		/**
29 29
 		 * The logger instance
30 30
 		 * @var object
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 		 * The signleton of the logger
36 36
 		 * @return Object the Log instance
37 37
 		 */
38
-		public static function getLogger(){
39
-			if(self::$logger == null){
38
+		public static function getLogger() {
39
+			if (self::$logger == null) {
40 40
 				$logger = array();
41
-				$logger[0] =& class_loader('Log', 'classes');
41
+				$logger[0] = & class_loader('Log', 'classes');
42 42
 				$logger[0]->setLogger('Class::' . get_called_class());
43 43
 				self::$logger = $logger[0];
44 44
 			}
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		 * @param object $logger the log object
51 51
 		 * @return object the log instance
52 52
 		 */
53
-		public static function setLogger($logger){
53
+		public static function setLogger($logger) {
54 54
 			self::$logger = $logger;
55 55
 			return self::$logger;
56 56
 		}
Please login to merge, or discard this patch.
core/classes/Log.php 2 patches
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -1,293 +1,293 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Log{
27
+    class Log{
28 28
 		
29
-		/**
30
-		 * The defined constante for Log level
31
-		 */
32
-		const NONE = 99999999;
33
-		const FATAL = 500;
34
-		const ERROR = 400;
35
-		const WARNING = 300;
36
-		const INFO = 200;
37
-		const DEBUG = 100;
38
-		const ALL = -99999999;
29
+        /**
30
+         * The defined constante for Log level
31
+         */
32
+        const NONE = 99999999;
33
+        const FATAL = 500;
34
+        const ERROR = 400;
35
+        const WARNING = 300;
36
+        const INFO = 200;
37
+        const DEBUG = 100;
38
+        const ALL = -99999999;
39 39
 
40
-		/**
41
-		 * The logger name
42
-		 * @var string
43
-		 */
44
-		private $logger = 'ROOT_LOGGER';
40
+        /**
41
+         * The logger name
42
+         * @var string
43
+         */
44
+        private $logger = 'ROOT_LOGGER';
45 45
 		
46
-		/**
47
-		 * List of valid log level to be checked for the configuration
48
-		 * @var array
49
-		 */
50
-		private static $validConfigLevel = array('off', 'none', 'fatal', 'error', 'warning', 'warn', 'info', 'debug', 'all');
46
+        /**
47
+         * List of valid log level to be checked for the configuration
48
+         * @var array
49
+         */
50
+        private static $validConfigLevel = array('off', 'none', 'fatal', 'error', 'warning', 'warn', 'info', 'debug', 'all');
51 51
 
52
-		/**
53
-		 * Create new Log instance
54
-		 */
55
-		public function __construct(){
56
-		}
52
+        /**
53
+         * Create new Log instance
54
+         */
55
+        public function __construct(){
56
+        }
57 57
 
58
-		/**
59
-		 * Set the logger to identify each message in the log
60
-		 * @param string $logger the logger name
61
-		 */
62
-		public  function setLogger($logger){
63
-			$this->logger = $logger;
64
-		}
58
+        /**
59
+         * Set the logger to identify each message in the log
60
+         * @param string $logger the logger name
61
+         */
62
+        public  function setLogger($logger){
63
+            $this->logger = $logger;
64
+        }
65 65
 
66
-		/**
67
-		 * Save the fatal message in the log
68
-		 * @see Log::writeLog for more detail
69
-		 * @param  string $message the log message to save
70
-		 */
71
-		public function fatal($message){
72
-			$this->writeLog($message, self::FATAL);
73
-		} 
66
+        /**
67
+         * Save the fatal message in the log
68
+         * @see Log::writeLog for more detail
69
+         * @param  string $message the log message to save
70
+         */
71
+        public function fatal($message){
72
+            $this->writeLog($message, self::FATAL);
73
+        } 
74 74
 		
75
-		/**
76
-		 * Save the error message in the log
77
-		 * @see Log::writeLog for more detail
78
-		 * @param  string $message the log message to save
79
-		 */
80
-		public function error($message){
81
-			$this->writeLog($message, self::ERROR);
82
-		} 
75
+        /**
76
+         * Save the error message in the log
77
+         * @see Log::writeLog for more detail
78
+         * @param  string $message the log message to save
79
+         */
80
+        public function error($message){
81
+            $this->writeLog($message, self::ERROR);
82
+        } 
83 83
 
84
-		/**
85
-		 * Save the warning message in the log
86
-		 * @see Log::writeLog for more detail
87
-		 * @param  string $message the log message to save
88
-		 */
89
-		public function warning($message){
90
-			$this->writeLog($message, self::WARNING);
91
-		} 
84
+        /**
85
+         * Save the warning message in the log
86
+         * @see Log::writeLog for more detail
87
+         * @param  string $message the log message to save
88
+         */
89
+        public function warning($message){
90
+            $this->writeLog($message, self::WARNING);
91
+        } 
92 92
 		
93
-		/**
94
-		 * Save the info message in the log
95
-		 * @see Log::writeLog for more detail
96
-		 * @param  string $message the log message to save
97
-		 */
98
-		public function info($message){
99
-			$this->writeLog($message, self::INFO);
100
-		} 
93
+        /**
94
+         * Save the info message in the log
95
+         * @see Log::writeLog for more detail
96
+         * @param  string $message the log message to save
97
+         */
98
+        public function info($message){
99
+            $this->writeLog($message, self::INFO);
100
+        } 
101 101
 		
102
-		/**
103
-		 * Save the debug message in the log
104
-		 * @see Log::writeLog for more detail
105
-		 * @param  string $message the log message to save
106
-		 */
107
-		public function debug($message){
108
-			$this->writeLog($message, self::DEBUG);
109
-		} 
102
+        /**
103
+         * Save the debug message in the log
104
+         * @see Log::writeLog for more detail
105
+         * @param  string $message the log message to save
106
+         */
107
+        public function debug($message){
108
+            $this->writeLog($message, self::DEBUG);
109
+        } 
110 110
 		
111 111
 		
112
-		/**
113
-		 * Save the log message
114
-		 * @param  string $message the log message to be saved
115
-		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116
-		 * to allow check the log level threshold.
117
-		 */
118
-		public function writeLog($message, $level = self::INFO){
119
-			$configLogLevel = get_config('log_level');
120
-			if(! $configLogLevel){
121
-				//so means no need log just stop here
122
-				return;
123
-			}
124
-			//check config log level
125
-			if(! self::isValidConfigLevel($configLogLevel)){
126
-				//NOTE: here need put the show_error() "logging" to false to prevent loop
127
-				show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128
-			}
112
+        /**
113
+         * Save the log message
114
+         * @param  string $message the log message to be saved
115
+         * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116
+         * to allow check the log level threshold.
117
+         */
118
+        public function writeLog($message, $level = self::INFO){
119
+            $configLogLevel = get_config('log_level');
120
+            if(! $configLogLevel){
121
+                //so means no need log just stop here
122
+                return;
123
+            }
124
+            //check config log level
125
+            if(! self::isValidConfigLevel($configLogLevel)){
126
+                //NOTE: here need put the show_error() "logging" to false to prevent loop
127
+                show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128
+            }
129 129
 			
130
-			//check if config log_logger_name and current log can save log data
131
-			if(! $this->canSaveLogDataForLogger()){
132
-				return;
133
-			}
130
+            //check if config log_logger_name and current log can save log data
131
+            if(! $this->canSaveLogDataForLogger()){
132
+                return;
133
+            }
134 134
 			
135
-			//if $level is not an integer
136
-			if(! is_numeric($level)){
137
-				$level = self::getLevelValue($level);
138
-			}
135
+            //if $level is not an integer
136
+            if(! is_numeric($level)){
137
+                $level = self::getLevelValue($level);
138
+            }
139 139
 			
140
-			//check if can logging regarding the log level config
141
-			$configLevel = self::getLevelValue($configLogLevel);
142
-			if($configLevel > $level){
143
-				//can't log
144
-				return;
145
-			}
146
-			//check log file and directory
147
-			$path = $this->checkAndSetLogFileDirectory();
148
-			//save the log data
149
-			$this->saveLogData($path, $level, $message);
150
-		}	
140
+            //check if can logging regarding the log level config
141
+            $configLevel = self::getLevelValue($configLogLevel);
142
+            if($configLevel > $level){
143
+                //can't log
144
+                return;
145
+            }
146
+            //check log file and directory
147
+            $path = $this->checkAndSetLogFileDirectory();
148
+            //save the log data
149
+            $this->saveLogData($path, $level, $message);
150
+        }	
151 151
 
152
-		/**
153
-		 * Save the log data into file
154
-		 * @param  string $path    the path of the log file
155
-		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
156
-		 * @param  string $message the log message to save
157
-		 * @return void
158
-		 */
159
-		protected function saveLogData($path, $level, $message){
160
-			//may be at this time helper user_agent not yet included
161
-			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
152
+        /**
153
+         * Save the log data into file
154
+         * @param  string $path    the path of the log file
155
+         * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
156
+         * @param  string $message the log message to save
157
+         * @return void
158
+         */
159
+        protected function saveLogData($path, $level, $message){
160
+            //may be at this time helper user_agent not yet included
161
+            require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
162 162
 			
163
-			///////////////////// date //////////////
164
-			$timestampWithMicro = microtime(true);
165
-			$microtime = sprintf('%06d', ($timestampWithMicro - floor($timestampWithMicro)) * 1000000);
166
-			$dateTime = new DateTime(date('Y-m-d H:i:s.' . $microtime, $timestampWithMicro));
167
-			$logDate = $dateTime->format('Y-m-d H:i:s.u'); 
168
-			//ip
169
-			$ip = get_ip();
163
+            ///////////////////// date //////////////
164
+            $timestampWithMicro = microtime(true);
165
+            $microtime = sprintf('%06d', ($timestampWithMicro - floor($timestampWithMicro)) * 1000000);
166
+            $dateTime = new DateTime(date('Y-m-d H:i:s.' . $microtime, $timestampWithMicro));
167
+            $logDate = $dateTime->format('Y-m-d H:i:s.u'); 
168
+            //ip
169
+            $ip = get_ip();
170 170
 			
171
-			//if $level is not an integer
172
-			if(! is_numeric($level)){
173
-				$level = self::getLevelValue($level);
174
-			}
171
+            //if $level is not an integer
172
+            if(! is_numeric($level)){
173
+                $level = self::getLevelValue($level);
174
+            }
175 175
 
176
-			//level name
177
-			$levelName = self::getLevelName($level);
176
+            //level name
177
+            $levelName = self::getLevelName($level);
178 178
 			
179
-			//debug info
180
-			$dtrace = debug_backtrace();
181
-			$fileInfo = $dtrace[0];
182
-			if ($dtrace[0]['file'] == __FILE__ || $dtrace[1]['file'] == __FILE__){
183
-				$fileInfo = $dtrace[2];
184
-			}
179
+            //debug info
180
+            $dtrace = debug_backtrace();
181
+            $fileInfo = $dtrace[0];
182
+            if ($dtrace[0]['file'] == __FILE__ || $dtrace[1]['file'] == __FILE__){
183
+                $fileInfo = $dtrace[2];
184
+            }
185 185
 			
186
-			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
187
-			$fp = fopen($path, 'a+');
188
-			if(is_resource($fp)){
189
-				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
190
-				fwrite($fp, $str);
191
-				fclose($fp);
192
-			}
193
-		}	
186
+            $str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
187
+            $fp = fopen($path, 'a+');
188
+            if(is_resource($fp)){
189
+                flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
190
+                fwrite($fp, $str);
191
+                fclose($fp);
192
+            }
193
+        }	
194 194
 
195
-		/**
196
-		 * Check if the current logger can save log data regarding the configuration
197
-		 * of logger filter
198
-		 * @return boolean
199
-		 */
200
-		protected function canSaveLogDataForLogger(){
201
-			if(! empty($this->logger)){
202
-				$configLoggersName = get_config('log_logger_name', array());
203
-				if (!empty($configLoggersName)) {
204
-					//for best comparaison put all string to lowercase
205
-					$configLoggersName = array_map('strtolower', $configLoggersName);
206
-					if(! in_array(strtolower($this->logger), $configLoggersName)){
207
-						return false;
208
-					}
209
-				}
210
-			}
211
-			return true;
212
-		}
195
+        /**
196
+         * Check if the current logger can save log data regarding the configuration
197
+         * of logger filter
198
+         * @return boolean
199
+         */
200
+        protected function canSaveLogDataForLogger(){
201
+            if(! empty($this->logger)){
202
+                $configLoggersName = get_config('log_logger_name', array());
203
+                if (!empty($configLoggersName)) {
204
+                    //for best comparaison put all string to lowercase
205
+                    $configLoggersName = array_map('strtolower', $configLoggersName);
206
+                    if(! in_array(strtolower($this->logger), $configLoggersName)){
207
+                        return false;
208
+                    }
209
+                }
210
+            }
211
+            return true;
212
+        }
213 213
 
214
-		/**
215
-		 * Check the file and directory 
216
-		 * @return string the log file path
217
-		 */
218
-		protected function checkAndSetLogFileDirectory(){
219
-			$logSavePath = get_config('log_save_path');
220
-			if(! $logSavePath){
221
-				$logSavePath = LOGS_PATH;
222
-			}
214
+        /**
215
+         * Check the file and directory 
216
+         * @return string the log file path
217
+         */
218
+        protected function checkAndSetLogFileDirectory(){
219
+            $logSavePath = get_config('log_save_path');
220
+            if(! $logSavePath){
221
+                $logSavePath = LOGS_PATH;
222
+            }
223 223
 			
224
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
225
-				//NOTE: here need put the show_error() "logging" to false to prevent loop
226
-				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
227
-			}
224
+            if(! is_dir($logSavePath) || !is_writable($logSavePath)){
225
+                //NOTE: here need put the show_error() "logging" to false to prevent loop
226
+                show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
227
+            }
228 228
 			
229
-			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
230
-			if(! file_exists($path)){
231
-				touch($path);
232
-			}
233
-			return $path;
234
-		}
229
+            $path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
230
+            if(! file_exists($path)){
231
+                touch($path);
232
+            }
233
+            return $path;
234
+        }
235 235
 		
236
-		/**
237
-		 * Check if the given log level is valid
238
-		 *
239
-		 * @param  string  $level the log level
240
-		 *
241
-		 * @return boolean        true if the given log level is valid, false if not
242
-		 */
243
-		protected static function isValidConfigLevel($level){
244
-			$level = strtolower($level);
245
-			return in_array($level, self::$validConfigLevel);
246
-		}
236
+        /**
237
+         * Check if the given log level is valid
238
+         *
239
+         * @param  string  $level the log level
240
+         *
241
+         * @return boolean        true if the given log level is valid, false if not
242
+         */
243
+        protected static function isValidConfigLevel($level){
244
+            $level = strtolower($level);
245
+            return in_array($level, self::$validConfigLevel);
246
+        }
247 247
 
248
-		/**
249
-		 * Get the log level number for the given level string
250
-		 * @param  string $level the log level in string format
251
-		 * 
252
-		 * @return int        the log level in integer format using the predefined constants
253
-		 */
254
-		protected static function getLevelValue($level){
255
-			$level = strtolower($level);
256
-			$levelMaps = array(
257
-				'fatal'   => self::FATAL,
258
-				'error'   => self::ERROR,
259
-				'warning' => self::WARNING,
260
-				'warn'    => self::WARNING,
261
-				'info'    => self::INFO,
262
-				'debug'   => self::DEBUG,
263
-				'all'     => self::ALL
264
-			);
265
-			//the default value is NONE, so means no need test for NONE
266
-			$value = self::NONE;
267
-			if(isset($levelMaps[$level])){
268
-				$value = $levelMaps[$level];
269
-			}
270
-			return $value;
271
-		}
248
+        /**
249
+         * Get the log level number for the given level string
250
+         * @param  string $level the log level in string format
251
+         * 
252
+         * @return int        the log level in integer format using the predefined constants
253
+         */
254
+        protected static function getLevelValue($level){
255
+            $level = strtolower($level);
256
+            $levelMaps = array(
257
+                'fatal'   => self::FATAL,
258
+                'error'   => self::ERROR,
259
+                'warning' => self::WARNING,
260
+                'warn'    => self::WARNING,
261
+                'info'    => self::INFO,
262
+                'debug'   => self::DEBUG,
263
+                'all'     => self::ALL
264
+            );
265
+            //the default value is NONE, so means no need test for NONE
266
+            $value = self::NONE;
267
+            if(isset($levelMaps[$level])){
268
+                $value = $levelMaps[$level];
269
+            }
270
+            return $value;
271
+        }
272 272
 
273
-		/**
274
-		 * Get the log level string for the given log level integer
275
-		 * @param  integer $level the log level in integer format
276
-		 * @return string        the log level in string format
277
-		 */
278
-		protected static function getLevelName($level){
279
-			$levelMaps = array(
280
-				self::FATAL   => 'FATAL',
281
-				self::ERROR   => 'ERROR',
282
-				self::WARNING => 'WARNING',
283
-				self::INFO    => 'INFO',
284
-				self::DEBUG   => 'DEBUG'
285
-			);
286
-			$value = '';
287
-			if(isset($levelMaps[$level])){
288
-				$value = $levelMaps[$level];
289
-			}
290
-			return $value;
291
-		}
273
+        /**
274
+         * Get the log level string for the given log level integer
275
+         * @param  integer $level the log level in integer format
276
+         * @return string        the log level in string format
277
+         */
278
+        protected static function getLevelName($level){
279
+            $levelMaps = array(
280
+                self::FATAL   => 'FATAL',
281
+                self::ERROR   => 'ERROR',
282
+                self::WARNING => 'WARNING',
283
+                self::INFO    => 'INFO',
284
+                self::DEBUG   => 'DEBUG'
285
+            );
286
+            $value = '';
287
+            if(isset($levelMaps[$level])){
288
+                $value = $levelMaps[$level];
289
+            }
290
+            return $value;
291
+        }
292 292
 
293
-	}
293
+    }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Log{
27
+	class Log {
28 28
 		
29 29
 		/**
30 30
 		 * The defined constante for Log level
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 		/**
53 53
 		 * Create new Log instance
54 54
 		 */
55
-		public function __construct(){
55
+		public function __construct() {
56 56
 		}
57 57
 
58 58
 		/**
59 59
 		 * Set the logger to identify each message in the log
60 60
 		 * @param string $logger the logger name
61 61
 		 */
62
-		public  function setLogger($logger){
62
+		public  function setLogger($logger) {
63 63
 			$this->logger = $logger;
64 64
 		}
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 * @see Log::writeLog for more detail
69 69
 		 * @param  string $message the log message to save
70 70
 		 */
71
-		public function fatal($message){
71
+		public function fatal($message) {
72 72
 			$this->writeLog($message, self::FATAL);
73 73
 		} 
74 74
 		
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		 * @see Log::writeLog for more detail
78 78
 		 * @param  string $message the log message to save
79 79
 		 */
80
-		public function error($message){
80
+		public function error($message) {
81 81
 			$this->writeLog($message, self::ERROR);
82 82
 		} 
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		 * @see Log::writeLog for more detail
87 87
 		 * @param  string $message the log message to save
88 88
 		 */
89
-		public function warning($message){
89
+		public function warning($message) {
90 90
 			$this->writeLog($message, self::WARNING);
91 91
 		} 
92 92
 		
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * @see Log::writeLog for more detail
96 96
 		 * @param  string $message the log message to save
97 97
 		 */
98
-		public function info($message){
98
+		public function info($message) {
99 99
 			$this->writeLog($message, self::INFO);
100 100
 		} 
101 101
 		
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		 * @see Log::writeLog for more detail
105 105
 		 * @param  string $message the log message to save
106 106
 		 */
107
-		public function debug($message){
107
+		public function debug($message) {
108 108
 			$this->writeLog($message, self::DEBUG);
109 109
 		} 
110 110
 		
@@ -115,31 +115,31 @@  discard block
 block discarded – undo
115 115
 		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116 116
 		 * to allow check the log level threshold.
117 117
 		 */
118
-		public function writeLog($message, $level = self::INFO){
118
+		public function writeLog($message, $level = self::INFO) {
119 119
 			$configLogLevel = get_config('log_level');
120
-			if(! $configLogLevel){
120
+			if (!$configLogLevel) {
121 121
 				//so means no need log just stop here
122 122
 				return;
123 123
 			}
124 124
 			//check config log level
125
-			if(! self::isValidConfigLevel($configLogLevel)){
125
+			if (!self::isValidConfigLevel($configLogLevel)) {
126 126
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
127 127
 				show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128 128
 			}
129 129
 			
130 130
 			//check if config log_logger_name and current log can save log data
131
-			if(! $this->canSaveLogDataForLogger()){
131
+			if (!$this->canSaveLogDataForLogger()) {
132 132
 				return;
133 133
 			}
134 134
 			
135 135
 			//if $level is not an integer
136
-			if(! is_numeric($level)){
136
+			if (!is_numeric($level)) {
137 137
 				$level = self::getLevelValue($level);
138 138
 			}
139 139
 			
140 140
 			//check if can logging regarding the log level config
141 141
 			$configLevel = self::getLevelValue($configLogLevel);
142
-			if($configLevel > $level){
142
+			if ($configLevel > $level) {
143 143
 				//can't log
144 144
 				return;
145 145
 			}
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		 * @param  string $message the log message to save
157 157
 		 * @return void
158 158
 		 */
159
-		protected function saveLogData($path, $level, $message){
159
+		protected function saveLogData($path, $level, $message) {
160 160
 			//may be at this time helper user_agent not yet included
161 161
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
162 162
 			
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			$ip = get_ip();
170 170
 			
171 171
 			//if $level is not an integer
172
-			if(! is_numeric($level)){
172
+			if (!is_numeric($level)) {
173 173
 				$level = self::getLevelValue($level);
174 174
 			}
175 175
 
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 			//debug info
180 180
 			$dtrace = debug_backtrace();
181 181
 			$fileInfo = $dtrace[0];
182
-			if ($dtrace[0]['file'] == __FILE__ || $dtrace[1]['file'] == __FILE__){
182
+			if ($dtrace[0]['file'] == __FILE__ || $dtrace[1]['file'] == __FILE__) {
183 183
 				$fileInfo = $dtrace[2];
184 184
 			}
185 185
 			
186 186
 			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
187 187
 			$fp = fopen($path, 'a+');
188
-			if(is_resource($fp)){
188
+			if (is_resource($fp)) {
189 189
 				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
190 190
 				fwrite($fp, $str);
191 191
 				fclose($fp);
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
 		 * of logger filter
198 198
 		 * @return boolean
199 199
 		 */
200
-		protected function canSaveLogDataForLogger(){
201
-			if(! empty($this->logger)){
200
+		protected function canSaveLogDataForLogger() {
201
+			if (!empty($this->logger)) {
202 202
 				$configLoggersName = get_config('log_logger_name', array());
203 203
 				if (!empty($configLoggersName)) {
204 204
 					//for best comparaison put all string to lowercase
205 205
 					$configLoggersName = array_map('strtolower', $configLoggersName);
206
-					if(! in_array(strtolower($this->logger), $configLoggersName)){
206
+					if (!in_array(strtolower($this->logger), $configLoggersName)) {
207 207
 						return false;
208 208
 					}
209 209
 				}
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
 		 * Check the file and directory 
216 216
 		 * @return string the log file path
217 217
 		 */
218
-		protected function checkAndSetLogFileDirectory(){
218
+		protected function checkAndSetLogFileDirectory() {
219 219
 			$logSavePath = get_config('log_save_path');
220
-			if(! $logSavePath){
220
+			if (!$logSavePath) {
221 221
 				$logSavePath = LOGS_PATH;
222 222
 			}
223 223
 			
224
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
224
+			if (!is_dir($logSavePath) || !is_writable($logSavePath)) {
225 225
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
226 226
 				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
227 227
 			}
228 228
 			
229 229
 			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
230
-			if(! file_exists($path)){
230
+			if (!file_exists($path)) {
231 231
 				touch($path);
232 232
 			}
233 233
 			return $path;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		 *
241 241
 		 * @return boolean        true if the given log level is valid, false if not
242 242
 		 */
243
-		protected static function isValidConfigLevel($level){
243
+		protected static function isValidConfigLevel($level) {
244 244
 			$level = strtolower($level);
245 245
 			return in_array($level, self::$validConfigLevel);
246 246
 		}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		 * 
252 252
 		 * @return int        the log level in integer format using the predefined constants
253 253
 		 */
254
-		protected static function getLevelValue($level){
254
+		protected static function getLevelValue($level) {
255 255
 			$level = strtolower($level);
256 256
 			$levelMaps = array(
257 257
 				'fatal'   => self::FATAL,
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 			);
265 265
 			//the default value is NONE, so means no need test for NONE
266 266
 			$value = self::NONE;
267
-			if(isset($levelMaps[$level])){
267
+			if (isset($levelMaps[$level])) {
268 268
 				$value = $levelMaps[$level];
269 269
 			}
270 270
 			return $value;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		 * @param  integer $level the log level in integer format
276 276
 		 * @return string        the log level in string format
277 277
 		 */
278
-		protected static function getLevelName($level){
278
+		protected static function getLevelName($level) {
279 279
 			$levelMaps = array(
280 280
 				self::FATAL   => 'FATAL',
281 281
 				self::ERROR   => 'ERROR',
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 				self::DEBUG   => 'DEBUG'
285 285
 			);
286 286
 			$value = '';
287
-			if(isset($levelMaps[$level])){
287
+			if (isset($levelMaps[$level])) {
288 288
 				$value = $levelMaps[$level];
289 289
 			}
290 290
 			return $value;
Please login to merge, or discard this patch.