Passed
Push — 1.0.0-dev ( 83bedf...ceb5d8 )
by nguereza
02:34
created
core/classes/cache/ApcCache.php 1 patch
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -1,215 +1,215 @@
 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 ApcCache implements CacheInterface{
27
+    class ApcCache implements CacheInterface{
28 28
 
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private $logger;
34 34
 		
35 35
 		
36
-		public function __construct(Log $logger = null){
37
-			if(! $this->isSupported()){
38
-				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39
-			}
36
+        public function __construct(Log $logger = null){
37
+            if(! $this->isSupported()){
38
+                show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
39
+            }
40 40
 
41
-			/**
42
-	         * instance of the Log class
43
-	         */
44
-	        if(is_object($logger)){
45
-	          $this->logger = $logger;
46
-	        }
47
-	        else{
48
-	            $this->logger =& class_loader('Log', 'classes');
49
-	            $this->logger->setLogger('Library::ApcCache');
50
-	        }
51
-		}
41
+            /**
42
+             * instance of the Log class
43
+             */
44
+            if(is_object($logger)){
45
+                $this->logger = $logger;
46
+            }
47
+            else{
48
+                $this->logger =& class_loader('Log', 'classes');
49
+                $this->logger->setLogger('Library::ApcCache');
50
+            }
51
+        }
52 52
 
53
-		/**
54
-		 * This is used to get the cache data using the key
55
-		 * @param  string $key the key to identify the cache data
56
-		 * @return mixed      the cache data if exists else return false
57
-		 */
58
-		public function get($key){
59
-			$this->logger->debug('Getting cache data for key ['. $key .']');
60
-			$success = false;
61
-			$data = apc_fetch($key, $success);
62
-			if($success === false){
63
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
64
-				return false;
65
-			}
66
-			else{
67
-				$cacheInfo = $this->_getCacheInfo($key);
68
-				$expire = time();
69
-				if($cacheInfo){
70
-					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
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) . ']');
73
-				return $data;
74
-			}
75
-		}
53
+        /**
54
+         * This is used to get the cache data using the key
55
+         * @param  string $key the key to identify the cache data
56
+         * @return mixed      the cache data if exists else return false
57
+         */
58
+        public function get($key){
59
+            $this->logger->debug('Getting cache data for key ['. $key .']');
60
+            $success = false;
61
+            $data = apc_fetch($key, $success);
62
+            if($success === false){
63
+                $this->logger->info('No cache found for the key ['. $key .'], return false');
64
+                return false;
65
+            }
66
+            else{
67
+                $cacheInfo = $this->_getCacheInfo($key);
68
+                $expire = time();
69
+                if($cacheInfo){
70
+                    $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
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) . ']');
73
+                return $data;
74
+            }
75
+        }
76 76
 
77 77
 
78
-		/**
79
-		 * Save data to the cache
80
-		 * @param string  $key  the key to identify this cache data
81
-		 * @param mixed  $data the cache data to be saved
82
-		 * @param integer $ttl  the cache life time
83
-		 * @return boolean true if success otherwise will return false
84
-		 */
85
-		public function set($key, $data, $ttl = 0){
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) . ']');
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');
91
-		    	return false;
92
-		    }
93
-		    else{
94
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
95
-		    	return true;
96
-		    }
97
-		}
78
+        /**
79
+         * Save data to the cache
80
+         * @param string  $key  the key to identify this cache data
81
+         * @param mixed  $data the cache data to be saved
82
+         * @param integer $ttl  the cache life time
83
+         * @return boolean true if success otherwise will return false
84
+         */
85
+        public function set($key, $data, $ttl = 0){
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) . ']');
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');
91
+                return false;
92
+            }
93
+            else{
94
+                $this->logger->info('Cache data saved for the key ['. $key .']');
95
+                return true;
96
+            }
97
+        }
98 98
 
99 99
 
100
-		/**
101
-		 * Delete the cache data for given key
102
-		 * @param  string $key the key for cache to be deleted
103
-		 * @return boolean      true if the cache is deleted, false if can't delete 
104
-		 * the cache or the cache with the given key not exist
105
-		 */
106
-		public function delete($key){
107
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
108
-			$cacheInfo = $this->_getCacheInfo($key);
109
-			if($cacheInfo === false){
110
-				$this->logger->info('This cache data does not exists skipping');
111
-				return false;
112
-			}
113
-			else{
114
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
-	      		return apc_delete($key) === true;
116
-			}
117
-		}
100
+        /**
101
+         * Delete the cache data for given key
102
+         * @param  string $key the key for cache to be deleted
103
+         * @return boolean      true if the cache is deleted, false if can't delete 
104
+         * the cache or the cache with the given key not exist
105
+         */
106
+        public function delete($key){
107
+            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
108
+            $cacheInfo = $this->_getCacheInfo($key);
109
+            if($cacheInfo === false){
110
+                $this->logger->info('This cache data does not exists skipping');
111
+                return false;
112
+            }
113
+            else{
114
+                $this->logger->info('Found cache data for the key [' .$key. '] remove it');
115
+                    return apc_delete($key) === true;
116
+            }
117
+        }
118 118
 		
119
-		/**
120
-		 * Get the cache information for given key
121
-		 * @param  string $key the key for cache to get the information for
122
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
123
-		 * 'mtime' => creation time of the cache (Unix timestamp),
124
-		 * 'expire' => expiration time of the cache (Unix timestamp),
125
-		 * 'ttl' => the time to live of the cache in second
126
-		 */
127
-		public function getInfo($key){
128
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
129
-			$cacheInfos = $this->_getCacheInfo($key);
130
-			if($cacheInfos){
131
-				$data = array(
132
-							'mtime' => $cacheInfos['creation_time'],
133
-							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
134
-							'ttl' => $cacheInfos['ttl']
135
-							);
136
-				return $data;
137
-			}
138
-			else{
139
-				$this->logger->info('This cache does not exists skipping');
140
-				return false;
141
-			}
142
-		}
119
+        /**
120
+         * Get the cache information for given key
121
+         * @param  string $key the key for cache to get the information for
122
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
123
+         * 'mtime' => creation time of the cache (Unix timestamp),
124
+         * 'expire' => expiration time of the cache (Unix timestamp),
125
+         * 'ttl' => the time to live of the cache in second
126
+         */
127
+        public function getInfo($key){
128
+            $this->logger->debug('Getting of cache info for key [' .$key. ']');
129
+            $cacheInfos = $this->_getCacheInfo($key);
130
+            if($cacheInfos){
131
+                $data = array(
132
+                            'mtime' => $cacheInfos['creation_time'],
133
+                            'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
134
+                            'ttl' => $cacheInfos['ttl']
135
+                            );
136
+                return $data;
137
+            }
138
+            else{
139
+                $this->logger->info('This cache does not exists skipping');
140
+                return false;
141
+            }
142
+        }
143 143
 
144 144
 
145
-		/**
146
-		 * Used to delete expired cache data
147
-		 */
148
-		public function deleteExpiredCache(){
149
-			//for APC[u] is done automatically
150
-			return true;
151
-		}
145
+        /**
146
+         * Used to delete expired cache data
147
+         */
148
+        public function deleteExpiredCache(){
149
+            //for APC[u] is done automatically
150
+            return true;
151
+        }
152 152
 
153
-		/**
154
-		 * Remove all cache data
155
-		 */
156
-		public function clean(){
157
-			$this->logger->debug('Deleting of all cache data');
158
-			$cacheInfos = apc_cache_info('user');
159
-			if(empty($cacheInfos['cache_list'])){
160
-				$this->logger->info('No cache data were found skipping');
161
-				return false;
162
-			}
163
-			else{
164
-				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165
-				return apc_clear_cache('user');
166
-			}
167
-		}
153
+        /**
154
+         * Remove all cache data
155
+         */
156
+        public function clean(){
157
+            $this->logger->debug('Deleting of all cache data');
158
+            $cacheInfos = apc_cache_info('user');
159
+            if(empty($cacheInfos['cache_list'])){
160
+                $this->logger->info('No cache data were found skipping');
161
+                return false;
162
+            }
163
+            else{
164
+                $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
165
+                return apc_clear_cache('user');
166
+            }
167
+        }
168 168
 		
169 169
 		
170
-		/**
171
-		 * Check whether the cache feature for the handle is supported
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function isSupported(){
176
-			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177
-		}
170
+        /**
171
+         * Check whether the cache feature for the handle is supported
172
+         *
173
+         * @return bool
174
+         */
175
+        public function isSupported(){
176
+            return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
177
+        }
178 178
 
179
-		/**
180
-	     * Return the Log instance
181
-	     * @return Log
182
-	     */
183
-	    public function getLogger(){
184
-	      return $this->logger;
185
-	    }
179
+        /**
180
+         * Return the Log instance
181
+         * @return Log
182
+         */
183
+        public function getLogger(){
184
+            return $this->logger;
185
+        }
186 186
 
187
-	    /**
188
-	     * Set the log instance
189
-	     * @param Log $logger the log object
190
-	     */
191
-	    public function setLogger(Log $logger){
192
-	      $this->logger = $logger;
193
-	      return $this;
194
-	    }
187
+        /**
188
+         * Set the log instance
189
+         * @param Log $logger the log object
190
+         */
191
+        public function setLogger(Log $logger){
192
+            $this->logger = $logger;
193
+            return $this;
194
+        }
195 195
 		
196
-		/**
197
-		* Return the array of cache information
198
-		*
199
-		* @param string $key the cache key to get the cache information 
200
-		* @return boolean|array
201
-		*/
202
-		private function _getCacheInfo($key){
203
-			$caches = apc_cache_info('user');
204
-			if(! empty($caches['cache_list'])){
205
-				$cacheLists = $caches['cache_list'];
206
-				foreach ($cacheLists as $c){
207
-					if(isset($c['info']) && $c['info'] === $key){
208
-						return $c;
209
-					}
210
-				}
196
+        /**
197
+         * Return the array of cache information
198
+         *
199
+         * @param string $key the cache key to get the cache information 
200
+         * @return boolean|array
201
+         */
202
+        private function _getCacheInfo($key){
203
+            $caches = apc_cache_info('user');
204
+            if(! empty($caches['cache_list'])){
205
+                $cacheLists = $caches['cache_list'];
206
+                foreach ($cacheLists as $c){
207
+                    if(isset($c['info']) && $c['info'] === $key){
208
+                        return $c;
209
+                    }
210
+                }
211 211
 				
212
-			}
213
-			return false;
214
-		}
215
-	}
212
+            }
213
+            return false;
214
+        }
215
+    }
Please login to merge, or discard this patch.
core/classes/cache/CacheInterface.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,84 +1,84 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 	
27
-	interface CacheInterface{
27
+    interface CacheInterface{
28 28
 
29
-		/**
30
-		 * This is used to get the cache data using the key
31
-		 * @param  string $key the key to identify the cache data
32
-		 * @return mixed      the cache data if exists else return false
33
-		 */
34
-		public function get($key);
29
+        /**
30
+         * This is used to get the cache data using the key
31
+         * @param  string $key the key to identify the cache data
32
+         * @return mixed      the cache data if exists else return false
33
+         */
34
+        public function get($key);
35 35
 
36 36
 
37
-		/**
38
-		 * Save data to the cache
39
-		 * @param string  $key  the key to identify this cache data
40
-		 * @param mixed  $data the cache data to be saved
41
-		 * @param integer $ttl  the cache life time
42
-		 * @return boolean true if success otherwise will return false
43
-		 */
44
-		public function set($key, $data, $ttl = 0);
37
+        /**
38
+         * Save data to the cache
39
+         * @param string  $key  the key to identify this cache data
40
+         * @param mixed  $data the cache data to be saved
41
+         * @param integer $ttl  the cache life time
42
+         * @return boolean true if success otherwise will return false
43
+         */
44
+        public function set($key, $data, $ttl = 0);
45 45
 
46 46
 
47
-		/**
48
-		 * Delete the cache data for given key
49
-		 * @param  string $key the key for cache to be deleted
50
-		 * @return boolean      true if the cache is deleted, false if can't delete 
51
-		 * the cache or the cache with the given key not exist
52
-		 */
53
-		public function delete($key);
47
+        /**
48
+         * Delete the cache data for given key
49
+         * @param  string $key the key for cache to be deleted
50
+         * @return boolean      true if the cache is deleted, false if can't delete 
51
+         * the cache or the cache with the given key not exist
52
+         */
53
+        public function delete($key);
54 54
 		
55 55
 		
56
-		/**
57
-		 * Get the cache information for given key
58
-		 * @param  string $key the key for cache to get the information for
59
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
60
-		 * 'mtime' => creation time of the cache (Unix timestamp),
61
-		 * 'expire' => expiration time of the cache (Unix timestamp),
62
-		 * 'ttl' => the time to live of the cache in second
63
-		 */
64
-		public function getInfo($key);
56
+        /**
57
+         * Get the cache information for given key
58
+         * @param  string $key the key for cache to get the information for
59
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
60
+         * 'mtime' => creation time of the cache (Unix timestamp),
61
+         * 'expire' => expiration time of the cache (Unix timestamp),
62
+         * 'ttl' => the time to live of the cache in second
63
+         */
64
+        public function getInfo($key);
65 65
 
66 66
 
67
-		/**
68
-		 * Used to delete expired cache data
69
-		 */
70
-		public function deleteExpiredCache();
67
+        /**
68
+         * Used to delete expired cache data
69
+         */
70
+        public function deleteExpiredCache();
71 71
 
72
-		/**
73
-		 * Remove all cache data
74
-		 */
75
-		public function clean();
72
+        /**
73
+         * Remove all cache data
74
+         */
75
+        public function clean();
76 76
 		
77 77
 		
78
-		/**
79
-		 * Check whether the cache feature for the handle is supported
80
-		 *
81
-		 * @return bool
82
-		 */
83
-		public function isSupported();
84
-	}
78
+        /**
79
+         * Check whether the cache feature for the handle is supported
80
+         *
81
+         * @return bool
82
+         */
83
+        public function isSupported();
84
+    }
Please login to merge, or discard this patch.
core/classes/EventDispatcher.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,182 +1,182 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 * This class represent the event dispatcher management, permit to record the listener and 
29
-	 * also to dispatch the event
30
-	 */
27
+    /**
28
+     * This class represent the event dispatcher management, permit to record the listener and 
29
+     * also to dispatch the event
30
+     */
31 31
 	
32
-	class EventDispatcher{
32
+    class EventDispatcher{
33 33
 		
34
-		/**
35
-		 * The list of the registered listeners
36
-		 * @var array
37
-		 */
38
-		private $listeners = array();
34
+        /**
35
+         * The list of the registered listeners
36
+         * @var array
37
+         */
38
+        private $listeners = array();
39 39
 		
40 40
 
41
-		/**
42
-		 * The logger instance
43
-		 * @var Log
44
-		 */
45
-		private $logger;
41
+        /**
42
+         * The logger instance
43
+         * @var Log
44
+         */
45
+        private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
49
-			$this->logger->setLogger('Library::EventDispatcher');
50
-		}
47
+        public function __construct(){
48
+            $this->logger =& class_loader('Log', 'classes');
49
+            $this->logger->setLogger('Library::EventDispatcher');
50
+        }
51 51
 
52
-		/**
53
-		 * Register new listener
54
-		 * @param string   $eventName the name of the event to register for
55
-		 * @param callable $listener  the function or class method to receive the event information after dispatch
56
-		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
60
-				$this->logger->info('This event does not have the registered event listener before, adding new one');
61
-				$this->listeners[$eventName] = array();
62
-			}
63
-			else{
64
-				$this->logger->info('This event already have the registered listener, add this listener to the list');
65
-			}
66
-			$this->listeners[$eventName][] = $listener;
67
-		}
52
+        /**
53
+         * Register new listener
54
+         * @param string   $eventName the name of the event to register for
55
+         * @param callable $listener  the function or class method to receive the event information after dispatch
56
+         */
57
+        public function addListener($eventName, callable $listener){
58
+            $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
+            if(! isset($this->listeners[$eventName])){
60
+                $this->logger->info('This event does not have the registered event listener before, adding new one');
61
+                $this->listeners[$eventName] = array();
62
+            }
63
+            else{
64
+                $this->logger->info('This event already have the registered listener, add this listener to the list');
65
+            }
66
+            $this->listeners[$eventName][] = $listener;
67
+        }
68 68
 		
69
-		/**
70
-		 * Remove the event listener from list
71
-		 * @param  string   $eventName the event name
72
-		 * @param  callable $listener  the listener callback
73
-		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
77
-				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
80
-					unset($this->listeners[$eventName][$index]);
81
-				}
82
-				else{
83
-					$this->logger->info('Cannot found this listener in the event listener list');
84
-				}
85
-			}
86
-			else{
87
-				$this->logger->info('This event does not have this listener ignore remove');
88
-			}
89
-		}
69
+        /**
70
+         * Remove the event listener from list
71
+         * @param  string   $eventName the event name
72
+         * @param  callable $listener  the listener callback
73
+         */
74
+        public function removeListener($eventName, callable $listener){
75
+            $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
+            if(isset($this->listeners[$eventName])){
77
+                $this->logger->info('This event have the listeners, check if this listener exists');
78
+                if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
+                    $this->logger->info('Found the listener at index [' .$index. '] remove it');
80
+                    unset($this->listeners[$eventName][$index]);
81
+                }
82
+                else{
83
+                    $this->logger->info('Cannot found this listener in the event listener list');
84
+                }
85
+            }
86
+            else{
87
+                $this->logger->info('This event does not have this listener ignore remove');
88
+            }
89
+        }
90 90
 		
91
-		/**
92
-		 * Remove all the event listener. If event name is null will remove all listeners, else will just 
93
-		 * remove all listeners for this event
94
-		 * @param  string $eventName the event name
95
-		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
-			if($eventName !== null && isset($this->listeners[$eventName])){
99
-				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100
-				unset($this->listeners[$eventName]);
101
-			}
102
-			else{
103
-				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104
-				$this->listeners = array();
105
-			}
106
-		}
91
+        /**
92
+         * Remove all the event listener. If event name is null will remove all listeners, else will just 
93
+         * remove all listeners for this event
94
+         * @param  string $eventName the event name
95
+         */
96
+        public function removeAllListener($eventName = null){
97
+            $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
+            if($eventName !== null && isset($this->listeners[$eventName])){
99
+                $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100
+                unset($this->listeners[$eventName]);
101
+            }
102
+            else{
103
+                $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104
+                $this->listeners = array();
105
+            }
106
+        }
107 107
 		
108
-		/**
109
-		 * Get the list of listener for this event
110
-		 * @param string $eventName the event name
111
-		 * @return array the listeners for this event or empty array if this event does not contain any listener
112
-		 */
113
-		public function getListeners($eventName){
114
-			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115
-		}
108
+        /**
109
+         * Get the list of listener for this event
110
+         * @param string $eventName the event name
111
+         * @return array the listeners for this event or empty array if this event does not contain any listener
112
+         */
113
+        public function getListeners($eventName){
114
+            return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115
+        }
116 116
 		
117
-		/**
118
-		 * Dispatch the event to the registered listeners.
119
-		 * @param  mixed|object $event the event information
120
-		 * @return void|object if event need return, will return the final EventInfo object.
121
-		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof EventInfo){
124
-				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125
-				$event = new EventInfo((string) $event);
126
-			}			
127
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
129
-				$this->logger->info('This event need stopped, no need call any listener');
130
-				return;
131
-			}
132
-			if($event->returnBack){
133
-				$this->logger->info('This event need return back, return the result for future use');
134
-				return $this->dispatchToListerners($event);
135
-			}
136
-			else{
137
-				$this->logger->info('This event no need return back the result, just dispatch it');
138
-				$this->dispatchToListerners($event);
139
-			}
140
-		}
117
+        /**
118
+         * Dispatch the event to the registered listeners.
119
+         * @param  mixed|object $event the event information
120
+         * @return void|object if event need return, will return the final EventInfo object.
121
+         */	
122
+        public function dispatch($event){
123
+            if(! $event || !$event instanceof EventInfo){
124
+                $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125
+                $event = new EventInfo((string) $event);
126
+            }			
127
+            $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
+            if(isset($event->stop) && $event->stop){
129
+                $this->logger->info('This event need stopped, no need call any listener');
130
+                return;
131
+            }
132
+            if($event->returnBack){
133
+                $this->logger->info('This event need return back, return the result for future use');
134
+                return $this->dispatchToListerners($event);
135
+            }
136
+            else{
137
+                $this->logger->info('This event no need return back the result, just dispatch it');
138
+                $this->dispatchToListerners($event);
139
+            }
140
+        }
141 141
 		
142
-		/**
143
-		 * Dispatch the event to the registered listeners.
144
-		 * @param  object EventInfo $event  the event information
145
-		 * @return void|object if event need return, will return the final EventInfo instance.
146
-		 */	
147
-		private function dispatchToListerners(EventInfo $event){
148
-			$eBackup = $event;
149
-			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
153
-					return $event;
154
-				}
155
-				return;
156
-			}
157
-			else{
158
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159
-			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
162
-					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof EventInfo){
164
-						$event = $returnedEvent;
165
-					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
168
-					}
169
-				}
170
-				else{
171
-					call_user_func_array($listener, array($event));
172
-				}
173
-				if($event->stop){
174
-					break;
175
-				}
176
-			}
177
-			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
179
-				return $event;
180
-			}
181
-		}
182
-	}
142
+        /**
143
+         * Dispatch the event to the registered listeners.
144
+         * @param  object EventInfo $event  the event information
145
+         * @return void|object if event need return, will return the final EventInfo instance.
146
+         */	
147
+        private function dispatchToListerners(EventInfo $event){
148
+            $eBackup = $event;
149
+            $list = $this->getListeners($event->name);
150
+            if(empty($list)){
151
+                $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
+                if($event->returnBack){
153
+                    return $event;
154
+                }
155
+                return;
156
+            }
157
+            else{
158
+                $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159
+            }
160
+            foreach($list as $listener){
161
+                if($eBackup->returnBack){
162
+                    $returnedEvent = call_user_func_array($listener, array($event));
163
+                    if($returnedEvent instanceof EventInfo){
164
+                        $event = $returnedEvent;
165
+                    }
166
+                    else{
167
+                        show_error('This event [' .$event->name. '] need you return the event object after processing');
168
+                    }
169
+                }
170
+                else{
171
+                    call_user_func_array($listener, array($event));
172
+                }
173
+                if($event->stop){
174
+                    break;
175
+                }
176
+            }
177
+            //only test for original event may be during the flow some listeners change this parameter
178
+            if($eBackup->returnBack){
179
+                return $event;
180
+            }
181
+        }
182
+    }
Please login to merge, or discard this patch.
core/classes/Loader.php 1 patch
Indentation   +496 added lines, -496 removed lines patch added patch discarded remove patch
@@ -1,521 +1,521 @@
 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
-	*/
26
-	class Loader{
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
+    class Loader{
27 27
 		
28
-		/**
29
-		 * List of loaded resources
30
-		 * @var array
31
-		 */
32
-		public static $loaded = array();
28
+        /**
29
+         * List of loaded resources
30
+         * @var array
31
+         */
32
+        public static $loaded = array();
33 33
 		
34
-		/**
35
-		 * The logger instance
36
-		 * @var Log
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var Log
37
+         */
38
+        private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
42
-			//add the resources already loaded during application bootstrap
43
-			//in the list to prevent duplicate or loading the resources again.
44
-			static::$loaded = class_loaded();
41
+        public function __construct(){
42
+            //add the resources already loaded during application bootstrap
43
+            //in the list to prevent duplicate or loading the resources again.
44
+            static::$loaded = class_loaded();
45 45
 			
46
-			//Load resources from autoload configuration
47
-			$this->loadResourcesFromAutoloadConfig();
48
-		}
46
+            //Load resources from autoload configuration
47
+            $this->loadResourcesFromAutoloadConfig();
48
+        }
49 49
 
50
-		/**
51
-		 * Get the logger singleton instance
52
-		 * @return Log the logger instance
53
-		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Loader');
58
-			}
59
-			return self::$logger[0];
60
-		}
50
+        /**
51
+         * Get the logger singleton instance
52
+         * @return Log the logger instance
53
+         */
54
+        private static function getLogger(){
55
+            if(self::$logger == null){
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Loader');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62
-		/**
63
-		 * Load the model class
64
-		 *
65
-		 * @param  string $class    the class name to be loaded
66
-		 * @param  string $instance the name of the instance to use in super object
67
-		 *
68
-		 * @return void
69
-		 */
70
-		public static function model($class, $instance = null){
71
-			$logger = static::getLogger();
72
-			$class = str_ireplace('.php', '', $class);
73
-			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
75
-			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
77
-				//for module
78
-				if(strpos($class, '/') !== false){
79
-					$path = explode('/', $class);
80
-					if(isset($path[1])){
81
-						$instance = strtolower($path[1]);
82
-					}
83
-				}
84
-				else{
85
-					$instance = strtolower($class);
86
-				}
87
-			}
88
-			if(isset(static::$loaded[$instance])){
89
-				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90
-				return;
91
-			}
92
-			$classFilePath = APPS_MODEL_PATH . $file;
93
-			//first check if this model is in the module
94
-			$logger->debug('Checking model [' . $class . '] from module list ...');
95
-			$searchModuleName = null;
96
-			$obj = & get_instance();
97
-			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
99
-				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
101
-					$searchModuleName = $path[0];
102
-					$class = ucfirst($path[1]);
103
-				}
104
-			}
105
-			else{
106
-				$class = ucfirst($class);
107
-			}
62
+        /**
63
+         * Load the model class
64
+         *
65
+         * @param  string $class    the class name to be loaded
66
+         * @param  string $instance the name of the instance to use in super object
67
+         *
68
+         * @return void
69
+         */
70
+        public static function model($class, $instance = null){
71
+            $logger = static::getLogger();
72
+            $class = str_ireplace('.php', '', $class);
73
+            $class = trim($class, '/\\');
74
+            $file = ucfirst($class).'.php';
75
+            $logger->debug('Loading model [' . $class . '] ...');
76
+            if(! $instance){
77
+                //for module
78
+                if(strpos($class, '/') !== false){
79
+                    $path = explode('/', $class);
80
+                    if(isset($path[1])){
81
+                        $instance = strtolower($path[1]);
82
+                    }
83
+                }
84
+                else{
85
+                    $instance = strtolower($class);
86
+                }
87
+            }
88
+            if(isset(static::$loaded[$instance])){
89
+                $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90
+                return;
91
+            }
92
+            $classFilePath = APPS_MODEL_PATH . $file;
93
+            //first check if this model is in the module
94
+            $logger->debug('Checking model [' . $class . '] from module list ...');
95
+            $searchModuleName = null;
96
+            $obj = & get_instance();
97
+            //check if the request class contains module name
98
+            if(strpos($class, '/') !== false){
99
+                $path = explode('/', $class);
100
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
101
+                    $searchModuleName = $path[0];
102
+                    $class = ucfirst($path[1]);
103
+                }
104
+            }
105
+            else{
106
+                $class = ucfirst($class);
107
+            }
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
110
-				$searchModuleName = $obj->moduleName;
111
-			}
112
-			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
115
-				$classFilePath = $moduleModelFilePath;
116
-			}
117
-			else{
118
-				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119
-			}
120
-			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
122
-				require_once $classFilePath;
123
-				if(class_exists($class)){
124
-					$c = new $class();
125
-					$obj = & get_instance();
126
-					$obj->{$instance} = $c;
127
-					static::$loaded[$instance] = $class;
128
-					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129
-				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
132
-				}
133
-			}
134
-			else{
135
-				show_error('Unable to find the model [' . $class . ']');
136
-			}
137
-		}
109
+            if(! $searchModuleName && !empty($obj->moduleName)){
110
+                $searchModuleName = $obj->moduleName;
111
+            }
112
+            $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
+            if($moduleModelFilePath){
114
+                $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
115
+                $classFilePath = $moduleModelFilePath;
116
+            }
117
+            else{
118
+                $logger->info('Cannot find model [' . $class . '] from modules using the default location');
119
+            }
120
+            $logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
+            if(file_exists($classFilePath)){
122
+                require_once $classFilePath;
123
+                if(class_exists($class)){
124
+                    $c = new $class();
125
+                    $obj = & get_instance();
126
+                    $obj->{$instance} = $c;
127
+                    static::$loaded[$instance] = $class;
128
+                    $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129
+                }
130
+                else{
131
+                    show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
132
+                }
133
+            }
134
+            else{
135
+                show_error('Unable to find the model [' . $class . ']');
136
+            }
137
+        }
138 138
 
139 139
 
140
-		/**
141
-		 * Load the library class
142
-		 *
143
-		 * @param  string $class    the library class name to be loaded
144
-		 * @param  string $instance the instance name to use in super object
145
-		 * @param mixed $params the arguments to pass to the constructor
146
-		 *
147
-		 * @return void
148
-		 */
149
-		public static function library($class, $instance = null, array $params = array()){
150
-			$logger = static::getLogger();
151
-			$class = str_ireplace('.php', '', $class);
152
-			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
154
-			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
156
-				//for module
157
-				if(strpos($class, '/') !== false){
158
-					$path = explode('/', $class);
159
-					if(isset($path[1])){
160
-						$instance = strtolower($path[1]);
161
-					}
162
-				}
163
-				else{
164
-					$instance = strtolower($class);
165
-				}
166
-			}
167
-			if(isset(static::$loaded[$instance])){
168
-				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169
-				return;
170
-			}
171
-			$obj = & get_instance();
172
-			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
174
-				$logger->info('This is the Database library ...');
175
-				$dbInstance = & class_loader('Database', 'classes/database', $params);
176
-				$obj->{$instance} = $dbInstance;
177
-				static::$loaded[$instance] = $class;
178
-				$logger->info('Library Database loaded successfully.');
179
-				return;
180
-			}
181
-			$libraryFilePath = null;
182
-			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
184
-				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185
-				$class = ucfirst($class);
186
-				$logger->info('This library is a system library');
187
-			}
188
-			else{
189
-				$logger->info('This library is not a system library');	
190
-				//first check if this library is in the module
191
-				$logger->debug('Checking library [' . $class . '] from module list ...');
192
-				$searchModuleName = null;
193
-				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
195
-					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
197
-						$searchModuleName = $path[0];
198
-						$class = ucfirst($path[1]);
199
-					}
200
-				}
201
-				else{
202
-					$class = ucfirst($class);
203
-				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
205
-					$searchModuleName = $obj->moduleName;
206
-				}
207
-				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
210
-					$libraryFilePath = $moduleLibraryPath;
211
-				}
212
-				else{
213
-					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214
-				}
215
-			}
216
-			if(! $libraryFilePath){
217
-				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
219
-					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
221
-						$libraryFilePath = $filePath;
222
-						//is already found not to continue
223
-						break;
224
-					}
225
-				}
226
-			}
227
-			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
229
-				require_once $libraryFilePath;
230
-				if(class_exists($class)){
231
-					$c = $params ? new $class($params) : new $class();
232
-					$obj = & get_instance();
233
-					$obj->{$instance} = $c;
234
-					static::$loaded[$instance] = $class;
235
-					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236
-				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
239
-				}
240
-			}
241
-			else{
242
-				show_error('Unable to find library class [' . $class . ']');
243
-			}
244
-		}
140
+        /**
141
+         * Load the library class
142
+         *
143
+         * @param  string $class    the library class name to be loaded
144
+         * @param  string $instance the instance name to use in super object
145
+         * @param mixed $params the arguments to pass to the constructor
146
+         *
147
+         * @return void
148
+         */
149
+        public static function library($class, $instance = null, array $params = array()){
150
+            $logger = static::getLogger();
151
+            $class = str_ireplace('.php', '', $class);
152
+            $class = trim($class, '/\\');
153
+            $file = ucfirst($class) .'.php';
154
+            $logger->debug('Loading library [' . $class . '] ...');
155
+            if(! $instance){
156
+                //for module
157
+                if(strpos($class, '/') !== false){
158
+                    $path = explode('/', $class);
159
+                    if(isset($path[1])){
160
+                        $instance = strtolower($path[1]);
161
+                    }
162
+                }
163
+                else{
164
+                    $instance = strtolower($class);
165
+                }
166
+            }
167
+            if(isset(static::$loaded[$instance])){
168
+                $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169
+                return;
170
+            }
171
+            $obj = & get_instance();
172
+            //TODO for Database library
173
+            if(strtolower($class) == 'database'){
174
+                $logger->info('This is the Database library ...');
175
+                $dbInstance = & class_loader('Database', 'classes/database', $params);
176
+                $obj->{$instance} = $dbInstance;
177
+                static::$loaded[$instance] = $class;
178
+                $logger->info('Library Database loaded successfully.');
179
+                return;
180
+            }
181
+            $libraryFilePath = null;
182
+            $logger->debug('Check if this is a system library ...');
183
+            if(file_exists(CORE_LIBRARY_PATH . $file)){
184
+                $libraryFilePath = CORE_LIBRARY_PATH . $file;
185
+                $class = ucfirst($class);
186
+                $logger->info('This library is a system library');
187
+            }
188
+            else{
189
+                $logger->info('This library is not a system library');	
190
+                //first check if this library is in the module
191
+                $logger->debug('Checking library [' . $class . '] from module list ...');
192
+                $searchModuleName = null;
193
+                //check if the request class contains module name
194
+                if(strpos($class, '/') !== false){
195
+                    $path = explode('/', $class);
196
+                    if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
197
+                        $searchModuleName = $path[0];
198
+                        $class = ucfirst($path[1]);
199
+                    }
200
+                }
201
+                else{
202
+                    $class = ucfirst($class);
203
+                }
204
+                if(! $searchModuleName && !empty($obj->moduleName)){
205
+                    $searchModuleName = $obj->moduleName;
206
+                }
207
+                $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
+                if($moduleLibraryPath){
209
+                    $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
210
+                    $libraryFilePath = $moduleLibraryPath;
211
+                }
212
+                else{
213
+                    $logger->info('Cannot find library [' . $class . '] from modules using the default location');
214
+                }
215
+            }
216
+            if(! $libraryFilePath){
217
+                $searchDir = array(LIBRARY_PATH);
218
+                foreach($searchDir as $dir){
219
+                    $filePath = $dir . $file;
220
+                    if(file_exists($filePath)){
221
+                        $libraryFilePath = $filePath;
222
+                        //is already found not to continue
223
+                        break;
224
+                    }
225
+                }
226
+            }
227
+            $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
+            if($libraryFilePath){
229
+                require_once $libraryFilePath;
230
+                if(class_exists($class)){
231
+                    $c = $params ? new $class($params) : new $class();
232
+                    $obj = & get_instance();
233
+                    $obj->{$instance} = $c;
234
+                    static::$loaded[$instance] = $class;
235
+                    $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236
+                }
237
+                else{
238
+                    show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
239
+                }
240
+            }
241
+            else{
242
+                show_error('Unable to find library class [' . $class . ']');
243
+            }
244
+        }
245 245
 
246
-		/**
247
-		 * Load the helper
248
-		 *
249
-		 * @param  string $function the helper name to be loaded
250
-		 *
251
-		 * @return void
252
-		 */
253
-		public static function functions($function){
254
-			$logger = static::getLogger();
255
-			$function = str_ireplace('.php', '', $function);
256
-			$function = trim($function, '/\\');
257
-			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
259
-			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
261
-				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262
-				return;
263
-			}
264
-			$functionFilePath = null;
265
-			//first check if this helper is in the module
266
-			$logger->debug('Checking helper [' . $function . '] from module list ...');
267
-			$searchModuleName = null;
268
-			$obj = & get_instance();
269
-			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
271
-				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
273
-					$searchModuleName = $path[0];
274
-					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
276
-				}
277
-			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
279
-				$searchModuleName = $obj->moduleName;
280
-			}
281
-			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
284
-				$functionFilePath = $moduleFunctionPath;
285
-			}
286
-			else{
287
-				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288
-			}
289
-			if(! $functionFilePath){
290
-				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
292
-					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
294
-						$functionFilePath = $filePath;
295
-						//is already found not to continue
296
-						break;
297
-					}
298
-				}
299
-			}
300
-			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
302
-				require_once $functionFilePath;
303
-				static::$loaded['function_' . $function] = $functionFilePath;
304
-				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305
-			}
306
-			else{
307
-				show_error('Unable to find helper file [' . $file . ']');
308
-			}
309
-		}
246
+        /**
247
+         * Load the helper
248
+         *
249
+         * @param  string $function the helper name to be loaded
250
+         *
251
+         * @return void
252
+         */
253
+        public static function functions($function){
254
+            $logger = static::getLogger();
255
+            $function = str_ireplace('.php', '', $function);
256
+            $function = trim($function, '/\\');
257
+            $function = str_ireplace('function_', '', $function);
258
+            $file = 'function_'.$function.'.php';
259
+            $logger->debug('Loading helper [' . $function . '] ...');
260
+            if(isset(static::$loaded['function_' . $function])){
261
+                $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262
+                return;
263
+            }
264
+            $functionFilePath = null;
265
+            //first check if this helper is in the module
266
+            $logger->debug('Checking helper [' . $function . '] from module list ...');
267
+            $searchModuleName = null;
268
+            $obj = & get_instance();
269
+            //check if the request class contains module name
270
+            if(strpos($function, '/') !== false){
271
+                $path = explode('/', $function);
272
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
273
+                    $searchModuleName = $path[0];
274
+                    $function = 'function_' . $path[1] . '.php';
275
+                    $file = $path[0] . DS . 'function_'.$function.'.php';
276
+                }
277
+            }
278
+            if(! $searchModuleName && !empty($obj->moduleName)){
279
+                $searchModuleName = $obj->moduleName;
280
+            }
281
+            $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
+            if($moduleFunctionPath){
283
+                $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
284
+                $functionFilePath = $moduleFunctionPath;
285
+            }
286
+            else{
287
+                $logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288
+            }
289
+            if(! $functionFilePath){
290
+                $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
+                foreach($searchDir as $dir){
292
+                    $filePath = $dir . $file;
293
+                    if(file_exists($filePath)){
294
+                        $functionFilePath = $filePath;
295
+                        //is already found not to continue
296
+                        break;
297
+                    }
298
+                }
299
+            }
300
+            $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
+            if($functionFilePath){
302
+                require_once $functionFilePath;
303
+                static::$loaded['function_' . $function] = $functionFilePath;
304
+                $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305
+            }
306
+            else{
307
+                show_error('Unable to find helper file [' . $file . ']');
308
+            }
309
+        }
310 310
 
311
-		/**
312
-		 * Load the configuration file
313
-		 *
314
-		 * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
315
-		 *
316
-		 * @return void
317
-		 */
318
-		public static function config($filename){
319
-			$logger = static::getLogger();
320
-			$filename = str_ireplace('.php', '', $filename);
321
-			$filename = trim($filename, '/\\');
322
-			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
324
-			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
326
-				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327
-				return;
328
-			}
329
-			$configFilePath = CONFIG_PATH . $file;
330
-			//first check if this config is in the module
331
-			$logger->debug('Checking config [' . $filename . '] from module list ...');
332
-			$searchModuleName = null;
333
-			$obj = & get_instance();
334
-			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
336
-				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
338
-					$searchModuleName = $path[0];
339
-					$filename = $path[1] . '.php';
340
-				}
341
-			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
343
-				$searchModuleName = $obj->moduleName;
344
-			}
345
-			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
348
-				$configFilePath = $moduleConfigPath;
349
-			}
350
-			else{
351
-				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352
-			}
353
-			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
-			$config = array();
355
-			if(file_exists($configFilePath)){
356
-				require_once $configFilePath;
357
-				if(! empty($config) && is_array($config)){
358
-					Config::setAll($config);
359
-				}
360
-			}
361
-			else{
362
-				show_error('Unable to find config file ['. $configFilePath . ']');
363
-			}
364
-			static::$loaded['config_' . $filename] = $configFilePath;
365
-			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
366
-			$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
367
-			unset($config);
368
-		}
311
+        /**
312
+         * Load the configuration file
313
+         *
314
+         * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
315
+         *
316
+         * @return void
317
+         */
318
+        public static function config($filename){
319
+            $logger = static::getLogger();
320
+            $filename = str_ireplace('.php', '', $filename);
321
+            $filename = trim($filename, '/\\');
322
+            $filename = str_ireplace('config_', '', $filename);
323
+            $file = 'config_'.$filename.'.php';
324
+            $logger->debug('Loading configuration [' . $filename . '] ...');
325
+            if(isset(static::$loaded['config_' . $filename])){
326
+                $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327
+                return;
328
+            }
329
+            $configFilePath = CONFIG_PATH . $file;
330
+            //first check if this config is in the module
331
+            $logger->debug('Checking config [' . $filename . '] from module list ...');
332
+            $searchModuleName = null;
333
+            $obj = & get_instance();
334
+            //check if the request class contains module name
335
+            if(strpos($filename, '/') !== false){
336
+                $path = explode('/', $filename);
337
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
338
+                    $searchModuleName = $path[0];
339
+                    $filename = $path[1] . '.php';
340
+                }
341
+            }
342
+            if(! $searchModuleName && !empty($obj->moduleName)){
343
+                $searchModuleName = $obj->moduleName;
344
+            }
345
+            $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
+            if($moduleConfigPath){
347
+                $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
348
+                $configFilePath = $moduleConfigPath;
349
+            }
350
+            else{
351
+                $logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352
+            }
353
+            $logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
+            $config = array();
355
+            if(file_exists($configFilePath)){
356
+                require_once $configFilePath;
357
+                if(! empty($config) && is_array($config)){
358
+                    Config::setAll($config);
359
+                }
360
+            }
361
+            else{
362
+                show_error('Unable to find config file ['. $configFilePath . ']');
363
+            }
364
+            static::$loaded['config_' . $filename] = $configFilePath;
365
+            $logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
366
+            $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
367
+            unset($config);
368
+        }
369 369
 
370 370
 
371
-		/**
372
-		 * Load the language
373
-		 *
374
-		 * @param  string $language the language name to be loaded
375
-		 *
376
-		 * @return void
377
-		 */
378
-		public static function lang($language){
379
-			$logger = static::getLogger();
380
-			$language = str_ireplace('.php', '', $language);
381
-			$language = trim($language, '/\\');
382
-			$language = str_ireplace('lang_', '', $language);
383
-			$file = 'lang_'.$language.'.php';
384
-			$logger->debug('Loading language [' . $language . '] ...');
385
-			if(isset(static::$loaded['lang_' . $language])){
386
-				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387
-				return;
388
-			}
389
-			//determine the current language
390
-			$appLang = get_config('default_language');
391
-			//if the language exists in the cookie use it
392
-			$cfgKey = get_config('language_cookie_name');
393
-			$objCookie = & class_loader('Cookie');
394
-			$cookieLang = $objCookie->get($cfgKey);
395
-			if($cookieLang){
396
-				$appLang = $cookieLang;
397
-			}
398
-			$languageFilePath = null;
399
-			//first check if this language is in the module
400
-			$logger->debug('Checking language [' . $language . '] from module list ...');
401
-			$searchModuleName = null;
402
-			$obj = & get_instance();
403
-			//check if the request class contains module name
404
-			if(strpos($language, '/') !== false){
405
-				$path = explode('/', $language);
406
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
407
-					$searchModuleName = $path[0];
408
-					$language = 'lang_' . $path[1] . '.php';
409
-					$file = $path[0] . DS .$language;
410
-				}
411
-			}
412
-			if(! $searchModuleName && !empty($obj->moduleName)){
413
-				$searchModuleName = $obj->moduleName;
414
-			}
415
-			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
-			if($moduleLanguagePath){
417
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
418
-				$languageFilePath = $moduleLanguagePath;
419
-			}
420
-			else{
421
-				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
422
-			}
423
-			if(! $languageFilePath){
424
-				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
-				foreach($searchDir as $dir){
426
-					$filePath = $dir . $appLang . DS . $file;
427
-					if(file_exists($filePath)){
428
-						$languageFilePath = $filePath;
429
-						//is already found not to continue
430
-						break;
431
-					}
432
-				}
433
-			}
434
-			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
-			if($languageFilePath){
436
-				$lang = array();
437
-				require_once $languageFilePath;
438
-				if(! empty($lang) && is_array($lang)){
439
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
440
-					//Note: may be here the class 'Lang' not yet loaded
441
-					$langObj =& class_loader('Lang', 'classes');
442
-					$langObj->addLangMessages($lang);
443
-					//free the memory
444
-					unset($lang);
445
-				}
446
-				static::$loaded['lang_' . $language] = $languageFilePath;
447
-				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448
-			}
449
-			else{
450
-				show_error('Unable to find language file [' . $file . ']');
451
-			}
452
-		}
371
+        /**
372
+         * Load the language
373
+         *
374
+         * @param  string $language the language name to be loaded
375
+         *
376
+         * @return void
377
+         */
378
+        public static function lang($language){
379
+            $logger = static::getLogger();
380
+            $language = str_ireplace('.php', '', $language);
381
+            $language = trim($language, '/\\');
382
+            $language = str_ireplace('lang_', '', $language);
383
+            $file = 'lang_'.$language.'.php';
384
+            $logger->debug('Loading language [' . $language . '] ...');
385
+            if(isset(static::$loaded['lang_' . $language])){
386
+                $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387
+                return;
388
+            }
389
+            //determine the current language
390
+            $appLang = get_config('default_language');
391
+            //if the language exists in the cookie use it
392
+            $cfgKey = get_config('language_cookie_name');
393
+            $objCookie = & class_loader('Cookie');
394
+            $cookieLang = $objCookie->get($cfgKey);
395
+            if($cookieLang){
396
+                $appLang = $cookieLang;
397
+            }
398
+            $languageFilePath = null;
399
+            //first check if this language is in the module
400
+            $logger->debug('Checking language [' . $language . '] from module list ...');
401
+            $searchModuleName = null;
402
+            $obj = & get_instance();
403
+            //check if the request class contains module name
404
+            if(strpos($language, '/') !== false){
405
+                $path = explode('/', $language);
406
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
407
+                    $searchModuleName = $path[0];
408
+                    $language = 'lang_' . $path[1] . '.php';
409
+                    $file = $path[0] . DS .$language;
410
+                }
411
+            }
412
+            if(! $searchModuleName && !empty($obj->moduleName)){
413
+                $searchModuleName = $obj->moduleName;
414
+            }
415
+            $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
+            if($moduleLanguagePath){
417
+                $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
418
+                $languageFilePath = $moduleLanguagePath;
419
+            }
420
+            else{
421
+                $logger->info('Cannot find language [' . $language . '] from modules using the default location');
422
+            }
423
+            if(! $languageFilePath){
424
+                $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
+                foreach($searchDir as $dir){
426
+                    $filePath = $dir . $appLang . DS . $file;
427
+                    if(file_exists($filePath)){
428
+                        $languageFilePath = $filePath;
429
+                        //is already found not to continue
430
+                        break;
431
+                    }
432
+                }
433
+            }
434
+            $logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
+            if($languageFilePath){
436
+                $lang = array();
437
+                require_once $languageFilePath;
438
+                if(! empty($lang) && is_array($lang)){
439
+                    $logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
440
+                    //Note: may be here the class 'Lang' not yet loaded
441
+                    $langObj =& class_loader('Lang', 'classes');
442
+                    $langObj->addLangMessages($lang);
443
+                    //free the memory
444
+                    unset($lang);
445
+                }
446
+                static::$loaded['lang_' . $language] = $languageFilePath;
447
+                $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448
+            }
449
+            else{
450
+                show_error('Unable to find language file [' . $file . ']');
451
+            }
452
+        }
453 453
 
454 454
 
455
-		private function getResourcesFromAutoloadConfig(){
456
-			$autoloads = array();
457
-			$autoloads['config']    = array();
458
-			$autoloads['languages'] = array();
459
-			$autoloads['libraries'] = array();
460
-			$autoloads['models']    = array();
461
-			$autoloads['functions'] = array();
462
-			//loading of the resources in autoload.php configuration file
463
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
464
-				$autoload = array();
465
-				require_once CONFIG_PATH . 'autoload.php';
466
-				if(! empty($autoload) && is_array($autoload)){
467
-					$autoloads = array_merge($autoloads, $autoload);
468
-					unset($autoload);
469
-				}
470
-			}
471
-			//loading autoload configuration for modules
472
-			$modulesAutoloads = Module::getModulesAutoloadConfig();
473
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
474
-				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475
-			}
476
-			return $autoloads;
477
-		}
455
+        private function getResourcesFromAutoloadConfig(){
456
+            $autoloads = array();
457
+            $autoloads['config']    = array();
458
+            $autoloads['languages'] = array();
459
+            $autoloads['libraries'] = array();
460
+            $autoloads['models']    = array();
461
+            $autoloads['functions'] = array();
462
+            //loading of the resources in autoload.php configuration file
463
+            if(file_exists(CONFIG_PATH . 'autoload.php')){
464
+                $autoload = array();
465
+                require_once CONFIG_PATH . 'autoload.php';
466
+                if(! empty($autoload) && is_array($autoload)){
467
+                    $autoloads = array_merge($autoloads, $autoload);
468
+                    unset($autoload);
469
+                }
470
+            }
471
+            //loading autoload configuration for modules
472
+            $modulesAutoloads = Module::getModulesAutoloadConfig();
473
+            if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
474
+                $autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475
+            }
476
+            return $autoloads;
477
+        }
478 478
 
479
-		/**
480
-		 * Load the autoload configuration
481
-		 * @return void
482
-		 */
483
-		private function loadResourcesFromAutoloadConfig(){
484
-			$autoloads = array();
485
-			$autoloads['config']    = array();
486
-			$autoloads['languages'] = array();
487
-			$autoloads['libraries'] = array();
488
-			$autoloads['models']    = array();
489
-			$autoloads['functions'] = array();
479
+        /**
480
+         * Load the autoload configuration
481
+         * @return void
482
+         */
483
+        private function loadResourcesFromAutoloadConfig(){
484
+            $autoloads = array();
485
+            $autoloads['config']    = array();
486
+            $autoloads['languages'] = array();
487
+            $autoloads['libraries'] = array();
488
+            $autoloads['models']    = array();
489
+            $autoloads['functions'] = array();
490 490
 
491
-			$list = $this->getResourcesFromAutoloadConfig();
492
-			$autoloads = array_merge($autoloads, $list);
491
+            $list = $this->getResourcesFromAutoloadConfig();
492
+            $autoloads = array_merge($autoloads, $list);
493 493
 			
494
-			//config autoload
495
-			$this->loadAutoloadResourcesArray('config', $autoloads['config']);
494
+            //config autoload
495
+            $this->loadAutoloadResourcesArray('config', $autoloads['config']);
496 496
 			
497
-			//languages autoload
498
-			$this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
497
+            //languages autoload
498
+            $this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
499 499
 			
500
-			//libraries autoload
501
-			$this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
500
+            //libraries autoload
501
+            $this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
502 502
 
503
-			//models autoload
504
-			$this->loadAutoloadResourcesArray('model', $autoloads['models']);
503
+            //models autoload
504
+            $this->loadAutoloadResourcesArray('model', $autoloads['models']);
505 505
 			
506
-			//functions autoload
507
-			$this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
508
-		}
506
+            //functions autoload
507
+            $this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
508
+        }
509 509
 
510
-		/**
511
-		 * Load the resources autoload array
512
-		 * @param  string $method    this object method name to call
513
-		 * @param  array  $resources the resource to load
514
-		 * @return void            
515
-		 */
516
-		private function loadAutoloadResourcesArray($method, array $resources){
517
-			foreach ($resources as $name) {
518
-				$this->{$method}($name);
519
-			}
520
-		}
521
-	}
510
+        /**
511
+         * Load the resources autoload array
512
+         * @param  string $method    this object method name to call
513
+         * @param  array  $resources the resource to load
514
+         * @return void            
515
+         */
516
+        private function loadAutoloadResourcesArray($method, array $resources){
517
+            foreach ($resources as $name) {
518
+                $this->{$method}($name);
519
+            }
520
+        }
521
+    }
Please login to merge, or discard this patch.
core/classes/Controller.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -1,145 +1,145 @@
 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{
27
+    class Controller{
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
-		/**
42
-		 * The logger instance
43
-		 * @var Log
44
-		 */
45
-		protected $logger;
41
+        /**
42
+         * The logger instance
43
+         * @var Log
44
+         */
45
+        protected $logger;
46 46
 
47
-		/**
48
-		 * Class constructor
49
-		 * @param object $logger the Log instance to use if is null will create one
50
-		 */
51
-		public function __construct(Log $logger = null){
52
-			//setting the Log instance
53
-			$this->setLoggerFromParamOrCreateNewInstance($logger);
47
+        /**
48
+         * Class constructor
49
+         * @param object $logger the Log instance to use if is null will create one
50
+         */
51
+        public function __construct(Log $logger = null){
52
+            //setting the Log instance
53
+            $this->setLoggerFromParamOrCreateNewInstance($logger);
54 54
 			
55
-			//instance of the super object
56
-			self::$instance = & $this;
55
+            //instance of the super object
56
+            self::$instance = & $this;
57 57
 			
58
-			//load the required resources
59
-			$this->loadRequiredResources();
58
+            //load the required resources
59
+            $this->loadRequiredResources();
60 60
 			
61
-			//set the cache using the configuration
62
-			$this->setCacheFromParamOrConfig(null);
61
+            //set the cache using the configuration
62
+            $this->setCacheFromParamOrConfig(null);
63 63
 			
64
-			//set application session configuration
65
-			$this->logger->debug('Setting PHP application session handler');
66
-			set_session_config();
64
+            //set application session configuration
65
+            $this->logger->debug('Setting PHP application session handler');
66
+            set_session_config();
67 67
 			
68
-			//set module using the router
69
-			$this->setModuleNameFromRouter();
68
+            //set module using the router
69
+            $this->setModuleNameFromRouter();
70 70
 
71
-			//dispatch the loaded instance of super controller event
72
-			$this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
73
-		}
71
+            //dispatch the loaded instance of super controller event
72
+            $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
73
+        }
74 74
 
75 75
 
76
-		/**
77
-		 * This is a very useful method it's used to get the super object instance
78
-		 * @return Controller the super object instance
79
-		 */
80
-		public static function &get_instance(){
81
-			return self::$instance;
82
-		}
76
+        /**
77
+         * This is a very useful method it's used to get the super object instance
78
+         * @return Controller the super object instance
79
+         */
80
+        public static function &get_instance(){
81
+            return self::$instance;
82
+        }
83 83
 
84
-		/**
85
-		 * This method is used to set the module name
86
-		 */
87
-		protected function setModuleNameFromRouter(){
88
-			//determine the current module
89
-			if(isset($this->router) && $this->router->getModule()){
90
-				$this->moduleName = $this->router->getModule();
91
-			}
92
-		}
84
+        /**
85
+         * This method is used to set the module name
86
+         */
87
+        protected function setModuleNameFromRouter(){
88
+            //determine the current module
89
+            if(isset($this->router) && $this->router->getModule()){
90
+                $this->moduleName = $this->router->getModule();
91
+            }
92
+        }
93 93
 
94
-		/**
95
-		 * Set the cache using the argument otherwise will use the configuration
96
-		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
97
-		 */
98
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
99
-			$this->logger->debug('Setting the cache handler instance');
100
-			//set cache handler instance
101
-			if(get_config('cache_enable', false)){
102
-				if ($cache !== null){
103
-					$this->cache = $cache;
104
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
105
-					$this->cache = $this->{strtolower(get_config('cache_handler'))};
106
-					unset($this->{strtolower(get_config('cache_handler'))});
107
-				} 
108
-			}
109
-		}
94
+        /**
95
+         * Set the cache using the argument otherwise will use the configuration
96
+         * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
97
+         */
98
+        protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
99
+            $this->logger->debug('Setting the cache handler instance');
100
+            //set cache handler instance
101
+            if(get_config('cache_enable', false)){
102
+                if ($cache !== null){
103
+                    $this->cache = $cache;
104
+                } else if (isset($this->{strtolower(get_config('cache_handler'))})){
105
+                    $this->cache = $this->{strtolower(get_config('cache_handler'))};
106
+                    unset($this->{strtolower(get_config('cache_handler'))});
107
+                } 
108
+            }
109
+        }
110 110
 
111
-		/**
112
-		 * Set the Log instance using argument or create new instance
113
-		 * @param object $logger the Log instance if not null
114
-		 */
115
-		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116
-			if($logger !== null){
117
-	          $this->logger = $logger;
118
-	        }
119
-	        else{
120
-	            $this->logger =& class_loader('Log', 'classes');
121
-				$this->logger->setLogger('MainController');
122
-	        }
123
-		}
111
+        /**
112
+         * Set the Log instance using argument or create new instance
113
+         * @param object $logger the Log instance if not null
114
+         */
115
+        protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116
+            if($logger !== null){
117
+                $this->logger = $logger;
118
+            }
119
+            else{
120
+                $this->logger =& class_loader('Log', 'classes');
121
+                $this->logger->setLogger('MainController');
122
+            }
123
+        }
124 124
 
125
-		/**
126
-		 * This method is used to load the required resources for framework to work
127
-		 * @return void 
128
-		 */
129
-		private function loadRequiredResources(){
130
-			$this->logger->debug('Adding the loaded classes to the super instance');
131
-			foreach (class_loaded() as $var => $class){
132
-				$this->$var =& class_loader($class);
133
-			}
125
+        /**
126
+         * This method is used to load the required resources for framework to work
127
+         * @return void 
128
+         */
129
+        private function loadRequiredResources(){
130
+            $this->logger->debug('Adding the loaded classes to the super instance');
131
+            foreach (class_loaded() as $var => $class){
132
+                $this->$var =& class_loader($class);
133
+            }
134 134
 
135
-			$this->logger->debug('Loading the required classes into super instance');
136
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
137
-			$this->loader =& class_loader('Loader', 'classes');
138
-			$this->lang =& class_loader('Lang', 'classes');
139
-			$this->request =& class_loader('Request', 'classes');
140
-			//dispatch the request instance created event
141
-			$this->eventdispatcher->dispatch('REQUEST_CREATED');
142
-			$this->response =& class_loader('Response', 'classes', 'classes');
143
-		}
135
+            $this->logger->debug('Loading the required classes into super instance');
136
+            $this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
137
+            $this->loader =& class_loader('Loader', 'classes');
138
+            $this->lang =& class_loader('Lang', 'classes');
139
+            $this->request =& class_loader('Request', 'classes');
140
+            //dispatch the request instance created event
141
+            $this->eventdispatcher->dispatch('REQUEST_CREATED');
142
+            $this->response =& class_loader('Response', 'classes', 'classes');
143
+        }
144 144
 
145
-	}
145
+    }
Please login to merge, or discard this patch.
core/classes/model/DBSessionHandlerModel.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,39 +1,39 @@  discard block
 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
-	/**
28
-	 * DB session handler class
29
-	 */
30
- 	abstract class DBSessionHandlerModel extends Model {
27
+    /**
28
+     * DB session handler class
29
+     */
30
+        abstract class DBSessionHandlerModel extends Model {
31 31
 		
32
-		/**
33
-		 * The session table columns to use
34
-		 * @var array
35
-		 * @example
36
-		 * 	array(
32
+        /**
33
+         * The session table columns to use
34
+         * @var array
35
+         * @example
36
+         * 	array(
37 37
 				'sid' => '', //VARCHAR(255) Note: this a primary key
38 38
 				'sdata' => '', //TEXT
39 39
 				'stime' => '', //unix timestamp (INT|BIGINT)
@@ -42,41 +42,41 @@  discard block
 block discarded – undo
42 42
 				'sbrowser' => '', //VARCHAR(255) 
43 43
 				'skey' => '' //VARCHAR(255) 
44 44
 			);
45
-		 */
46
-		protected $sessionTableColumns = array();
45
+         */
46
+        protected $sessionTableColumns = array();
47 47
 
48
-		public function __construct(Database $db = null){
49
-			parent::__construct($db);
50
-		}
48
+        public function __construct(Database $db = null){
49
+            parent::__construct($db);
50
+        }
51 51
 
52
-		/**
53
-		 * Return the session database table columns
54
-		 * @return array 
55
-		 */
56
-		public function getSessionTableColumns(){
57
-			return $this->sessionTableColumns;
58
-		}
52
+        /**
53
+         * Return the session database table columns
54
+         * @return array 
55
+         */
56
+        public function getSessionTableColumns(){
57
+            return $this->sessionTableColumns;
58
+        }
59 59
 
60
-		/**
61
-		 * Set the session database table columns
62
-		 * @param array $columns the columns definition
63
-		 */
64
-		public function setSessionTableColumns(array $columns){
65
-			$this->sessionTableColumns = $columns;
66
-			return $this;
67
-		}
60
+        /**
61
+         * Set the session database table columns
62
+         * @param array $columns the columns definition
63
+         */
64
+        public function setSessionTableColumns(array $columns){
65
+            $this->sessionTableColumns = $columns;
66
+            return $this;
67
+        }
68 68
 
69
-		/**
70
-		 * Delete the expire session
71
-		 * @param  int $time the unix timestamp
72
-		 * @return int       affected rows
73
-		 */
74
-		abstract public function deleteByTime($time);
69
+        /**
70
+         * Delete the expire session
71
+         * @param  int $time the unix timestamp
72
+         * @return int       affected rows
73
+         */
74
+        abstract public function deleteByTime($time);
75 75
 
76 76
 		
77
-		/**
78
-		 * How to get the value of the table column key. Generally is the session key
79
-		 * @return mixed the key value like used to identify the data
80
-		 */
81
-		abstract public function getKeyValue();
82
-	}
77
+        /**
78
+         * How to get the value of the table column key. Generally is the session key
79
+         * @return mixed the key value like used to identify the data
80
+         */
81
+        abstract public function getKeyValue();
82
+    }
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28 28
     /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
         protected $_temporary_return_type = NULL;
121 121
     	
122 122
     	
123
-    	/**
123
+        /**
124 124
     		The database cache time 
125
-    	*/
126
-    	protected $dbCacheTime = 0;
125
+         */
126
+        protected $dbCacheTime = 0;
127 127
 
128 128
         /**
129 129
          * Instance of the Loader class
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
             }
152 152
             else{
153 153
                 $obj = & get_instance();
154
-        		if (isset($obj->database) && is_object($obj->database)){
154
+                if (isset($obj->database) && is_object($obj->database)){
155 155
                     /**
156
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
-                    * to prevent duplication
158
-                    */
159
-        			$this->setDatabaseInstance(clone $obj->database);
156
+                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
+                     * to prevent duplication
158
+                     */
159
+                    $this->setDatabaseInstance(clone $obj->database);
160 160
                 }
161 161
             }
162 162
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
          */
175 175
         public function get($primary_value)
176 176
         {
177
-    		return $this->get_by($this->primary_key, $primary_value);
177
+            return $this->get_by($this->primary_key, $primary_value);
178 178
         }
179 179
 
180 180
         /**
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
             {
190 190
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
191 191
             }
192
-    		$this->_set_where($where);
192
+            $this->_set_where($where);
193 193
 
194 194
             $this->trigger('before_get');
195
-			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
195
+            $type = $this->_temporary_return_type == 'array' ? 'array' : false;
196 196
             $this->getQueryBuilder()->from($this->_table);
197
-			$row = $this->_database->get($type);
197
+            $row = $this->_database->get($type);
198 198
             $this->_temporary_return_type = $this->return_type;
199 199
             $row = $this->trigger('after_get', $row);
200 200
             $this->_with = array();
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
             {
232 232
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
233 233
             }
234
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
234
+            $type = $this->_temporary_return_type == 'array' ? 'array':false;
235 235
             $this->getQueryBuilder()->from($this->_table);
236
-			$result = $this->_database->getAll($type);
236
+            $result = $this->_database->getAll($type);
237 237
             $this->_temporary_return_type = $this->return_type;
238 238
 
239 239
             foreach ($result as $key => &$row)
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         /**
248 248
          * Insert a new row into the table. $data should be an associative array
249 249
          * of data to be inserted. Returns newly created ID.
250
-		 * @see Database::insert
250
+         * @see Database::insert
251 251
          */
252 252
         public function insert($data = array(), $skip_validation = FALSE, $escape = true)
253 253
         {
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
             {
261 261
                 $data = $this->trigger('before_create', $data);
262 262
                 $this->getQueryBuilder()->from($this->_table);
263
-				$this->_database->insert($data, $escape);
263
+                $this->_database->insert($data, $escape);
264 264
                 $insert_id = $this->_database->insertId();
265 265
                 $this->trigger('after_create', $insert_id);
266
-				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
-				return ! $insert_id ? true : $insert_id;
266
+                //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
+                return ! $insert_id ? true : $insert_id;
268 268
             }
269 269
             else
270 270
             {
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
             {
325 325
                 $this->getQueryBuilder()->in($this->primary_key, $primary_values)
326 326
                                         ->from($this->_table);
327
-				$result = $this->_database->update($data, $escape);
327
+                $result = $this->_database->update($data, $escape);
328 328
                 $this->trigger('after_update', array($data, $result));
329 329
                 return $result;
330 330
             }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             {
357 357
                 $this->_set_where($args);
358 358
                 $this->getQueryBuilder()->from($this->_table);
359
-				$result = $this->_database->update($data);
359
+                $result = $this->_database->update($data);
360 360
                 $this->trigger('after_update', array($data, $result));
361 361
                 return $result;
362 362
             }
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         {
374 374
             $data = $this->trigger('before_update', $data);
375 375
             $this->getQueryBuilder()->from($this->_table);
376
-			$result = $this->_database->update($data, $escape);
376
+            $result = $this->_database->update($data, $escape);
377 377
             $this->trigger('after_update', array($data, $result));
378 378
             return $result;
379 379
         }
@@ -385,16 +385,16 @@  discard block
 block discarded – undo
385 385
         {
386 386
             $this->trigger('before_delete', $id);
387 387
             $this->getQueryBuilder()->where($this->primary_key, $id);
388
-			$result = false;
388
+            $result = false;
389 389
             if ($this->soft_delete)
390 390
             {
391 391
                 $this->getQueryBuilder()->from($this->_table);	
392
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
392
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
393 393
             }
394 394
             else
395 395
             {
396 396
                 $this->getQueryBuilder()->from($this->_table); 
397
-				$result = $this->_database->delete();
397
+                $result = $this->_database->delete();
398 398
             }
399 399
 
400 400
             $this->trigger('after_delete', $result);
@@ -407,18 +407,18 @@  discard block
 block discarded – undo
407 407
         public function delete_by()
408 408
         {
409 409
             $where = func_get_args();
410
-    	    $where = $this->trigger('before_delete', $where);
410
+            $where = $this->trigger('before_delete', $where);
411 411
             $this->_set_where($where);
412
-			$result = false;
412
+            $result = false;
413 413
             if ($this->soft_delete)
414 414
             {
415 415
                 $this->getQueryBuilder()->from($this->_table);	
416
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
416
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
417 417
             }
418 418
             else
419 419
             {
420 420
                 $this->getQueryBuilder()->from($this->_table); 
421
-				$result = $this->_database->delete();
421
+                $result = $this->_database->delete();
422 422
             }
423 423
             $this->trigger('after_delete', $result);
424 424
             return $result;
@@ -431,16 +431,16 @@  discard block
 block discarded – undo
431 431
         {
432 432
             $primary_values = $this->trigger('before_delete', $primary_values);
433 433
             $this->getQueryBuilder()->in($this->primary_key, $primary_values);
434
-			$result = false;
434
+            $result = false;
435 435
             if ($this->soft_delete)
436 436
             {
437 437
                 $this->getQueryBuilder()->from($this->_table);	
438
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
438
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
439 439
             }
440 440
             else
441 441
             {
442 442
                 $this->getQueryBuilder()->from($this->_table); 
443
-				$result = $this->_database->delete();
443
+                $result = $this->_database->delete();
444 444
             }
445 445
             $this->trigger('after_delete', $result);
446 446
             return $result;
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
          */
453 453
         public function truncate()
454 454
         {
455
-			$this->getQueryBuilder()->from($this->_table); 
456
-			$result = $this->_database->delete();
455
+            $this->getQueryBuilder()->from($this->_table); 
456
+            $result = $this->_database->delete();
457 457
             return $result;
458 458
         }
459 459
 
@@ -471,14 +471,14 @@  discard block
 block discarded – undo
471 471
             return $this;
472 472
         }
473 473
 		
474
-		/**
475
-		* Relationship
476
-		*/
474
+        /**
475
+         * Relationship
476
+         */
477 477
         public function relate($row)
478 478
         {
479
-    		if (empty($row))
479
+            if (empty($row))
480 480
             {
481
-    		    return $row;
481
+                return $row;
482 482
             }
483 483
 
484 484
             $row = $this->relateBelongsTo($row);
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
512 512
             }
513 513
             $this->getQueryBuilder()
514
-									 ->select(array($key, $value))
515
-									 ->from($this->_table);
516
-			$result = $this->_database->getAll();
514
+                                        ->select(array($key, $value))
515
+                                        ->from($this->_table);
516
+            $result = $this->_database->getAll();
517 517
             $options = array();
518 518
             foreach ($result as $row)
519 519
             {
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
             $where = func_get_args();
536 536
             $this->_set_where($where);
537 537
             $this->getQueryBuilder()->from($this->_table);
538
-			$this->_database->getAll();
538
+            $this->_database->getAll();
539 539
             return $this->_database->numRows();
540 540
         }
541 541
 
@@ -548,20 +548,20 @@  discard block
 block discarded – undo
548 548
             {
549 549
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
550 550
             }
551
-			$this->getQueryBuilder()->from($this->_table);
552
-			$this->_database->getAll();
551
+            $this->getQueryBuilder()->from($this->_table);
552
+            $this->_database->getAll();
553 553
             return $this->_database->numRows();
554 554
         }
555 555
 		
556
-		/**
557
-		* Enabled cache temporary
558
-		*/
559
-		public function cached($ttl = 0){
560
-		  if ($ttl > 0){
561
-			$this->_database = $this->_database->cached($ttl);
562
-		  }
563
-		  return $this;
564
-		}
556
+        /**
557
+         * Enabled cache temporary
558
+         */
559
+        public function cached($ttl = 0){
560
+            if ($ttl > 0){
561
+            $this->_database = $this->_database->cached($ttl);
562
+            }
563
+            return $this;
564
+        }
565 565
 
566 566
         /**
567 567
          * Tell the class to skip the insert validation
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
585 585
          */
586 586
         public function get_next_id()
587 587
         {
588
-			$this->getQueryBuilder()->select('AUTO_INCREMENT')
589
-									->from('information_schema.TABLES')
590
-									->where('TABLE_NAME', $this->_table)
591
-									->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
588
+            $this->getQueryBuilder()->select('AUTO_INCREMENT')
589
+                                    ->from('information_schema.TABLES')
590
+                                    ->where('TABLE_NAME', $this->_table)
591
+                                    ->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
592 592
             return (int) $this->_database->get()->AUTO_INCREMENT;
593 593
         }
594 594
 
@@ -711,24 +711,24 @@  discard block
 block discarded – undo
711 711
             {
712 712
                 if (is_object($row))
713 713
                 {
714
-					if (isset($row->$attr)){
715
-						unset($row->$attr);
716
-					}
714
+                    if (isset($row->$attr)){
715
+                        unset($row->$attr);
716
+                    }
717 717
                 }
718 718
                 else
719 719
                 {
720
-					if (isset($row[$attr])){
721
-						unset($row[$attr]);
722
-					}
720
+                    if (isset($row[$attr])){
721
+                        unset($row[$attr]);
722
+                    }
723 723
                 }
724 724
             }
725 725
             return $row;
726 726
         }
727 727
 		
728
-		 /**
729
-         * Return the database instance
730
-         * @return Database the database instance
731
-         */
728
+            /**
729
+             * Return the database instance
730
+             * @return Database the database instance
731
+             */
732 732
         public function getDatabaseInstance(){
733 733
             return $this->_database;
734 734
         }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
          * set the Database instance for future use
738 738
          * @param Database $db the database object
739 739
          */
740
-         public function setDatabaseInstance($db){
740
+            public function setDatabaseInstance($db){
741 741
             $this->_database = $db;
742 742
             if ($this->dbCacheTime > 0){
743 743
                 $this->_database->setCache($this->dbCacheTime);
@@ -756,14 +756,14 @@  discard block
 block discarded – undo
756 756
         /**
757 757
          * Set the loader instance for future use
758 758
          * @param Loader $loader the loader object
759
-		 * @return object
759
+         * @return object
760 760
          */
761
-         public function setLoader($loader){
761
+            public function setLoader($loader){
762 762
             $this->loaderInstance = $loader;
763 763
             return $this;
764 764
         }
765 765
 
766
-		/**
766
+        /**
767 767
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
768 768
          * @return object the DatabaseQueryBuilder instance
769 769
          */
@@ -774,9 +774,9 @@  discard block
 block discarded – undo
774 774
         /**
775 775
          * Set the DatabaseQueryBuilder instance for future use
776 776
          * @param object $queryBuilder the DatabaseQueryBuilder object
777
-		 * @return object
777
+         * @return object
778 778
          */
779
-         public function setQueryBuilder($queryBuilder){
779
+            public function setQueryBuilder($queryBuilder){
780 780
             $this->_database->setQueryBuilder($queryBuilder);
781 781
             return $this;
782 782
         }
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
         /**
794 794
          * Set the form validation instance for future use
795 795
          * @param FormValidation $fv the form validation object
796
-		 * @return object
796
+         * @return object
797 797
          */
798
-         public function setFormValidation($fv){
798
+            public function setFormValidation($fv){
799 799
             $this->formValidationInstance = $fv;
800 800
             return $this;
801 801
         }
@@ -836,12 +836,12 @@  discard block
 block discarded – undo
836 836
          * INTERNAL METHODS
837 837
          * ------------------------------------------------------------ */
838 838
 
839
-		/**
840
-		* relate for the relation "belongs_to"
841
-		* @return mixed
842
-		*/
843
-		protected function relateBelongsTo($row){
844
-			foreach ($this->belongs_to as $key => $value)
839
+        /**
840
+         * relate for the relation "belongs_to"
841
+         * @return mixed
842
+         */
843
+        protected function relateBelongsTo($row){
844
+            foreach ($this->belongs_to as $key => $value)
845 845
             {
846 846
                 if (is_string($value))
847 847
                 {
@@ -872,15 +872,15 @@  discard block
 block discarded – undo
872 872
                     }
873 873
                 }
874 874
             }
875
-			return $row;
876
-		}
877
-
878
-		/**
879
-		* relate for the relation "has_many"
880
-		* @return mixed
881
-		*/
882
-		protected function relateHasMany($row){
883
-			foreach ($this->has_many as $key => $value)
875
+            return $row;
876
+        }
877
+
878
+        /**
879
+         * relate for the relation "has_many"
880
+         * @return mixed
881
+         */
882
+        protected function relateHasMany($row){
883
+            foreach ($this->has_many as $key => $value)
884 884
             {
885 885
                 if (is_string($value))
886 886
                 {
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
                     }
912 912
                 }
913 913
             }
914
-			return $row;
915
-		}
914
+            return $row;
915
+        }
916 916
 		
917 917
         /**
918 918
          * Trigger an event and call its observers. Pass through the event name
@@ -977,30 +977,30 @@  discard block
 block discarded – undo
977 977
         }
978 978
 		
979 979
 		
980
-		/**
981
-		* Set WHERE parameters, when is array
982
-		* @param array $params
983
-		*/
984
-		protected function _set_where_array(array $params){
985
-			foreach ($params as $field => $filter)
986
-			{
987
-				if (is_array($filter))
988
-				{
989
-					$this->getQueryBuilder()->in($field, $filter);
990
-				}
991
-				else
992
-				{
993
-					if (is_int($field))
994
-					{
995
-						$this->getQueryBuilder()->where($filter);
996
-					}
997
-					else
998
-					{
999
-						$this->getQueryBuilder()->where($field, $filter);
1000
-					}
1001
-				}
1002
-			}
1003
-		}
980
+        /**
981
+         * Set WHERE parameters, when is array
982
+         * @param array $params
983
+         */
984
+        protected function _set_where_array(array $params){
985
+            foreach ($params as $field => $filter)
986
+            {
987
+                if (is_array($filter))
988
+                {
989
+                    $this->getQueryBuilder()->in($field, $filter);
990
+                }
991
+                else
992
+                {
993
+                    if (is_int($field))
994
+                    {
995
+                        $this->getQueryBuilder()->where($filter);
996
+                    }
997
+                    else
998
+                    {
999
+                        $this->getQueryBuilder()->where($field, $filter);
1000
+                    }
1001
+                }
1002
+            }
1003
+        }
1004 1004
 
1005 1005
 
1006 1006
         /**
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
             {
1017 1017
                 $this->getQueryBuilder()->where($params[0]);
1018 1018
             }
1019
-        	else if (count($params) == 2)
1020
-    		{
1019
+            else if (count($params) == 2)
1020
+            {
1021 1021
                 if (is_array($params[1]))
1022 1022
                 {
1023 1023
                     $this->getQueryBuilder()->in($params[0], $params[1]);
@@ -1026,11 +1026,11 @@  discard block
 block discarded – undo
1026 1026
                 {
1027 1027
                     $this->getQueryBuilder()->where($params[0], $params[1]);
1028 1028
                 }
1029
-    		}
1030
-    		else if (count($params) == 3)
1031
-    		{
1032
-    			$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
-    		}
1029
+            }
1030
+            else if (count($params) == 3)
1031
+            {
1032
+                $this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
+            }
1034 1034
             else
1035 1035
             {
1036 1036
                 if (is_array($params[1]))
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 
1047 1047
         /**
1048 1048
             Shortcut to controller
1049
-        */
1049
+         */
1050 1050
         public function __get($key){
1051 1051
             return get_instance()->{$key};
1052 1052
         }
Please login to merge, or discard this patch.
core/classes/Lang.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -1,208 +1,208 @@
 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
-	*/
26
-
27
-	/**
28
-	 * For application languages management
29
-	 */
30
-	class Lang{
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
+
27
+    /**
28
+     * For application languages management
29
+     */
30
+    class Lang{
31 31
 		
32
-		/**
33
-		 * The supported available language for this application.
34
-		 * @example "en" => "english" 
35
-		 * @see Lang::addLang()
36
-		 * @var array
37
-		 */
38
-		protected $availables = array();
39
-
40
-		/**
41
-		 * The all messages language
42
-		 * @var array
43
-		 */
44
-		protected $languages = array();
45
-
46
-		/**
47
-		 * The default language to use if can not
48
-		 *  determine the client language
49
-		 *  
50
-		 * @example $default = 'en'
51
-		 * @var string
52
-		 */
53
-		protected $default = null;
54
-
55
-		/**
56
-		 * The current client language
57
-		 * @var string
58
-		 */
59
-		protected $current = null;
60
-
61
-		/**
62
-		 * The logger instance
63
-		 * @var Log
64
-		 */
65
-		private $logger;
66
-
67
-		/**
68
-		 * Construct new Lang instance
69
-		 */
70
-		public function __construct(){
71
-	        $this->logger =& class_loader('Log', 'classes');
72
-	        $this->logger->setLogger('Library::Lang');
73
-
74
-			$this->default = get_config('default_language', 'en');
75
-			$this->logger->debug('Setting the supported languages');
32
+        /**
33
+         * The supported available language for this application.
34
+         * @example "en" => "english" 
35
+         * @see Lang::addLang()
36
+         * @var array
37
+         */
38
+        protected $availables = array();
39
+
40
+        /**
41
+         * The all messages language
42
+         * @var array
43
+         */
44
+        protected $languages = array();
45
+
46
+        /**
47
+         * The default language to use if can not
48
+         *  determine the client language
49
+         *  
50
+         * @example $default = 'en'
51
+         * @var string
52
+         */
53
+        protected $default = null;
54
+
55
+        /**
56
+         * The current client language
57
+         * @var string
58
+         */
59
+        protected $current = null;
60
+
61
+        /**
62
+         * The logger instance
63
+         * @var Log
64
+         */
65
+        private $logger;
66
+
67
+        /**
68
+         * Construct new Lang instance
69
+         */
70
+        public function __construct(){
71
+            $this->logger =& class_loader('Log', 'classes');
72
+            $this->logger->setLogger('Library::Lang');
73
+
74
+            $this->default = get_config('default_language', 'en');
75
+            $this->logger->debug('Setting the supported languages');
76 76
 			
77
-			//add the supported languages ('key', 'display name')
78
-			$languages = get_config('languages', null);
79
-			if(! empty($languages)){
80
-				foreach($languages as $key => $displayName){
81
-					$this->addLang($key, $displayName);
82
-				}
83
-			}
84
-			unset($languages);
85
-
86
-			//if the language exists in cookie use it
87
-			$cfgKey = get_config('language_cookie_name');
88
-			$this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
89
-			$objCookie = & class_loader('Cookie');
90
-			$cookieLang = $objCookie->get($cfgKey);
91
-			if($cookieLang && $this->isValid($cookieLang)){
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. ']');
94
-			}
95
-			else{
96
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
97
-				$this->current = $this->getDefault();
98
-			}
99
-		}
100
-
101
-		/**
102
-		 * Get the all languages messages
103
-		 *
104
-		 * @return array the language message list
105
-		 */
106
-		public function getAll(){
107
-			return $this->languages;
108
-		}
109
-
110
-		/**
111
-		 * Set the language message
112
-		 *
113
-		 * @param string $key the language key to identify
114
-		 * @param string $value the language message value
115
-		 */
116
-		public function set($key, $value){
117
-			$this->languages[$key] = $value;
118
-		}
119
-
120
-		/**
121
-		 * Get the language message for the given key. If can't find return the default value
122
-		 *
123
-		 * @param  string $key the message language key
124
-		 * @param  string $default the default value to return if can not found the language message key
125
-		 *
126
-		 * @return string the language message value
127
-		 */
128
-		public function get($key, $default = 'LANGUAGE_ERROR'){
129
-			if(isset($this->languages[$key])){
130
-				return $this->languages[$key];
131
-			}
132
-			$this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
133
-			return $default;
134
-		}
135
-
136
-		/**
137
-		 * Check whether the language file for given name exists
138
-		 *
139
-		 * @param  string  $language the language name like "fr", "en", etc.
140
-		 *
141
-		 * @return boolean true if the language directory exists, false or not
142
-		 */
143
-		public function isValid($language){
144
-			$searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
-			foreach($searchDir as $dir){
146
-				if(file_exists($dir . $language) && is_dir($dir . $language)){
147
-					return true;
148
-				}
149
-			}
150
-			return false;
151
-		}
152
-
153
-		/**
154
-		 * Get the default language value like "en" , "fr", etc.
155
-		 *
156
-		 * @return string the default language
157
-		 */
158
-		public function getDefault(){
159
-			return $this->default;
160
-		}
161
-
162
-		/**
163
-		 * Get the current language defined by cookie or the default value
164
-		 *
165
-		 * @return string the current language
166
-		 */
167
-		public function getCurrent(){
168
-			return $this->current;
169
-		}
170
-
171
-		/**
172
-		 * Add new supported or available language
173
-		 *
174
-		 * @param string $name the short language name like "en", "fr".
175
-		 * @param string $description the human readable description of this language
176
-		 */
177
-		public function addLang($name, $description){
178
-			if(isset($this->availables[$name])){
179
-				return; //already added cost in performance
180
-			}
181
-			if($this->isValid($name)){
182
-				$this->availables[$name] = $description;
183
-			}
184
-			else{
185
-				show_error('The language [' . $name . '] is not valid or does not exists.');
186
-			}
187
-		}
188
-
189
-		/**
190
-		 * Get the list of the application supported language
191
-		 *
192
-		 * @return array the list of the application language
193
-		 */
194
-		public function getSupported(){
195
-			return $this->availables;
196
-		}
197
-
198
-		/**
199
-		 * Add new language messages
200
-		 *
201
-		 * @param array $langs the languages array of the messages to be added
202
-		 */
203
-		public function addLangMessages(array $langs){
204
-			foreach ($langs as $key => $value) {
205
-				$this->set($key, $value);
206
-			}
207
-		}
208
-	}
77
+            //add the supported languages ('key', 'display name')
78
+            $languages = get_config('languages', null);
79
+            if(! empty($languages)){
80
+                foreach($languages as $key => $displayName){
81
+                    $this->addLang($key, $displayName);
82
+                }
83
+            }
84
+            unset($languages);
85
+
86
+            //if the language exists in cookie use it
87
+            $cfgKey = get_config('language_cookie_name');
88
+            $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
89
+            $objCookie = & class_loader('Cookie');
90
+            $cookieLang = $objCookie->get($cfgKey);
91
+            if($cookieLang && $this->isValid($cookieLang)){
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. ']');
94
+            }
95
+            else{
96
+                $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
97
+                $this->current = $this->getDefault();
98
+            }
99
+        }
100
+
101
+        /**
102
+         * Get the all languages messages
103
+         *
104
+         * @return array the language message list
105
+         */
106
+        public function getAll(){
107
+            return $this->languages;
108
+        }
109
+
110
+        /**
111
+         * Set the language message
112
+         *
113
+         * @param string $key the language key to identify
114
+         * @param string $value the language message value
115
+         */
116
+        public function set($key, $value){
117
+            $this->languages[$key] = $value;
118
+        }
119
+
120
+        /**
121
+         * Get the language message for the given key. If can't find return the default value
122
+         *
123
+         * @param  string $key the message language key
124
+         * @param  string $default the default value to return if can not found the language message key
125
+         *
126
+         * @return string the language message value
127
+         */
128
+        public function get($key, $default = 'LANGUAGE_ERROR'){
129
+            if(isset($this->languages[$key])){
130
+                return $this->languages[$key];
131
+            }
132
+            $this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
133
+            return $default;
134
+        }
135
+
136
+        /**
137
+         * Check whether the language file for given name exists
138
+         *
139
+         * @param  string  $language the language name like "fr", "en", etc.
140
+         *
141
+         * @return boolean true if the language directory exists, false or not
142
+         */
143
+        public function isValid($language){
144
+            $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
145
+            foreach($searchDir as $dir){
146
+                if(file_exists($dir . $language) && is_dir($dir . $language)){
147
+                    return true;
148
+                }
149
+            }
150
+            return false;
151
+        }
152
+
153
+        /**
154
+         * Get the default language value like "en" , "fr", etc.
155
+         *
156
+         * @return string the default language
157
+         */
158
+        public function getDefault(){
159
+            return $this->default;
160
+        }
161
+
162
+        /**
163
+         * Get the current language defined by cookie or the default value
164
+         *
165
+         * @return string the current language
166
+         */
167
+        public function getCurrent(){
168
+            return $this->current;
169
+        }
170
+
171
+        /**
172
+         * Add new supported or available language
173
+         *
174
+         * @param string $name the short language name like "en", "fr".
175
+         * @param string $description the human readable description of this language
176
+         */
177
+        public function addLang($name, $description){
178
+            if(isset($this->availables[$name])){
179
+                return; //already added cost in performance
180
+            }
181
+            if($this->isValid($name)){
182
+                $this->availables[$name] = $description;
183
+            }
184
+            else{
185
+                show_error('The language [' . $name . '] is not valid or does not exists.');
186
+            }
187
+        }
188
+
189
+        /**
190
+         * Get the list of the application supported language
191
+         *
192
+         * @return array the list of the application language
193
+         */
194
+        public function getSupported(){
195
+            return $this->availables;
196
+        }
197
+
198
+        /**
199
+         * Add new language messages
200
+         *
201
+         * @param array $langs the languages array of the messages to be added
202
+         */
203
+        public function addLangMessages(array $langs){
204
+            foreach ($langs as $key => $value) {
205
+                $this->set($key, $value);
206
+            }
207
+        }
208
+    }
Please login to merge, or discard this patch.
core/functions/function_lang.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -1,52 +1,52 @@
 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
-	if(! function_exists('__')){
28
-		/**
29
-		 * function for the shortcut to Lang::get()
30
-		 * @param  string $key the language key to retrieve
31
-		 * @param mixed $default the default value to return if can not find the value
32
-		 * for the given key
33
-		 * @return string  the language value
34
-		 */
35
-		function __($key, $default = 'LANGUAGE_ERROR'){
36
-			return get_instance()->lang->get($key, $default);
37
-		}
27
+    if(! function_exists('__')){
28
+        /**
29
+         * function for the shortcut to Lang::get()
30
+         * @param  string $key the language key to retrieve
31
+         * @param mixed $default the default value to return if can not find the value
32
+         * for the given key
33
+         * @return string  the language value
34
+         */
35
+        function __($key, $default = 'LANGUAGE_ERROR'){
36
+            return get_instance()->lang->get($key, $default);
37
+        }
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 
42
-	if(! function_exists('get_languages')){
43
-		/**
44
-		 * function for the shortcut to Lang::getSupported()
45
-		 * 
46
-		 * @return array all the supported languages
47
-		 */
48
-		function get_languages(){
49
-			return get_instance()->lang->getSupported();
50
-		}
42
+    if(! function_exists('get_languages')){
43
+        /**
44
+         * function for the shortcut to Lang::getSupported()
45
+         * 
46
+         * @return array all the supported languages
47
+         */
48
+        function get_languages(){
49
+            return get_instance()->lang->getSupported();
50
+        }
51 51
 
52
-	}
53 52
\ No newline at end of file
53
+    }
54 54
\ No newline at end of file
Please login to merge, or discard this patch.