Passed
Push — 1.0.0-dev ( ead601...e21083 )
by nguereza
04:39
created
core/classes/cache/ApcCache.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 	
27
-	class ApcCache implements CacheInterface{
27
+	class ApcCache implements CacheInterface {
28 28
 
29 29
 		/**
30 30
 		 * The logger instance
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
 		private $logger;
34 34
 		
35 35
 		
36
-		public function __construct(Log $logger = null){
37
-			if(! $this->isSupported()){
36
+		public function __construct(Log $logger = null) {
37
+			if (!$this->isSupported()) {
38 38
 				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39 39
 			}
40 40
 
41 41
 			/**
42 42
 	         * instance of the Log class
43 43
 	         */
44
-	        if(is_object($logger)){
44
+	        if (is_object($logger)) {
45 45
 	          $this->logger = $logger;
46 46
 	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
47
+	        else {
48
+	            $this->logger = & class_loader('Log', 'classes');
49 49
 	            $this->logger->setLogger('Library::ApcCache');
50 50
 	        }
51 51
 		}
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 		 * @param  string $key the key to identify the cache data
56 56
 		 * @return mixed      the cache data if exists else return false
57 57
 		 */
58
-		public function get($key){
59
-			$this->logger->debug('Getting cache data for key ['. $key .']');
58
+		public function get($key) {
59
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
60 60
 			$success = false;
61 61
 			$data = apc_fetch($key, $success);
62
-			if($success === false){
63
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
62
+			if ($success === false) {
63
+				$this->logger->info('No cache found for the key [' . $key . '], return false');
64 64
 				return false;
65 65
 			}
66
-			else{
66
+			else {
67 67
 				$cacheInfo = $this->_getCacheInfo($key);
68 68
 				$expire = time();
69
-				if($cacheInfo){
69
+				if ($cacheInfo) {
70 70
 					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
71 71
 				}
72
-				$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
72
+				$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73 73
 				return $data;
74 74
 			}
75 75
 		}
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 		 * @param integer $ttl  the cache life time
83 83
 		 * @return boolean true if success otherwise will return false
84 84
 		 */
85
-		public function set($key, $data, $ttl = 0){
85
+		public function set($key, $data, $ttl = 0) {
86 86
 			$expire = time() + $ttl;
87
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
87
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
88 88
 			$result = apc_store($key, $data, $ttl);
89
-			if($result === false){
90
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
89
+			if ($result === false) {
90
+		    	$this->logger->error('Can not write cache data for the key [' . $key . '], return false');
91 91
 		    	return false;
92 92
 		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
93
+		    else {
94
+		    	$this->logger->info('Cache data saved for the key [' . $key . ']');
95 95
 		    	return true;
96 96
 		    }
97 97
 		}
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 		 * @return boolean      true if the cache is deleted, false if can't delete 
104 104
 		 * the cache or the cache with the given key not exist
105 105
 		 */
106
-		public function delete($key){
107
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
106
+		public function delete($key) {
107
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
108 108
 			$cacheInfo = $this->_getCacheInfo($key);
109
-			if($cacheInfo === false){
109
+			if ($cacheInfo === false) {
110 110
 				$this->logger->info('This cache data does not exists skipping');
111 111
 				return false;
112 112
 			}
113
-			else{
114
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
113
+			else {
114
+				$this->logger->info('Found cache data for the key [' . $key . '] remove it');
115 115
 	      		return apc_delete($key) === true;
116 116
 			}
117 117
 		}
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
 		 * 'expire' => expiration time of the cache (Unix timestamp),
125 125
 		 * 'ttl' => the time to live of the cache in second
126 126
 		 */
127
-		public function getInfo($key){
128
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
127
+		public function getInfo($key) {
128
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
129 129
 			$cacheInfos = $this->_getCacheInfo($key);
130
-			if($cacheInfos){
130
+			if ($cacheInfos) {
131 131
 				$data = array(
132 132
 							'mtime' => $cacheInfos['creation_time'],
133 133
 							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 							);
136 136
 				return $data;
137 137
 			}
138
-			else{
138
+			else {
139 139
 				$this->logger->info('This cache does not exists skipping');
140 140
 				return false;
141 141
 			}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		/**
146 146
 		 * Used to delete expired cache data
147 147
 		 */
148
-		public function deleteExpiredCache(){
148
+		public function deleteExpiredCache() {
149 149
 			//for APC[u] is done automatically
150 150
 			return true;
151 151
 		}
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 		/**
154 154
 		 * Remove all cache data
155 155
 		 */
156
-		public function clean(){
156
+		public function clean() {
157 157
 			$this->logger->debug('Deleting of all cache data');
158 158
 			$cacheInfos = apc_cache_info('user');
159
-			if(empty($cacheInfos['cache_list'])){
159
+			if (empty($cacheInfos['cache_list'])) {
160 160
 				$this->logger->info('No cache data were found skipping');
161 161
 				return false;
162 162
 			}
163
-			else{
163
+			else {
164 164
 				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165 165
 				return apc_clear_cache('user');
166 166
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		 *
173 173
 		 * @return bool
174 174
 		 */
175
-		public function isSupported(){
175
+		public function isSupported() {
176 176
 			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177 177
 		}
178 178
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	     * Return the Log instance
181 181
 	     * @return Log
182 182
 	     */
183
-	    public function getLogger(){
183
+	    public function getLogger() {
184 184
 	      return $this->logger;
185 185
 	    }
186 186
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	     * Set the log instance
189 189
 	     * @param Log $logger the log object
190 190
 	     */
191
-	    public function setLogger(Log $logger){
191
+	    public function setLogger(Log $logger) {
192 192
 	      $this->logger = $logger;
193 193
 	      return $this;
194 194
 	    }
@@ -199,12 +199,12 @@  discard block
 block discarded – undo
199 199
 		* @param string $key the cache key to get the cache information 
200 200
 		* @return boolean|array
201 201
 		*/
202
-		private function _getCacheInfo($key){
202
+		private function _getCacheInfo($key) {
203 203
 			$caches = apc_cache_info('user');
204
-			if(! empty($caches['cache_list'])){
204
+			if (!empty($caches['cache_list'])) {
205 205
 				$cacheLists = $caches['cache_list'];
206
-				foreach ($cacheLists as $c){
207
-					if(isset($c['info']) && $c['info'] === $key){
206
+				foreach ($cacheLists as $c) {
207
+					if (isset($c['info']) && $c['info'] === $key) {
208 208
 						return $c;
209 209
 					}
210 210
 				}
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 1 patch
Spacing   +62 added lines, -62 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 implements CacheInterface{
27
+	class FileCache implements CacheInterface {
28 28
 		
29 29
 		/**
30 30
 		 * Whether to enable compression of the cache data file.
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 		private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
42
+		public function __construct(Log $logger = null) {
43
+			if (!$this->isSupported()) {
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47 47
 	         * instance of the Log class
48 48
 	         */
49
-	        if(is_object($logger)){
49
+	        if (is_object($logger)) {
50 50
 	          $this->logger = $logger;
51 51
 	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
52
+	        else {
53
+	            $this->logger = & class_loader('Log', 'classes');
54 54
 	            $this->logger->setLogger('Library::FileCache');
55 55
 	        }
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
58
+			if (!extension_loaded('zlib')) {
59 59
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60 60
 				$this->compressCacheData = false;
61 61
 			}
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 		 * @param  string $key the key to identify the cache data
67 67
 		 * @return mixed      the cache data if exists else return false
68 68
 		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
69
+		public function get($key) {
70
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
71 71
 			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
72
+			if (!file_exists($filePath)) {
73
+				$this->logger->info('No cache file found for the key [' . $key . '], return false');
74 74
 				return false;
75 75
 			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if(! is_resource($handle)){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
76
+			$this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid');
77
+			$handle = fopen($filePath, 'r');
78
+			if (!is_resource($handle)) {
79
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 		    $data = file_get_contents($filePath);
85 85
       		fclose($handle);
86 86
       		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
87
+      		if (!$data) {
88
+      			$this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false');
89 89
 		         // If unserializing somehow didn't work out, we'll delete the file
90 90
 		         unlink($filePath);
91 91
 		         return false;
92 92
 	      	}
93 93
 	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
94
+	      		$this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']');
95 95
 		        // Unlinking when the file was expired
96 96
 		        unlink($filePath);
97 97
 		        return false;
98 98
 		     }
99
-		     else{
100
-		     	$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']) . ']');
99
+		     else {
100
+		     	$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']) . ']');
101 101
 		     	return $data['data'];
102 102
 		     }
103 103
 		}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 		 * @param integer $ttl  the cache life time
111 111
 		 * @return boolean true if success otherwise will return false
112 112
 		 */
113
-		public function set($key, $data, $ttl = 0){
113
+		public function set($key, $data, $ttl = 0) {
114 114
 			$expire = time() + $ttl;
115
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
115
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116 116
 			$filePath = $this->getFilePath($key);
117
-			$handle = fopen($filePath,'w');
118
-			if(! is_resource($handle)){
119
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
117
+			$handle = fopen($filePath, 'w');
118
+			if (!is_resource($handle)) {
119
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
120 120
 				return false;
121 121
 			}
122 122
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 									)
130 130
 								);		   
131 131
 		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
132
+		    if (!$result) {
133
+		    	$this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false');
134 134
 		    	fclose($handle);
135 135
 		    	return false;
136 136
 		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
137
+		    else {
138
+		    	$this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']');
139 139
 		    	fclose($handle);
140 140
 				chmod($filePath, 0640);
141 141
 				return true;
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 		 * @return boolean      true if the cache is delete, false if can't delete 
150 150
 		 * the cache or the cache with the given key not exist
151 151
 		 */
152
-		public function delete($key){
153
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
152
+		public function delete($key) {
153
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
154 154
 			$filePath = $this->getFilePath($key);
155
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
-			if(! file_exists($filePath)){
155
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
156
+			if (!file_exists($filePath)) {
157 157
 				$this->logger->info('This cache file does not exists skipping');
158 158
 				return false;
159 159
 			}
160
-			else{
161
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
160
+			else {
161
+				$this->logger->info('Found cache file [' . $filePath . '] remove it');
162 162
 	      		unlink($filePath);
163 163
 				return true;
164 164
 			}
@@ -172,25 +172,25 @@  discard block
 block discarded – undo
172 172
 		 * 'expire' => expiration time of the cache (Unix timestamp),
173 173
 		 * 'ttl' => the time to live of the cache in second
174 174
 		 */
175
-		public function getInfo($key){
176
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
175
+		public function getInfo($key) {
176
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
177 177
 			$filePath = $this->getFilePath($key);
178
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
-			if(! file_exists($filePath)){
178
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
179
+			if (!file_exists($filePath)) {
180 180
 				$this->logger->info('This cache file does not exists skipping');
181 181
 				return false;
182 182
 			}
183
-			else{
184
-				$this->logger->info('Found cache file [' .$filePath. '] check the validity');
183
+			else {
184
+				$this->logger->info('Found cache file [' . $filePath . '] check the validity');
185 185
 	      		$data = file_get_contents($filePath);
186 186
 				$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
187
-				if(! $data){
187
+				if (!$data) {
188 188
 					$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
189 189
 					return false;
190 190
 				}
191
-				else{
191
+				else {
192 192
 					$this->logger->info('This cache data is OK check for expire');
193
-					if(isset($data['expire']) && $data['expire'] > time()){
193
+					if (isset($data['expire']) && $data['expire'] > time()) {
194 194
 						$this->logger->info('This cache not yet expired return cache informations');
195 195
 						$info = array(
196 196
 							'mtime' => $data['mtime'],
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 							);
200 200
 						return $info;
201 201
 					}
202
-					else{
202
+					else {
203 203
 						$this->logger->info('This cache already expired return false');
204 204
 						return false;
205 205
 					}
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
 		/**
212 212
 		 * Used to delete expired cache data
213 213
 		 */
214
-		public function deleteExpiredCache(){
214
+		public function deleteExpiredCache() {
215 215
 			$this->logger->debug('Deleting of expired cache files');
216 216
 			$list = glob(CACHE_PATH . '*.cache');
217
-			if(! $list){
217
+			if (!$list) {
218 218
 				$this->logger->info('No cache files were found skipping');
219 219
 			}
220
-			else{
220
+			else {
221 221
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
222 222
 				foreach ($list as $file) {
223 223
 					$this->logger->debug('Processing the cache file [' . $file . ']');
224 224
 					$data = file_get_contents($file);
225 225
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
226
-		      		if(! $data){
226
+		      		if (!$data) {
227 227
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
228 228
 		      		}
229
-		      		else if(time() > $data['expire']){
229
+		      		else if (time() > $data['expire']) {
230 230
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
231 231
 		      			unlink($file);
232 232
 		      		}
233
-		      		else{
233
+		      		else {
234 234
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
235 235
 		      		}
236 236
 				}
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 		/**
241 241
 		 * Remove all file from cache folder
242 242
 		 */
243
-		public function clean(){
243
+		public function clean() {
244 244
 			$this->logger->debug('Deleting of all cache files');
245 245
 			$list = glob(CACHE_PATH . '*.cache');
246
-			if(! $list){
246
+			if (!$list) {
247 247
 				$this->logger->info('No cache files were found skipping');
248 248
 			}
249
-			else{
249
+			else {
250 250
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
251 251
 				foreach ($list as $file) {
252 252
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	    /**
259 259
 	     * @return boolean
260 260
 	     */
261
-	    public function isCompressCacheData(){
261
+	    public function isCompressCacheData() {
262 262
 	        return $this->compressCacheData;
263 263
 	    }
264 264
 
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
 	     *
268 268
 	     * @return self
269 269
 	     */
270
-	    public function setCompressCacheData($status = true){
270
+	    public function setCompressCacheData($status = true) {
271 271
 			//if Zlib extension is not loaded set compressCacheData to false
272
-			if($status === true && ! extension_loaded('zlib')){
272
+			if ($status === true && !extension_loaded('zlib')) {
273 273
 				
274 274
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
275 275
 				$this->compressCacheData = false;
276 276
 			}
277
-			else{
277
+			else {
278 278
 				$this->compressCacheData = $status;
279 279
 			}
280 280
 			return $this;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		 *
286 286
 		 * @return bool
287 287
 		 */
288
-		public function isSupported(){
288
+		public function isSupported() {
289 289
 			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
290 290
 		}
291 291
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 	     * Return the Log instance
294 294
 	     * @return Log
295 295
 	     */
296
-	    public function getLogger(){
296
+	    public function getLogger() {
297 297
 	      return $this->logger;
298 298
 	    }
299 299
 
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	     * Set the log instance
302 302
 	     * @param Log $logger the log object
303 303
 	     */
304
-	    public function setLogger(Log $logger){
304
+	    public function setLogger(Log $logger) {
305 305
 	      $this->logger = $logger;
306 306
 	      return $this;
307 307
 	    }
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 		* @param $key the cache item key
313 313
 		* @return string the full cache file path for this key
314 314
 		*/
315
-		private function getFilePath($key){
315
+		private function getFilePath($key) {
316 316
 			return CACHE_PATH . md5($key) . '.cache';
317 317
 		}
318 318
 	}
Please login to merge, or discard this patch.
core/libraries/Cookie.php 1 patch
Spacing   +15 added lines, -15 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 Cookie{
27
+	class Cookie {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * The signleton of the logger
37 37
 		 * @return Object the Log instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (self::$logger == null) {
41
+				self::$logger[0] = & class_loader('Log', 'classes');
42 42
 				self::$logger[0]->setLogger('Library::Cookie');
43 43
 			}
44 44
 			return self::$logger[0];
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 		 * @param  mixed $default the default value to use if can not find the cokkie item in the list
51 51
 		 * @return mixed          the cookie value if exist or the default value
52 52
 		 */
53
-		public static function get($item, $default = null){
53
+		public static function get($item, $default = null) {
54 54
 			$logger = self::getLogger();
55
-			if(array_key_exists($item, $_COOKIE)){
55
+			if (array_key_exists($item, $_COOKIE)) {
56 56
 				return $_COOKIE[$item];
57 57
 			}
58 58
 			$logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
 		 * @param boolean $secure   if this cookie will be available on secure connection or not
70 70
 		 * @param boolean $httponly if this cookie will be available under HTTP protocol.
71 71
 		 */
72
-		public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){
73
-			if(headers_sent()){
72
+		public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false) {
73
+			if (headers_sent()) {
74 74
 				show_error('There exists a cookie that we wanted to create that we couldn\'t 
75 75
 						    because headers was already sent. Make sure to do this first 
76 76
 							before outputing anything.');
77 77
 			}
78 78
 			$timestamp = $expire;
79
-			if($expire){
79
+			if ($expire) {
80 80
 				$timestamp = time() + $expire;
81 81
 			}
82 82
 			setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
 		 * @param  string $item the cookie item name to be cleared
88 88
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
89 89
 		 */
90
-		public static function delete($item){
90
+		public static function delete($item) {
91 91
 			$logger = self::getLogger();
92
-			if(array_key_exists($item, $_COOKIE)){
93
-				$logger->info('Delete cookie item ['.$item.']');
92
+			if (array_key_exists($item, $_COOKIE)) {
93
+				$logger->info('Delete cookie item [' . $item . ']');
94 94
 				unset($_COOKIE[$item]);
95 95
 				return true;
96 96
 			}
97
-			else{
98
-				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
97
+			else {
98
+				$logger->warning('Cookie item [' . $item . '] to be deleted does not exists');
99 99
 				return false;
100 100
 			}
101 101
 		}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * @param  string $item the cookie item name
106 106
 		 * @return boolean       true if the cookie item is set, false or not
107 107
 		 */
108
-		public static function exists($item){
108
+		public static function exists($item) {
109 109
 			return array_key_exists($item, $_COOKIE);
110 110
 		}
111 111
 
Please login to merge, or discard this patch.
core/libraries/Assets.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *  @since 1.0.0
39 39
 	 *  @filesource
40 40
 	 */
41
-	class Assets{
41
+	class Assets {
42 42
 		
43 43
 		/**
44 44
 		 * The logger instance
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		 * The signleton of the logger
51 51
 		 * @return Object the Log instance
52 52
 		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
53
+		private static function getLogger() {
54
+			if (self::$logger == null) {
55 55
 				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Assets');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 		 *  @param $asset the name of the assets file path with the extension.
73 73
 		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74 74
 		 */
75
-		public static function path($asset){
75
+		public static function path($asset) {
76 76
 			$logger = self::getLogger();	
77 77
 			$path = ASSETS_PATH . $asset;
78 78
 			
79 79
 			$logger->debug('Including the Assets file [' . $path . ']');
80 80
 			//Check if the file exists
81
-			if(file_exists($path)){
81
+			if (file_exists($path)) {
82 82
 				$logger->info('Assets file [' . $path . '] included successfully');
83 83
 				return Url::base_url($path);
84 84
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 *  @param $path the name of the css file without the extension.
99 99
 		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100 100
 		 */
101
-		public static function css($path){
101
+		public static function css($path) {
102 102
 			$logger = self::getLogger();
103 103
 			/*
104 104
 			* if the file name contains the ".css" extension, replace it with 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			
110 110
 			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111 111
 			//Check if the file exists
112
-			if(file_exists($path)){
112
+			if (file_exists($path)) {
113 113
 				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114 114
 				return Url::base_url($path);
115 115
 			}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		 *  @param $path the name of the javascript file without the extension.
130 130
 		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131 131
 		 */
132
-		public static function js($path){
132
+		public static function js($path) {
133 133
 			$logger = self::getLogger();
134 134
 			$path = str_ireplace('.js', '', $path);
135 135
 			$path = ASSETS_PATH . 'js/' . $path . '.js';
136 136
 			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
137
+			if (file_exists($path)) {
138 138
 				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139 139
 				return Url::base_url($path);
140 140
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		 *  @param $path the name of the image file with the extension.
155 155
 		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156 156
 		 */
157
-		public static function img($path){
157
+		public static function img($path) {
158 158
 			$logger = self::getLogger();
159 159
 			$path = ASSETS_PATH . 'images/' . $path;
160 160
 			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
161
+			if (file_exists($path)) {
162 162
 				$logger->info('Assets file [' . $path . '] for image included successfully');
163 163
 				return Url::base_url($path);
164 164
 			}
Please login to merge, or discard this patch.
core/libraries/Benchmark.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * Class for Benchmark
29 29
 	 */
30
-	class Benchmark{
30
+	class Benchmark {
31 31
 		/**
32 32
 		 * The markers for excution time
33 33
 		 * @var array
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		 * This method is used to mark one point for benchmark (execution time and memory usage)
45 45
 		 * @param  string $name the marker name
46 46
 		 */
47
-		public function mark($name){
47
+		public function mark($name) {
48 48
 			//Marker for execution time
49 49
 			$this->markersTime[$name] = microtime(true);
50 50
 			//Marker for memory usage
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 		 * @param  integer $decimalCount   the number of decimal
59 59
 		 * @return string         the total execution time
60 60
 		 */
61
-		public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
62
-			if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){
61
+		public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
62
+			if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) {
63 63
 				return 0;
64 64
 			}
65 65
 			
66
-			if(! isset($this->markersTime[$endMarkerName])){
66
+			if (!isset($this->markersTime[$endMarkerName])) {
67 67
 				$this->markersTime[$endMarkerName] = microtime(true);
68 68
 			}
69 69
 			return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount);
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 		 * @param  integer $decimalCount   the number of decimal
77 77
 		 * @return string         the total memory usage
78 78
 		 */
79
-		public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
80
-			if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){
79
+		public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
80
+			if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) {
81 81
 				return 0;
82 82
 			}
83 83
 			
84
-			if(! isset($this->markersMemory[$endMarkerName])){
84
+			if (!isset($this->markersMemory[$endMarkerName])) {
85 85
 				$this->markersMemory[$endMarkerName] = microtime(true);
86 86
 			}
87 87
 			return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount);
Please login to merge, or discard this patch.
core/libraries/Email.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		 */
87 87
 		public function __construct()
88 88
 		{
89
-			$this->logger =& class_loader('Log', 'classes');
89
+			$this->logger = & class_loader('Log', 'classes');
90 90
             $this->logger->setLogger('Library::Email');
91 91
 			$this->reset();
92 92
 		}
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 		public function setTos(array $emails)
149 149
 		{
150 150
 			foreach ($emails as $name => $email) {
151
-				if(is_numeric($name)){
151
+				if (is_numeric($name)) {
152 152
 					$this->setTo($email);
153 153
 				}
154
-				else{
154
+				else {
155 155
 					$this->setTo($email, $name);
156 156
 				}
157 157
 			}
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 		 */
282 282
 		public function addAttachment($path, $filename = null, $data = null)
283 283
 		{
284
-			if(! file_exists($path)){
285
-				show_error('The file [' .$path. '] does not exists.');
284
+			if (!file_exists($path)) {
285
+				show_error('The file [' . $path . '] does not exists.');
286 286
 			}
287 287
 			$filename = empty($filename) ? basename($path) : $filename;
288 288
 			$filename = $this->encodeUtf8($this->filterOther((string) $filename));
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
 		 */
305 305
 		public function getAttachmentData($path)
306 306
 		{
307
-			if(! file_exists($path)){
308
-				show_error('The file [' .$path. '] does not exists.');
307
+			if (!file_exists($path)) {
308
+				show_error('The file [' . $path . '] does not exists.');
309 309
 			}
310 310
 			$filesize = filesize($path);
311 311
 			$handle = fopen($path, "r");
312 312
 			$attachment = null;
313
-			if(is_resource($handle)){
313
+			if (is_resource($handle)) {
314 314
 				$attachment = fread($handle, $filesize);
315 315
 				fclose($handle);
316 316
 			}
Please login to merge, or discard this patch.
core/classes/Router.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -92,36 +92,36 @@  discard block
 block discarded – undo
92 92
 		/**
93 93
 		 * Construct the new Router instance
94 94
 		 */
95
-		public function __construct(){
96
-			$this->logger =& class_loader('Log', 'classes');
95
+		public function __construct() {
96
+			$this->logger = & class_loader('Log', 'classes');
97 97
 	        $this->logger->setLogger('Library::Router');
98 98
 	        $routesPath = CONFIG_PATH . 'routes.php';
99 99
 	        $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...');
100
-			if(file_exists($routesPath)){
101
-				 $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it');
100
+			if (file_exists($routesPath)) {
101
+				 $this->logger->info('Found routes configuration file --> ' . $routesPath . ' now load it');
102 102
 				require_once $routesPath;
103
-				if(! empty($route) && is_array($route)){
103
+				if (!empty($route) && is_array($route)) {
104 104
 					$this->routes = $route;
105 105
 					unset($route);
106 106
 				}
107 107
 			}
108
-			else{
108
+			else {
109 109
 				show_error('Unable to find the routes configuration file [' . $routesPath . ']');
110 110
 			}
111 111
 			
112 112
 			//loading routes for module
113 113
 			$this->logger->debug('Loading of modules routes ... ');
114 114
 			$modulesRoutes = Module::getModulesRoutes();
115
-			if($modulesRoutes && is_array($modulesRoutes)){
115
+			if ($modulesRoutes && is_array($modulesRoutes)) {
116 116
 				$this->routes = array_merge($this->routes, $modulesRoutes);
117 117
 				$this->logger->info('Routes for all modules loaded successfully');
118 118
 			}
119
-			else{
119
+			else {
120 120
 				$this->logger->info('No routes found for all modules skipping.');
121 121
 			}
122 122
 			$this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes));
123 123
 
124
-			foreach($this->routes as $pattern => $callback){
124
+			foreach ($this->routes as $pattern => $callback) {
125 125
 				$this->add($pattern, $callback);
126 126
 			}
127 127
 			
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 			$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
130 130
 			$this->logger->debug('Check if URL suffix is enabled in the configuration');
131 131
 			//remove url suffix from the request URI
132
-			if($suffix = get_config('url_suffix')){
133
-				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
132
+			if ($suffix = get_config('url_suffix')) {
133
+				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
134 134
 				$uri = str_ireplace($suffix, '', $uri);
135 135
 			}
136
-			else{
136
+			else {
137 137
 				$this->logger->info('URL suffix is not enabled in the configuration');
138 138
 			}
139
-			if(strpos($uri, '?') !== false){
139
+			if (strpos($uri, '?') !== false) {
140 140
 				$uri = substr($uri, 0, strpos($uri, '?'));
141 141
 			}
142 142
 			$uri = trim($uri, $this->uriTrim);
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		*/
152 152
 		public function add($uri, $callback) {
153 153
 			$uri = trim($uri, $this->uriTrim);
154
-			if(in_array($uri, $this->pattern)){
154
+			if (in_array($uri, $this->pattern)) {
155 155
 				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
156 156
 			}
157 157
 			$this->pattern[] = $uri;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		 * Get the module name
163 163
 		 * @return string
164 164
 		 */
165
-		public function getModule(){
165
+		public function getModule() {
166 166
 			return $this->module;
167 167
 		}
168 168
 		
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		 * Get the controller name
171 171
 		 * @return string
172 172
 		 */
173
-		public function getController(){
173
+		public function getController() {
174 174
 			return $this->controller;
175 175
 		}
176 176
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 		 * Get the controller file path
179 179
 		 * @return string
180 180
 		 */
181
-		public function getControllerPath(){
181
+		public function getControllerPath() {
182 182
 			return $this->controllerPath;
183 183
 		}
184 184
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		 * Get the controller method
187 187
 		 * @return string
188 188
 		 */
189
-		public function getMethod(){
189
+		public function getMethod() {
190 190
 			return $this->method;
191 191
 		}
192 192
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 		 * Get the request arguments
195 195
 		 * @return array
196 196
 		 */
197
-		public function getArgs(){
197
+		public function getArgs() {
198 198
 			return $this->args;
199 199
 		}
200 200
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		 * Get the URL segments array
203 203
 		 * @return array
204 204
 		 */
205
-		public function getSegments(){
205
+		public function getSegments() {
206 206
 			return $this->segments;
207 207
 		}
208 208
 
@@ -211,27 +211,27 @@  discard block
 block discarded – undo
211 211
 		 * otherwise send 404 error.
212 212
 		 */
213 213
 		public function run() {
214
-			$benchmark =& class_loader('Benchmark');
214
+			$benchmark = & class_loader('Benchmark');
215 215
 			$benchmark->mark('ROUTING_PROCESS_START');
216 216
 			$this->logger->debug('Routing process start ...');
217 217
 			$segment = $this->segments;
218 218
 			$baseUrl = get_config('base_url');
219 219
 			//check if the app is not in DOCUMENT_ROOT
220
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){
220
+			if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) {
221 221
 				array_shift($segment);
222 222
 				$this->segments = $segment;
223 223
 			}
224 224
 			$this->logger->debug('Check if the request URI contains the front controller');
225
-			if(isset($segment[0]) && $segment[0] == SELF){
225
+			if (isset($segment[0]) && $segment[0] == SELF) {
226 226
 				$this->logger->info('The request URI contains the front controller');
227 227
 				array_shift($segment);
228 228
 				$this->segments = $segment;
229 229
 			}
230
-			else{
230
+			else {
231 231
 				$this->logger->info('The request URI does not contain the front controller');
232 232
 			}
233 233
 			$uri = implode('/', $segment);
234
-			$this->logger->info('The final Request URI is [' . $uri . ']' );
234
+			$this->logger->info('The final Request URI is [' . $uri . ']');
235 235
 			//generic routes
236 236
 			$pattern = array(':num', ':alpha', ':alnum', ':any');
237 237
 			$replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*');
@@ -245,20 +245,20 @@  discard block
 block discarded – undo
245 245
 					array_shift($args);
246 246
 					//check if this contains an module
247 247
 					$moduleControllerMethod = explode('#', $this->callback[$index]);
248
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
249
-						$this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']');
248
+					if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
249
+						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
250 250
 						$this->module = $moduleControllerMethod[0];
251 251
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
252 252
 					}
253
-					else{
253
+					else {
254 254
 						$this->logger->info('The current request does not use the module');
255 255
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
256 256
 					}
257
-					if(is_array($moduleControllerMethod)){
258
-						if(isset($moduleControllerMethod[0])){
257
+					if (is_array($moduleControllerMethod)) {
258
+						if (isset($moduleControllerMethod[0])) {
259 259
 							$this->controller = $moduleControllerMethod[0];	
260 260
 						}
261
-						if(isset($moduleControllerMethod[1])){
261
+						if (isset($moduleControllerMethod[1])) {
262 262
 							$this->method = $moduleControllerMethod[1];
263 263
 						}
264 264
 						$this->args = $args;
@@ -268,73 +268,73 @@  discard block
 block discarded – undo
268 268
 				}
269 269
 			}
270 270
 			//first if the controller is not set and the module is set use the module name as the controller
271
-			if(! $this->getController() && $this->getModule()){
271
+			if (!$this->getController() && $this->getModule()) {
272 272
 				$this->logger->info('After loop in predefined routes configuration, the module name is set but the controller is not set, so we will use module as the controller');
273 273
 				$this->controller = $this->getModule();
274 274
 			}
275 275
 			//if can not determine the module/controller/method via the defined routes configuration we will use
276 276
 			//the URL like http://domain.com/module/controller/method/arg1/arg2
277
-			if(! $this->getController()){
277
+			if (!$this->getController()) {
278 278
 				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
279 279
 				$nbSegment = count($segment);
280 280
 				//if segment is null so means no need to perform
281
-				if($nbSegment > 0){
281
+				if ($nbSegment > 0) {
282 282
 					//get the module list
283 283
 					$modules = Module::getModuleList();
284 284
 					//first check if no module
285
-					if(! $modules){
285
+					if (!$modules) {
286 286
 						$this->logger->info('No module was loaded will skip the module checking');
287 287
 						//the application don't use module
288 288
 						//controller
289
-						if(isset($segment[0])){
289
+						if (isset($segment[0])) {
290 290
 							$this->controller = $segment[0];
291 291
 							array_shift($segment);
292 292
 						}
293 293
 						//method
294
-						if(isset($segment[0])){
294
+						if (isset($segment[0])) {
295 295
 							$this->method = $segment[0];
296 296
 							array_shift($segment);
297 297
 						}
298 298
 						//args
299 299
 						$this->args = $segment;
300 300
 					}
301
-					else{
301
+					else {
302 302
 						$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
303
-						if(in_array($segment[0], $modules)){
303
+						if (in_array($segment[0], $modules)) {
304 304
 							$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
305 305
 							$this->module = $segment[0];
306 306
 							array_shift($segment);
307 307
 							//check if the second arg is the controller from module
308
-							if(isset($segment[0])){
308
+							if (isset($segment[0])) {
309 309
 								$this->controller = $segment[0];
310 310
 								//check if the request use the same module name and controller
311 311
 								$path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
312
-								if(! $path){
312
+								if (!$path) {
313 313
 									$this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller');
314 314
 									$this->controller = $this->getModule();
315 315
 								}
316
-								else{
316
+								else {
317 317
 									$this->controllerPath = $path;
318 318
 									array_shift($segment);
319 319
 								}
320 320
 							}
321 321
 							//check for method
322
-							if(isset($segment[0])){
322
+							if (isset($segment[0])) {
323 323
 								$this->method = $segment[0];
324 324
 								array_shift($segment);
325 325
 							}
326 326
 							//the remaining is for args
327 327
 							$this->args = $segment;
328 328
 						}
329
-						else{
329
+						else {
330 330
 							$this->logger->info('The current request information is not found in the module list');
331 331
 							//controller
332
-							if(isset($segment[0])){
332
+							if (isset($segment[0])) {
333 333
 								$this->controller = $segment[0];
334 334
 								array_shift($segment);
335 335
 							}
336 336
 							//method
337
-							if(isset($segment[0])){
337
+							if (isset($segment[0])) {
338 338
 								$this->method = $segment[0];
339 339
 								array_shift($segment);
340 340
 							}
@@ -344,18 +344,18 @@  discard block
 block discarded – undo
344 344
 					}
345 345
 				}
346 346
 			}
347
-			if(! $this->getController() && $this->getModule()){
347
+			if (!$this->getController() && $this->getModule()) {
348 348
 				$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
349 349
 				$this->controller = $this->getModule();
350 350
 			}
351 351
 			//did we set the controller, so set the controller path
352
-			if($this->getController() && ! $this->getControllerPath()){
352
+			if ($this->getController() && !$this->getControllerPath()) {
353 353
 				$this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']');
354 354
 				//if it is the module controller
355
-				if($this->getModule()){
355
+				if ($this->getModule()) {
356 356
 					$this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule());
357 357
 				}
358
-				else{
358
+				else {
359 359
 					$this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php';
360 360
 				}
361 361
 			}
@@ -365,20 +365,20 @@  discard block
 block discarded – undo
365 365
 			$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
366 366
 			$benchmark->mark('ROUTING_PROCESS_END');
367 367
 			$e404 = false;
368
-			if(file_exists($classFilePath)){
368
+			if (file_exists($classFilePath)) {
369 369
 				require_once $classFilePath;
370
-				if(! class_exists($controller, false)){
370
+				if (!class_exists($controller, false)) {
371 371
 					$e404 = true;
372
-					$this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
372
+					$this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
373 373
 				}
374
-				else{
374
+				else {
375 375
 					$controllerInstance = new $controller();
376 376
 					$controllerMethod = $this->getMethod();
377
-					if(! method_exists($controllerInstance, $controllerMethod)){
377
+					if (!method_exists($controllerInstance, $controllerMethod)) {
378 378
 						$e404 = true;
379 379
 						$this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
380 380
 					}
381
-					else{
381
+					else {
382 382
 						$this->logger->info('Routing data is set correctly now GO!');
383 383
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs());
384 384
 						$obj = & get_instance();
@@ -388,12 +388,12 @@  discard block
 block discarded – undo
388 388
 					}
389 389
 				}
390 390
 			}
391
-			else{
391
+			else {
392 392
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
393 393
 				$e404 = true;
394 394
 			}
395
-			if($e404){
396
-				$response =& class_loader('Response', 'classes');
395
+			if ($e404) {
396
+				$response = & class_loader('Response', 'classes');
397 397
 				$response->send404();
398 398
 			}
399 399
 		}
Please login to merge, or discard this patch.
core/classes/Log.php 1 patch
Spacing   +36 added lines, -36 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,59 +115,59 @@  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 is set
131
-			if($this->logger){
131
+			if ($this->logger) {
132 132
 				$configLoggerName = get_config('log_logger_name', '');
133
-				if($configLoggerName){
134
-					if (is_array($configLoggerName)){
133
+				if ($configLoggerName) {
134
+					if (is_array($configLoggerName)) {
135 135
 						//for best comparaison put all string to lowercase
136 136
 						$configLoggerName = array_map('strtolower', $configLoggerName);
137
-						if(! in_array(strtolower($this->logger), $configLoggerName)){
137
+						if (!in_array(strtolower($this->logger), $configLoggerName)) {
138 138
 							return;
139 139
 						}
140 140
 					}
141
-					else if(strtolower($this->logger) !== strtolower($configLoggerName)){
141
+					else if (strtolower($this->logger) !== strtolower($configLoggerName)) {
142 142
 						return; 
143 143
 					}
144 144
 				}
145 145
 			}
146 146
 			
147 147
 			//if $level is not an integer
148
-			if(! is_numeric($level)){
148
+			if (!is_numeric($level)) {
149 149
 				$level = self::getLevelValue($level);
150 150
 			}
151 151
 			
152 152
 			//check if can logging regarding the log level config
153 153
 			$configLevel = self::getLevelValue($configLogLevel);
154
-			if($configLevel > $level){
154
+			if ($configLevel > $level) {
155 155
 				//can't log
156 156
 				return;
157 157
 			}
158 158
 			
159 159
 			$logSavePath = get_config('log_save_path');
160
-			if(! $logSavePath){
160
+			if (!$logSavePath) {
161 161
 				$logSavePath = LOGS_PATH;
162 162
 			}
163 163
 			
164
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
164
+			if (!is_dir($logSavePath) || !is_writable($logSavePath)) {
165 165
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
166 166
 				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
167 167
 			}
168 168
 			
169 169
 			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
170
-			if(! file_exists($path)){
170
+			if (!file_exists($path)) {
171 171
 				touch($path);
172 172
 			}
173 173
 			//may be at this time helper user_agent not yet included
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			
190 190
 			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
191 191
 			$fp = fopen($path, 'a+');
192
-			if(is_resource($fp)){
192
+			if (is_resource($fp)) {
193 193
 				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
194 194
 				fwrite($fp, $str);
195 195
 				fclose($fp);
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		 *
204 204
 		 * @return boolean        true if the given log level is valid, false if not
205 205
 		 */
206
-		private static function isValidConfigLevel($level){
206
+		private static function isValidConfigLevel($level) {
207 207
 			$level = strtolower($level);
208 208
 			return in_array($level, self::$validConfigLevel);
209 209
 		}
@@ -213,27 +213,27 @@  discard block
 block discarded – undo
213 213
 		 * @param  string $level the log level in string format
214 214
 		 * @return int        the log level in integer format using the predefinied constants
215 215
 		 */
216
-		private static function getLevelValue($level){
216
+		private static function getLevelValue($level) {
217 217
 			$level = strtolower($level);
218 218
 			$value = self::NONE;
219 219
 			
220 220
 			//the default value is NONE, so means no need test for NONE
221
-			if($level == 'fatal'){
221
+			if ($level == 'fatal') {
222 222
 				$value = self::FATAL;
223 223
 			}
224
-			else if($level == 'error'){
224
+			else if ($level == 'error') {
225 225
 				$value = self::ERROR;
226 226
 			}
227
-			else if($level == 'warning' || $level == 'warn'){
227
+			else if ($level == 'warning' || $level == 'warn') {
228 228
 				$value = self::WARNING;
229 229
 			}
230
-			else if($level == 'info'){
230
+			else if ($level == 'info') {
231 231
 				$value = self::INFO;
232 232
 			}
233
-			else if($level == 'debug'){
233
+			else if ($level == 'debug') {
234 234
 				$value = self::DEBUG;
235 235
 			}
236
-			else if($level == 'all'){
236
+			else if ($level == 'all') {
237 237
 				$value = self::ALL;
238 238
 			}
239 239
 			return $value;
@@ -244,23 +244,23 @@  discard block
 block discarded – undo
244 244
 		 * @param  integer $level the log level in integer format
245 245
 		 * @return string        the log level in string format
246 246
 		 */
247
-		private static function getLevelName($level){
247
+		private static function getLevelName($level) {
248 248
 			$value = '';
249 249
 			
250 250
 			//the default value is NONE, so means no need test for NONE
251
-			if($level == self::FATAL){
251
+			if ($level == self::FATAL) {
252 252
 				$value = 'FATAL';
253 253
 			}
254
-			else if($level == self::ERROR){
254
+			else if ($level == self::ERROR) {
255 255
 				$value = 'ERROR';
256 256
 			}
257
-			else if($level == self::WARNING){
257
+			else if ($level == self::WARNING) {
258 258
 				$value = 'WARNING';
259 259
 			}
260
-			else if($level == self::INFO){
260
+			else if ($level == self::INFO) {
261 261
 				$value = 'INFO';
262 262
 			}
263
-			else if($level == self::DEBUG){
263
+			else if ($level == self::DEBUG) {
264 264
 				$value = 'DEBUG';
265 265
 			}
266 266
 			//no need for ALL
Please login to merge, or discard this patch.
core/classes/Lang.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * For application languages management
29 29
 	 */
30
-	class Lang{
30
+	class Lang {
31 31
 		
32 32
 		/**
33 33
 		 * The supported available language for this application.
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 		/**
68 68
 		 * Construct new Lang instance
69 69
 		 */
70
-		public function __construct(){
71
-	        $this->logger =& class_loader('Log', 'classes');
70
+		public function __construct() {
71
+	        $this->logger = & class_loader('Log', 'classes');
72 72
 	        $this->logger->setLogger('Library::Lang');
73 73
 
74 74
 			$this->default = get_config('default_language', 'en');
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 			
77 77
 			//add the supported languages ('key', 'display name')
78 78
 			$languages = get_config('languages', null);
79
-			if(! empty($languages)){
80
-				foreach($languages as $key => $displayName){
79
+			if (!empty($languages)) {
80
+				foreach ($languages as $key => $displayName) {
81 81
 					$this->addLang($key, $displayName);
82 82
 				}
83 83
 			}
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
 
86 86
 			//if the language exists in cookie use it
87 87
 			$cfgKey = get_config('language_cookie_name');
88
-			$this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
88
+			$this->logger->debug('Getting current language from cookie [' . $cfgKey . ']');
89 89
 			$objCookie = & class_loader('Cookie');
90 90
 			$cookieLang = $objCookie->get($cfgKey);
91
-			if($cookieLang && $this->isValid($cookieLang)){
91
+			if ($cookieLang && $this->isValid($cookieLang)) {
92 92
 				$this->current = $cookieLang;
93
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
93
+				$this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']');
94 94
 			}
95
-			else{
96
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
95
+			else {
96
+				$this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']');
97 97
 				$this->current = $this->getDefault();
98 98
 			}
99 99
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		 *
104 104
 		 * @return array the language message list
105 105
 		 */
106
-		public function getAll(){
106
+		public function getAll() {
107 107
 			return $this->languages;
108 108
 		}
109 109
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * @param string $key the language key to identify
114 114
 		 * @param string $value the language message value
115 115
 		 */
116
-		public function set($key, $value){
116
+		public function set($key, $value) {
117 117
 			$this->languages[$key] = $value;
118 118
 		}
119 119
 
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 		 *
126 126
 		 * @return string the language message value
127 127
 		 */
128
-		public function get($key, $default = 'LANGUAGE_ERROR'){
129
-			if(isset($this->languages[$key])){
128
+		public function get($key, $default = 'LANGUAGE_ERROR') {
129
+			if (isset($this->languages[$key])) {
130 130
 				return $this->languages[$key];
131 131
 			}
132
-			$this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
132
+			$this->logger->warning('Language key  [' . $key . '] does not exist use the default value [' . $default . ']');
133 133
 			return $default;
134 134
 		}
135 135
 
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 		 *
141 141
 		 * @return boolean true if the language directory exists, false or not
142 142
 		 */
143
-		public function isValid($language){
143
+		public function isValid($language) {
144 144
 			$searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
-			foreach($searchDir as $dir){
146
-				if(file_exists($dir . $language) && is_dir($dir . $language)){
145
+			foreach ($searchDir as $dir) {
146
+				if (file_exists($dir . $language) && is_dir($dir . $language)) {
147 147
 					return true;
148 148
 				}
149 149
 			}
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		 *
156 156
 		 * @return string the default language
157 157
 		 */
158
-		public function getDefault(){
158
+		public function getDefault() {
159 159
 			return $this->default;
160 160
 		}
161 161
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		 *
165 165
 		 * @return string the current language
166 166
 		 */
167
-		public function getCurrent(){
167
+		public function getCurrent() {
168 168
 			return $this->current;
169 169
 		}
170 170
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 		 * @param string $name the short language name like "en", "fr".
175 175
 		 * @param string $description the human readable description of this language
176 176
 		 */
177
-		public function addLang($name, $description){
178
-			if(isset($this->availables[$name])){
177
+		public function addLang($name, $description) {
178
+			if (isset($this->availables[$name])) {
179 179
 				return; //already added cost in performance
180 180
 			}
181
-			if($this->isValid($name)){
181
+			if ($this->isValid($name)) {
182 182
 				$this->availables[$name] = $description;
183 183
 			}
184
-			else{
184
+			else {
185 185
 				show_error('The language [' . $name . '] is not valid or does not exists.');
186 186
 			}
187 187
 		}
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 		 *
192 192
 		 * @return array the list of the application language
193 193
 		 */
194
-		public function getSupported(){
194
+		public function getSupported() {
195 195
 			return $this->availables;
196 196
 		}
197 197
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 		 *
201 201
 		 * @param array $langs the languages array of the messages to be added
202 202
 		 */
203
-		public function addLangMessages(array $langs){
203
+		public function addLangMessages(array $langs) {
204 204
 			foreach ($langs as $key => $value) {
205 205
 				$this->set($key, $value);
206 206
 			}
Please login to merge, or discard this patch.